types: remove extra validation in VerifyCommit

plus make sure LastCommit is always non-nil
This commit is contained in:
Anton Kaliaev
2020-05-07 09:49:51 +00:00
committed by GitHub
parent 413e554fd0
commit 826a7150b7
3 changed files with 16 additions and 14 deletions
+3 -6
View File
@@ -86,12 +86,9 @@ func validateBlock(evidencePool EvidencePool, stateDB dbm.DB, state State, block
return errors.New("block at height 1 can't have LastCommit signatures")
}
} else {
if len(block.LastCommit.Signatures) != state.LastValidators.Size() {
return types.NewErrInvalidCommitSignatures(state.LastValidators.Size(), len(block.LastCommit.Signatures))
}
err := state.LastValidators.VerifyCommit(
state.ChainID, state.LastBlockID, block.Height-1, block.LastCommit)
if err != nil {
// LastCommit.Signatures length is checked in VerifyCommit.
if err := state.LastValidators.VerifyCommit(
state.ChainID, state.LastBlockID, block.Height-1, block.LastCommit); err != nil {
return err
}
}
+3 -3
View File
@@ -60,10 +60,10 @@ func (b *Block) ValidateBasic() error {
}
// Validate the last commit and its hash.
if b.LastCommit == nil {
return errors.New("nil LastCommit")
}
if b.Header.Height > 1 {
if b.LastCommit == nil {
return errors.New("nil LastCommit")
}
if err := b.LastCommit.ValidateBasic(); err != nil {
return fmt.Errorf("wrong LastCommit: %v", err)
}
+10 -5
View File
@@ -642,8 +642,13 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
return NewErrInvalidCommitSignatures(vals.Size(), len(commit.Signatures))
}
if err := commit.ValidateBasic(); err != nil {
return err
// Validate Height and BlockID.
if height != commit.Height {
return NewErrInvalidCommitHeight(height, commit.Height)
}
if !blockID.Equals(commit.BlockID) {
return fmt.Errorf("invalid commit -- wrong block ID: want %v, got %v",
blockID, commit.BlockID)
}
if height != commit.Height {
return NewErrInvalidCommitHeight(height, commit.Height)
@@ -670,12 +675,12 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
}
// Good!
if blockID.Equals(commitSig.BlockID(commit.BlockID)) {
if commitSig.ForBlock() {
talliedVotingPower += val.VotingPower
}
// else {
// It's OK that the BlockID doesn't match. We include stray
// signatures (~votes for nil) to measure validator availability.
// It's OK. We include stray signatures (~votes for nil) to measure
// validator availability.
// }
// return as soon as +2/3 of the signatures are verified