types: reject blocks w/ ConflictingHeadersEvidence (#5041)

* types: reject blocks w/ ConflictingHeadersEvidence

Closes #5037

* types: reject blocks w/ PotentialAmnesiaEvidence

as well

PotentialAmnesiaEvidence does not contribute anything on its own,
therefore should not be committed on chain.

* fix lint issue
This commit is contained in:
Anton Kaliaev
2020-06-23 16:55:16 +04:00
committed by GitHub
parent ceac02b891
commit 44b306b38e
2 changed files with 17 additions and 0 deletions

View File

@@ -89,6 +89,17 @@ func (b *Block) ValidateBasic() error {
// NOTE: b.Evidence.Evidence may be nil, but we're just looping.
for i, ev := range b.Evidence.Evidence {
switch ev.(type) {
case *ConflictingHeadersEvidence, ConflictingHeadersEvidence:
// ConflictingHeadersEvidence must be broken up in pieces and never
// committed as a single piece.
return fmt.Errorf("found ConflictingHeadersEvidence (#%d)", i)
case *PotentialAmnesiaEvidence, PotentialAmnesiaEvidence:
// PotentialAmnesiaEvidence does not contribute to anything on its own, so
// reject it as well.
return fmt.Errorf("found PotentialAmnesiaEvidence (#%d)", i)
}
if err := ev.ValidateBasic(); err != nil {
return fmt.Errorf("invalid evidence (#%d): %v", i, err)
}

View File

@@ -86,6 +86,12 @@ func TestBlockValidateBasic(t *testing.T) {
{"Tampered EvidenceHash", func(blk *Block) {
blk.EvidenceHash = []byte("something else")
}, true},
{"ConflictingHeadersEvidence", func(blk *Block) {
blk.Evidence = EvidenceData{Evidence: []Evidence{&ConflictingHeadersEvidence{}}}
}, true},
{"PotentialAmnesiaEvidence", func(blk *Block) {
blk.Evidence = EvidenceData{Evidence: []Evidence{&PotentialAmnesiaEvidence{}}}
}, true},
}
for i, tc := range testCases {
tc := tc