trie: separate hashes and committer, collapse on commit
* trie: make db insert use size instead of full data * core/state: minor optimization in state onleaf allocation * trie: implement dedicated committer and hasher * trie: use dedicated committer/hasher * trie: linter nitpicks * core/state, trie: avoid unnecessary storage trie load+commit * trie: review feedback, mainly docs + minor changes * trie: start deprecating old hasher * trie: fix misspell+lint * trie: deprecate hasher.go, make proof framework use new hasher * trie: rename pure_committer/hasher to committer/hasher * trie, core/state: fix review concerns * trie: more review concerns * trie: make commit collapse into hashnode, don't touch dirtyness * trie: goimports fixes * trie: remove panics
This commit is contained in:
committed by
GitHub
parent
4cc89a5a32
commit
5a9c96454e
@ -64,26 +64,24 @@ func (t *Trie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) e
|
||||
panic(fmt.Sprintf("%T: invalid node: %v", tn, tn))
|
||||
}
|
||||
}
|
||||
hasher := newHasher(nil)
|
||||
hasher := newHasher()
|
||||
defer returnHasherToPool(hasher)
|
||||
|
||||
for i, n := range nodes {
|
||||
// Don't bother checking for errors here since hasher panics
|
||||
// if encoding doesn't work and we're not writing to any database.
|
||||
n, _, _ = hasher.hashChildren(n, nil)
|
||||
hn, _ := hasher.store(n, nil, false)
|
||||
if fromLevel > 0 {
|
||||
fromLevel--
|
||||
continue
|
||||
}
|
||||
var hn node
|
||||
n, hn = hasher.proofHash(n)
|
||||
if hash, ok := hn.(hashNode); ok || i == 0 {
|
||||
// If the node's database encoding is a hash (or is the
|
||||
// root node), it becomes a proof element.
|
||||
if fromLevel > 0 {
|
||||
fromLevel--
|
||||
} else {
|
||||
enc, _ := rlp.EncodeToBytes(n)
|
||||
if !ok {
|
||||
hash = hasher.makeHashNode(enc)
|
||||
}
|
||||
proofDb.Put(hash, enc)
|
||||
enc, _ := rlp.EncodeToBytes(n)
|
||||
if !ok {
|
||||
hash = hasher.hashData(enc)
|
||||
}
|
||||
proofDb.Put(hash, enc)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user