-
Notifications
You must be signed in to change notification settings - Fork 175
/
metrics_wrapper.go
75 lines (65 loc) · 2.65 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package verification
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"
)
// SignerMetricsWrapper implements the hotstuff.SignerVerifier interface.
// It wraps a hotstuff.SignerVerifier instance and measures the time which the HotStuff's core logic
// spends in the hotstuff.Signer component, i.e. the with crypto-related operations.
// The measured time durations are reported as values for the
// SignerProcessingDuration metric.
// TODO: to be moved to consensus/hotstuff/signature
type SignerMetricsWrapper struct {
signer hotstuff.Signer
metrics module.HotstuffMetrics
}
var _ hotstuff.Signer = (*SignerMetricsWrapper)(nil)
func NewMetricsWrapper(signer hotstuff.Signer, metrics module.HotstuffMetrics) *SignerMetricsWrapper {
return &SignerMetricsWrapper{
signer: signer,
metrics: metrics,
}
}
// TODO: to be moved to VerifierMetricsWrapper
// func (w SignerMetricsWrapper) VerifyVote(voter *flow.Identity, sigData []byte, block *model.Block) (bool, error) {
// processStart := time.Now()
// valid, err := w.signer.VerifyVote(voter, sigData, block)
// w.metrics.SignerProcessingDuration(time.Since(processStart))
// return valid, err
// }
//
// func (w SignerMetricsWrapper) VerifyQC(signers flow.IdentityList, sigData []byte, block *model.Block) (bool, error) {
// processStart := time.Now()
// valid, err := w.signer.VerifyQC(signers, sigData, block)
// w.metrics.SignerProcessingDuration(time.Since(processStart))
// return valid, err
// }
func (w SignerMetricsWrapper) CreateProposal(block *model.Block) (*model.Proposal, error) {
processStart := time.Now()
proposal, err := w.signer.CreateProposal(block)
w.metrics.SignerProcessingDuration(time.Since(processStart))
return proposal, err
}
func (w SignerMetricsWrapper) CreateVote(block *model.Block) (*model.Vote, error) {
processStart := time.Now()
vote, err := w.signer.CreateVote(block)
w.metrics.SignerProcessingDuration(time.Since(processStart))
return vote, err
}
func (w SignerMetricsWrapper) CreateTimeout(curView uint64,
newestQC *flow.QuorumCertificate,
lastViewTC *flow.TimeoutCertificate) (*model.TimeoutObject, error) {
processStart := time.Now()
timeout, err := w.signer.CreateTimeout(curView, newestQC, lastViewTC)
w.metrics.SignerProcessingDuration(time.Since(processStart))
return timeout, err
}
// func (w SignerMetricsWrapper) CreateQC(votes []*model.Vote) (*flow.QuorumCertificate, error) {
// processStart := time.Now()
// qc, err := w.signer.CreateQC(votes)
// w.metrics.SignerProcessingDuration(time.Since(processStart))
// return qc, err
// }