diff --git a/state/state.go b/state/state.go index 871e2f708..54ad0b104 100644 --- a/state/state.go +++ b/state/state.go @@ -389,6 +389,13 @@ func (s *State) GetValidators() (last *types.ValidatorSet, current *types.Valida // NOTE: return error may be ErrNoValSetForHeight, in which case the validator set // for the evidence height could not be loaded. func (s *State) VerifyEvidence(evidence types.Evidence) (priority int, err error) { + evidenceAge := s.LastBlockHeight - evidence.Height() + maxAge := s.Params.EvidenceParams.MaxAge + if evidenceAge > maxAge { + return priority, fmt.Errorf("Evidence from height %d is too old. Min height is %d", + evidence.Height(), s.LastBlockHeight-maxAge) + } + if err := evidence.Verify(s.ChainID); err != nil { return priority, err } diff --git a/types/params.go b/types/params.go index 15d8dbe21..216f13907 100644 --- a/types/params.go +++ b/types/params.go @@ -40,7 +40,7 @@ type BlockGossip struct { // EvidenceParams determine how we handle evidence of malfeasance type EvidenceParams struct { - MaxHeightDiff int `json:"max_height_diff"` // only accept new evidence more recent than this + MaxAge int `json:"max_age"` // only accept new evidence more recent than this } // DefaultConsensusParams returns a default ConsensusParams. @@ -80,7 +80,7 @@ func DefaultBlockGossip() BlockGossip { // DefaultEvidence Params returns a default EvidenceParams. func DefaultEvidenceParams() EvidenceParams { return EvidenceParams{ - MaxHeightDiff: 100000, // 27.8 hrs at 1block/s + MaxAge: 100000, // 27.8 hrs at 1block/s } }