mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 13:51:21 +00:00
state.VerifyEvidence enforces EvidenceParams.MaxAge
This commit is contained in:
@ -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
|
// NOTE: return error may be ErrNoValSetForHeight, in which case the validator set
|
||||||
// for the evidence height could not be loaded.
|
// for the evidence height could not be loaded.
|
||||||
func (s *State) VerifyEvidence(evidence types.Evidence) (priority int, err error) {
|
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 {
|
if err := evidence.Verify(s.ChainID); err != nil {
|
||||||
return priority, err
|
return priority, err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ type BlockGossip struct {
|
|||||||
|
|
||||||
// EvidenceParams determine how we handle evidence of malfeasance
|
// EvidenceParams determine how we handle evidence of malfeasance
|
||||||
type EvidenceParams struct {
|
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.
|
// DefaultConsensusParams returns a default ConsensusParams.
|
||||||
@ -80,7 +80,7 @@ func DefaultBlockGossip() BlockGossip {
|
|||||||
// DefaultEvidence Params returns a default EvidenceParams.
|
// DefaultEvidence Params returns a default EvidenceParams.
|
||||||
func DefaultEvidenceParams() EvidenceParams {
|
func DefaultEvidenceParams() EvidenceParams {
|
||||||
return EvidenceParams{
|
return EvidenceParams{
|
||||||
MaxHeightDiff: 100000, // 27.8 hrs at 1block/s
|
MaxAge: 100000, // 27.8 hrs at 1block/s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user