From 43a19358c71d3735a472c113eae2d066e626a186 Mon Sep 17 00:00:00 2001 From: Bojie Wu Date: Tue, 9 Oct 2018 13:28:45 +0800 Subject: app: correct process pending block logic --- .../dexon-consensus-core/core/interfaces.go | 2 +- .../dexon-foundation/dexon-consensus-core/core/lattice.go | 3 ++- .../dexon-consensus-core/core/nonblocking.go | 2 +- .../dexon-consensus-core/core/types/block.go | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) (limited to 'vendor/github.com') diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go index 7b985cf7a..2ba8e0d3a 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go @@ -35,7 +35,7 @@ type Application interface { PrepareWitness(consensusHeight uint64) (types.Witness, error) // VerifyBlock verifies if the block is valid. - VerifyBlock(block *types.Block) bool + VerifyBlock(block *types.Block) types.BlockVerifyStatus // BlockConfirmed is called when a block is confirmed and added to lattice. BlockConfirmed(block types.Block) diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go index 984203d7d..0357a8d99 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/lattice.go @@ -136,7 +136,8 @@ func (s *Lattice) SanityCheck(b *types.Block, checkRelation bool) (err error) { } // Verify data in application layer. s.logger.Debug("Calling Application.VerifyBlock", "block", b) - if !s.app.VerifyBlock(b) { + // TODO(jimmy-dexon): handle types.VerifyRetryLater. + if s.app.VerifyBlock(b) == types.VerifyInvalidBlock { err = ErrInvalidBlock return err } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/nonblocking.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/nonblocking.go index 675675b2f..36135fdd9 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/nonblocking.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/nonblocking.go @@ -129,7 +129,7 @@ func (nb *nonBlocking) PrepareWitness(height uint64) (types.Witness, error) { } // VerifyBlock cannot be non-blocking. -func (nb *nonBlocking) VerifyBlock(block *types.Block) bool { +func (nb *nonBlocking) VerifyBlock(block *types.Block) types.BlockVerifyStatus { return nb.app.VerifyBlock(block) } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go index 9de467397..29b1c841f 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go @@ -33,6 +33,20 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto" ) +// BlockVerifyStatus is the return code for core.Application.VerifyBlock +type BlockVerifyStatus int + +// Enums for return value of core.Application.VerifyBlock. +const ( + // VerifyOK: Block is verified. + VerifyOK BlockVerifyStatus = iota + // VerifyRetryLater: Block is unable to be verified at this moment. + // Try again later. + VerifyRetryLater + // VerifyInvalidBlock: Block is an invalid one. + VerifyInvalidBlock +) + var ( // blockPool is the blocks cache to reuse allocated blocks. blockPool = sync.Pool{ -- cgit v1.2.3