mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-11 17:31:35 +00:00
core/state: forward cache stats from prefetchStateReader
This commit is contained in:
parent
2bb95a19a4
commit
f089266126
2 changed files with 37 additions and 0 deletions
|
|
@ -362,3 +362,13 @@ func (r *readerTracker) TouchStorage(addr common.Address, slot common.Hash) {
|
||||||
}
|
}
|
||||||
list[slot] = struct{}{}
|
list[slot] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStateStats forwards stats from the wrapped *stateReaderWithStats so the
|
||||||
|
// reader-aggregator type assertion at reader.go:553 succeeds. Without this,
|
||||||
|
// account/storage cache hit/miss counts emit zero on BAL blocks.
|
||||||
|
func (r *prefetchStateReader) GetStateStats() StateReaderStats {
|
||||||
|
if stater, ok := r.StateReader.(StateReaderStater); ok {
|
||||||
|
return stater.GetStateStats()
|
||||||
|
}
|
||||||
|
return StateReaderStats{}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -263,3 +263,30 @@ func TestTrackerSurvivesStateDBCache(t *testing.T) {
|
||||||
t.Fatal("slot must be tracked on cache hit (storage)")
|
t.Fatal("slot must be tracked on cache hit (storage)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestPrefetchStateReaderForwardsStats locks down that prefetchStateReader
|
||||||
|
// exposes the underlying stateReaderWithStats counters via GetStateStats.
|
||||||
|
func TestPrefetchStateReaderForwardsStats(t *testing.T) {
|
||||||
|
stub := newRefStateReader()
|
||||||
|
addr := testrand.Address()
|
||||||
|
|
||||||
|
cached := newStateReaderWithCache(stub)
|
||||||
|
withStats := newStateReaderWithStats(cached)
|
||||||
|
prefetch := newPrefetchStateReaderInternal(withStats, nil, 1)
|
||||||
|
|
||||||
|
if _, err := prefetch.Account(addr); err != nil {
|
||||||
|
t.Fatalf("Account: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := prefetch.Account(addr); err != nil {
|
||||||
|
t.Fatalf("Account (second): %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stats := withStats.GetStateStats()
|
||||||
|
if stats.AccountCacheHit == 0 || stats.AccountCacheMiss == 0 {
|
||||||
|
t.Fatalf("inner stats not populated: %+v", stats)
|
||||||
|
}
|
||||||
|
gotStats := prefetch.GetStateStats()
|
||||||
|
if gotStats != stats {
|
||||||
|
t.Fatalf("forward mismatch: got %+v, want %+v", gotStats, stats)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue