aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-03 14:51:21 +0800
committerGitHub <noreply@github.com>2019-04-03 14:51:21 +0800
commitf2fb45707b788b8e422c9f1016f1f0cdd0a411ab (patch)
treef4d617c30afcc90f928331bb6fc3fb0f9b313e19
parent37bb1f320bbdd7ef1a33d400a3ea6b67e301a135 (diff)
downloaddexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.tar
dexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.tar.gz
dexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.tar.bz2
dexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.tar.lz
dexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.tar.xz
dexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.tar.zst
dexon-consensus-f2fb45707b788b8e422c9f1016f1f0cdd0a411ab.zip
core: syncer: add deliver pending blocks (#546)
* core: syncer: deliver pending blocks * fixup
-rw-r--r--core/syncer/consensus.go31
-rw-r--r--integration_test/consensus_test.go2
2 files changed, 33 insertions, 0 deletions
diff --git a/core/syncer/consensus.go b/core/syncer/consensus.go
index f777e35..f4681a2 100644
--- a/core/syncer/consensus.go
+++ b/core/syncer/consensus.go
@@ -86,6 +86,7 @@ type Consensus struct {
// NewConsensus creates an instance for Consensus (syncer consensus).
func NewConsensus(
+ initHeight uint64,
dMoment time.Time,
app core.Application,
gov core.Governance,
@@ -122,9 +123,39 @@ func NewConsensus(
defer con.agreementWaitGroup.Done()
con.agreementModule.run()
}()
+ if err := con.deliverPendingBlocks(initHeight); err != nil {
+ panic(err)
+ }
return con
}
+func (con *Consensus) deliverPendingBlocks(height uint64) error {
+ if height >= con.initChainTipHeight {
+ return nil
+ }
+ blocks := make([]*types.Block, 0, con.initChainTipHeight-height)
+ hash, _ := con.db.GetCompactionChainTipInfo()
+ for {
+ block, err := con.db.GetBlock(hash)
+ if err != nil {
+ return err
+ }
+ if block.Position.Height == height {
+ break
+ }
+ blocks = append(blocks, &block)
+ hash = block.ParentHash
+ }
+ sort.Sort(types.BlocksByPosition(blocks))
+ for _, b := range blocks {
+ con.logger.Debug("Syncer BlockConfirmed", "block", b)
+ con.app.BlockConfirmed(*b)
+ con.logger.Debug("Syncer BlockDelivered", "block", b)
+ con.app.BlockDelivered(b.Hash, b.Position, b.Randomness)
+ }
+ return nil
+}
+
func (con *Consensus) assureBuffering() {
if func() bool {
con.lock.RLock()
diff --git a/integration_test/consensus_test.go b/integration_test/consensus_test.go
index eab0c22..ae56af2 100644
--- a/integration_test/consensus_test.go
+++ b/integration_test/consensus_test.go
@@ -469,6 +469,7 @@ ReachAlive:
}
logger := common.NewCustomLogger(log.New(f, "", log.LstdFlags|log.Lmicroseconds))
syncerObj := syncer.NewConsensus(
+ 0,
dMoment,
syncNode.app,
syncNode.gov,
@@ -634,6 +635,7 @@ ReachStop:
nID := types.NewNodeID(prvKey.PublicKey())
node := nodes[nID]
syncerCon[nID] = syncer.NewConsensus(
+ latestHeight,
dMoment,
node.app,
node.gov,