forked from cerc-io/plugeth
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:
+24
-2
@@ -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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user