trie: polishes to trie committer (#21351)
* trie: update tests to check commit integrity * trie: polish committer * trie: fix typo * trie: remove hasvalue notion According to the benchmarks, type assertion between the pointer and interface is extremely fast. BenchmarkIntmethod-12 1000000000 1.91 ns/op BenchmarkInterface-12 1000000000 2.13 ns/op BenchmarkTypeSwitch-12 1000000000 1.81 ns/op BenchmarkTypeAssertion-12 2000000000 1.78 ns/op So the overhead for asserting whether the shortnode has "valuenode" child is super tiny. No necessary to have another field. * trie: linter nitpicks Co-authored-by: Martin Holst Swende <martin@swende.se>
This commit is contained in:
@ -505,13 +505,16 @@ func (t *Trie) Commit(onleaf LeafCallback) (root common.Hash, err error) {
|
||||
if t.root == nil {
|
||||
return emptyRoot, nil
|
||||
}
|
||||
// Derive the hash for all dirty nodes first. We hold the assumption
|
||||
// in the following procedure that all nodes are hashed.
|
||||
rootHash := t.Hash()
|
||||
h := newCommitter()
|
||||
defer returnCommitterToPool(h)
|
||||
|
||||
// Do a quick check if we really need to commit, before we spin
|
||||
// up goroutines. This can happen e.g. if we load a trie for reading storage
|
||||
// values, but don't write to it.
|
||||
if !h.commitNeeded(t.root) {
|
||||
if _, dirty := t.root.cache(); !dirty {
|
||||
return rootHash, nil
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
|
Reference in New Issue
Block a user