From 12eb73d51de4ad7dc29bc1055164a785334b57fc Mon Sep 17 00:00:00 2001 From: William Banfield Date: Sun, 14 Nov 2021 17:09:35 -0500 Subject: [PATCH] switch to duration for easier use with timeout scheduling --- internal/consensus/state.go | 8 ++++---- internal/consensus/state_test.go | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 4646426a6..4adc00fa7 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -2413,14 +2413,14 @@ func repairWalFile(src, dst string) error { return nil } -// proposerWaitUntil determines when the proposer should propose its next block +// proposerWaitTime determines how long the proposer should wait to propose its next block. // Block times must be monotonically increasing, so if the block time of the previous // block is larger than the proposer's current time, then the proposer will sleep // until its local clock exceeds the previous block time. -func proposerWaitUntil(lt tmtime.Source, h types.Header) time.Time { +func proposerWaitTime(lt tmtime.Source, h types.Header) time.Duration { t := lt.Now() if t.After(h.Time) { - return t + return 0 } - return h.Time + return h.Time.Sub(t) } diff --git a/internal/consensus/state_test.go b/internal/consensus/state_test.go index 767f5defc..f0b193422 100644 --- a/internal/consensus/state_test.go +++ b/internal/consensus/state_test.go @@ -2448,25 +2448,25 @@ func TestProposerWaitUntil(t *testing.T) { name string blockTime time.Time localTime time.Time - expectedTime time.Time + expectedWait time.Duration }{ { name: "block time greater than local time", blockTime: genesisTime.Add(5 * time.Nanosecond), localTime: genesisTime.Add(1 * time.Nanosecond), - expectedTime: genesisTime.Add(5 * time.Nanosecond), + expectedWait: 4 * time.Nanosecond, }, { name: "local time greater than block time", blockTime: genesisTime.Add(1 * time.Nanosecond), localTime: genesisTime.Add(5 * time.Nanosecond), - expectedTime: genesisTime.Add(5 * time.Nanosecond), + expectedWait: 0, }, { name: "both times equal", blockTime: genesisTime.Add(5 * time.Nanosecond), localTime: genesisTime.Add(5 * time.Nanosecond), - expectedTime: genesisTime.Add(5 * time.Nanosecond), + expectedWait: 0, }, } for _, testCase := range testCases { @@ -2480,8 +2480,8 @@ func TestProposerWaitUntil(t *testing.T) { mockSource := new(tmtimemocks.Source) mockSource.On("Now").Return(testCase.localTime) - ti := proposerWaitUntil(mockSource, b.Header) - assert.Equal(t, testCase.expectedTime, ti) + ti := proposerWaitTime(mockSource, b.Header) + assert.Equal(t, testCase.expectedWait, ti) }) } }