Browse Source

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
pull/5040/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
44b306b38e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions
  1. +11
    -0
      types/block.go
  2. +6
    -0
      types/block_test.go

+ 11
- 0
types/block.go 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)
}


+ 6
- 0
types/block_test.go 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


Loading…
Cancel
Save