diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-23 17:14:47 +0800 |
---|---|---|
committer | Wei-Ning Huang <aitjcize@gmail.com> | 2018-10-23 17:14:47 +0800 |
commit | 23779823a7816d07c41fd7c135c6c0edf39182db (patch) | |
tree | 8e58408721dc0a25de858cbed101beb4b17741d0 | |
parent | 726e855384bf686b192f9d4b1c4cb0e9d006d414 (diff) | |
download | dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.gz dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.bz2 dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.lz dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.xz dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.zst dexon-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.zip |
core: Change interface of Application.VerifyBlock (#246)
* Change interface of Application.VerifyBlock
-rw-r--r-- | core/interfaces.go | 2 | ||||
-rw-r--r-- | core/lattice.go | 3 | ||||
-rw-r--r-- | core/nonblocking.go | 2 | ||||
-rw-r--r-- | core/nonblocking_test.go | 6 | ||||
-rw-r--r-- | core/test/app.go | 4 | ||||
-rw-r--r-- | core/types/block.go | 14 | ||||
-rw-r--r-- | simulation/app.go | 4 |
7 files changed, 25 insertions, 10 deletions
diff --git a/core/interfaces.go b/core/interfaces.go index 7b985cf..2ba8e0d 100644 --- a/core/interfaces.go +++ b/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/core/lattice.go b/core/lattice.go index 984203d..0357a8d 100644 --- a/core/lattice.go +++ b/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/core/nonblocking.go b/core/nonblocking.go index 675675b..36135fd 100644 --- a/core/nonblocking.go +++ b/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/core/nonblocking_test.go b/core/nonblocking_test.go index b1f1cb5..2ab40ea 100644 --- a/core/nonblocking_test.go +++ b/core/nonblocking_test.go @@ -54,8 +54,8 @@ func (app *slowApp) PrepareWitness(_ uint64) (types.Witness, error) { return types.Witness{}, nil } -func (app *slowApp) VerifyBlock(_ *types.Block) bool { - return true +func (app *slowApp) VerifyBlock(_ *types.Block) types.BlockVerifyStatus { + return types.VerifyOK } func (app *slowApp) BlockConfirmed(block types.Block) { @@ -103,7 +103,7 @@ func (app *noDebugApp) PrepareWitness(_ uint64) (types.Witness, error) { panic("test") } -func (app *noDebugApp) VerifyBlock(_ *types.Block) bool { +func (app *noDebugApp) VerifyBlock(_ *types.Block) types.BlockVerifyStatus { panic("test") } diff --git a/core/test/app.go b/core/test/app.go index a48b3c8..ba949b3 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -109,8 +109,8 @@ func (app *App) PrepareWitness(height uint64) (types.Witness, error) { } // VerifyBlock implements Application. -func (app *App) VerifyBlock(block *types.Block) bool { - return true +func (app *App) VerifyBlock(block *types.Block) types.BlockVerifyStatus { + return types.VerifyOK } // BlockConfirmed implements Application interface. diff --git a/core/types/block.go b/core/types/block.go index 9de4673..29b1c84 100644 --- a/core/types/block.go +++ b/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{ diff --git a/simulation/app.go b/simulation/app.go index f8bbcc6..419bb0a 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -67,8 +67,8 @@ func (a *simApp) BlockConfirmed(block types.Block) { } // VerifyBlock implements core.Application. -func (a *simApp) VerifyBlock(block *types.Block) bool { - return true +func (a *simApp) VerifyBlock(block *types.Block) types.BlockVerifyStatus { + return types.VerifyOK } // getAckedBlocks will return all unconfirmed blocks' hash with lower Height |