diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-12-13 18:15:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-13 18:15:03 +0800 |
commit | 155e31175aeaa3685c57383e386c6e62c46318ef (patch) | |
tree | 58333399ca2e08bc856e3c23ecca7eefe3c5db5e /core/consensus.go | |
parent | 0ead4a7c012af9ddaa4a934729e216539d2caeb1 (diff) | |
download | tangerine-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.gz tangerine-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.zst tangerine-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.zip |
db: cache compaction chain tip in db (#369)
* Replace JSON with RLP in levelDB implementation.
* Make sure blocks to sync following compaction chain tip
Diffstat (limited to 'core/consensus.go')
-rw-r--r-- | core/consensus.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/core/consensus.go b/core/consensus.go index a6d8037..a0336ed 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -1003,6 +1003,14 @@ func (con *Consensus) preProcessBlock(b *types.Block) (err error) { // deliverBlock deliver a block to application layer. func (con *Consensus) deliverBlock(b *types.Block) { + if err := con.db.UpdateBlock(*b); err != nil { + panic(err) + } + if err := con.db.PutCompactionChainTipInfo( + b.Hash, b.Finalization.Height); err != nil { + panic(err) + } + con.cfgModule.untouchTSigHash(b.Hash) con.logger.Debug("Calling Application.BlockDelivered", "block", b) con.app.BlockDelivered(b.Hash, b.Position, b.Finalization.Clone()) if b.Position.Round == con.roundToNotify { @@ -1032,6 +1040,9 @@ func (con *Consensus) deliverBlock(b *types.Block) { con.roundToNotify, b.Finalization.Height) con.roundToNotify++ } + if con.debugApp != nil { + con.debugApp.BlockReady(b.Hash) + } } // processBlock is the entry point to submit one block to a Consensus instance. @@ -1072,14 +1083,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { "delivered", con.ccModule.lastDeliveredBlock(), "pending", con.ccModule.lastPendingBlock()) for _, b := range deliveredBlocks { - if err = con.db.UpdateBlock(*b); err != nil { - panic(err) - } - con.cfgModule.untouchTSigHash(b.Hash) con.deliverBlock(b) - if con.debugApp != nil { - con.debugApp.BlockReady(b.Hash) - } } if err = con.lattice.PurgeBlocks(deliveredBlocks); err != nil { return |