Prevote nil if not timely

This commit is contained in:
Anca Zamfir
2021-12-09 08:25:54 -05:00
parent b03dced9af
commit 7180e47e92
6 changed files with 18 additions and 8 deletions
+2 -2
View File
@@ -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",
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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,
+10
View File
@@ -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(
+2 -2
View File
@@ -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,
}
}
+2 -2
View File
@@ -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
}