github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/consensus/hotstuff/committees/metrics_wrapper.go (about) 1 package committees 2 3 import ( 4 "time" 5 6 "github.com/onflow/flow-go/consensus/hotstuff" 7 "github.com/onflow/flow-go/model/flow" 8 "github.com/onflow/flow-go/module" 9 ) 10 11 // CommitteeMetricsWrapper implements the hotstuff.DynamicCommittee interface. 12 // It wraps a hotstuff.DynamicCommittee instance and measures the time which the HotStuff's core logic 13 // spends in the hotstuff.DynamicCommittee component, i.e. the time determining consensus committee 14 // relations. The measured time durations are reported as values for the 15 // CommitteeProcessingDuration metric. 16 type CommitteeMetricsWrapper struct { 17 committee hotstuff.DynamicCommittee 18 metrics module.HotstuffMetrics 19 } 20 21 var _ hotstuff.Replicas = (*CommitteeMetricsWrapper)(nil) 22 var _ hotstuff.DynamicCommittee = (*CommitteeMetricsWrapper)(nil) 23 24 func NewMetricsWrapper(committee hotstuff.DynamicCommittee, metrics module.HotstuffMetrics) *CommitteeMetricsWrapper { 25 return &CommitteeMetricsWrapper{ 26 committee: committee, 27 metrics: metrics, 28 } 29 } 30 31 func (w CommitteeMetricsWrapper) IdentitiesByBlock(blockID flow.Identifier) (flow.IdentityList, error) { 32 processStart := time.Now() 33 identities, err := w.committee.IdentitiesByBlock(blockID) 34 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 35 return identities, err 36 } 37 38 func (w CommitteeMetricsWrapper) IdentityByBlock(blockID flow.Identifier, participantID flow.Identifier) (*flow.Identity, error) { 39 processStart := time.Now() 40 identity, err := w.committee.IdentityByBlock(blockID, participantID) 41 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 42 return identity, err 43 } 44 45 func (w CommitteeMetricsWrapper) IdentitiesByEpoch(view uint64) (flow.IdentitySkeletonList, error) { 46 processStart := time.Now() 47 identities, err := w.committee.IdentitiesByEpoch(view) 48 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 49 return identities, err 50 } 51 52 func (w CommitteeMetricsWrapper) IdentityByEpoch(view uint64, participantID flow.Identifier) (*flow.IdentitySkeleton, error) { 53 processStart := time.Now() 54 identity, err := w.committee.IdentityByEpoch(view, participantID) 55 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 56 return identity, err 57 } 58 59 func (w CommitteeMetricsWrapper) LeaderForView(view uint64) (flow.Identifier, error) { 60 processStart := time.Now() 61 id, err := w.committee.LeaderForView(view) 62 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 63 return id, err 64 } 65 66 func (w CommitteeMetricsWrapper) QuorumThresholdForView(view uint64) (uint64, error) { 67 processStart := time.Now() 68 id, err := w.committee.QuorumThresholdForView(view) 69 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 70 return id, err 71 } 72 73 func (w CommitteeMetricsWrapper) TimeoutThresholdForView(view uint64) (uint64, error) { 74 processStart := time.Now() 75 id, err := w.committee.TimeoutThresholdForView(view) 76 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 77 return id, err 78 } 79 80 func (w CommitteeMetricsWrapper) Self() flow.Identifier { 81 processStart := time.Now() 82 id := w.committee.Self() 83 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 84 return id 85 } 86 87 func (w CommitteeMetricsWrapper) DKG(view uint64) (hotstuff.DKG, error) { 88 processStart := time.Now() 89 dkg, err := w.committee.DKG(view) 90 w.metrics.CommitteeProcessingDuration(time.Since(processStart)) 91 return dkg, err 92 }