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
+3 -1
View File
@@ -27,9 +27,11 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/trienode"
"golang.org/x/crypto/sha3"
)
@@ -184,7 +186,7 @@ func (f *fuzzer) fuzz() int {
// Flush trie -> database
rootA, nodes := trieA.Commit(false)
if nodes != nil {
dbA.Update(trie.NewWithNodeSet(nodes))
dbA.Update(rootA, types.EmptyRootHash, trienode.NewWithNodeSet(nodes))
}
// Flush memdb -> disk (sponge)
dbA.Commit(rootA, false)
+10 -6
View File
@@ -22,7 +22,9 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/trienode"
)
// randTest performs random trie operations.
@@ -139,11 +141,12 @@ func Fuzz(input []byte) int {
}
func runRandTest(rt randTest) error {
triedb := trie.NewDatabase(rawdb.NewMemoryDatabase())
tr := trie.NewEmpty(triedb)
values := make(map[string]string) // tracks content of the trie
var (
triedb = trie.NewDatabase(rawdb.NewMemoryDatabase())
tr = trie.NewEmpty(triedb)
origin = types.EmptyRootHash
values = make(map[string]string) // tracks content of the trie
)
for i, step := range rt {
switch step.op {
case opUpdate:
@@ -163,7 +166,7 @@ func runRandTest(rt randTest) error {
case opCommit:
hash, nodes := tr.Commit(false)
if nodes != nil {
if err := triedb.Update(trie.NewWithNodeSet(nodes)); err != nil {
if err := triedb.Update(hash, origin, trienode.NewWithNodeSet(nodes)); err != nil {
return err
}
}
@@ -172,6 +175,7 @@ func runRandTest(rt randTest) error {
return err
}
tr = newtr
origin = hash
case opItercheckhash:
checktr := trie.NewEmpty(triedb)
it := trie.NewIterator(tr.NodeIterator(nil))