Votes constructed from commits cannot include extensions or signatures

Signed-off-by: Thane Thomson <connect@thanethomson.com>
This commit is contained in:
Thane Thomson
2022-04-05 14:12:45 -04:00
parent 89385531e7
commit 9b12360bc2
2 changed files with 13 additions and 3 deletions

View File

@@ -274,7 +274,7 @@ func TestCommit(t *testing.T) {
require.NotNil(t, commit.BitArray())
assert.Equal(t, bits.NewBitArray(10).Size(), commit.BitArray().Size())
assert.Equal(t, voteSet.GetByIndex(0), commit.GetByIndex(0))
assert.Equal(t, voteWithoutExtension(voteSet.GetByIndex(0)), commit.GetByIndex(0))
assert.True(t, commit.IsCommit())
}
@@ -571,8 +571,8 @@ func TestCommitToVoteSet(t *testing.T) {
voteSet2 := CommitToVoteSet(chainID, commit, valSet)
for i := int32(0); int(i) < len(vals); i++ {
vote1 := voteSet.GetByIndex(i)
vote2 := voteSet2.GetByIndex(i)
vote1 := voteWithoutExtension(voteSet.GetByIndex(i))
vote2 := voteWithoutExtension(voteSet2.GetByIndex(i))
vote3 := commit.GetVote(i)
vote1bz, err := vote1.ToProto().Marshal()

View File

@@ -46,3 +46,13 @@ func signAddVote(ctx context.Context, privVal PrivValidator, vote *Vote, voteSet
vote.ExtensionSignature = v.ExtensionSignature
return voteSet.AddVote(vote)
}
// Votes constructed from commits don't have extensions, because we don't store
// the extensions themselves in the commit. This method is used to construct a
// copy of a vote, but nil its extension and signature.
func voteWithoutExtension(v *Vote) *Vote {
vc := v.Copy()
vc.Extension = nil
vc.ExtensionSignature = nil
return vc
}