diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-15 12:12:22 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-22 17:17:15 +0800 |
commit | 0eec7dc3cb07f3c1385664c9aa13ba8b15e523b1 (patch) | |
tree | 24f564f83012b081862b7ff488fa441834e269cd | |
parent | 619688d19e4275f4c5ebd6bb54bc75c37070f679 (diff) | |
download | dexon-consensus-0eec7dc3cb07f3c1385664c9aa13ba8b15e523b1.tar.gz dexon-consensus-0eec7dc3cb07f3c1385664c9aa13ba8b15e523b1.tar.zst dexon-consensus-0eec7dc3cb07f3c1385664c9aa13ba8b15e523b1.zip |
core: start next BA only when previous block delivered (#571)
-rw-r--r-- | core/agreement-mgr.go | 12 | ||||
-rw-r--r-- | core/blockchain.go | 7 | ||||
-rw-r--r-- | core/blockchain_test.go | 1 | ||||
-rw-r--r-- | core/consensus.go | 4 |
4 files changed, 19 insertions, 5 deletions
diff --git a/core/agreement-mgr.go b/core/agreement-mgr.go index af0adf2..791c5ce 100644 --- a/core/agreement-mgr.go +++ b/core/agreement-mgr.go @@ -521,11 +521,13 @@ func (mgr *agreementMgr) baRoutineForOneRound( default: } nextHeight, nextTime = mgr.bcModule.nextBlock() - if isStop(restartPos) { - break - } - if nextHeight > restartPos.Height { - break + if nextHeight != notReadyHeight { + if isStop(restartPos) { + break + } + if nextHeight > restartPos.Height { + break + } } mgr.logger.Debug("BlockChain not ready!!!", "old", oldPos, "restart", restartPos, "next", nextHeight) diff --git a/core/blockchain.go b/core/blockchain.go index 9fbb861..335e75c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -21,6 +21,7 @@ import ( "bytes" "errors" "fmt" + "math" "sort" "sync" "time" @@ -49,6 +50,8 @@ var ( ErrMissingRandomness = errors.New("missing block randomness") ) +const notReadyHeight uint64 = math.MaxUint64 + type pendingBlockRecord struct { position types.Position block *types.Block @@ -387,6 +390,10 @@ func (bc *blockChain) nextBlock() (uint64, time.Time) { if tip == nil { return types.GenesisHeight, bc.dMoment } + if tip != bc.lastDelivered { + // If tip is not delivered, we should not proceed to next block. + return notReadyHeight, time.Time{} + } return tip.Position.Height + 1, tip.Timestamp.Add(config.minBlockInterval) } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index ea604a2..c3d2cb7 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -415,6 +415,7 @@ func (s *BlockChainTestSuite) TestNextBlockAndTipRound() { s.Require().Equal(nextT, s.dMoment) // Add one block. s.Require().NoError(bc.addBlock(blocks[0])) + s.Require().Len(bc.extractBlocks(), 1) nextH, nextT = bc.nextBlock() s.Require().Equal(nextH, uint64(2)) s.Require().Equal( diff --git a/core/consensus.go b/core/consensus.go index 689a1c1..ce0217a 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -1124,6 +1124,10 @@ func (con *Consensus) generateBlockRandomness(blocks []*types.Block) { "block", block, "result", result) con.network.BroadcastAgreementResult(result) + if err := con.deliverFinalizedBlocks(); err != nil { + con.logger.Error("Failed to deliver finalized block", + "error", err) + } } }(block) } |