github.com/koko1123/flow-go-1@v0.29.6/consensus/hotstuff/validator/metrics_wrapper.go (about) 1 package validator 2 3 import ( 4 "time" 5 6 "github.com/koko1123/flow-go-1/consensus/hotstuff" 7 "github.com/koko1123/flow-go-1/consensus/hotstuff/model" 8 "github.com/koko1123/flow-go-1/model/flow" 9 "github.com/koko1123/flow-go-1/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, block *model.Block) error { 30 processStart := time.Now() 31 err := w.validator.ValidateQC(qc, block) 32 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 33 return err 34 } 35 36 func (w ValidatorMetricsWrapper) ValidateProposal(proposal *model.Proposal) error { 37 processStart := time.Now() 38 err := w.validator.ValidateProposal(proposal) 39 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 40 return err 41 } 42 43 func (w ValidatorMetricsWrapper) ValidateVote(vote *model.Vote, block *model.Block) (*flow.Identity, error) { 44 processStart := time.Now() 45 identity, err := w.validator.ValidateVote(vote, block) 46 w.metrics.ValidatorProcessingDuration(time.Since(processStart)) 47 return identity, err 48 }