Skip to content

Commit 2c59e15

Browse files
committed
chore: add validate metrics
1 parent a5e12fe commit 2c59e15

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

core/block_validator.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ethereum/go-ethereum/consensus"
2626
"github.com/ethereum/go-ethereum/core/state"
2727
"github.com/ethereum/go-ethereum/core/types"
28+
"github.com/ethereum/go-ethereum/metrics"
2829
"github.com/ethereum/go-ethereum/params"
2930
"github.com/ethereum/go-ethereum/trie"
3031
)
@@ -40,6 +41,12 @@ func EnableRemoteVerifyManager(remoteValidator *remoteVerifyManager) BlockValida
4041
}
4142
}
4243

44+
var (
45+
validateBloomTimer = metrics.NewRegisteredTimer("validate/bloom/time", nil)
46+
validateReceiptTimer = metrics.NewRegisteredTimer("validate/receipt/time", nil)
47+
validateRootTimer = metrics.NewRegisteredTimer("validate/root/time", nil)
48+
)
49+
4350
// BlockValidator is responsible for validating block headers, uncles and
4451
// processed state.
4552
//
@@ -184,13 +191,20 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
184191
// For valid blocks this should always validate to true.
185192
validateFuns := []func() error{
186193
func() error {
194+
defer func(start time.Time) {
195+
validateBloomTimer.UpdateSince(start)
196+
}(time.Now())
197+
187198
rbloom := types.CreateBloom(receipts)
188199
if rbloom != header.Bloom {
189200
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom)
190201
}
191202
return nil
192203
},
193204
func() error {
205+
defer func(start time.Time) {
206+
validateReceiptTimer.UpdateSince(start)
207+
}(time.Now())
194208
receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
195209
if receiptSha != header.ReceiptHash {
196210
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
@@ -209,6 +223,9 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
209223
})
210224
} else {
211225
validateFuns = append(validateFuns, func() error {
226+
defer func(start time.Time) {
227+
validateRootTimer.UpdateSince(start)
228+
}(time.Now())
212229
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
213230
return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
214231
}

core/state/metrics.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ var (
3434
slotDeletionCount = metrics.NewRegisteredMeter("state/delete/storage/slot", nil)
3535
slotDeletionSize = metrics.NewRegisteredMeter("state/delete/storage/size", nil)
3636
slotDeletionSkip = metrics.NewRegisteredGauge("state/delete/storage/skip", nil)
37+
38+
accountIntermediateRootTimer = metrics.NewRegisteredTimer("state/account/intermediate/root/time", nil)
39+
storageIntermediateRootTimer = metrics.NewRegisteredTimer("state/storage/intermediate/root/time", nil)
3740
)

core/state/statedb.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,10 @@ func (s *StateDB) populateSnapStorage(obj *stateObject) bool {
11771177
}
11781178

11791179
func (s *StateDB) AccountsIntermediateRoot() {
1180+
defer func(start time.Time) {
1181+
storageIntermediateRootTimer.UpdateSince(start)
1182+
}(time.Now())
1183+
11801184
tasks := make(chan func())
11811185
finishCh := make(chan struct{})
11821186
defer close(finishCh)
@@ -1221,6 +1225,9 @@ func (s *StateDB) AccountsIntermediateRoot() {
12211225
}
12221226

12231227
func (s *StateDB) StateIntermediateRoot() common.Hash {
1228+
defer func(start time.Time) {
1229+
accountIntermediateRootTimer.UpdateSince(start)
1230+
}(time.Now())
12241231
// If there was a trie prefetcher operating, it gets aborted and irrevocably
12251232
// modified after we start retrieving tries. Remove it from the statedb after
12261233
// this round of use.

0 commit comments

Comments
 (0)