@@ -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 }
0 commit comments