core/state: polish

This commit is contained in:
Gary Rong 2025-06-10 14:32:32 +08:00
parent bed5c68b5c
commit 954f28d26f

View file

@ -91,7 +91,7 @@ type ReaderStats struct {
StorageMiss int64 StorageMiss int64
} }
// ReaderWithStats wraps the additional methods to retrieve the reader statistics from. // ReaderWithStats wraps the additional method to retrieve the reader statistics from.
type ReaderWithStats interface { type ReaderWithStats interface {
Reader Reader
GetStats() ReaderStats GetStats() ReaderStats
@ -530,11 +530,11 @@ func newReaderWithCacheStats(reader *readerWithCache) *readerWithCacheStats {
// //
// An error will be returned if the state is corrupted in the underlying reader. // An error will be returned if the state is corrupted in the underlying reader.
func (r *readerWithCacheStats) Account(addr common.Address) (*types.StateAccount, error) { func (r *readerWithCacheStats) Account(addr common.Address) (*types.StateAccount, error) {
account, found, err := r.readerWithCache.account(addr) account, incache, err := r.readerWithCache.account(addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if found { if incache {
r.accountHit.Add(1) r.accountHit.Add(1)
} else { } else {
r.accountMiss.Add(1) r.accountMiss.Add(1)
@ -548,11 +548,11 @@ func (r *readerWithCacheStats) Account(addr common.Address) (*types.StateAccount
// //
// An error will be returned if the state is corrupted in the underlying reader. // An error will be returned if the state is corrupted in the underlying reader.
func (r *readerWithCacheStats) Storage(addr common.Address, slot common.Hash) (common.Hash, error) { func (r *readerWithCacheStats) Storage(addr common.Address, slot common.Hash) (common.Hash, error) {
value, found, err := r.readerWithCache.storage(addr, slot) value, incache, err := r.readerWithCache.storage(addr, slot)
if err != nil { if err != nil {
return common.Hash{}, err return common.Hash{}, err
} }
if found { if incache {
r.storageHit.Add(1) r.storageHit.Add(1)
} else { } else {
r.storageMiss.Add(1) r.storageMiss.Add(1)
@ -560,7 +560,7 @@ func (r *readerWithCacheStats) Storage(addr common.Address, slot common.Hash) (c
return value, nil return value, nil
} }
// GetStats implements ReaderWithStats, returns the statistics of state reader. // GetStats implements ReaderWithStats, returning the statistics of state reader.
func (r *readerWithCacheStats) GetStats() ReaderStats { func (r *readerWithCacheStats) GetStats() ReaderStats {
return ReaderStats{ return ReaderStats{
AccountHit: r.accountHit.Load(), AccountHit: r.accountHit.Load(),