switch to duration for easier use with timeout scheduling

This commit is contained in:
William Banfield
2021-11-14 17:09:35 -05:00
parent 6f173b8bba
commit 12eb73d51d
2 changed files with 10 additions and 10 deletions

View File

@@ -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)
}

View File

@@ -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)
})
}
}