types: Require vote extensions on non-nil precommits and not otherwise

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-05-10 11:00:55 -04:00
parent 68013b8fad
commit 15220bb7bb
2 changed files with 5 additions and 3 deletions

View File

@@ -67,7 +67,7 @@ func TestMsgToProto(t *testing.T) {
pv := types.NewMockPV()
vote, err := factory.MakeVote(ctx, pv, factory.DefaultTestChainID,
0, 1, 0, 2, types.BlockID{}, time.Now())
0, 1, 0, 2, bi, time.Now())
require.NoError(t, err)
pbVote := vote.ToProto()

View File

@@ -294,8 +294,10 @@ func (vote *Vote) ValidateBasic() error {
return fmt.Errorf("signature is too big (max: %d)", MaxSignatureSize)
}
// We should only ever see vote extensions in precommits.
if vote.Type != tmproto.PrecommitType {
// We should only ever see vote extensions in non-nil precommits, otherwise
// this is a violation of the specification.
// https://github.com/tendermint/tendermint/issues/8487
if vote.Type != tmproto.PrecommitType || (vote.Type == tmproto.PrecommitType && vote.BlockID.IsNil()) {
if len(vote.Extension) > 0 {
return errors.New("unexpected vote extension")
}