From c62c486918e3d13b87961fd1278864579c328d02 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Thu, 18 Jun 2026 14:26:17 -0400 Subject: [PATCH] more cleanups --- core/block_validator.go | 2 ++ core/blockchain.go | 15 +++++---------- core/state/bal_state_transition.go | 12 +----------- core/state/reader_eip_7928.go | 10 +++++++--- tests/init_test.go | 7 +++---- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/core/block_validator.go b/core/block_validator.go index f2df77a27d..0b45cb020f 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -19,6 +19,7 @@ package core import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" @@ -143,6 +144,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error { return nil } +// StateRootSource computes a new state root during block execution. type StateRootSource interface { IntermediateRoot(deleteEmptyObjects bool) common.Hash Error() error diff --git a/core/blockchain.go b/core/blockchain.go index 27776da938..c55a38c233 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -21,7 +21,6 @@ import ( "context" "errors" "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" "io" "math/big" "runtime" @@ -32,6 +31,8 @@ import ( "sync/atomic" "time" + "github.com/ethereum/go-ethereum/core/types/bal" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/lru" "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) al := block.AccessList() - // Preprocess the access list once for the whole block; the resulting - // structure is read-only and shared by the prefetch reader, the state - // transition and every per-transaction execution reader. - prepared := bal.NewAccessListReader(*al) - prefetchReader, err := sdb.ReaderWithPrefetch(parentRoot, prepared.StorageKeys()) + reader := bal.NewAccessListReader(*al) + prefetchReader, err := sdb.ReaderWithPrefetch(parentRoot, reader.StorageKeys()) if err != nil { return nil, err } - stateTransition, err := state.NewBALStateTransition(block, prefetchReader, sdb, parentRoot, prepared) + stateTransition, err := state.NewBALStateTransition(block, prefetchReader, sdb, parentRoot, reader) if err != nil { return nil, err } @@ -2202,9 +2200,6 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block * if m := res.StateTransitionMetrics; m != nil { 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 = prefetchReader.(state.PrefetcherMetricer).Metrics().Elapsed diff --git a/core/state/bal_state_transition.go b/core/state/bal_state_transition.go index 996a7e0645..bafaee671c 100644 --- a/core/state/bal_state_transition.go +++ b/core/state/bal_state_transition.go @@ -83,13 +83,6 @@ type BALStateTransitionMetrics struct { StatePrefetch time.Duration StateUpdate 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 @@ -190,7 +183,7 @@ func (s *BALStateTransition) updateAccount(addr common.Address) (*types.StateAcc func (s *BALStateTransition) commitAccount(addr common.Address) (*AccountUpdate, *trienode.NodeSet, error) { op := &AccountUpdate{ Address: addr, - Data: s.postStates[addr], // TODO: cache the updated state account somewhere + Data: s.postStates[addr], } var prestate *types.StateAccount 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 // writes to run in parallel with the computations. var ( - start = time.Now() root common.Hash workers errgroup.Group ) @@ -320,7 +312,6 @@ func (s *BALStateTransition) CommitWithUpdate(block uint64, deleteEmptyObjects b if err := merge(set); err != nil { return err } - s.metrics.AccountCommits = time.Since(start) return nil }) @@ -350,7 +341,6 @@ func (s *BALStateTransition) CommitWithUpdate(block uint64, deleteEmptyObjects b } lock.Lock() updates[crypto.Keccak256Hash(address[:])] = update - s.metrics.StorageCommits = time.Since(start) // overwrite with the longest storage commit runtime lock.Unlock() return nil }) diff --git a/core/state/reader_eip_7928.go b/core/state/reader_eip_7928.go index 72d9672b19..0b1bfb0874 100644 --- a/core/state/reader_eip_7928.go +++ b/core/state/reader_eip_7928.go @@ -220,9 +220,13 @@ type ReaderWithBlockLevelAccessList struct { TxIndex int } -// NewReaderWithAccessList wraps a base reader with a shared, already -// preprocessed access list. This is the cheap constructor used on the hot path: -// the prepared list is built once per block and borrowed by every per-tx reader. +// NewReaderWithAccessList constructs a reader for accessing states +// with the mutations made by transactions prior to txIndex. +// +// The txIndex refers to the call frame as such: +// - 0 for pre‑execution system contract calls. +// - 1 … n for transactions (in block order). +// - n + 1 for post‑execution system contract calls. func NewReaderWithAccessList(base Reader, prepared *bal.AccessListReader, txIndex int) *ReaderWithBlockLevelAccessList { return &ReaderWithBlockLevelAccessList{ Reader: base, diff --git a/tests/init_test.go b/tests/init_test.go index 20c9e8e1c9..b933c9808c 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -41,10 +41,9 @@ var ( transactionTestDir = filepath.Join(baseDir, "TransactionTests") rlpTestDir = filepath.Join(baseDir, "RLPTests") difficultyTestDir = filepath.Join(baseDir, "BasicTests") - 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") - executionSpecTransactionTestDir = filepath.Join(".", "spec-tests", "fixtures", "transaction_tests") + executionSpecBlockchainTestDir = filepath.Join(".", "spec-tests", "fixtures", "blockchain_tests") + executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests") + executionSpecTransactionTestDir = filepath.Join(".", "spec-tests", "fixtures", "transaction_tests") benchmarksDir = filepath.Join(".", "evm-benchmarks", "benchmarks") )