ibc: check commit against blockID

This commit is contained in:
Ethan Buchman 2017-02-14 01:34:24 -05:00
parent dcfc9a542d
commit 67cf948f26
1 changed files with 6 additions and 7 deletions

View File

@ -431,23 +431,22 @@ func verifyCommit(chainState BlockchainState, header *tm.Header, commit *tm.Comm
return errors.New(cmn.Fmt("Commit has no signatures"))
}
chainID := chainState.ChainID
vote0 := commit.Precommits[0]
vals := chainState.Validators
valSet := tm.NewValidatorSet(vals)
// Ensure the commit is for the header
if !bytes.Equal(header.Hash(), vote0.BlockID.Hash) {
return errors.New(cmn.Fmt("Commit.BlockID.Hash (%X) does not match header.Hash (%X)", vote0.BlockID.Hash, header.Hash()))
}
// NOTE: Currently this only works with the exact same validator set.
// Not this, but perhaps "ValidatorSet.VerifyCommitAny" should expose
// the functionality to verify commits even after validator changes.
err := valSet.VerifyCommit(chainID, vote0.BlockID, vote0.Height, commit)
blockID, err := valSet.VerifyCommitReturnBlockID(chainID, header.Height, commit)
if err != nil {
return err
}
// Ensure the committed blockID matches the header
if !bytes.Equal(header.Hash(), blockID.Hash) {
return errors.New(cmn.Fmt("blockID.Hash (%X) does not match header.Hash (%X)", blockID.Hash, header.Hash()))
}
// All ok!
return nil
}