Skip to content

Commit e21dd40

Browse files
authored
Merge pull request #2290 from CortexFoundation/dev
add preimage miss metric
2 parents 6e1673c + f639e64 commit e21dd40

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

core/rawdb/accessors_state.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,24 @@ import (
2525
// ReadPreimage retrieves a single preimage of the provided hash.
2626
func ReadPreimage(db ctxcdb.KeyValueReader, hash common.Hash) []byte {
2727
data, _ := db.Get(preimageKey(hash))
28+
if len(data) == 0 {
29+
preimageMissCounter.Inc(1)
30+
} else {
31+
preimageHitsCounter.Inc(1)
32+
}
2833
return data
2934
}
3035

36+
// WritePreimages writes the provided set of preimages to the database.
37+
func WritePreimages(db ctxcdb.KeyValueWriter, preimages map[common.Hash][]byte) {
38+
for hash, preimage := range preimages {
39+
if err := db.Put(preimageKey(hash), preimage); err != nil {
40+
log.Crit("Failed to store trie preimage", "err", err)
41+
}
42+
}
43+
preimageCounter.Inc(int64(len(preimages)))
44+
}
45+
3146
// ReadCode retrieves the contract code of the provided code hash.
3247
func ReadCode(db ctxcdb.KeyValueReader, hash common.Hash) []byte {
3348
// Try with the prefixed code scheme first, if not then try with legacy
@@ -80,17 +95,6 @@ func HasTrieNode(db ctxcdb.KeyValueReader, hash common.Hash) bool {
8095
return ok
8196
}
8297

83-
// WritePreimages writes the provided set of preimages to the database.
84-
func WritePreimages(db ctxcdb.KeyValueWriter, preimages map[common.Hash][]byte) {
85-
for hash, preimage := range preimages {
86-
if err := db.Put(preimageKey(hash), preimage); err != nil {
87-
log.Crit("Failed to store trie preimage", "err", err)
88-
}
89-
}
90-
preimageCounter.Inc(int64(len(preimages)))
91-
preimageHitCounter.Inc(int64(len(preimages)))
92-
}
93-
9498
// WriteCode writes the provided contract code database.
9599
func WriteCode(db ctxcdb.KeyValueWriter, hash common.Hash, code []byte) {
96100
if err := db.Put(codeKey(hash), code); err != nil {

core/rawdb/schema.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ var (
122122

123123
CliqueSnapshotPrefix = []byte("clique-")
124124

125-
preimageCounter = metrics.NewRegisteredCounter("db/preimage/total", nil)
126-
preimageHitCounter = metrics.NewRegisteredCounter("db/preimage/hits", nil)
125+
BestUpdateKey = []byte("update-") // bigEndian64(syncPeriod) -> RLP(types.LightClientUpdate) (nextCommittee only referenced by root hash)
126+
FixedCommitteeRootKey = []byte("fixedRoot-") // bigEndian64(syncPeriod) -> committee root hash
127+
SyncCommitteeKey = []byte("committee-") // bigEndian64(syncPeriod) -> serialized committee
128+
129+
preimageCounter = metrics.NewRegisteredCounter("db/preimage/total", nil)
130+
preimageHitsCounter = metrics.NewRegisteredCounter("db/preimage/hits", nil)
131+
preimageMissCounter = metrics.NewRegisteredCounter("db/preimage/miss", nil)
127132
)
128133

129134
// LegacyTxLookupEntry is the legacy TxLookupEntry definition with some unnecessary

core/state/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package state
1818
import "github.com/CortexFoundation/CortexTheseus/metrics"
1919

2020
var (
21+
accountReadMeters = metrics.NewRegisteredMeter("state/read/account", nil)
22+
storageReadMeters = metrics.NewRegisteredMeter("state/read/storage", nil)
2123
accountUpdatedMeter = metrics.NewRegisteredMeter("state/update/account", nil)
2224
storageUpdatedMeter = metrics.NewRegisteredMeter("state/update/storage", nil)
2325
accountDeletedMeter = metrics.NewRegisteredMeter("state/delete/account", nil)

0 commit comments

Comments
 (0)