mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-22 15:16:24 +00:00
Mark proposal invalid in SetProposal, fix in the future test
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user