github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/validator/metrics_wrapper.go (about) 1 package validator 2 3 import ( 4 "time" 5 6 "github.com/onflow/flow-go/consensus/hotstuff" 7 "github.com/onflow/flow-go/consensus/hotstuff/model" 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/module" 10 ) 11 12 // ValidatorMetricsWrapper implements the hotstuff.Validator interface. 13 // It wraps a hotstuff.Validator instance and measures the time which the HotStuff's core logic 14 // spends in the hotstuff.Validator component, i.e. the with verifying higher-level consensus 15 // messages. The measured time durations are reported as values for the 16 // ValidatorProcessingDuration metric. 17 type ValidatorMetricsWrapper struct { 18 validator hotstuff.Validator 19 metrics module.HotstuffMetrics 20 } 21 22 func NewMetricsWrapper(validator hotstuff.Validator, metrics module.HotstuffMetrics) *ValidatorMetricsWrapper { 23 return &ValidatorMetricsWrapper{ 24 validator: validator, 25 metrics: metrics, 26 } 27 } 28 29 func (w ValidatorMetricsWrapper) ValidateQC(qc *flow.QuorumCertificate) error { 30 processStart := time.Now() 31 err := w.validator.ValidateQC(qc) 32 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 33 return err 34 } 35 36 func (w ValidatorMetricsWrapper) ValidateTC(tc *flow.TimeoutCertificate) error { 37 processStart := time.Now() 38 err := w.validator.ValidateTC(tc) 39 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 40 return err 41 } 42 43 func (w ValidatorMetricsWrapper) ValidateProposal(proposal *model.Proposal) error { 44 processStart := time.Now() 45 err := w.validator.ValidateProposal(proposal) 46 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 47 return err 48 } 49 50 func (w ValidatorMetricsWrapper) ValidateVote(vote *model.Vote) (*flow.IdentitySkeleton, error) { 51 processStart := time.Now() 52 identity, err := w.validator.ValidateVote(vote) 53 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 54 return identity, err 55 }