mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-08 07:58:40 +00:00
core: refresh BAL Metrics() snapshot after writeBlockWithState
The first Metrics() call inside calcAndVerifyRoot snapshots accountReadNS and storageReadNS into the cached AccountReadTime/StorageReadTime fields. But commitAccount (called from writeBlockWithState's CommitWithUpdate path) increments storageReadNS *after* that snapshot, so reading m.StorageReadTime later would silently drop those reads. Re-call Metrics() before reading the read-time fields so the cache reflects the post-commit atomics. Other metric fields (AccountUpdate, AccountCommits, etc.) are written directly to s.metrics elsewhere and remain untouched by Metrics(). Found via the metric-correctness audit.
This commit is contained in:
parent
1afcea992c
commit
16e98f5d93
1 changed files with 6 additions and 5 deletions
|
|
@ -677,11 +677,12 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
|
||||||
stats.DatabaseCommit = m.TrieDBCommits
|
stats.DatabaseCommit = m.TrieDBCommits
|
||||||
stats.Prefetch = m.StatePrefetch
|
stats.Prefetch = m.StatePrefetch
|
||||||
}
|
}
|
||||||
// Read durations: sum across all three sources (per-tx execution, BAL
|
// Refresh BAL read-time cache: commitAccount runs storage reads during
|
||||||
// state-transition recomputation, prefetcher async fetches). This is
|
// writeBlockWithState, after the first Metrics() snapshot.
|
||||||
// sum-of-CPU-time across parallel workers, not wall-clock — it can
|
stateTransition.Metrics()
|
||||||
// exceed TotalTime, which is the intended interpretation under parallel
|
|
||||||
// execution: "total CPU-time spent reading state across the block".
|
// Sum read times across per-tx execution, BAL state-transition, and
|
||||||
|
// prefetcher async fetches. Sum-of-CPU-time, not wall-clock.
|
||||||
var prefetchAccountReads, prefetchStorageReads time.Duration
|
var prefetchAccountReads, prefetchStorageReads time.Duration
|
||||||
if pr, ok := prefetchReader.(interface {
|
if pr, ok := prefetchReader.(interface {
|
||||||
PrefetchReadTimes() (time.Duration, time.Duration)
|
PrefetchReadTimes() (time.Duration, time.Duration)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue