From 43a5264814bf318e6bd133fb0df51351f0811ddb Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Wed, 31 Oct 2018 12:15:57 +0800 Subject: core: fix NotifyRoundHeight is not called when processing blocks - also add missing logs when calling Application.BlockDelivered. --- core/consensus.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/core/consensus.go b/core/consensus.go index 938337f..394ae36 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -910,6 +910,20 @@ func (con *Consensus) preProcessBlock(b *types.Block) (err error) { return } +// deliverBlock deliver a block to application layer. +func (con *Consensus) deliverBlock(b *types.Block) { + // TODO(mission): clone types.FinalizationResult + con.logger.Debug("Calling Application.BlockDelivered", "block", b) + con.app.BlockDelivered(b.Hash, b.Finalization) + if b.Position.Round+2 == con.roundToNotify { + // Only the first block delivered of that round would + // trigger this noitification. + con.gov.NotifyRoundHeight( + con.roundToNotify, b.Finalization.Height) + con.roundToNotify++ + } +} + // processBlock is the entry point to submit one block to a Consensus instance. func (con *Consensus) processBlock(block *types.Block) (err error) { if err = con.db.Put(*block); err != nil && err != blockdb.ErrBlockExists { @@ -936,8 +950,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { panic(err) } con.cfgModule.untouchTSigHash(b.Hash) - // TODO(mission): clone types.FinalizationResult - con.app.BlockDelivered(b.Hash, b.Finalization) + con.deliverBlock(b) } if err = con.lattice.PurgeBlocks(deliveredBlocks); err != nil { return @@ -966,14 +979,7 @@ func (con *Consensus) processFinalizedBlock(block *types.Block) (err error) { } err = nil } - con.app.BlockDelivered(b.Hash, b.Finalization) - if b.Position.Round+2 == con.roundToNotify { - // Only the first block delivered of that round would - // trigger this noitification. - con.gov.NotifyRoundHeight( - con.roundToNotify, b.Finalization.Height) - con.roundToNotify++ - } + con.deliverBlock(b) } } return -- cgit v1.2.3