瀏覽代碼

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.
Felix Lange 9 年之前
父節點
當前提交
187d6a66a5
共有 1 個文件被更改,包括 4 次插入6 次删除
  1. 4 6
      trie/trie.go

+ 4 - 6
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
 }