aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-15 12:12:22 +0800
committerGitHub <noreply@github.com>2019-04-15 12:12:22 +0800
commite9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5 (patch)
tree70a511cb1527e3c0d0752a40c8ff314ab768b099
parent79be89a6b0b1d24b889e7c9fe0244026af4d49d0 (diff)
downloaddexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.tar
dexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.tar.gz
dexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.tar.bz2
dexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.tar.lz
dexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.tar.xz
dexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.tar.zst
dexon-consensus-e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5.zip
core: start next BA only when previous block delivered (#571)
-rw-r--r--core/agreement-mgr.go12
-rw-r--r--core/blockchain.go7
-rw-r--r--core/blockchain_test.go1
-rw-r--r--core/consensus.go4
4 files changed, 19 insertions, 5 deletions
diff --git a/core/agreement-mgr.go b/core/agreement-mgr.go
index 4597fe9..f65903d 100644
--- a/core/agreement-mgr.go
+++ b/core/agreement-mgr.go
@@ -564,11 +564,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 1efd867..4fae221 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
@@ -384,6 +387,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 7c44bdf..ba7d8fd 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -1148,6 +1148,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)
}