-
Notifications
You must be signed in to change notification settings - Fork 175
/
metrics_wrapper.go
48 lines (41 loc) · 1.63 KB
/
metrics_wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package validator
import (
"time"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/model"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
)
// ValidatorMetricsWrapper implements the hotstuff.Validator interface.
// It wraps a hotstuff.Validator instance and measures the time which the HotStuff's core logic
// spends in the hotstuff.Validator component, i.e. the with verifying higher-level consensus
// messages. The measured time durations are reported as values for the
// ValidatorProcessingDuration metric.
type ValidatorMetricsWrapper struct {
validator hotstuff.Validator
metrics module.HotstuffMetrics
}
func NewMetricsWrapper(validator hotstuff.Validator, metrics module.HotstuffMetrics) *ValidatorMetricsWrapper {
return &ValidatorMetricsWrapper{
validator: validator,
metrics: metrics,
}
}
func (w ValidatorMetricsWrapper) ValidateQC(qc *flow.QuorumCertificate, block *model.Block) error {
processStart := time.Now()
err := w.validator.ValidateQC(qc, block)
w.metrics.ValidatorProcessingDuration(time.Since(processStart))
return err
}
func (w ValidatorMetricsWrapper) ValidateProposal(proposal *model.Proposal) error {
processStart := time.Now()
err := w.validator.ValidateProposal(proposal)
w.metrics.ValidatorProcessingDuration(time.Since(processStart))
return err
}
func (w ValidatorMetricsWrapper) ValidateVote(vote *model.Vote, block *model.Block) (*flow.Identity, error) {
processStart := time.Now()
identity, err := w.validator.ValidateVote(vote, block)
w.metrics.ValidatorProcessingDuration(time.Since(processStart))
return identity, err
}