aboutsummaryrefslogtreecommitdiffstats
path: root/core/syncer/consensus.go
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 /core/syncer/consensus.go
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
Diffstat (limited to 'core/syncer/consensus.go')
-rw-r--r--core/syncer/consensus.go31
1 files changed, 31 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()