core/rawdb,state: add preimage miss metric (#31295)

1. The metric of preimage/hits are always the same as preimage/total, prefer to replace
   the hits with miss instead.
2. For the state/read/accounts metric, follow the same naming of others,
  change into singuar.
This commit is contained in:
Delweng 2025-03-07 18:23:19 +08:00 committed by GitHub
parent d219e9b005
commit 9aba6895b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 4 deletions

View file

@ -27,6 +27,11 @@ import (
// ReadPreimage retrieves a single preimage of the provided hash.
func ReadPreimage(db ethdb.KeyValueReader, hash common.Hash) []byte {
data, _ := db.Get(preimageKey(hash))
if len(data) == 0 {
preimageMissCounter.Inc(1)
} else {
preimageHitsCounter.Inc(1)
}
return data
}
@ -38,7 +43,6 @@ func WritePreimages(db ethdb.KeyValueWriter, preimages map[common.Hash][]byte) {
}
}
preimageCounter.Inc(int64(len(preimages)))
preimageHitCounter.Inc(int64(len(preimages)))
}
// ReadCode retrieves the contract code of the provided code hash.

View file

@ -145,8 +145,9 @@ var (
FixedCommitteeRootKey = []byte("fixedRoot-") // bigEndian64(syncPeriod) -> committee root hash
SyncCommitteeKey = []byte("committee-") // bigEndian64(syncPeriod) -> serialized committee
preimageCounter = metrics.NewRegisteredCounter("db/preimage/total", nil)
preimageHitCounter = metrics.NewRegisteredCounter("db/preimage/hits", nil)
preimageCounter = metrics.NewRegisteredCounter("db/preimage/total", nil)
preimageHitsCounter = metrics.NewRegisteredCounter("db/preimage/hits", nil)
preimageMissCounter = metrics.NewRegisteredCounter("db/preimage/miss", nil)
)
// LegacyTxLookupEntry is the legacy TxLookupEntry definition with some unnecessary

View file

@ -19,7 +19,7 @@ package state
import "github.com/ethereum/go-ethereum/metrics"
var (
accountReadMeters = metrics.NewRegisteredMeter("state/read/accounts", nil)
accountReadMeters = metrics.NewRegisteredMeter("state/read/account", nil)
storageReadMeters = metrics.NewRegisteredMeter("state/read/storage", nil)
accountUpdatedMeter = metrics.NewRegisteredMeter("state/update/account", nil)
storageUpdatedMeter = metrics.NewRegisteredMeter("state/update/storage", nil)