Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions internal/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"math"
"os"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -1447,10 +1448,13 @@ func (cs *State) defaultDoPrevote(height int64, round int32) {
if cs.Proposal.POLRound == -1 && !cs.proposalIsTimely() {
lowerBound, upperBound := cs.timelyProposalMargins()
// TODO: use Warn level once available.
// Use .String() to avoid passing a raw time.Duration to the logger,
// which can panic in some logger implementations (e.g. phuslu/log)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If thats the case, we should really switch out from phuslu in beaconkit, no need to let logger panic in that case

// when time.Sub overflows to math.MinInt64 for far-future timestamps.
logger.Info("prevote step: Proposal is not timely; prevoting nil",
"timestamp", cs.Proposal.Timestamp.Format(time.RFC3339Nano),
"receive_time", cs.ProposalReceiveTime.Format(time.RFC3339Nano),
"timestamp_difference", cs.ProposalReceiveTime.Sub(cs.Proposal.Timestamp),
"timestamp_difference", cs.ProposalReceiveTime.Sub(cs.Proposal.Timestamp).String(),
"lower_bound", lowerBound,
"upper_bound", upperBound)
cs.signAddVote(types.PrevoteType, nil, types.PartSetHeader{}, nil)
Expand All @@ -1461,7 +1465,7 @@ func (cs *State) defaultDoPrevote(height int64, round int32) {
logger.Debug("prevote step: Proposal is timely",
"timestamp", cs.Proposal.Timestamp.Format(time.RFC3339Nano),
"receive_time", cs.ProposalReceiveTime.Format(time.RFC3339Nano),
"timestamp_difference", cs.ProposalReceiveTime.Sub(cs.Proposal.Timestamp))
"timestamp_difference", cs.ProposalReceiveTime.Sub(cs.Proposal.Timestamp).String())
}
}

Expand Down Expand Up @@ -2856,9 +2860,15 @@ func (cs *State) calculateProposalTimestampDifferenceMetric() {
sp := cs.state.ConsensusParams.Synchrony.InRound(cs.Proposal.Round)

isTimely := cs.Proposal.IsTimely(cs.ProposalReceiveTime, sp)
diff := cs.ProposalReceiveTime.Sub(cs.Proposal.Timestamp)
// Clamp overflowed durations to avoid recording garbage metric values.
// time.Sub sub/overflows when the difference exceeds ~±292 years.
if diff == time.Duration(math.MinInt64) || diff == time.Duration(math.MaxInt64) {
return
}
cs.metrics.ProposalTimestampDifference.
With("is_timely", strconv.FormatBool(isTimely)).
Observe(cs.ProposalReceiveTime.Sub(cs.Proposal.Timestamp).Seconds())
Observe(diff.Seconds())
}
}

Expand Down
Loading