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/test/utils.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/test/utils.go')
-rw-r--r-- | core/test/utils.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/test/utils.go b/core/test/utils.go index 56c5eac..6abd0b5 100644 --- a/core/test/utils.go +++ b/core/test/utils.go @@ -18,6 +18,7 @@ package test import ( + "errors" "fmt" "math" "net" @@ -26,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus/common" "github.com/dexon-foundation/dexon-consensus/core/crypto" "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa" + "github.com/dexon-foundation/dexon-consensus/core/db" "github.com/dexon-foundation/dexon-consensus/core/types" typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg" "github.com/dexon-foundation/dexon/rlp" @@ -170,3 +172,32 @@ func cloneBlockRandomnessResult(rand *types.BlockRandomnessResult) ( } return } + +var ( + // ErrCompactionChainTipBlockNotExists raised when the hash of compaction + // chain tip doesn't match a block in database. + ErrCompactionChainTipBlockNotExists = errors.New( + "compaction chain tip block not exists") + // ErrEmptyCompactionChainTipInfo raised when a compaction chain tip info + // is empty. + ErrEmptyCompactionChainTipInfo = errors.New( + "empty compaction chain tip info") + // ErrMismatchBlockHash raise when the hash for that block mismatched. + ErrMismatchBlockHash = errors.New("mismatched block hash") +) + +// VerifyDB check if a database is valid after test. +func VerifyDB(db db.Database) error { + hash, height := db.GetCompactionChainTipInfo() + if (hash == common.Hash{}) || height == 0 { + return ErrEmptyCompactionChainTipInfo + } + b, err := db.GetBlock(hash) + if err != nil { + return err + } + if b.Hash != hash { + return ErrMismatchBlockHash + } + return nil +} |