Skip to content

Commit

Permalink
fix: vote extension marshal panic
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Dec 21, 2023
1 parent 9e1d9a1 commit 615251a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
16 changes: 9 additions & 7 deletions abci/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,19 @@ func (m *RequestFinalizeBlock) ToCanonicalVote() (types.CanonicalVote, error) {
// Convert to proto.types.VoteExtension.
// Signature field will be nil, as ExtendVoteExtension doesn't have it.
func (m *ExtendVoteExtension) ToVoteExtension() types.VoteExtension {
var requestID *types.VoteExtension_SignRequestId
ve := types.VoteExtension{
Type: m.Type,
Extension: m.Extension,
}

// workaround for a bug in gogoproto
if m.XSignRequestId != nil {
src := m.GetSignRequestId()

requestID = &types.VoteExtension_SignRequestId{
ve.XSignRequestId = &types.VoteExtension_SignRequestId{
SignRequestId: bytes.Clone(src),
}
}
return types.VoteExtension{
Type: m.Type,
Extension: m.Extension,
XSignRequestId: requestID,
}

return ve
}
30 changes: 14 additions & 16 deletions proto/tendermint/types/dash.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,19 @@ func (v *VoteExtension) Clone() VoteExtension {
panic("cannot clone nil vote-extension")
}

var xSignRequestID isVoteExtension_XSignRequestId
ve := VoteExtension{
Type: v.Type,
Extension: v.Extension,
Signature: v.Signature,
}

if v.XSignRequestId != nil && v.XSignRequestId.Size() > 0 {
xSignRequestID = &VoteExtension_SignRequestId{
ve.XSignRequestId = &VoteExtension_SignRequestId{
SignRequestId: v.GetSignRequestId(),
}
}

return VoteExtension{
Type: v.Type,
Extension: v.Extension,
Signature: v.Signature,
XSignRequestId: xSignRequestID,
}
return ve
}

// Copy returns a deep copy of current vote-extension.
Expand All @@ -50,20 +49,19 @@ func (v *VoteExtension) Copy() VoteExtension {
panic("cannot copy nil vote-extension")
}

var xSignRequestID isVoteExtension_XSignRequestId
ve := VoteExtension{
Type: v.Type,
Extension: bytes.Clone(v.Extension),
Signature: bytes.Clone(v.Signature),
}

if v.XSignRequestId != nil && v.XSignRequestId.Size() > 0 {
xSignRequestID = &VoteExtension_SignRequestId{
ve.XSignRequestId = &VoteExtension_SignRequestId{
SignRequestId: bytes.Clone(v.GetSignRequestId()),
}
}

return VoteExtension{
Type: v.Type,
Extension: bytes.Clone(v.Extension),
Signature: bytes.Clone(v.Signature),
XSignRequestId: xSignRequestID,
}
return ve
}

func (v *VoteExtension) Equal(other *VoteExtension) bool {
Expand Down
13 changes: 6 additions & 7 deletions types/vote_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,20 @@ func (e VoteExtensions) ToExtendProto() []*abci.ExtendVoteExtension {
}

pb := ext.ToProto()
eve := &abci.ExtendVoteExtension{
Type: pb.Type,
Extension: pb.Extension,
}

var requestID *abci.ExtendVoteExtension_SignRequestId
if pb.XSignRequestId != nil {
if src := pb.GetSignRequestId(); len(src) > 0 {
requestID = &abci.ExtendVoteExtension_SignRequestId{
eve.XSignRequestId = &abci.ExtendVoteExtension_SignRequestId{
SignRequestId: bytes.Clone(src),
}
}
}

proto = append(proto, &abci.ExtendVoteExtension{
Type: pb.Type,
Extension: pb.Extension,
XSignRequestId: requestID,
})
proto = append(proto, eve)
}

return proto
Expand Down

0 comments on commit 615251a

Please sign in to comment.