core: sum prefetcher + per-tx + BAL state-transition reads into state_read_ms

This commit is contained in:
CPerezz 2026-04-30 12:22:59 +02:00
parent cd93a42b5b
commit d611185f09
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -677,10 +677,24 @@ func (bc *BlockChain) processBlockWithAccessList(parentRoot common.Hash, block *
stats.DatabaseCommit = m.TrieDBCommits
stats.Prefetch = m.StatePrefetch
}
// AccountReads, StorageReads, CodeReads, AccountUpdates, StorageUpdates
// remain zero: no wall-clock equivalent under parallel execution. Their
// sum-over-tx interpretation conflicts with mgas/sec accounting, so the
// serialized-time meaning is honored only via stats.Execution.
// Read durations: sum across all three sources (per-tx execution, BAL
// state-transition recomputation, prefetcher async fetches). This is
// sum-of-CPU-time across parallel workers, not wall-clock — it can
// exceed TotalTime, which is the intended interpretation under parallel
// execution: "total CPU-time spent reading state across the block".
var prefetchAccountReads, prefetchStorageReads time.Duration
if pr, ok := prefetchReader.(interface {
PrefetchReadTimes() (time.Duration, time.Duration)
}); ok {
prefetchAccountReads, prefetchStorageReads = pr.PrefetchReadTimes()
}
stats.AccountReads = res.PerTxAccountReads + prefetchAccountReads
stats.StorageReads = res.PerTxStorageReads + prefetchStorageReads
stats.CodeReads = res.PerTxCodeReads
if m := res.StateTransitionMetrics; m != nil {
stats.AccountReads += m.AccountReadTime
stats.StorageReads += m.StorageReadTime
}
// Cache stats from the shared prefetch reader (accumulates centrally).
if r, ok := prefetchReader.(state.ReaderStater); ok {