mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-17 20:56:14 +00:00
types: remove extra validation in VerifyCommit
plus make sure LastCommit is always non-nil
This commit is contained in:
+3
-6
@@ -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
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user