change accuracy to precision

This commit is contained in:
William Banfield
2021-11-23 10:08:53 -05:00
parent 00cbab12c9
commit 6ee6f349a1
2 changed files with 16 additions and 15 deletions

View File

@@ -2421,10 +2421,10 @@ func repairWalFile(src, dst string) error {
// until its local clock exceeds the previous block time.
func proposerWaitTime(lt tmtime.Source, h types.Header) time.Duration {
t := lt.Now()
if t.After(h.Time) {
return 0
if h.Time.After(t) {
return h.Time.Sub(t)
}
return h.Time.Sub(t)
return 0
}
// proposalStepWaitingTime is used along with the `timeout-propose` configuration
@@ -2433,15 +2433,16 @@ func proposerWaitTime(lt tmtime.Source, h types.Header) time.Duration {
// deliver a block with a monotically increasing timestamp.
//
// To ensure that the validator waits long enough, it must wait until the previous
// block's timestamp. It also must account for inaccuracy in its own clock, inaccuracy
// in the proposer's clock and the amount of time for the message to be transmitted.
// block's timestamp. It also must account for the difference between its own clock and
// the proposer's clock, i.e. the 'Precision', and the amount of time for the message to be transmitted,
// i.e. the MsgDelay.
//
// The result of proposalStepWaitingTime is compared with the configured `timeout-propose` duration,
// and the validator waits for whichever duration is larger before advancing to the next step
// and prevoting nil.
func proposalStepWaitingTime(lt tmtime.Source, h types.Header, tp types.TimestampParams) time.Duration {
t := lt.Now()
wt := h.Time.Add(2 * tp.Accuracy).Add(tp.MsgDelay)
wt := h.Time.Add(tp.Precision).Add(tp.MsgDelay)
if t.After(wt) {
return 0
}

View File

@@ -2493,31 +2493,31 @@ func TestProposalTimeout(t *testing.T) {
name string
localTime time.Time
previousBlockTime time.Time
accuracy time.Duration
precision time.Duration
msgDelay time.Duration
expectedDuration time.Duration
}{
{
name: "MsgDelay + 2 * Accuracy has not quite elapsed",
name: "MsgDelay + Precision has not quite elapsed",
localTime: genesisTime.Add(525 * time.Millisecond),
previousBlockTime: genesisTime.Add(6 * time.Millisecond),
accuracy: time.Millisecond * 10,
precision: time.Millisecond * 20,
msgDelay: time.Millisecond * 500,
expectedDuration: 1 * time.Millisecond,
},
{
name: "MsgDelay + 2 * Accuracy equals current time",
name: "MsgDelay + Precision equals current time",
localTime: genesisTime.Add(525 * time.Millisecond),
previousBlockTime: genesisTime.Add(5 * time.Millisecond),
accuracy: time.Millisecond * 10,
precision: time.Millisecond * 20,
msgDelay: time.Millisecond * 500,
expectedDuration: 0,
},
{
name: "MsgDelay + 2 * Accuracy has elapsed",
name: "MsgDelay + Precision has elapsed",
localTime: genesisTime.Add(725 * time.Millisecond),
previousBlockTime: genesisTime.Add(5 * time.Millisecond),
accuracy: time.Millisecond * 10,
precision: time.Millisecond * 20,
msgDelay: time.Millisecond * 500,
expectedDuration: 0,
},
@@ -2534,8 +2534,8 @@ func TestProposalTimeout(t *testing.T) {
mockSource.On("Now").Return(testCase.localTime)
tp := types.TimestampParams{
Accuracy: testCase.accuracy,
MsgDelay: testCase.msgDelay,
Precision: testCase.precision,
MsgDelay: testCase.msgDelay,
}
ti := proposalStepWaitingTime(mockSource, b.Header, tp)