Commit 187d6a66 authored by Felix Lange's avatar Felix Lange

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.
parent b19b7c39
...@@ -93,13 +93,11 @@ func New(root common.Hash, db Database) (*Trie, error) { ...@@ -93,13 +93,11 @@ func New(root common.Hash, db Database) (*Trie, error) {
if db == nil { if db == nil {
panic("trie.New: cannot use existing root without a database") panic("trie.New: cannot use existing root without a database")
} }
if v, _ := trie.db.Get(root[:]); len(v) == 0 { rootnode, err := trie.resolveHash(root[:], nil, nil)
return nil, &MissingNodeError{ if err != nil {
RootHash: root, return nil, err
NodeHash: root,
}
} }
trie.root = hashNode(root.Bytes()) trie.root = rootnode
} }
return trie, nil return trie, nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment