core, trie: rework trie committer (#25320)

* all: rework trie and trie committer

* all: get rid of internal cache in trie

* all: fixes

* trie: polish

* core, trie: address comments

* trie: fix imports

* core/state: address comments

* core/state/snapshot: polish

* trie: remove unused code

* trie: update tests

* trie: don't set db as nil

* trie: address comments

* trie: unskip test
This commit is contained in:
rjl493456442
2022-08-04 11:03:20 +03:00
committed by GitHub
parent 733d76a88d
commit 8b53b92eb4
24 changed files with 587 additions and 432 deletions
+24 -2
View File
@@ -217,7 +217,18 @@ func (c *ChtIndexerBackend) Process(ctx context.Context, header *types.Header) e
// Commit implements core.ChainIndexerBackend
func (c *ChtIndexerBackend) Commit() error {
root, _, err := c.trie.Commit(nil)
root, nodes, err := c.trie.Commit(false)
if err != nil {
return err
}
// Commit trie changes into trie database in case it's not nil.
if nodes != nil {
if err := c.triedb.Update(trie.NewWithNodeSet(nodes)); err != nil {
return err
}
}
// Re-create trie with newly generated root and updated database.
c.trie, err = trie.New(common.Hash{}, root, c.triedb)
if err != nil {
return err
}
@@ -453,7 +464,18 @@ func (b *BloomTrieIndexerBackend) Commit() error {
b.trie.Delete(encKey[:])
}
}
root, _, err := b.trie.Commit(nil)
root, nodes, err := b.trie.Commit(false)
if err != nil {
return err
}
// Commit trie changes into trie database in case it's not nil.
if nodes != nil {
if err := b.triedb.Update(trie.NewWithNodeSet(nodes)); err != nil {
return err
}
}
// Re-create trie with newly generated root and updated database.
b.trie, err = trie.New(common.Hash{}, root, b.triedb)
if err != nil {
return err
}
+3 -3
View File
@@ -137,11 +137,11 @@ func (t *odrTrie) TryDelete(key []byte) error {
})
}
func (t *odrTrie) Commit(onleaf trie.LeafCallback) (common.Hash, int, error) {
func (t *odrTrie) Commit(collectLeaf bool) (common.Hash, *trie.NodeSet, error) {
if t.trie == nil {
return t.id.Root, 0, nil
return t.id.Root, nil, nil
}
return t.trie.Commit(onleaf)
return t.trie.Commit(collectLeaf)
}
func (t *odrTrie) Hash() common.Hash {