Browse Source

types: remove extra validation in VerifyCommit

plus make sure LastCommit is always non-nil
pull/4808/head
Anton Kaliaev 5 years ago
committed by GitHub
parent
commit
826a7150b7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions
  1. +3
    -6
      state/validation.go
  2. +3
    -3
      types/block.go
  3. +10
    -5
      types/validator_set.go

+ 3
- 6
state/validation.go 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
types/block.go 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
types/validator_set.go 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


Loading…
Cancel
Save