Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: sanitize gov v1 proposal in e2e tests for compatibility with 0.52 #7861

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
cosmossdk.io/errors v1.0.1
cosmossdk.io/math v1.5.0
cosmossdk.io/x/upgrade v0.1.4
cosmossdk.io/api v0.8.1
github.com/cometbft/cometbft v1.0.0
github.com/cosmos/cosmos-sdk v0.53.0
github.com/cosmos/gogoproto v1.7.0
Expand Down
54 changes: 54 additions & 0 deletions e2e/testsuite/sanitize/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

cmtcrypto "github.com/cometbft/cometbft/api/cometbft/crypto/v1"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"

"github.com/cosmos/ibc-go/e2e/semverutil"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"
)

var (
Expand All @@ -28,6 +33,14 @@ var (
"v8.1",
},
}
// groupsv1ProposalProposalType represents the releases that support the new proposal type field.
govv1ProposalProposalType = semverutil.FeatureReleases{
MajorVersion: "v10",
}
// cometBFTv1Validator represents the releases that support the new validator fields.
cometBFTv1Validator = semverutil.FeatureReleases{
MajorVersion: "v10",
}
)

// Messages removes any fields that are not supported by the chain version.
Expand All @@ -49,6 +62,9 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
msg.Title = ""
msg.Summary = ""
}
if !govv1ProposalProposalType.IsSupported(tag) {
msg.ProposalType = govtypesv1.ProposalType_PROPOSAL_TYPE_UNSPECIFIED
}
// sanitize messages contained in the x/gov proposal
msgs, err := msg.GetMsgs()
if err != nil {
Expand Down Expand Up @@ -78,6 +94,44 @@ func removeUnknownFields(tag string, msg sdk.Msg) sdk.Msg {
if !icaUnorderedChannelFeatureReleases.IsSupported(tag) {
msg.Ordering = channeltypes.NONE
}
case *clienttypes.MsgUpdateClient:
if !cometBFTv1Validator.IsSupported(tag) {
clientMessage, err := clienttypes.UnpackClientMessage(msg.ClientMessage)
if err != nil {
panic(err)
}
header, ok := clientMessage.(*ibctm.Header)
if !ok {
return msg
}

replaceCometBFTValidatorV1(header.ValidatorSet.Proposer)
for _, validator := range header.ValidatorSet.Validators {
replaceCometBFTValidatorV1(validator)
}

replaceCometBFTValidatorV1(header.TrustedValidators.Proposer)
for _, validator := range header.TrustedValidators.Validators {
replaceCometBFTValidatorV1(validator)
}

// repack the client message
clientMessageAny, err := clienttypes.PackClientMessage(header)
if err != nil {
panic(err)
}
msg.ClientMessage = clientMessageAny
}
}
return msg
}

func replaceCometBFTValidatorV1(validator *cmtproto.Validator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe mutate or convert instead of replace. since i expected this to be returning a new type rather than mutating in-place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Done!

validator.PubKey = &cmtcrypto.PublicKey{
Sum: &cmtcrypto.PublicKey_Ed25519{
Ed25519: validator.PubKeyBytes,
},
}
validator.PubKeyBytes = nil
validator.PubKeyType = ""
}
Loading