more cleanups

This commit is contained in:
Jared Wasinger 2026-06-18 14:26:17 -04:00
parent 6eee5253b8
commit c62c486918
5 changed files with 18 additions and 28 deletions

View file

@ -19,6 +19,7 @@ package core
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
@ -143,6 +144,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
return nil return nil
} }
// StateRootSource computes a new state root during block execution.
type StateRootSource interface { type StateRootSource interface {
IntermediateRoot(deleteEmptyObjects bool) common.Hash IntermediateRoot(deleteEmptyObjects bool) common.Hash
Error() error Error() error

View file

@ -21,7 +21,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/core/types/bal"
"io" "io"
"math/big" "math/big"
"runtime" "runtime"
@ -32,6 +31,8 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/ethereum/go-ethereum/core/types/bal"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/lru" "github.com/ethereum/go-ethereum/common/lru"
"github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/common/mclock"
@ -2124,16 +2125,13 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
sdb := state.NewMPTDatabase(bc.triedb, bc.codedb).WithSnapshot(bc.snaps) sdb := state.NewMPTDatabase(bc.triedb, bc.codedb).WithSnapshot(bc.snaps)
al := block.AccessList() al := block.AccessList()
// Preprocess the access list once for the whole block; the resulting reader := bal.NewAccessListReader(*al)
// structure is read-only and shared by the prefetch reader, the state prefetchReader, err := sdb.ReaderWithPrefetch(parentRoot, reader.StorageKeys())
// transition and every per-transaction execution reader.
prepared := bal.NewAccessListReader(*al)
prefetchReader, err := sdb.ReaderWithPrefetch(parentRoot, prepared.StorageKeys())
if err != nil { if err != nil {
return nil, err return nil, err
} }
stateTransition, err := state.NewBALStateTransition(block, prefetchReader, sdb, parentRoot, prepared) stateTransition, err := state.NewBALStateTransition(block, prefetchReader, sdb, parentRoot, reader)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -2202,9 +2200,6 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
if m := res.StateTransitionMetrics; m != nil { if m := res.StateTransitionMetrics; m != nil {
stats.AccountHashes = m.AccountUpdate + m.StateUpdate + m.StateHash stats.AccountHashes = m.AccountUpdate + m.StateUpdate + m.StateHash
stats.AccountCommits = m.AccountCommits
stats.StorageCommits = m.StorageCommits
stats.DatabaseCommit = m.TrieDBCommits
//stats.Prefetch = m.StatePrefetch //stats.Prefetch = m.StatePrefetch
} }
//stats.Prefetch = prefetchReader.(state.PrefetcherMetricer).Metrics().Elapsed //stats.Prefetch = prefetchReader.(state.PrefetcherMetricer).Metrics().Elapsed

View file

@ -83,13 +83,6 @@ type BALStateTransitionMetrics struct {
StatePrefetch time.Duration StatePrefetch time.Duration
StateUpdate time.Duration StateUpdate time.Duration
StateHash time.Duration StateHash time.Duration
// commit metrics
AccountCommits time.Duration
StorageCommits time.Duration
SnapshotCommits time.Duration
TrieDBCommits time.Duration
TotalCommitTime time.Duration
} }
// NewBALStateTransition creates a BALStateTransition instance // NewBALStateTransition creates a BALStateTransition instance
@ -190,7 +183,7 @@ func (s *BALStateTransition) updateAccount(addr common.Address) (*types.StateAcc
func (s *BALStateTransition) commitAccount(addr common.Address) (*AccountUpdate, *trienode.NodeSet, error) { func (s *BALStateTransition) commitAccount(addr common.Address) (*AccountUpdate, *trienode.NodeSet, error) {
op := &AccountUpdate{ op := &AccountUpdate{
Address: addr, Address: addr,
Data: s.postStates[addr], // TODO: cache the updated state account somewhere Data: s.postStates[addr],
} }
var prestate *types.StateAccount var prestate *types.StateAccount
if ps, exist := s.prestates.Load(addr); exist { if ps, exist := s.prestates.Load(addr); exist {
@ -299,7 +292,6 @@ func (s *BALStateTransition) CommitWithUpdate(block uint64, deleteEmptyObjects b
// off some milliseconds from the commit operation. Also accumulate the code // off some milliseconds from the commit operation. Also accumulate the code
// writes to run in parallel with the computations. // writes to run in parallel with the computations.
var ( var (
start = time.Now()
root common.Hash root common.Hash
workers errgroup.Group workers errgroup.Group
) )
@ -320,7 +312,6 @@ func (s *BALStateTransition) CommitWithUpdate(block uint64, deleteEmptyObjects b
if err := merge(set); err != nil { if err := merge(set); err != nil {
return err return err
} }
s.metrics.AccountCommits = time.Since(start)
return nil return nil
}) })
@ -350,7 +341,6 @@ func (s *BALStateTransition) CommitWithUpdate(block uint64, deleteEmptyObjects b
} }
lock.Lock() lock.Lock()
updates[crypto.Keccak256Hash(address[:])] = update updates[crypto.Keccak256Hash(address[:])] = update
s.metrics.StorageCommits = time.Since(start) // overwrite with the longest storage commit runtime
lock.Unlock() lock.Unlock()
return nil return nil
}) })

View file

@ -220,9 +220,13 @@ type ReaderWithBlockLevelAccessList struct {
TxIndex int TxIndex int
} }
// NewReaderWithAccessList wraps a base reader with a shared, already // NewReaderWithAccessList constructs a reader for accessing states
// preprocessed access list. This is the cheap constructor used on the hot path: // with the mutations made by transactions prior to txIndex.
// the prepared list is built once per block and borrowed by every per-tx reader. //
// The txIndex refers to the call frame as such:
// - 0 for preexecution system contract calls.
// - 1 … n for transactions (in block order).
// - n + 1 for postexecution system contract calls.
func NewReaderWithAccessList(base Reader, prepared *bal.AccessListReader, txIndex int) *ReaderWithBlockLevelAccessList { func NewReaderWithAccessList(base Reader, prepared *bal.AccessListReader, txIndex int) *ReaderWithBlockLevelAccessList {
return &ReaderWithBlockLevelAccessList{ return &ReaderWithBlockLevelAccessList{
Reader: base, Reader: base,

View file

@ -41,10 +41,9 @@ var (
transactionTestDir = filepath.Join(baseDir, "TransactionTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests") rlpTestDir = filepath.Join(baseDir, "RLPTests")
difficultyTestDir = filepath.Join(baseDir, "BasicTests") difficultyTestDir = filepath.Join(baseDir, "BasicTests")
executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests") executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests")
executionSpecBALBlockchainTestDir = filepath.Join(".", "spec-tests-bal", "fixtures", "blockchain_tests") executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests")
executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests") executionSpecTransactionTestDir = filepath.Join(".", "spec-tests", "fixtures", "transaction_tests")
executionSpecTransactionTestDir = filepath.Join(".", "spec-tests", "fixtures", "transaction_tests")
benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks")
) )