aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-23 17:14:47 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-10-23 17:14:47 +0800
commit23779823a7816d07c41fd7c135c6c0edf39182db (patch)
tree8e58408721dc0a25de858cbed101beb4b17741d0 /core
parent726e855384bf686b192f9d4b1c4cb0e9d006d414 (diff)
downloadtangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar
tangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.gz
tangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.bz2
tangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.lz
tangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.xz
tangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.tar.zst
tangerine-consensus-23779823a7816d07c41fd7c135c6c0edf39182db.zip
core: Change interface of Application.VerifyBlock (#246)
* Change interface of Application.VerifyBlock
Diffstat (limited to 'core')
-rw-r--r--core/interfaces.go2
-rw-r--r--core/lattice.go3
-rw-r--r--core/nonblocking.go2
-rw-r--r--core/nonblocking_test.go6
-rw-r--r--core/test/app.go4
-rw-r--r--core/types/block.go14
6 files changed, 23 insertions, 8 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{