mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 23:14:37 +00:00
save proposal time on roundstate
This commit is contained in:
+4
-6
@@ -30,7 +30,6 @@ type Proposal struct {
|
||||
BlockID BlockID `json:"block_id"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Signature []byte `json:"signature"`
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewProposal returns a new Proposal.
|
||||
@@ -90,16 +89,15 @@ func (p *Proposal) ValidateBasic() error {
|
||||
//
|
||||
// For more information on the meaning of 'timely', see the proposer-based timestamp specification:
|
||||
// https://github.com/tendermint/spec/tree/master/spec/consensus/proposer-based-timestamp
|
||||
func (p *Proposal) IsTimely(clock tmtime.Source, tp TimingParams, initialHeight int64) bool {
|
||||
localTime := clock.Now()
|
||||
func (p *Proposal) IsTimely(recvTime time.Time, tp TimingParams, initialHeight int64) bool {
|
||||
// lhs is `proposedBlockTime - Precision` in the first inequality
|
||||
lhs := p.Timestamp.Add(-tp.Precision)
|
||||
// rhs is `proposedBlockTime + MsgDelay + Precision` in the second inequality
|
||||
rhs := p.Timestamp.Add(tp.MessageDelay).Add(tp.Precision)
|
||||
|
||||
localTimeAfterOrEqLHS := localTime.After(lhs) || localTime.Equal(lhs)
|
||||
localTimeBeforeOrEqRHS := localTime.Before(rhs) || localTime.Equal(rhs)
|
||||
if localTimeAfterOrEqLHS && (p.Height == initialHeight || localTimeBeforeOrEqRHS) {
|
||||
recvTimeAfterOrEqLHS := recvTime.After(lhs) || recvTime.Equal(lhs)
|
||||
recvTimeBeforeOrEqRHS := recvTime.Before(rhs) || recvTime.Equal(rhs)
|
||||
if recvTimeAfterOrEqLHS && (p.Height == initialHeight || recvTimeBeforeOrEqRHS) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/tendermint/tendermint/internal/libs/protoio"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmtime "github.com/tendermint/tendermint/libs/time"
|
||||
tmtimemocks "github.com/tendermint/tendermint/libs/time/mocks"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
)
|
||||
|
||||
@@ -200,7 +199,7 @@ func TestIsTimely(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
proposalTime time.Time
|
||||
localTime time.Time
|
||||
recvTime time.Time
|
||||
precision time.Duration
|
||||
msgDelay time.Duration
|
||||
expectTimely bool
|
||||
@@ -211,7 +210,7 @@ func TestIsTimely(t *testing.T) {
|
||||
// 0 - 2 <= 1 <= 0 + 1 + 2
|
||||
name: "basic timely",
|
||||
proposalTime: genesisTime,
|
||||
localTime: genesisTime.Add(1 * time.Nanosecond),
|
||||
recvTime: genesisTime.Add(1 * time.Nanosecond),
|
||||
precision: time.Nanosecond * 2,
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: true,
|
||||
@@ -221,7 +220,7 @@ func TestIsTimely(t *testing.T) {
|
||||
// 0 - 2 <= 4 <= 0 + 1 + 2
|
||||
name: "local time too large",
|
||||
proposalTime: genesisTime,
|
||||
localTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
recvTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
precision: time.Nanosecond * 2,
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: false,
|
||||
@@ -231,7 +230,7 @@ func TestIsTimely(t *testing.T) {
|
||||
// 4 - 2 <= 0 <= 4 + 2 + 1
|
||||
name: "proposal time too large",
|
||||
proposalTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
localTime: genesisTime,
|
||||
recvTime: genesisTime,
|
||||
precision: time.Nanosecond * 2,
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: false,
|
||||
@@ -248,10 +247,7 @@ func TestIsTimely(t *testing.T) {
|
||||
MessageDelay: testCase.msgDelay,
|
||||
}
|
||||
|
||||
mockSource := new(tmtimemocks.Source)
|
||||
mockSource.On("Now").Return(testCase.localTime)
|
||||
|
||||
ti := p.IsTimely(mockSource, tp, 2)
|
||||
ti := p.IsTimely(testCase.recvTime, tp, 2)
|
||||
assert.Equal(t, testCase.expectTimely, ti)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user