From 187d6a66a5176a1dc3e75d5ad4baad623762acb9 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 17 Oct 2016 21:31:27 +0200 Subject: 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. --- trie/trie.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'trie') 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 } -- cgit v1.2.3