From 7180e47e92b5bf0e7931c4df768d3739b7a5f8c9 Mon Sep 17 00:00:00 2001 From: Anca Zamfir Date: Thu, 9 Dec 2021 08:06:55 -0500 Subject: [PATCH] Prevote nil if not timely --- config/toml.go | 4 ++-- internal/consensus/common_test.go | 2 +- internal/consensus/pbts_test.go | 2 +- internal/consensus/state.go | 10 ++++++++++ types/params.go | 4 ++-- types/proposal.go | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/config/toml.go b/config/toml.go index 0319f0902..f2e60eaf1 100644 --- a/config/toml.go +++ b/config/toml.go @@ -570,8 +570,8 @@ var testGenesisFmt = `{ "time_iota_ms": "10" }, "timing": { - "message_delay": "200", - "precision": "50" + "message_delay": "500000000", + "precision": "10000000" }, "evidence": { "max_age_num_blocks": "100000", diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index 550c60b2b..b0458a5a6 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -41,7 +41,7 @@ const ( testSubscriber = "test-client" // genesis, chain_id, priv_val - ensureTimeout = time.Millisecond * 200 + ensureTimeout = time.Second ) // A cleanupFunc cleans up any config / test files created for a particular diff --git a/internal/consensus/pbts_test.go b/internal/consensus/pbts_test.go index 7d8755470..9cc661553 100644 --- a/internal/consensus/pbts_test.go +++ b/internal/consensus/pbts_test.go @@ -407,7 +407,7 @@ func TestProposerWaitsForGenesisTime(t *testing.T) { cfg := pbtsTestConfiguration{ timingParams: types.TimingParams{ Precision: 10 * time.Millisecond, - MessageDelay: 10 * time.Millisecond, + MessageDelay: 100 * time.Millisecond, }, timeoutPropose: 10 * time.Millisecond, genesisTime: initialTime, diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 29e72d234..46cce3eb1 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -36,6 +36,7 @@ import ( var ( ErrInvalidProposalSignature = errors.New("error invalid proposal signature") ErrInvalidProposalPOLRound = errors.New("error invalid proposal POL round") + ErrInvalidProposalNotTimely = errors.New("error invalid proposal un-timely block timestamp ") ErrAddingVote = errors.New("error adding vote") ErrSignatureFoundInPastBlocks = errors.New("found signature from the same key") @@ -1886,6 +1887,15 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error { return ErrInvalidProposalPOLRound } + // Verify timely + tp := types.TimingParams{ + Precision: cs.state.ConsensusParams.Timing.Precision, + MessageDelay: cs.state.ConsensusParams.Timing.MessageDelay, + } + if proposal.POLRound == -1 && !proposal.IsTimely(tmtime.DefaultSource{}, tp) { + return ErrInvalidProposalNotTimely + } + p := proposal.ToProto() // Verify signature if !cs.Validators.GetProposer().PubKey.VerifySignature( diff --git a/types/params.go b/types/params.go index 255181415..90f29e66a 100644 --- a/types/params.go +++ b/types/params.go @@ -129,8 +129,8 @@ func DefaultTimingParams() TimingParams { // TODO(@wbanfield): Determine experimental values for these defaults // https://github.com/tendermint/tendermint/issues/7202 return TimingParams{ - Precision: 1 * time.Nanosecond, - MessageDelay: 1 * time.Nanosecond, + Precision: 10 * time.Millisecond, + MessageDelay: 500 * time.Millisecond, } } diff --git a/types/proposal.go b/types/proposal.go index 26df39a56..d09a993fb 100644 --- a/types/proposal.go +++ b/types/proposal.go @@ -90,8 +90,8 @@ func (p *Proposal) ValidateBasic() error { // https://github.com/tendermint/spec/tree/master/spec/consensus/proposer-based-timestamp func (p *Proposal) IsTimely(clock tmtime.Source, tp TimingParams) bool { lt := clock.Now() - lhs := lt.Add(-tp.Precision) - rhs := lt.Add(tp.Precision).Add(tp.MessageDelay) + lhs := lt.Add(-tp.Precision).Add(-tp.MessageDelay) + rhs := lt.Add(tp.Precision) if lhs.Before(p.Timestamp) && rhs.After(p.Timestamp) { return true }