diff --git a/core/block_validator.go b/core/block_validator.go index b82965a99d..19f64b2a7f 100644 --- a/core/block_validator.go +++ b/core/block_validator.go @@ -25,6 +25,7 @@ import ( "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/trie" ) @@ -40,6 +41,12 @@ func EnableRemoteVerifyManager(remoteValidator *remoteVerifyManager) BlockValida } } +var ( + validateBloomTimer = metrics.NewRegisteredTimer("validate/bloom/time", nil) + validateReceiptTimer = metrics.NewRegisteredTimer("validate/receipt/time", nil) + validateRootTimer = metrics.NewRegisteredTimer("validate/root/time", nil) +) + // BlockValidator is responsible for validating block headers, uncles and // processed state. // @@ -184,6 +191,10 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD // For valid blocks this should always validate to true. validateFuns := []func() error{ func() error { + defer func(start time.Time) { + validateBloomTimer.UpdateSince(start) + }(time.Now()) + rbloom := types.CreateBloom(receipts) if rbloom != header.Bloom { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom) @@ -191,6 +202,9 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD return nil }, func() error { + defer func(start time.Time) { + validateReceiptTimer.UpdateSince(start) + }(time.Now()) receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil)) if receiptSha != header.ReceiptHash { 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 }) } else { validateFuns = append(validateFuns, func() error { + defer func(start time.Time) { + validateRootTimer.UpdateSince(start) + }(time.Now()) if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root { return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error()) } diff --git a/core/state/metrics.go b/core/state/metrics.go index 64c651461e..085d6c4f4b 100644 --- a/core/state/metrics.go +++ b/core/state/metrics.go @@ -34,4 +34,7 @@ var ( slotDeletionCount = metrics.NewRegisteredMeter("state/delete/storage/slot", nil) slotDeletionSize = metrics.NewRegisteredMeter("state/delete/storage/size", nil) slotDeletionSkip = metrics.NewRegisteredGauge("state/delete/storage/skip", nil) + + accountIntermediateRootTimer = metrics.NewRegisteredTimer("state/account/intermediate/root/time", nil) + storageIntermediateRootTimer = metrics.NewRegisteredTimer("state/storage/intermediate/root/time", nil) ) diff --git a/core/state/statedb.go b/core/state/statedb.go index 73a9c08c84..eb92a8d72d 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1177,6 +1177,10 @@ func (s *StateDB) populateSnapStorage(obj *stateObject) bool { } func (s *StateDB) AccountsIntermediateRoot() { + defer func(start time.Time) { + storageIntermediateRootTimer.UpdateSince(start) + }(time.Now()) + tasks := make(chan func()) finishCh := make(chan struct{}) defer close(finishCh) @@ -1221,6 +1225,9 @@ func (s *StateDB) AccountsIntermediateRoot() { } func (s *StateDB) StateIntermediateRoot() common.Hash { + defer func(start time.Time) { + accountIntermediateRootTimer.UpdateSince(start) + }(time.Now()) // If there was a trie prefetcher operating, it gets aborted and irrevocably // modified after we start retrieving tries. Remove it from the statedb after // this round of use.