mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-12 19:16:10 +00:00
Use proposer timestamp instead of genesis time for height 1 block time (#7541)
This commit is contained in:
+2
-5
@@ -87,20 +87,17 @@ func (p *Proposal) ValidateBasic() error {
|
||||
// localtime >= proposedBlockTime - Precision
|
||||
// localtime <= proposedBlockTime + MsgDelay + Precision
|
||||
//
|
||||
// Note: If the proposal is for the `initialHeight` the second inequality is not checked. This is because
|
||||
// the timestamp in this case is set to the preconfigured genesis time.
|
||||
// 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(recvTime time.Time, sp SynchronyParams, initialHeight int64) bool {
|
||||
func (p *Proposal) IsTimely(recvTime time.Time, sp SynchronyParams) bool {
|
||||
// lhs is `proposedBlockTime - Precision` in the first inequality
|
||||
lhs := p.Timestamp.Add(-sp.Precision)
|
||||
// rhs is `proposedBlockTime + MsgDelay + Precision` in the second inequality
|
||||
rhs := p.Timestamp.Add(sp.MessageDelay).Add(sp.Precision)
|
||||
|
||||
if recvTime.Before(lhs) || (p.Height != initialHeight && recvTime.After(rhs)) {
|
||||
if recvTime.Before(lhs) || recvTime.After(rhs) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+1
-31
@@ -217,7 +217,6 @@ func TestIsTimely(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
testCases := []struct {
|
||||
name string
|
||||
genesisHeight int64
|
||||
proposalHeight int64
|
||||
proposalTime time.Time
|
||||
recvTime time.Time
|
||||
@@ -230,7 +229,6 @@ func TestIsTimely(t *testing.T) {
|
||||
// Checking that the following inequality evaluates to true:
|
||||
// 0 - 2 <= 1 <= 0 + 1 + 2
|
||||
name: "basic timely",
|
||||
genesisHeight: 1,
|
||||
proposalHeight: 2,
|
||||
proposalTime: genesisTime,
|
||||
recvTime: genesisTime.Add(1 * time.Nanosecond),
|
||||
@@ -242,7 +240,6 @@ func TestIsTimely(t *testing.T) {
|
||||
// Checking that the following inequality evaluates to false:
|
||||
// 0 - 2 <= 4 <= 0 + 1 + 2
|
||||
name: "local time too large",
|
||||
genesisHeight: 1,
|
||||
proposalHeight: 2,
|
||||
proposalTime: genesisTime,
|
||||
recvTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
@@ -254,7 +251,6 @@ func TestIsTimely(t *testing.T) {
|
||||
// Checking that the following inequality evaluates to false:
|
||||
// 4 - 2 <= 0 <= 4 + 2 + 1
|
||||
name: "proposal time too large",
|
||||
genesisHeight: 1,
|
||||
proposalHeight: 2,
|
||||
proposalTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
recvTime: genesisTime,
|
||||
@@ -262,32 +258,6 @@ func TestIsTimely(t *testing.T) {
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: false,
|
||||
},
|
||||
{
|
||||
// Checking that the following inequality evaluates to true:
|
||||
// 0 - 2 <= 4
|
||||
// and the following check is skipped
|
||||
// 4 <= 0 + 1 + 2
|
||||
name: "local time too large but proposal is for genesis",
|
||||
genesisHeight: 1,
|
||||
proposalHeight: 1,
|
||||
proposalTime: genesisTime,
|
||||
recvTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
precision: time.Nanosecond * 2,
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: true,
|
||||
},
|
||||
{
|
||||
// Checking that the following inequality evaluates to false:
|
||||
// 4 - 2 <= 0
|
||||
name: "proposal time too large for genesis block proposal",
|
||||
genesisHeight: 1,
|
||||
proposalHeight: 1,
|
||||
proposalTime: genesisTime.Add(4 * time.Nanosecond),
|
||||
recvTime: genesisTime,
|
||||
precision: time.Nanosecond * 2,
|
||||
msgDelay: time.Nanosecond,
|
||||
expectTimely: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
@@ -302,7 +272,7 @@ func TestIsTimely(t *testing.T) {
|
||||
MessageDelay: testCase.msgDelay,
|
||||
}
|
||||
|
||||
ti := p.IsTimely(testCase.recvTime, sp, testCase.genesisHeight)
|
||||
ti := p.IsTimely(testCase.recvTime, sp)
|
||||
assert.Equal(t, testCase.expectTimely, ti)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user