aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2019-01-11 19:49:12 +0800
committerPéter Szilágyi <peterke@gmail.com>2019-01-11 19:49:12 +0800
commitd5cad488be0069d768b358b2267cd5432b0f9a43 (patch)
tree07272f630b6486c7458c789b58bd75ff20c5480a /core
parent2eb838ed9776c9c3ec922e1116a5d50babda31c5 (diff)
downloadgo-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.tar
go-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.tar.gz
go-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.tar.bz2
go-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.tar.lz
go-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.tar.xz
go-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.tar.zst
go-tangerine-d5cad488be0069d768b358b2267cd5432b0f9a43.zip
core, eth: fix database version (#18429)
* core, eth: fix database version * eth: polish error message
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go2
-rw-r--r--core/rawdb/accessors_metadata.go22
2 files changed, 16 insertions, 8 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index c29063a73..49aedf669 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -65,7 +65,7 @@ const (
triesInMemory = 128
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
- BlockChainVersion = 3
+ BlockChainVersion uint64 = 3
)
// CacheConfig contains the configuration values for the trie caching/pruning
diff --git a/core/rawdb/accessors_metadata.go b/core/rawdb/accessors_metadata.go
index 3b6e6548d..82e4bf045 100644
--- a/core/rawdb/accessors_metadata.go
+++ b/core/rawdb/accessors_metadata.go
@@ -26,19 +26,27 @@ import (
)
// ReadDatabaseVersion retrieves the version number of the database.
-func ReadDatabaseVersion(db DatabaseReader) int {
- var version int
+func ReadDatabaseVersion(db DatabaseReader) *uint64 {
+ var version uint64
enc, _ := db.Get(databaseVerisionKey)
- rlp.DecodeBytes(enc, &version)
+ if len(enc) == 0 {
+ return nil
+ }
+ if err := rlp.DecodeBytes(enc, &version); err != nil {
+ return nil
+ }
- return version
+ return &version
}
// WriteDatabaseVersion stores the version number of the database
-func WriteDatabaseVersion(db DatabaseWriter, version int) {
- enc, _ := rlp.EncodeToBytes(version)
- if err := db.Put(databaseVerisionKey, enc); err != nil {
+func WriteDatabaseVersion(db DatabaseWriter, version uint64) {
+ enc, err := rlp.EncodeToBytes(version)
+ if err != nil {
+ log.Crit("Failed to encode database version", "err", err)
+ }
+ if err = db.Put(databaseVerisionKey, enc); err != nil {
log.Crit("Failed to store the database version", "err", err)
}
}