diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-14 02:44:03 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-14 02:44:03 +0800 |
commit | b8ca0a830e89d4d7c4314c13bcbc2629992f43d9 (patch) | |
tree | b7975a1ffc0884bbfeb7523e351f397ec3b67a3e | |
parent | a89cfe92ccdea31891bd7ea0869dac968c04202f (diff) | |
download | dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.tar dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.tar.gz dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.tar.bz2 dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.tar.lz dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.tar.xz dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.tar.zst dexon-b8ca0a830e89d4d7c4314c13bcbc2629992f43d9.zip |
eth, trie: removed key prefixing from state entries & merge db fix
Fixed database merge strategy to use the correct database. Due to a copy
paste fail when doing type evaluation the same database was being
iterated (chain), all others were ignored.
Removed state prefixing because {H(code): code} is stored in the same
database as the rest of the state.
-rw-r--r-- | eth/backend.go | 34 | ||||
-rw-r--r-- | trie/cache.go | 4 | ||||
-rw-r--r-- | trie/trie.go | 2 |
3 files changed, 19 insertions, 21 deletions
diff --git a/eth/backend.go b/eth/backend.go index c9b71803f..953a150ad 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -45,7 +45,6 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/nat" - "github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/whisper" ) @@ -738,48 +737,53 @@ func mergeDatabases(datadir string, newdb func(path string) (common.Database, er } defer database.Close() - glog.Infoln("Merging blockchain database...") + // Migrate blocks chainDb, err := newdb(chainPath) if err != nil { return fmt.Errorf("state db err: %v", err) } defer chainDb.Close() - if db, ok := chainDb.(*ethdb.LDBDatabase); ok { - it := db.NewIterator() + if chain, ok := chainDb.(*ethdb.LDBDatabase); ok { + glog.Infoln("Merging blockchain database...") + it := chain.NewIterator() for it.Next() { database.Put(it.Key(), it.Value()) } + it.Release() } - glog.Infoln("Merging state database...") - state := filepath.Join(datadir, "state") - stateDb, err := newdb(state) + // Migrate state + stateDb, err := newdb(filepath.Join(datadir, "state")) if err != nil { return fmt.Errorf("state db err: %v", err) } defer stateDb.Close() - if db, ok := chainDb.(*ethdb.LDBDatabase); ok { - it := db.NewIterator() + if state, ok := stateDb.(*ethdb.LDBDatabase); ok { + glog.Infoln("Merging state database...") + it := state.NewIterator() for it.Next() { - database.Put(append(trie.StatePre, it.Key()...), it.Value()) + database.Put(it.Key(), it.Value()) } + it.Release() } - glog.Infoln("Merging transaction database...") - extra := filepath.Join(datadir, "extra") - extraDb, err := newdb(extra) + // Migrate transaction / receipts + extraDb, err := newdb(filepath.Join(datadir, "extra")) if err != nil { return fmt.Errorf("state db err: %v", err) } defer extraDb.Close() - if db, ok := chainDb.(*ethdb.LDBDatabase); ok { - it := db.NewIterator() + if extra, ok := extraDb.(*ethdb.LDBDatabase); ok { + glog.Infoln("Merging transaction database...") + + it := extra.NewIterator() for it.Next() { database.Put(it.Key(), it.Value()) } + it.Release() } return nil diff --git a/trie/cache.go b/trie/cache.go index 99d8033a6..e475fc861 100644 --- a/trie/cache.go +++ b/trie/cache.go @@ -38,8 +38,6 @@ func NewCache(backend Backend) *Cache { } func (self *Cache) Get(key []byte) []byte { - key = append(StatePre, key...) - data := self.store[string(key)] if data == nil { data, _ = self.backend.Get(key) @@ -49,8 +47,6 @@ func (self *Cache) Get(key []byte) []byte { } func (self *Cache) Put(key []byte, data []byte) { - key = append(StatePre, key...) - self.batch.Put(key, data) self.store[string(key)] = data } diff --git a/trie/trie.go b/trie/trie.go index 2970bc185..abf48a850 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -27,8 +27,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" ) -var StatePre = []byte("state-") - func ParanoiaCheck(t1 *Trie, backend Backend) (bool, *Trie) { t2 := New(nil, backend) |