From 6ee6f349a1e15f385159b2866741f76e2c88e59c Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 23 Nov 2021 10:08:53 -0500 Subject: [PATCH] change accuracy to precision --- internal/consensus/state.go | 13 +++++++------ internal/consensus/state_test.go | 18 +++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index c51b36767..2e6d4eec9 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -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 } diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index fee073c37..c8adc2987 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -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)