aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-10-18 03:31:27 +0800
committerFelix Lange <fjl@twurst.com>2016-10-18 10:57:47 +0800
commit187d6a66a5176a1dc3e75d5ad4baad623762acb9 (patch)
tree3b16d6afdec475c4cd24c3742b59d723f298fdf8
parentb19b7c39ac1074592c0aea1dc2b282d08d9a42b0 (diff)
downloaddexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.tar
dexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.tar.gz
dexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.tar.bz2
dexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.tar.lz
dexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.tar.xz
dexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.tar.zst
dexon-187d6a66a5176a1dc3e75d5ad4baad623762acb9.zip
trie: avoid loading the root node twice
New checks whether the root node is present by loading it from the database. Keep the node around instead of discarding it.
-rw-r--r--trie/trie.go10
1 files changed, 4 insertions, 6 deletions
diff --git a/trie/trie.go b/trie/trie.go
index 65005bae8..cce4cfeb6 100644
--- a/trie/trie.go
+++ b/trie/trie.go
@@ -93,13 +93,11 @@ func New(root common.Hash, db Database) (*Trie, error) {
if db == nil {
panic("trie.New: cannot use existing root without a database")
}
- if v, _ := trie.db.Get(root[:]); len(v) == 0 {
- return nil, &MissingNodeError{
- RootHash: root,
- NodeHash: root,
- }
+ rootnode, err := trie.resolveHash(root[:], nil, nil)
+ if err != nil {
+ return nil, err
}
- trie.root = hashNode(root.Bytes())
+ trie.root = rootnode
}
return trie, nil
}