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 | |
parent | 0ead4a7c012af9ddaa4a934729e216539d2caeb1 (diff) | |
download | dexon-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar dexon-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.gz dexon-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.bz2 dexon-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.lz dexon-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.xz dexon-consensus-155e31175aeaa3685c57383e386c6e62c46318ef.tar.zst dexon-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')
-rw-r--r-- | core/test/blocks-generator_test.go | 2 | ||||
-rw-r--r-- | core/test/utils.go | 31 |
2 files changed, 31 insertions, 2 deletions
diff --git a/core/test/blocks-generator_test.go b/core/test/blocks-generator_test.go index bd7a5a2..78b609b 100644 --- a/core/test/blocks-generator_test.go +++ b/core/test/blocks-generator_test.go @@ -18,7 +18,6 @@ package test import ( - "fmt" "sort" "testing" "time" @@ -318,7 +317,6 @@ func (s *BlocksGeneratorTestSuite) TestConcateBlocksFromRounds() { totalAckCount += len(b.Acks) } // At least all blocks can ack some non-parent block. - fmt.Println(totalAckCount, totalBlockCount) req.True(totalAckCount/totalBlockCount >= 2) } 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 +} |