Mark proposal invalid in SetProposal, fix in the future test

This commit is contained in:
Anca Zamfir
2021-12-21 20:28:53 +01:00
parent f95abc275c
commit 6b8cf31510
3 changed files with 9 additions and 9 deletions
+1
View File
@@ -486,6 +486,7 @@ func TestTooFarInTheFutureProposal(t *testing.T) {
genesisTime: initialTime,
height2ProposedBlockTime: initialTime.Add(100 * time.Millisecond),
height2ProposalDeliverTime: initialTime.Add(10 * time.Millisecond),
height4ProposedBlockTime: initialTime.Add(150 * time.Millisecond),
}
pbtsTest := newPBTSTestHarness(ctx, t, cfg)
+5 -7
View File
@@ -36,7 +36,6 @@ 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")
@@ -1370,7 +1369,7 @@ func (cs *State) defaultDoPrevote(height int64, round int32) {
*/
if cs.Proposal.POLRound == -1 {
if cs.LockedRound == -1 {
if !cs.proposalIsTimely(cs.Proposal) {
if !cs.Proposal.Valid {
logger.Debug("prevote step: ProposalBlock is not timely; prevoting nil")
cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{})
return
@@ -1926,11 +1925,6 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error {
return ErrInvalidProposalPOLRound
}
// Verify that the proposal is not too far in the past or future
//if !cs.proposalIsTimely(proposal) {
// return ErrInvalidProposalNotTimely
//}
p := proposal.ToProto()
// Verify signature
if !cs.Validators.GetProposer().PubKey.VerifySignature(
@@ -1948,6 +1942,10 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error {
cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockID.PartSetHeader)
}
// Mark the proposal as invalid if too far in the past or future
if proposal.POLRound > -1 || cs.proposalIsTimely(proposal) {
cs.Proposal.Valid = true
}
cs.Logger.Info("received proposal", "proposal", proposal)
return nil
}
+3 -2
View File
@@ -30,6 +30,7 @@ type Proposal struct {
BlockID BlockID `json:"block_id"`
Timestamp time.Time `json:"timestamp"`
Signature []byte `json:"signature"`
Valid bool
}
// NewProposal returns a new Proposal.
@@ -89,7 +90,7 @@ 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, genesisHeight int64) bool {
func (p *Proposal) IsTimely(clock tmtime.Source, tp TimingParams, initialHeight int64) bool {
localTime := clock.Now()
// lhs is `proposedBlockTime - Precision` in the first inequality
lhs := p.Timestamp.Add(-tp.Precision)
@@ -98,7 +99,7 @@ func (p *Proposal) IsTimely(clock tmtime.Source, tp TimingParams, genesisHeight
localTimeAfterOrEqLHS := localTime.After(lhs) || localTime.Equal(lhs)
localTimeBeforeOrEqRHS := localTime.Before(rhs) || localTime.Equal(rhs)
if localTimeAfterOrEqLHS && (p.Height == genesisHeight || localTimeBeforeOrEqRHS) {
if localTimeAfterOrEqLHS && (p.Height == initialHeight || localTimeBeforeOrEqRHS) {
return true
}
return false