core/state: change StateCounts.Add to value receiver

The struct is 80 bytes (10 ints) — value semantics matches the type's
"snapshot, safe to pass by value" thesis stated in its doc comment, and
removes three unnecessary &-takings at call sites. No behavior change.
This commit is contained in:
CPerezz 2026-04-30 13:44:35 +02:00
parent cdfad0d343
commit 1afcea992c
No known key found for this signature in database
GPG key ID: 62045F34B97177DD
4 changed files with 8 additions and 7 deletions

View file

@ -657,7 +657,7 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
// (account/code/storage write counters via stateTransition.WriteCounts). // (account/code/storage write counters via stateTransition.WriteCounts).
stats.StateCounts = res.Counts stats.StateCounts = res.Counts
balWrites := stateTransition.WriteCounts() balWrites := stateTransition.WriteCounts()
stats.StateCounts.Add(&balWrites) stats.StateCounts.Add(balWrites)
// Time durations under parallel execution use wall-clock semantics. // Time durations under parallel execution use wall-clock semantics.
// Per-tx duration sums (CPU-time) are intentionally not plumbed: they // Per-tx duration sums (CPU-time) are intentionally not plumbed: they

View file

@ -53,7 +53,7 @@ func TestStateCountsAdd(t *testing.T) {
CodeUpdated: 900, CodeUpdated: 900,
CodeUpdateBytes: 1000, CodeUpdateBytes: 1000,
} }
a.Add(&b) a.Add(b)
want := state.StateCounts{ want := state.StateCounts{
AccountLoaded: 101, AccountLoaded: 101,
AccountUpdated: 202, AccountUpdated: 202,

View file

@ -183,7 +183,7 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, tExecStar
// would otherwise be discarded; this captures system-contract reads and // would otherwise be discarded; this captures system-contract reads and
// the engine.Finalize state mutations. // the engine.Finalize state mutations.
postTxCounts := postTxState.SnapshotCounts() postTxCounts := postTxState.SnapshotCounts()
aggCounts.Add(&postTxCounts) aggCounts.Add(postTxCounts)
// Fold post-tx statedb reads into the aggregate (system contracts, // Fold post-tx statedb reads into the aggregate (system contracts,
// withdrawal queue, consolidation queue). // withdrawal queue, consolidation queue).
@ -267,7 +267,7 @@ func (p *ParallelStateProcessor) resultHandler(block *types.Block, preTxReads ba
cumulativeStateGas += res.txState cumulativeStateGas += res.txState
results = append(results, res) results = append(results, res)
accesses.Merge(res.stateReads) accesses.Merge(res.stateReads)
aggCounts.Add(&res.counts) aggCounts.Add(res.counts)
aggAccountReads += res.accountReads aggAccountReads += res.accountReads
aggStorageReads += res.storageReads aggStorageReads += res.storageReads
aggCodeReads += res.codeReads aggCodeReads += res.codeReads

View file

@ -43,9 +43,10 @@ type StateCounts struct {
} }
// Add merges other into c. Plain integer addition — no atomics here, since // Add merges other into c. Plain integer addition — no atomics here, since
// StateCounts is the snapshot type. Callers must ensure other is no longer // StateCounts is the snapshot type. The receiver is the only mutated party;
// being mutated when Add is invoked. // other is taken by value (the struct is small and value semantics matches
func (c *StateCounts) Add(other *StateCounts) { // the snapshot thesis stated above).
func (c *StateCounts) Add(other StateCounts) {
c.AccountLoaded += other.AccountLoaded c.AccountLoaded += other.AccountLoaded
c.AccountUpdated += other.AccountUpdated c.AccountUpdated += other.AccountUpdated
c.AccountDeleted += other.AccountDeleted c.AccountDeleted += other.AccountDeleted