all: port boring changes from pbss (#27176)

* all: port boring changes from pbss

* core, trie: address comments from martin

* trie: minor fixes

* core/rawdb: update comment

* core, eth, tests, trie: address comments

* tests, trie: add extra check when update trie database

* trie/triedb/hashdb: degrade the error to warning
This commit is contained in:
rjl493456442
2023-05-09 10:11:04 +03:00
committed by GitHub
parent 81d328a73e
commit 5021d36d35
30 changed files with 1056 additions and 555 deletions
+7 -2
View File
@@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/trienode"
)
// IndexerConfig includes a set of configs for chain indexers.
@@ -134,6 +135,7 @@ type ChtIndexerBackend struct {
section, sectionSize uint64
lastHash common.Hash
trie *trie.Trie
originRoot common.Hash
}
// NewChtIndexer creates a Cht chain indexer
@@ -191,6 +193,7 @@ func (c *ChtIndexerBackend) Reset(ctx context.Context, section uint64, lastSecti
}
}
c.section = section
c.originRoot = root
return err
}
@@ -214,7 +217,7 @@ func (c *ChtIndexerBackend) Commit() error {
root, nodes := c.trie.Commit(false)
// 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 {
if err := c.triedb.Update(root, c.originRoot, trienode.NewWithNodeSet(nodes)); err != nil {
return err
}
if err := c.triedb.Commit(root, false); err != nil {
@@ -332,6 +335,7 @@ type BloomTrieIndexerBackend struct {
size uint64
bloomTrieRatio uint64
trie *trie.Trie
originRoot common.Hash
sectionHeads []common.Hash
}
@@ -413,6 +417,7 @@ func (b *BloomTrieIndexerBackend) Reset(ctx context.Context, section uint64, las
}
}
b.section = section
b.originRoot = root
return err
}
@@ -463,7 +468,7 @@ func (b *BloomTrieIndexerBackend) Commit() error {
root, nodes := b.trie.Commit(false)
// 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 {
if err := b.triedb.Update(root, b.originRoot, trienode.NewWithNodeSet(nodes)); err != nil {
return err
}
if err := b.triedb.Commit(root, false); err != nil {
+3 -2
View File
@@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/trienode"
)
var (
@@ -156,7 +157,7 @@ func (t *odrTrie) DeleteStorage(_ common.Address, key []byte) error {
})
}
// TryDeleteAccount abstracts an account deletion from the trie.
// DeleteAccount abstracts an account deletion from the trie.
func (t *odrTrie) DeleteAccount(address common.Address) error {
key := crypto.Keccak256(address.Bytes())
return t.do(key, func() error {
@@ -164,7 +165,7 @@ func (t *odrTrie) DeleteAccount(address common.Address) error {
})
}
func (t *odrTrie) Commit(collectLeaf bool) (common.Hash, *trie.NodeSet) {
func (t *odrTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet) {
if t.trie == nil {
return t.id.Root, nil
}