From f3e9eb613c7e8dec6b8c6b1b0a20ddbec4e91a9c Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Thu, 11 Oct 2018 17:04:06 +0800 Subject: core: Move BlockConfirmed to Application interface (#192) When a block is confirmed, all its txs are permitted to be executed. Therefore, exporting this method provides more and earlier information about txs to be executed, and helps application layer to process txs more efficiently. --- core/interfaces.go | 6 +++--- core/lattice.go | 2 +- core/nonblocking.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'core') diff --git a/core/interfaces.go b/core/interfaces.go index f4a6cd0..98cbb4d 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -37,6 +37,9 @@ type Application interface { // VerifyBlock verifies if the block is valid. VerifyBlock(block *types.Block) bool + // BlockConfirmed is called when a block is confirmed and added to lattice. + BlockConfirmed(blockHash common.Hash) + // BlockDelivered is called when a block is add to the compaction chain. BlockDelivered(block types.Block) } @@ -44,9 +47,6 @@ type Application interface { // Debug describes the application interface that requires // more detailed consensus execution. type Debug interface { - // BlockConfirmed is called when a block is confirmed and added to lattice. - BlockConfirmed(blockHash common.Hash) - // StronglyAcked is called when a block is strongly acked. StronglyAcked(blockHash common.Hash) diff --git a/core/lattice.go b/core/lattice.go index 3ee0b94..6ecb88f 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -153,8 +153,8 @@ func (s *Lattice) ProcessBlock( // be done here. if s.debug != nil { s.debug.StronglyAcked(input.Hash) - s.debug.BlockConfirmed(input.Hash) } + s.app.BlockConfirmed(input.Hash) // Purge blocks in pool with the same chainID and lower height. s.pool.purgeBlocks(input.Position.ChainID, input.Position.Height) // Replay tips in pool to check their validity. diff --git a/core/nonblocking.go b/core/nonblocking.go index 4948a4f..83c2351 100644 --- a/core/nonblocking.go +++ b/core/nonblocking.go @@ -94,7 +94,7 @@ func (nb *nonBlocking) run() { case stronglyAckedEvent: nb.debug.StronglyAcked(e.blockHash) case blockConfirmedEvent: - nb.debug.BlockConfirmed(e.blockHash) + nb.app.BlockConfirmed(e.blockHash) case totalOrderingDeliveredEvent: nb.debug.TotalOrderingDelivered(e.blockHashes, e.early) case blockDeliveredEvent: -- cgit v1.2.3