review feedback + fix CI

This commit is contained in:
Guillaume Ballet 2025-11-10 12:53:02 +01:00
parent b657f736b5
commit 8e08bf3902
6 changed files with 13 additions and 100 deletions

View file

@ -44,9 +44,9 @@ import (
) )
type Prestate struct { type Prestate struct {
Env stEnv `json:"env"` Env stEnv `json:"env"`
Pre types.GenesisAlloc `json:"pre"` Pre types.GenesisAlloc `json:"pre"`
BT map[common.Hash]hexutil.Bytes `json:"vkt,omitempty"` TreeLeaves map[common.Hash]hexutil.Bytes `json:"vkt,omitempty"`
} }
//go:generate go run github.com/fjl/gencodec -type ExecutionResult -field-override executionResultMarshaling -out gen_execresult.go //go:generate go run github.com/fjl/gencodec -type ExecutionResult -field-override executionResultMarshaling -out gen_execresult.go
@ -398,7 +398,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, isBintrie bool
} }
} }
// Commit and re-open to start with a clean state. // Commit and re-open to start with a clean state.
mptRoot, err := statedb.Commit(0, false, false) root, err = statedb.Commit(0, false, false)
if err != nil { if err != nil {
panic(fmt.Errorf("failed to commit initial state: %v", err)) panic(fmt.Errorf("failed to commit initial state: %v", err))
} }
@ -407,7 +407,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, isBintrie bool
return statedb return statedb
} }
// For MPT mode, reopen the state with the committed root // For MPT mode, reopen the state with the committed root
statedb, err = state.New(mptRoot, sdb) statedb, err = state.New(root, sdb)
if err != nil { if err != nil {
panic(fmt.Errorf("failed to reopen state after commit: %v", err)) panic(fmt.Errorf("failed to reopen state after commit: %v", err))
} }

View file

@ -125,7 +125,7 @@ func Transition(ctx *cli.Context) error {
return err return err
} }
} }
prestate.BT = inputData.BT prestate.TreeLeaves = inputData.BT
// Set the block environment // Set the block environment
if envStr != stdinSelector { if envStr != stdinSelector {

View file

@ -190,7 +190,7 @@ func flushAlloc(ga *types.GenesisAlloc, triedb *triedb.Database) (common.Hash, e
return common.Hash{}, err return common.Hash{}, err
} }
// Commit newly generated states into disk if it's not empty. // Commit newly generated states into disk if it's not empty.
if root != types.EmptyRootHash && root != types.EmptyVerkleHash { if root != emptyRoot {
if err := triedb.Commit(root, true); err != nil { if err := triedb.Commit(root, true); err != nil {
return common.Hash{}, err return common.Hash{}, err
} }

View file

@ -1,83 +0,0 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package bintrie
import (
"testing"
"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/ethdb"
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"
"github.com/holiman/uint256"
)
func newTestDatabase(diskdb ethdb.Database, scheme string) *triedb.Database {
config := &triedb.Config{Preimages: true}
if scheme == rawdb.HashScheme {
config.HashDB = &hashdb.Config{CleanCacheSize: 0}
} else {
config.PathDB = &pathdb.Config{TrieCleanSize: 0, StateCleanSize: 0}
}
return triedb.NewDatabase(diskdb, config)
}
func TestBinaryIterator(t *testing.T) {
trie, err := NewBinaryTrie(types.EmptyVerkleHash, newTestDatabase(rawdb.NewMemoryDatabase(), rawdb.PathScheme))
if err != nil {
t.Fatal(err)
}
account0 := &types.StateAccount{
Nonce: 1,
Balance: uint256.NewInt(2),
Root: types.EmptyRootHash,
CodeHash: nil,
}
// NOTE: the code size isn't written to the trie via TryUpdateAccount
// so it will be missing from the test nodes.
trie.UpdateAccount(common.Address{}, account0, 0)
account1 := &types.StateAccount{
Nonce: 1337,
Balance: uint256.NewInt(2000),
Root: types.EmptyRootHash,
CodeHash: nil,
}
// This address is meant to hash to a value that has the same first byte as 0xbf
var clash = common.HexToAddress("69fd8034cdb20934dedffa7dccb4fb3b8062a8be")
trie.UpdateAccount(clash, account1, 0)
// Manually go over every node to check that we get all
// the correct nodes.
it, err := trie.NodeIterator(nil)
if err != nil {
t.Fatal(err)
}
var leafcount int
for it.Next(true) {
t.Logf("Node: %x", it.Path())
if it.Leaf() {
leafcount++
t.Logf("\tLeaf: %x", it.LeafKey())
}
}
if leafcount != 2 {
t.Fatalf("invalid leaf count: %d != 6", leafcount)
}
}

View file

@ -251,27 +251,23 @@ func TestStemNodeGetValuesAtStem(t *testing.T) {
} }
// Check that all values match // Check that all values match
for i := 0; i < 256; i++ { for i := range 256 {
if !bytes.Equal(retrievedValues[i], values[i]) { if !bytes.Equal(retrievedValues[i], values[i]) {
t.Errorf("Value mismatch at index %d", i) t.Errorf("Value mismatch at index %d", i)
} }
} }
// GetValuesAtStem with different stem also returns the same values // GetValuesAtStem with different stem should return nil
// (implementation ignores the stem parameter)
differentStem := make([]byte, 31) differentStem := make([]byte, 31)
differentStem[0] = 0xFF differentStem[0] = 0xFF
retrievedValues2, err := node.GetValuesAtStem(differentStem, nil) shouldBeNil, err := node.GetValuesAtStem(differentStem, nil)
if err != nil { if err != nil {
t.Fatalf("Failed to get values with different stem: %v", err) t.Fatalf("Failed to get values with different stem: %v", err)
} }
// Should still return the same values (stem is ignored) if shouldBeNil != nil {
for i := 0; i < 256; i++ { t.Error("Expected nil for different stem, got non-nil")
if !bytes.Equal(retrievedValues2[i], values[i]) {
t.Errorf("Value mismatch at index %d with different stem", i)
}
} }
} }

View file

@ -108,7 +108,7 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
if config.HashDB != nil && config.PathDB != nil { if config.HashDB != nil && config.PathDB != nil {
log.Crit("Both 'hash' and 'path' mode are configured") log.Crit("Both 'hash' and 'path' mode are configured")
} }
if config.PathDB != nil || config.IsVerkle { if config.PathDB != nil {
db.backend = pathdb.New(diskdb, config.PathDB, config.IsVerkle) db.backend = pathdb.New(diskdb, config.PathDB, config.IsVerkle)
} else { } else {
db.backend = hashdb.New(diskdb, config.HashDB) db.backend = hashdb.New(diskdb, config.HashDB)