diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-08-08 22:16:38 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-08-09 17:33:30 +0800 |
commit | 11bbc660823246b9fc25e4b994121e30a9f17306 (patch) | |
tree | 04d6661dd289de85dc66eb29ccb6b9e5083139d5 | |
parent | 8051a0768a2af6c36b04ffa6fb225a45986d9b89 (diff) | |
download | dexon-11bbc660823246b9fc25e4b994121e30a9f17306.tar dexon-11bbc660823246b9fc25e4b994121e30a9f17306.tar.gz dexon-11bbc660823246b9fc25e4b994121e30a9f17306.tar.bz2 dexon-11bbc660823246b9fc25e4b994121e30a9f17306.tar.lz dexon-11bbc660823246b9fc25e4b994121e30a9f17306.tar.xz dexon-11bbc660823246b9fc25e4b994121e30a9f17306.tar.zst dexon-11bbc660823246b9fc25e4b994121e30a9f17306.zip |
eth, trie: fix tracer GC which accidentally pruned the metaroot
-rw-r--r-- | eth/api_tracer.go | 8 | ||||
-rw-r--r-- | trie/database.go | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 623e5ed1b..722e2a6e3 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -297,7 +297,9 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl database.TrieDB().Reference(root, common.Hash{}) } // Dereference all past tries we ourselves are done working with - database.TrieDB().Dereference(proot) + if proot != (common.Hash{}) { + database.TrieDB().Dereference(proot) + } proot = root // TODO(karalabe): Do we need the preimages? Won't they accumulate too much? @@ -526,7 +528,9 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (* return nil, err } database.TrieDB().Reference(root, common.Hash{}) - database.TrieDB().Dereference(proot) + if proot != (common.Hash{}) { + database.TrieDB().Dereference(proot) + } proot = root } nodes, imgs := database.TrieDB().Size() diff --git a/trie/database.go b/trie/database.go index 7df45fe2d..d0691b637 100644 --- a/trie/database.go +++ b/trie/database.go @@ -431,6 +431,11 @@ func (db *Database) reference(child common.Hash, parent common.Hash) { // Dereference removes an existing reference from a root node. func (db *Database) Dereference(root common.Hash) { + // Sanity check to ensure that the meta-root is not removed + if root == (common.Hash{}) { + log.Error("Attempted to dereference the trie cache meta root") + return + } db.lock.Lock() defer db.lock.Unlock() |