Skip to content

Commit

Permalink
sanitize validator for cometbft v1
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Jan 20, 2025
1 parent b400592 commit f40b1c6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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
48 changes: 48 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,9 +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 Down Expand Up @@ -84,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) {
validator.PubKey = &cmtcrypto.PublicKey{
Sum: &cmtcrypto.PublicKey_Ed25519{
Ed25519: validator.PubKeyBytes,
},
}
validator.PubKeyBytes = nil
validator.PubKeyType = ""
}

0 comments on commit f40b1c6

Please sign in to comment.