github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/verification/metrics_wrapper.go (about) 1 package verification 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 // SignerMetricsWrapper implements the hotstuff.SignerVerifier interface. 13 // It wraps a hotstuff.SignerVerifier instance and measures the time which the HotStuff's core logic 14 // spends in the hotstuff.Signer component, i.e. the with crypto-related operations. 15 // The measured time durations are reported as values for the 16 // SignerProcessingDuration metric. 17 // TODO: to be moved to consensus/hotstuff/signature 18 type SignerMetricsWrapper struct { 19 signer hotstuff.Signer 20 metrics module.HotstuffMetrics 21 } 22 23 var _ hotstuff.Signer = (*SignerMetricsWrapper)(nil) 24 25 func NewMetricsWrapper(signer hotstuff.Signer, metrics module.HotstuffMetrics) *SignerMetricsWrapper { 26 return &SignerMetricsWrapper{ 27 signer: signer, 28 metrics: metrics, 29 } 30 } 31 32 // TODO: to be moved to VerifierMetricsWrapper 33 // func (w SignerMetricsWrapper) VerifyVote(voter *flow.Identity, sigData []byte, block *model.Block) (bool, error) { 34 // processStart := time.Now() 35 // valid, err := w.signer.VerifyVote(voter, sigData, block) 36 // w.metrics.SignerProcessingDuration(time.Since(processStart)) 37 // return valid, err 38 // } 39 // 40 // func (w SignerMetricsWrapper) VerifyQC(signers flow.IdentityList, sigData []byte, block *model.Block) (bool, error) { 41 // processStart := time.Now() 42 // valid, err := w.signer.VerifyQC(signers, sigData, block) 43 // w.metrics.SignerProcessingDuration(time.Since(processStart)) 44 // return valid, err 45 // } 46 47 func (w SignerMetricsWrapper) CreateProposal(block *model.Block) (*model.Proposal, error) { 48 processStart := time.Now() 49 proposal, err := w.signer.CreateProposal(block) 50 w.metrics.SignerProcessingDuration(time.Since(processStart)) 51 return proposal, err 52 } 53 54 func (w SignerMetricsWrapper) CreateVote(block *model.Block) (*model.Vote, error) { 55 processStart := time.Now() 56 vote, err := w.signer.CreateVote(block) 57 w.metrics.SignerProcessingDuration(time.Since(processStart)) 58 return vote, err 59 } 60 61 func (w SignerMetricsWrapper) CreateTimeout(curView uint64, 62 newestQC *flow.QuorumCertificate, 63 lastViewTC *flow.TimeoutCertificate) (*model.TimeoutObject, error) { 64 processStart := time.Now() 65 timeout, err := w.signer.CreateTimeout(curView, newestQC, lastViewTC) 66 w.metrics.SignerProcessingDuration(time.Since(processStart)) 67 return timeout, err 68 } 69 70 // func (w SignerMetricsWrapper) CreateQC(votes []*model.Vote) (*flow.QuorumCertificate, error) { 71 // processStart := time.Now() 72 // qc, err := w.signer.CreateQC(votes) 73 // w.metrics.SignerProcessingDuration(time.Since(processStart)) 74 // return qc, err 75 // }