mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-28 11:56:15 +00:00
handle duration overflow
This commit is contained in:
@@ -99,6 +99,12 @@ func (p *Proposal) IsTimely(recvTime time.Time, sp SynchronyParams, round int32)
|
||||
roundModifier := time.Duration(math.Exp2(float64(round / 10)))
|
||||
msgDelay := sp.MessageDelay * roundModifier
|
||||
|
||||
if msgDelay <= 0 {
|
||||
// In the case that messaeg delay overflows after applying the round modifier, use the maximum
|
||||
// duration instead.
|
||||
msgDelay = time.Nanosecond * math.MaxInt64
|
||||
}
|
||||
|
||||
// lhs is `proposedBlockTime - Precision` in the first inequality
|
||||
lhs := p.Timestamp.Add(-sp.Precision)
|
||||
// rhs is `proposedBlockTime + MsgDelay + Precision` in the second inequality
|
||||
|
||||
@@ -266,6 +266,17 @@ func TestIsTimely(t *testing.T) {
|
||||
expectTimely: true,
|
||||
round: 10,
|
||||
},
|
||||
{
|
||||
// check that values that overflow time.Duration still correctly register
|
||||
// as timely when round relaxation applied.
|
||||
name: "message delay fixed to not overflow time.Duration",
|
||||
proposalTime: genesisTime,
|
||||
recvTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
precision: time.Nanosecond * 2,
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: true,
|
||||
round: 5000,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user