diff --git a/core/blockchain.go b/core/blockchain.go index 8a4cd67632..58e8be7362 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -657,7 +657,7 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block * // (account/code/storage write counters via stateTransition.WriteCounts). stats.StateCounts = res.Counts balWrites := stateTransition.WriteCounts() - stats.StateCounts.Add(&balWrites) + stats.StateCounts.Add(balWrites) // Time durations under parallel execution use wall-clock semantics. // Per-tx duration sums (CPU-time) are intentionally not plumbed: they diff --git a/core/blockchain_stats_test.go b/core/blockchain_stats_test.go index 7e64a9b1b9..adb5d0960d 100644 --- a/core/blockchain_stats_test.go +++ b/core/blockchain_stats_test.go @@ -53,7 +53,7 @@ func TestStateCountsAdd(t *testing.T) { CodeUpdated: 900, CodeUpdateBytes: 1000, } - a.Add(&b) + a.Add(b) want := state.StateCounts{ AccountLoaded: 101, AccountUpdated: 202, diff --git a/core/parallel_state_processor.go b/core/parallel_state_processor.go index 60e30a44f9..58a75ecca4 100644 --- a/core/parallel_state_processor.go +++ b/core/parallel_state_processor.go @@ -183,7 +183,7 @@ func (p *ParallelStateProcessor) prepareExecResult(block *types.Block, tExecStar // would otherwise be discarded; this captures system-contract reads and // the engine.Finalize state mutations. postTxCounts := postTxState.SnapshotCounts() - aggCounts.Add(&postTxCounts) + aggCounts.Add(postTxCounts) // Fold post-tx statedb reads into the aggregate (system contracts, // withdrawal queue, consolidation queue). @@ -267,7 +267,7 @@ func (p *ParallelStateProcessor) resultHandler(block *types.Block, preTxReads ba cumulativeStateGas += res.txState results = append(results, res) accesses.Merge(res.stateReads) - aggCounts.Add(&res.counts) + aggCounts.Add(res.counts) aggAccountReads += res.accountReads aggStorageReads += res.storageReads aggCodeReads += res.codeReads diff --git a/core/state/state_counts.go b/core/state/state_counts.go index 02116e0b3e..b5c109a657 100644 --- a/core/state/state_counts.go +++ b/core/state/state_counts.go @@ -43,9 +43,10 @@ type StateCounts struct { } // Add merges other into c. Plain integer addition — no atomics here, since -// StateCounts is the snapshot type. Callers must ensure other is no longer -// being mutated when Add is invoked. -func (c *StateCounts) Add(other *StateCounts) { +// StateCounts is the snapshot type. The receiver is the only mutated party; +// other is taken by value (the struct is small and value semantics matches +// the snapshot thesis stated above). +func (c *StateCounts) Add(other StateCounts) { c.AccountLoaded += other.AccountLoaded c.AccountUpdated += other.AccountUpdated c.AccountDeleted += other.AccountDeleted