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