From a33e38cb3aac75660b30f37dfa21d66283534734 Mon Sep 17 00:00:00 2001 From: William Banfield <4561443+williambanfield@users.noreply.github.com> Date: Tue, 18 Jan 2022 19:57:00 -0500 Subject: [PATCH] consensus: check proposal non-nil in prevote message delay metric (#7625) (cherry picked from commit b6307c42e095c6f8e9e7c2518fb1004cc8f201a1) # Conflicts: # consensus/state.go --- consensus/state.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/consensus/state.go b/consensus/state.go index ac016c91a..94e4ae19d 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -2274,6 +2274,34 @@ func (cs *State) checkDoubleSigningRisk(height int64) error { return nil } +<<<<<<< HEAD:consensus/state.go +======= +func (cs *State) calculatePrevoteMessageDelayMetrics() { + if cs.Proposal == nil { + return + } + ps := cs.Votes.Prevotes(cs.Round) + pl := ps.List() + + sort.Slice(pl, func(i, j int) bool { + return pl[i].Timestamp.Before(pl[j].Timestamp) + }) + + var votingPowerSeen int64 + for _, v := range pl { + _, val := cs.Validators.GetByAddress(v.ValidatorAddress) + votingPowerSeen += val.VotingPower + if votingPowerSeen >= cs.Validators.TotalVotingPower()*2/3+1 { + cs.metrics.QuorumPrevoteMessageDelay.Set(v.Timestamp.Sub(cs.Proposal.Timestamp).Seconds()) + break + } + } + if ps.HasAll() { + cs.metrics.FullPrevoteMessageDelay.Set(pl[len(pl)-1].Timestamp.Sub(cs.Proposal.Timestamp).Seconds()) + } +} + +>>>>>>> b6307c42e (consensus: check proposal non-nil in prevote message delay metric (#7625)):internal/consensus/state.go //--------------------------------------------------------- func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, s2 cstypes.RoundStepType) int {