From 4a3e47decc83b44110123c270098beb0b431bf18 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Fri, 13 May 2022 15:43:40 -0400 Subject: [PATCH] split ensure extension out of reactor validation --- internal/consensus/msgs.go | 6 +----- types/vote.go | 18 ++---------------- types/vote_test.go | 10 +++++----- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/internal/consensus/msgs.go b/internal/consensus/msgs.go index c59c06a41..1024c24ae 100644 --- a/internal/consensus/msgs.go +++ b/internal/consensus/msgs.go @@ -222,11 +222,7 @@ func (*VoteMessage) TypeTag() string { return "tendermint/Vote" } // ValidateBasic checks whether the vote within the message is well-formed. func (m *VoteMessage) ValidateBasic() error { - // Here we validate votes with vote extensions, since we require vote - // extensions to be sent in precommit messages during consensus. Prevote - // messages should never have vote extensions, and this is also validated - // here. - return m.Vote.ValidateWithExtension() + return m.Vote.ValidateBasic() } // String returns a string representation. diff --git a/types/vote.go b/types/vote.go index fb5ee3578..5a3598387 100644 --- a/types/vote.go +++ b/types/vote.go @@ -305,22 +305,8 @@ func (vote *Vote) ValidateBasic() error { return nil } -// ValidateWithExtension performs the same validations as ValidateBasic, but -// additionally checks whether a vote extension signature is present. This -// function is used in places where vote extension signatures are expected. -func (vote *Vote) ValidateWithExtension() error { - if err := vote.ValidateBasic(); err != nil { - return err - } - - if err := vote.EnsureExtension(); err != nil { - return err - } - - return nil -} - -// +// EnsureExtension checks for the presence of extensions signature data +// on precommit vote types. func (vote *Vote) EnsureExtension() error { // We should always see vote extension signatures in non-nil precommits if vote.Type == tmproto.PrecommitType && !vote.BlockID.IsNil() { diff --git a/types/vote_test.go b/types/vote_test.go index 70cd91381..6188131e0 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -361,7 +361,7 @@ func TestValidVotes(t *testing.T) { signVote(ctx, t, privVal, "test_chain_id", tc.vote) tc.malleateVote(tc.vote) require.NoError(t, tc.vote.ValidateBasic(), "ValidateBasic for %s", tc.name) - require.NoError(t, tc.vote.ValidateWithExtension(), "ValidateWithExtension for %s", tc.name) + require.NoError(t, tc.vote.EnsureExtension(), "EnsureExtension for %s", tc.name) } } @@ -387,13 +387,13 @@ func TestInvalidVotes(t *testing.T) { signVote(ctx, t, privVal, "test_chain_id", prevote) tc.malleateVote(prevote) require.Error(t, prevote.ValidateBasic(), "ValidateBasic for %s in invalid prevote", tc.name) - require.Error(t, prevote.ValidateWithExtension(), "ValidateWithExtension for %s in invalid prevote", tc.name) + require.Error(t, prevote.EnsureExtension(), "EnsureExtension for %s in invalid prevote", tc.name) precommit := examplePrecommit(t) signVote(ctx, t, privVal, "test_chain_id", precommit) tc.malleateVote(precommit) require.Error(t, precommit.ValidateBasic(), "ValidateBasic for %s in invalid precommit", tc.name) - require.Error(t, precommit.ValidateWithExtension(), "ValidateWithExtension for %s in invalid precommit", tc.name) + require.Error(t, precommit.EnsureExtension(), "EnsureExtension for %s in invalid precommit", tc.name) } } @@ -414,7 +414,7 @@ func TestInvalidPrevotes(t *testing.T) { signVote(ctx, t, privVal, "test_chain_id", prevote) tc.malleateVote(prevote) require.Error(t, prevote.ValidateBasic(), "ValidateBasic for %s", tc.name) - require.Error(t, prevote.ValidateWithExtension(), "ValidateWithExtension for %s", tc.name) + require.Error(t, prevote.EnsureExtension(), "EnsureExtension for %s", tc.name) } } @@ -442,7 +442,7 @@ func TestInvalidPrecommitExtensions(t *testing.T) { // We don't expect an error from ValidateBasic, because it doesn't // handle vote extensions. require.NoError(t, precommit.ValidateBasic(), "ValidateBasic for %s", tc.name) - require.Error(t, precommit.ValidateWithExtension(), "ValidateWithExtension for %s", tc.name) + require.Error(t, precommit.EnsureExtension(), "EnsureExtension for %s", tc.name) } }