From 0ee56e36e73f31672bb1408f564686e356d4731d Mon Sep 17 00:00:00 2001 From: blushi Date: Thu, 10 Mar 2022 11:34:43 +0100 Subject: [PATCH 1/7] Add RegisterAminoMsg fn --- baseapp/baseapp_test.go | 10 +++++----- codec/amino.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index d6505bfee94d..ab26281d13e0 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -106,10 +106,10 @@ func newBaseApp(name string, options ...func(*baseapp.BaseApp)) *baseapp.BaseApp func registerTestCodec(cdc *codec.LegacyAmino) { // register test types cdc.RegisterConcrete(&txTest{}, "cosmos-sdk/baseapp/txTest", nil) - cdc.RegisterConcrete(&msgCounter{}, "cosmos-sdk/baseapp/msgCounter", nil) - cdc.RegisterConcrete(&msgCounter2{}, "cosmos-sdk/baseapp/msgCounter2", nil) - cdc.RegisterConcrete(&msgKeyValue{}, "cosmos-sdk/baseapp/msgKeyValue", nil) - cdc.RegisterConcrete(&msgNoRoute{}, "cosmos-sdk/baseapp/msgNoRoute", nil) + codec.RegisterAminoMsg(cdc, &msgCounter{}, "cosmos-sdk/baseapp/msgCounter") + codec.RegisterAminoMsg(cdc, &msgCounter2{}, "cosmos-sdk/baseapp/msgCounter2") + codec.RegisterAminoMsg(cdc, &msgKeyValue{}, "cosmos-sdk/baseapp/msgKeyValue") + codec.RegisterAminoMsg(cdc, &msgNoRoute{}, "cosmos-sdk/baseapp/msgNoRoute") } // aminoTxEncoder creates a amino TxEncoder for testing purposes. @@ -1369,7 +1369,7 @@ func TestRunInvalidTransaction(t *testing.T) { newCdc := codec.NewLegacyAmino() sdk.RegisterLegacyAminoCodec(newCdc) // register Tx, Msg registerTestCodec(newCdc) - newCdc.RegisterConcrete(&msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode", nil) + codec.RegisterAminoMsg(newCdc, &msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode") txBytes, err := newCdc.Marshal(tx) require.NoError(t, err) diff --git a/codec/amino.go b/codec/amino.go index fe22fd14fbd4..02c1f9e25c15 100644 --- a/codec/amino.go +++ b/codec/amino.go @@ -61,6 +61,16 @@ func MustMarshalJSONIndent(cdc *LegacyAmino, obj interface{}) []byte { return bz } +// RegisterAminoMsg first checks that the msgName is <=40 chars +// (else this would break ledger nano signing: https://github.com/cosmos/cosmos-sdk/issues/10870) +// and then registers the concrete msg type with amino +func RegisterAminoMsg(cdc *LegacyAmino, msg interface{}, msgName string) { + if len(msgName) > 40 { + panic(fmt.Errorf("msg name %s is too long to be registered with amino", msgName)) + } + cdc.RegisterConcrete(msg, msgName, nil) +} + func (cdc *LegacyAmino) marshalAnys(o interface{}) error { return types.UnpackInterfaces(o, types.AminoPacker{Cdc: cdc.Amino}) } From 7513d9ccf72dcda54f068e8762e3107c029ab1e5 Mon Sep 17 00:00:00 2001 From: blushi Date: Thu, 10 Mar 2022 14:02:34 +0100 Subject: [PATCH 2/7] Update register msgs --- x/auth/vesting/types/codec.go | 4 ++-- x/authz/codec.go | 6 +++--- x/bank/types/codec.go | 4 ++-- x/crisis/types/codec.go | 2 +- x/distribution/types/codec.go | 8 ++++---- x/evidence/types/codec.go | 2 +- x/feegrant/codec.go | 4 ++-- x/gov/types/v1beta1/codec.go | 8 ++++---- x/gov/types/v1beta2/codec.go | 10 +++++----- x/group/codec.go | 29 +++++++++++++++-------------- x/slashing/types/codec.go | 2 +- x/staking/types/codec.go | 10 +++++----- x/upgrade/types/codec.go | 4 ++-- 13 files changed, 47 insertions(+), 46 deletions(-) diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 616978cb0aaf..3079c708a99c 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -19,8 +19,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil) cdc.RegisterConcrete(&PermanentLockedAccount{}, "cosmos-sdk/PermanentLockedAccount", nil) - cdc.RegisterConcrete(&MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount", nil) - cdc.RegisterConcrete(&MsgCreatePermanentLockedAccount{}, "cosmos-sdk/MsgCreatePermLockedAccount", nil) + codec.RegisterAminoMsg(cdc, &MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount") + codec.RegisterAminoMsg(cdc, &MsgCreatePermanentLockedAccount{}, "cosmos-sdk/MsgCreatePermLockedAccount") } // RegisterInterface associates protoName with AccountI and VestingAccount diff --git a/x/authz/codec.go b/x/authz/codec.go index f7f4710bd0f5..89e0d45db048 100644 --- a/x/authz/codec.go +++ b/x/authz/codec.go @@ -11,9 +11,9 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgGrant{}, "cosmos-sdk/MsgGrant", nil) - cdc.RegisterConcrete(&MsgRevoke{}, "cosmos-sdk/MsgRevoke", nil) - cdc.RegisterConcrete(&MsgExec{}, "cosmos-sdk/MsgExec", nil) + codec.RegisterAminoMsg(cdc, &MsgGrant{}, "cosmos-sdk/MsgGrant") + codec.RegisterAminoMsg(cdc, &MsgRevoke{}, "cosmos-sdk/MsgRevoke") + codec.RegisterAminoMsg(cdc, &MsgExec{}, "cosmos-sdk/MsgExec") cdc.RegisterInterface((*Authorization)(nil), nil) cdc.RegisterConcrete(&GenericAuthorization{}, "cosmos-sdk/GenericAuthorization", nil) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index c25d3cebaecd..6f843ec1ddeb 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -12,8 +12,8 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgSend{}, "cosmos-sdk/MsgSend", nil) - cdc.RegisterConcrete(&MsgMultiSend{}, "cosmos-sdk/MsgMultiSend", nil) + codec.RegisterAminoMsg(cdc, &MsgSend{}, "cosmos-sdk/MsgSend") + codec.RegisterAminoMsg(cdc, &MsgMultiSend{}, "cosmos-sdk/MsgMultiSend") cdc.RegisterConcrete(&SendAuthorization{}, "cosmos-sdk/SendAuthorization", nil) } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 56b8c1cfa7cb..565145585e47 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -11,7 +11,7 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant", nil) + codec.RegisterAminoMsg(cdc, &MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index c528ba539b19..0bca9a90fa80 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -12,10 +12,10 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/distribution interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward", nil) - cdc.RegisterConcrete(&MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission", nil) - cdc.RegisterConcrete(&MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress", nil) - cdc.RegisterConcrete(&MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool", nil) + codec.RegisterAminoMsg(cdc, &MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward") + codec.RegisterAminoMsg(cdc, &MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission") + codec.RegisterAminoMsg(cdc, &MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress") + codec.RegisterAminoMsg(cdc, &MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool") cdc.RegisterConcrete(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index 915b1f101af6..eff0bee9a936 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -13,7 +13,7 @@ import ( // evidence module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.Evidence)(nil), nil) - cdc.RegisterConcrete(&MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence", nil) + codec.RegisterAminoMsg(cdc, &MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence") cdc.RegisterConcrete(&Equivocation{}, "cosmos-sdk/Equivocation", nil) } diff --git a/x/feegrant/codec.go b/x/feegrant/codec.go index aebd654399d2..5e91053269a6 100644 --- a/x/feegrant/codec.go +++ b/x/feegrant/codec.go @@ -11,8 +11,8 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/feegrant interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgGrantAllowance{}, "cosmos-sdk/MsgGrantAllowance", nil) - cdc.RegisterConcrete(&MsgRevokeAllowance{}, "cosmos-sdk/MsgRevokeAllowance", nil) + codec.RegisterAminoMsg(cdc, &MsgGrantAllowance{}, "cosmos-sdk/MsgGrantAllowance") + codec.RegisterAminoMsg(cdc, &MsgRevokeAllowance{}, "cosmos-sdk/MsgRevokeAllowance") cdc.RegisterInterface((*FeeAllowanceI)(nil), nil) cdc.RegisterConcrete(&BasicAllowance{}, "cosmos-sdk/BasicAllowance", nil) diff --git a/x/gov/types/v1beta1/codec.go b/x/gov/types/v1beta1/codec.go index fabc3482f97e..e96d3dcfd183 100644 --- a/x/gov/types/v1beta1/codec.go +++ b/x/gov/types/v1beta1/codec.go @@ -12,10 +12,10 @@ import ( // governance module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*Content)(nil), nil) - cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal", nil) - cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/MsgDeposit", nil) - cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/MsgVote", nil) - cdc.RegisterConcrete(&MsgVoteWeighted{}, "cosmos-sdk/MsgVoteWeighted", nil) + codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal") + codec.RegisterAminoMsg(cdc, &MsgDeposit{}, "cosmos-sdk/MsgDeposit") + codec.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/MsgVote") + codec.RegisterAminoMsg(cdc, &MsgVoteWeighted{}, "cosmos-sdk/MsgVoteWeighted") cdc.RegisterConcrete(&TextProposal{}, "cosmos-sdk/TextProposal", nil) } diff --git a/x/gov/types/v1beta2/codec.go b/x/gov/types/v1beta2/codec.go index ca315e87cae9..9035381373af 100644 --- a/x/gov/types/v1beta2/codec.go +++ b/x/gov/types/v1beta2/codec.go @@ -11,11 +11,11 @@ import ( // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the // governance module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/v1beta2/MsgSubmitProposal", nil) - cdc.RegisterConcrete(&MsgDeposit{}, "cosmos-sdk/v1beta2/MsgDeposit", nil) - cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/v1beta2/MsgVote", nil) - cdc.RegisterConcrete(&MsgVoteWeighted{}, "cosmos-sdk/v1beta2/MsgVoteWeighted", nil) - cdc.RegisterConcrete(&MsgExecLegacyContent{}, "cosmos-sdk/v1beta2/MsgExecLegacyContent", nil) + codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/v1beta2/MsgSubmitProposal") + codec.RegisterAminoMsg(cdc, &MsgDeposit{}, "cosmos-sdk/v1beta2/MsgDeposit") + codec.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/v1beta2/MsgVote") + codec.RegisterAminoMsg(cdc, &MsgVoteWeighted{}, "cosmos-sdk/v1beta2/MsgVoteWeighted") + codec.RegisterAminoMsg(cdc, &MsgExecLegacyContent{}, "cosmos-sdk/v1beta2/MsgExecLegacyContent") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/group/codec.go b/x/group/codec.go index 2481e46ee89e..1b6b5996ffe3 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -15,20 +15,21 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*DecisionPolicy)(nil), nil) cdc.RegisterConcrete(&ThresholdDecisionPolicy{}, "cosmos-sdk/ThresholdDecisionPolicy", nil) cdc.RegisterConcrete(&PercentageDecisionPolicy{}, "cosmos-sdk/PercentageDecisionPolicy", nil) - cdc.RegisterConcrete(&MsgCreateGroup{}, "cosmos-sdk/MsgCreateGroup", nil) - cdc.RegisterConcrete(&MsgUpdateGroupMembers{}, "cosmos-sdk/MsgUpdateGroupMembers", nil) - cdc.RegisterConcrete(&MsgUpdateGroupAdmin{}, "cosmos-sdk/MsgUpdateGroupAdmin", nil) - cdc.RegisterConcrete(&MsgUpdateGroupMetadata{}, "cosmos-sdk/MsgUpdateGroupMetadata", nil) - cdc.RegisterConcrete(&MsgCreateGroupWithPolicy{}, "cosmos-sdk/MsgCreateGroupWithPolicy", nil) - cdc.RegisterConcrete(&MsgCreateGroupPolicy{}, "cosmos-sdk/MsgCreateGroupPolicy", nil) - cdc.RegisterConcrete(&MsgUpdateGroupPolicyAdmin{}, "cosmos-sdk/MsgUpdateGroupPolicyAdmin", nil) - cdc.RegisterConcrete(&MsgUpdateGroupPolicyDecisionPolicy{}, "cosmos-sdk/MsgUpdateGroupPolicyDecisionPolicy", nil) - cdc.RegisterConcrete(&MsgUpdateGroupPolicyMetadata{}, "cosmos-sdk/MsgUpdateGroupPolicyMetadata", nil) - cdc.RegisterConcrete(&MsgSubmitProposal{}, "cosmos-sdk/group/MsgSubmitProposal", nil) - cdc.RegisterConcrete(&MsgWithdrawProposal{}, "cosmos-sdk/group/MsgWithdrawProposal", nil) - cdc.RegisterConcrete(&MsgVote{}, "cosmos-sdk/group/MsgVote", nil) - cdc.RegisterConcrete(&MsgExec{}, "cosmos-sdk/group/MsgExec", nil) - cdc.RegisterConcrete(&MsgLeaveGroup{}, "cosmos-sdk/group/MsgLeaveGroup", nil) + + codec.RegisterAminoMsg(cdc, &MsgCreateGroup{}, "cosmos-sdk/MsgCreateGroup") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupMembers{}, "cosmos-sdk/MsgUpdateGroupMembers") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupAdmin{}, "cosmos-sdk/MsgUpdateGroupAdmin") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupMetadata{}, "cosmos-sdk/MsgUpdateGroupMetadata") + codec.RegisterAminoMsg(cdc, &MsgCreateGroupWithPolicy{}, "cosmos-sdk/MsgCreateGroupWithPolicy") + codec.RegisterAminoMsg(cdc, &MsgCreateGroupPolicy{}, "cosmos-sdk/MsgCreateGroupPolicy") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyAdmin{}, "cosmos-sdk/MsgUpdateGroupPolicyAdmin") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyDecisionPolicy{}, "cosmos-sdk/MsgUpdateGroupPolicyDecisionPolicy") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyMetadata{}, "cosmos-sdk/MsgUpdateGroupPolicyMetadata") + codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/group/MsgSubmitProposal") + codec.RegisterAminoMsg(cdc, &MsgWithdrawProposal{}, "cosmos-sdk/group/MsgWithdrawProposal") + codec.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/group/MsgVote") + codec.RegisterAminoMsg(cdc, &MsgExec{}, "cosmos-sdk/group/MsgExec") + codec.RegisterAminoMsg(cdc, &MsgLeaveGroup{}, "cosmos-sdk/group/MsgLeaveGroup") } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 7ac9b8643c48..72735977ec40 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -10,7 +10,7 @@ import ( // RegisterLegacyAminoCodec registers concrete types on LegacyAmino codec func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) + codec.RegisterAminoMsg(cdc, &MsgUnjail{}, "cosmos-sdk/MsgUnjail") } func RegisterInterfaces(registry types.InterfaceRegistry) { diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index ef8527512c83..50c007317a4e 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -12,11 +12,11 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/staking interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - cdc.RegisterConcrete(&MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) - cdc.RegisterConcrete(&MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) - cdc.RegisterConcrete(&MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) - cdc.RegisterConcrete(&MsgUndelegate{}, "cosmos-sdk/MsgUndelegate", nil) - cdc.RegisterConcrete(&MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil) + codec.RegisterAminoMsg(cdc, &MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator") + codec.RegisterAminoMsg(cdc, &MsgEditValidator{}, "cosmos-sdk/MsgEditValidator") + codec.RegisterAminoMsg(cdc, &MsgDelegate{}, "cosmos-sdk/MsgDelegate") + codec.RegisterAminoMsg(cdc, &MsgUndelegate{}, "cosmos-sdk/MsgUndelegate") + codec.RegisterAminoMsg(cdc, &MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate") cdc.RegisterInterface((*isStakeAuthorization_Validators)(nil), nil) cdc.RegisterConcrete(&StakeAuthorization_AllowList{}, "cosmos-sdk/StakeAuthorization/AllowList", nil) diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index 1d288926fc1c..38c1a13372e0 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -18,8 +18,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(Plan{}, "cosmos-sdk/Plan", nil) cdc.RegisterConcrete(&SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal", nil) cdc.RegisterConcrete(&CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal", nil) - cdc.RegisterConcrete(&MsgSoftwareUpgrade{}, "cosmos-sdk/MsgSoftwareUpgrade", nil) - cdc.RegisterConcrete(&MsgCancelUpgrade{}, "cosmos-sdk/MsgCancelUpgrade", nil) + codec.RegisterAminoMsg(cdc, &MsgSoftwareUpgrade{}, "cosmos-sdk/MsgSoftwareUpgrade") + codec.RegisterAminoMsg(cdc, &MsgCancelUpgrade{}, "cosmos-sdk/MsgCancelUpgrade") } func RegisterInterfaces(registry types.InterfaceRegistry) { From b10320a23e5ffe6e766def1a5c4cc0902dfa7556 Mon Sep 17 00:00:00 2001 From: blushi Date: Thu, 10 Mar 2022 14:43:38 +0100 Subject: [PATCH 3/7] Add tests and update too long msg names --- codec/amino.go | 8 ++++---- codec/amino_test.go | 37 +++++++++++++++++++++++++++++++++++ x/distribution/types/codec.go | 2 +- x/group/codec.go | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 codec/amino_test.go diff --git a/codec/amino.go b/codec/amino.go index 02c1f9e25c15..10ad52558fed 100644 --- a/codec/amino.go +++ b/codec/amino.go @@ -61,11 +61,11 @@ func MustMarshalJSONIndent(cdc *LegacyAmino, obj interface{}) []byte { return bz } -// RegisterAminoMsg first checks that the msgName is <=40 chars -// (else this would break ledger nano signing: https://github.com/cosmos/cosmos-sdk/issues/10870) -// and then registers the concrete msg type with amino +// RegisterAminoMsg first checks that the msgName is <40 chars +// (else this would break ledger nano signing: https://github.com/cosmos/cosmos-sdk/issues/10870), +// then registers the concrete msg type with amino. func RegisterAminoMsg(cdc *LegacyAmino, msg interface{}, msgName string) { - if len(msgName) > 40 { + if len(msgName) > 39 { panic(fmt.Errorf("msg name %s is too long to be registered with amino", msgName)) } cdc.RegisterConcrete(msg, msgName, nil) diff --git a/codec/amino_test.go b/codec/amino_test.go new file mode 100644 index 000000000000..5d2bc9682139 --- /dev/null +++ b/codec/amino_test.go @@ -0,0 +1,37 @@ +package codec_test + +import ( + "strings" + "testing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/stretchr/testify/require" +) + +func TestRegisterAminoMsg(t *testing.T) { + cdc := codec.NewLegacyAmino() + + testCases := map[string]struct { + msgName string + expPanic bool + }{ + "all good": { + msgName: "cosmos-sdk/Test", + }, + "msgName too long": { + msgName: strings.Repeat("a", 40), + expPanic: true, + }, + } + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + fn := func() { codec.RegisterAminoMsg(cdc, &testdata.TestMsg{}, tc.msgName) } + if tc.expPanic { + require.Panics(t, fn) + } else { + require.NotPanics(t, fn) + } + }) + } +} diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index 0bca9a90fa80..a3913050792e 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -13,7 +13,7 @@ import ( // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { codec.RegisterAminoMsg(cdc, &MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward") - codec.RegisterAminoMsg(cdc, &MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValidatorCommission") + codec.RegisterAminoMsg(cdc, &MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValCommission") codec.RegisterAminoMsg(cdc, &MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress") codec.RegisterAminoMsg(cdc, &MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool") cdc.RegisterConcrete(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) diff --git a/x/group/codec.go b/x/group/codec.go index 1b6b5996ffe3..6908e93edebd 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -23,7 +23,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { codec.RegisterAminoMsg(cdc, &MsgCreateGroupWithPolicy{}, "cosmos-sdk/MsgCreateGroupWithPolicy") codec.RegisterAminoMsg(cdc, &MsgCreateGroupPolicy{}, "cosmos-sdk/MsgCreateGroupPolicy") codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyAdmin{}, "cosmos-sdk/MsgUpdateGroupPolicyAdmin") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyDecisionPolicy{}, "cosmos-sdk/MsgUpdateGroupPolicyDecisionPolicy") + codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyDecisionPolicy{}, "cosmos-sdk/MsgUpdateGroupDecisionPolicy") codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyMetadata{}, "cosmos-sdk/MsgUpdateGroupPolicyMetadata") codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/group/MsgSubmitProposal") codec.RegisterAminoMsg(cdc, &MsgWithdrawProposal{}, "cosmos-sdk/group/MsgWithdrawProposal") From ac4c1cfadd2931039c0d91d0aec1a04f8e66e13b Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 11 Mar 2022 11:23:37 +0100 Subject: [PATCH 4/7] Move RegisterAminoMsg to codec/legacy --- baseapp/baseapp_test.go | 11 ++++---- codec/amino.go | 10 ------- codec/legacy/amino_msg.go | 18 ++++++++++++ .../amino_msg_test.go} | 5 ++-- x/auth/vesting/types/codec.go | 4 +-- x/authz/codec.go | 6 ++-- x/bank/types/codec.go | 4 +-- x/crisis/types/codec.go | 2 +- x/distribution/types/codec.go | 8 +++--- x/evidence/types/codec.go | 2 +- x/feegrant/codec.go | 4 +-- x/gov/types/v1beta1/codec.go | 8 +++--- x/gov/types/v1beta2/codec.go | 10 +++---- x/group/codec.go | 28 +++++++++---------- x/slashing/types/codec.go | 2 +- x/staking/types/codec.go | 10 +++---- x/upgrade/types/codec.go | 4 +-- 17 files changed, 73 insertions(+), 63 deletions(-) create mode 100644 codec/legacy/amino_msg.go rename codec/{amino_test.go => legacy/amino_msg_test.go} (80%) diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index ab26281d13e0..e996f1d4a1eb 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -28,6 +28,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/snapshots" @@ -106,10 +107,10 @@ func newBaseApp(name string, options ...func(*baseapp.BaseApp)) *baseapp.BaseApp func registerTestCodec(cdc *codec.LegacyAmino) { // register test types cdc.RegisterConcrete(&txTest{}, "cosmos-sdk/baseapp/txTest", nil) - codec.RegisterAminoMsg(cdc, &msgCounter{}, "cosmos-sdk/baseapp/msgCounter") - codec.RegisterAminoMsg(cdc, &msgCounter2{}, "cosmos-sdk/baseapp/msgCounter2") - codec.RegisterAminoMsg(cdc, &msgKeyValue{}, "cosmos-sdk/baseapp/msgKeyValue") - codec.RegisterAminoMsg(cdc, &msgNoRoute{}, "cosmos-sdk/baseapp/msgNoRoute") + legacy.RegisterAminoMsg(cdc, &msgCounter{}, "cosmos-sdk/baseapp/msgCounter") + legacy.RegisterAminoMsg(cdc, &msgCounter2{}, "cosmos-sdk/baseapp/msgCounter2") + legacy.RegisterAminoMsg(cdc, &msgKeyValue{}, "cosmos-sdk/baseapp/msgKeyValue") + legacy.RegisterAminoMsg(cdc, &msgNoRoute{}, "cosmos-sdk/baseapp/msgNoRoute") } // aminoTxEncoder creates a amino TxEncoder for testing purposes. @@ -1369,7 +1370,7 @@ func TestRunInvalidTransaction(t *testing.T) { newCdc := codec.NewLegacyAmino() sdk.RegisterLegacyAminoCodec(newCdc) // register Tx, Msg registerTestCodec(newCdc) - codec.RegisterAminoMsg(newCdc, &msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode") + legacy.RegisterAminoMsg(newCdc, &msgNoDecode{}, "cosmos-sdk/baseapp/msgNoDecode") txBytes, err := newCdc.Marshal(tx) require.NoError(t, err) diff --git a/codec/amino.go b/codec/amino.go index 10ad52558fed..fe22fd14fbd4 100644 --- a/codec/amino.go +++ b/codec/amino.go @@ -61,16 +61,6 @@ func MustMarshalJSONIndent(cdc *LegacyAmino, obj interface{}) []byte { return bz } -// RegisterAminoMsg first checks that the msgName is <40 chars -// (else this would break ledger nano signing: https://github.com/cosmos/cosmos-sdk/issues/10870), -// then registers the concrete msg type with amino. -func RegisterAminoMsg(cdc *LegacyAmino, msg interface{}, msgName string) { - if len(msgName) > 39 { - panic(fmt.Errorf("msg name %s is too long to be registered with amino", msgName)) - } - cdc.RegisterConcrete(msg, msgName, nil) -} - func (cdc *LegacyAmino) marshalAnys(o interface{}) error { return types.UnpackInterfaces(o, types.AminoPacker{Cdc: cdc.Amino}) } diff --git a/codec/legacy/amino_msg.go b/codec/legacy/amino_msg.go new file mode 100644 index 000000000000..58a02bed7b21 --- /dev/null +++ b/codec/legacy/amino_msg.go @@ -0,0 +1,18 @@ +package legacy + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterAminoMsg first checks that the msgName is <40 chars +// (else this would break ledger nano signing: https://github.com/cosmos/cosmos-sdk/issues/10870), +// then registers the concrete msg type with amino. +func RegisterAminoMsg(cdc *codec.LegacyAmino, msg sdk.Msg, msgName string) { + if len(msgName) > 39 { + panic(fmt.Errorf("msg name %s is too long to be registered with amino", msgName)) + } + cdc.RegisterConcrete(msg, msgName, nil) +} diff --git a/codec/amino_test.go b/codec/legacy/amino_msg_test.go similarity index 80% rename from codec/amino_test.go rename to codec/legacy/amino_msg_test.go index 5d2bc9682139..c38317020e76 100644 --- a/codec/amino_test.go +++ b/codec/legacy/amino_msg_test.go @@ -1,10 +1,11 @@ -package codec_test +package legacy_test import ( "strings" "testing" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/stretchr/testify/require" ) @@ -26,7 +27,7 @@ func TestRegisterAminoMsg(t *testing.T) { } for name, tc := range testCases { t.Run(name, func(t *testing.T) { - fn := func() { codec.RegisterAminoMsg(cdc, &testdata.TestMsg{}, tc.msgName) } + fn := func() { legacy.RegisterAminoMsg(cdc, &testdata.TestMsg{}, tc.msgName) } if tc.expPanic { require.Panics(t, fn) } else { diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 3079c708a99c..318c1ceea238 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -19,8 +19,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil) cdc.RegisterConcrete(&PermanentLockedAccount{}, "cosmos-sdk/PermanentLockedAccount", nil) - codec.RegisterAminoMsg(cdc, &MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount") - codec.RegisterAminoMsg(cdc, &MsgCreatePermanentLockedAccount{}, "cosmos-sdk/MsgCreatePermLockedAccount") + legacy.RegisterAminoMsg(cdc, &MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount") + legacy.RegisterAminoMsg(cdc, &MsgCreatePermanentLockedAccount{}, "cosmos-sdk/MsgCreatePermLockedAccount") } // RegisterInterface associates protoName with AccountI and VestingAccount diff --git a/x/authz/codec.go b/x/authz/codec.go index 89e0d45db048..8d44c4f41f9e 100644 --- a/x/authz/codec.go +++ b/x/authz/codec.go @@ -11,9 +11,9 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/authz interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgGrant{}, "cosmos-sdk/MsgGrant") - codec.RegisterAminoMsg(cdc, &MsgRevoke{}, "cosmos-sdk/MsgRevoke") - codec.RegisterAminoMsg(cdc, &MsgExec{}, "cosmos-sdk/MsgExec") + legacy.RegisterAminoMsg(cdc, &MsgGrant{}, "cosmos-sdk/MsgGrant") + legacy.RegisterAminoMsg(cdc, &MsgRevoke{}, "cosmos-sdk/MsgRevoke") + legacy.RegisterAminoMsg(cdc, &MsgExec{}, "cosmos-sdk/MsgExec") cdc.RegisterInterface((*Authorization)(nil), nil) cdc.RegisterConcrete(&GenericAuthorization{}, "cosmos-sdk/GenericAuthorization", nil) diff --git a/x/bank/types/codec.go b/x/bank/types/codec.go index 6f843ec1ddeb..498fb3272e0f 100644 --- a/x/bank/types/codec.go +++ b/x/bank/types/codec.go @@ -12,8 +12,8 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/bank interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgSend{}, "cosmos-sdk/MsgSend") - codec.RegisterAminoMsg(cdc, &MsgMultiSend{}, "cosmos-sdk/MsgMultiSend") + legacy.RegisterAminoMsg(cdc, &MsgSend{}, "cosmos-sdk/MsgSend") + legacy.RegisterAminoMsg(cdc, &MsgMultiSend{}, "cosmos-sdk/MsgMultiSend") cdc.RegisterConcrete(&SendAuthorization{}, "cosmos-sdk/SendAuthorization", nil) } diff --git a/x/crisis/types/codec.go b/x/crisis/types/codec.go index 565145585e47..868ebaa919bb 100644 --- a/x/crisis/types/codec.go +++ b/x/crisis/types/codec.go @@ -11,7 +11,7 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/crisis interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant") + legacy.RegisterAminoMsg(cdc, &MsgVerifyInvariant{}, "cosmos-sdk/MsgVerifyInvariant") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/distribution/types/codec.go b/x/distribution/types/codec.go index a3913050792e..6fe51998e4d3 100644 --- a/x/distribution/types/codec.go +++ b/x/distribution/types/codec.go @@ -12,10 +12,10 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/distribution interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward") - codec.RegisterAminoMsg(cdc, &MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValCommission") - codec.RegisterAminoMsg(cdc, &MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress") - codec.RegisterAminoMsg(cdc, &MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool") + legacy.RegisterAminoMsg(cdc, &MsgWithdrawDelegatorReward{}, "cosmos-sdk/MsgWithdrawDelegationReward") + legacy.RegisterAminoMsg(cdc, &MsgWithdrawValidatorCommission{}, "cosmos-sdk/MsgWithdrawValCommission") + legacy.RegisterAminoMsg(cdc, &MsgSetWithdrawAddress{}, "cosmos-sdk/MsgModifyWithdrawAddress") + legacy.RegisterAminoMsg(cdc, &MsgFundCommunityPool{}, "cosmos-sdk/MsgFundCommunityPool") cdc.RegisterConcrete(&CommunityPoolSpendProposal{}, "cosmos-sdk/CommunityPoolSpendProposal", nil) } diff --git a/x/evidence/types/codec.go b/x/evidence/types/codec.go index eff0bee9a936..559a119f81db 100644 --- a/x/evidence/types/codec.go +++ b/x/evidence/types/codec.go @@ -13,7 +13,7 @@ import ( // evidence module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*exported.Evidence)(nil), nil) - codec.RegisterAminoMsg(cdc, &MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence") + legacy.RegisterAminoMsg(cdc, &MsgSubmitEvidence{}, "cosmos-sdk/MsgSubmitEvidence") cdc.RegisterConcrete(&Equivocation{}, "cosmos-sdk/Equivocation", nil) } diff --git a/x/feegrant/codec.go b/x/feegrant/codec.go index 5e91053269a6..238c5f05f7ea 100644 --- a/x/feegrant/codec.go +++ b/x/feegrant/codec.go @@ -11,8 +11,8 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/feegrant interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgGrantAllowance{}, "cosmos-sdk/MsgGrantAllowance") - codec.RegisterAminoMsg(cdc, &MsgRevokeAllowance{}, "cosmos-sdk/MsgRevokeAllowance") + legacy.RegisterAminoMsg(cdc, &MsgGrantAllowance{}, "cosmos-sdk/MsgGrantAllowance") + legacy.RegisterAminoMsg(cdc, &MsgRevokeAllowance{}, "cosmos-sdk/MsgRevokeAllowance") cdc.RegisterInterface((*FeeAllowanceI)(nil), nil) cdc.RegisterConcrete(&BasicAllowance{}, "cosmos-sdk/BasicAllowance", nil) diff --git a/x/gov/types/v1beta1/codec.go b/x/gov/types/v1beta1/codec.go index e96d3dcfd183..583ab48963a8 100644 --- a/x/gov/types/v1beta1/codec.go +++ b/x/gov/types/v1beta1/codec.go @@ -12,10 +12,10 @@ import ( // governance module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterInterface((*Content)(nil), nil) - codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal") - codec.RegisterAminoMsg(cdc, &MsgDeposit{}, "cosmos-sdk/MsgDeposit") - codec.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/MsgVote") - codec.RegisterAminoMsg(cdc, &MsgVoteWeighted{}, "cosmos-sdk/MsgVoteWeighted") + legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/MsgSubmitProposal") + legacy.RegisterAminoMsg(cdc, &MsgDeposit{}, "cosmos-sdk/MsgDeposit") + legacy.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/MsgVote") + legacy.RegisterAminoMsg(cdc, &MsgVoteWeighted{}, "cosmos-sdk/MsgVoteWeighted") cdc.RegisterConcrete(&TextProposal{}, "cosmos-sdk/TextProposal", nil) } diff --git a/x/gov/types/v1beta2/codec.go b/x/gov/types/v1beta2/codec.go index 9035381373af..cbf13f1b39f8 100644 --- a/x/gov/types/v1beta2/codec.go +++ b/x/gov/types/v1beta2/codec.go @@ -11,11 +11,11 @@ import ( // RegisterLegacyAminoCodec registers all the necessary types and interfaces for the // governance module. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/v1beta2/MsgSubmitProposal") - codec.RegisterAminoMsg(cdc, &MsgDeposit{}, "cosmos-sdk/v1beta2/MsgDeposit") - codec.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/v1beta2/MsgVote") - codec.RegisterAminoMsg(cdc, &MsgVoteWeighted{}, "cosmos-sdk/v1beta2/MsgVoteWeighted") - codec.RegisterAminoMsg(cdc, &MsgExecLegacyContent{}, "cosmos-sdk/v1beta2/MsgExecLegacyContent") + legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/v1beta2/MsgSubmitProposal") + legacy.RegisterAminoMsg(cdc, &MsgDeposit{}, "cosmos-sdk/v1beta2/MsgDeposit") + legacy.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/v1beta2/MsgVote") + legacy.RegisterAminoMsg(cdc, &MsgVoteWeighted{}, "cosmos-sdk/v1beta2/MsgVoteWeighted") + legacy.RegisterAminoMsg(cdc, &MsgExecLegacyContent{}, "cosmos-sdk/v1beta2/MsgExecLegacyContent") } func RegisterInterfaces(registry codectypes.InterfaceRegistry) { diff --git a/x/group/codec.go b/x/group/codec.go index 6908e93edebd..0fa16e51ba20 100644 --- a/x/group/codec.go +++ b/x/group/codec.go @@ -16,20 +16,20 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&ThresholdDecisionPolicy{}, "cosmos-sdk/ThresholdDecisionPolicy", nil) cdc.RegisterConcrete(&PercentageDecisionPolicy{}, "cosmos-sdk/PercentageDecisionPolicy", nil) - codec.RegisterAminoMsg(cdc, &MsgCreateGroup{}, "cosmos-sdk/MsgCreateGroup") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupMembers{}, "cosmos-sdk/MsgUpdateGroupMembers") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupAdmin{}, "cosmos-sdk/MsgUpdateGroupAdmin") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupMetadata{}, "cosmos-sdk/MsgUpdateGroupMetadata") - codec.RegisterAminoMsg(cdc, &MsgCreateGroupWithPolicy{}, "cosmos-sdk/MsgCreateGroupWithPolicy") - codec.RegisterAminoMsg(cdc, &MsgCreateGroupPolicy{}, "cosmos-sdk/MsgCreateGroupPolicy") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyAdmin{}, "cosmos-sdk/MsgUpdateGroupPolicyAdmin") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyDecisionPolicy{}, "cosmos-sdk/MsgUpdateGroupDecisionPolicy") - codec.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyMetadata{}, "cosmos-sdk/MsgUpdateGroupPolicyMetadata") - codec.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/group/MsgSubmitProposal") - codec.RegisterAminoMsg(cdc, &MsgWithdrawProposal{}, "cosmos-sdk/group/MsgWithdrawProposal") - codec.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/group/MsgVote") - codec.RegisterAminoMsg(cdc, &MsgExec{}, "cosmos-sdk/group/MsgExec") - codec.RegisterAminoMsg(cdc, &MsgLeaveGroup{}, "cosmos-sdk/group/MsgLeaveGroup") + legacy.RegisterAminoMsg(cdc, &MsgCreateGroup{}, "cosmos-sdk/MsgCreateGroup") + legacy.RegisterAminoMsg(cdc, &MsgUpdateGroupMembers{}, "cosmos-sdk/MsgUpdateGroupMembers") + legacy.RegisterAminoMsg(cdc, &MsgUpdateGroupAdmin{}, "cosmos-sdk/MsgUpdateGroupAdmin") + legacy.RegisterAminoMsg(cdc, &MsgUpdateGroupMetadata{}, "cosmos-sdk/MsgUpdateGroupMetadata") + legacy.RegisterAminoMsg(cdc, &MsgCreateGroupWithPolicy{}, "cosmos-sdk/MsgCreateGroupWithPolicy") + legacy.RegisterAminoMsg(cdc, &MsgCreateGroupPolicy{}, "cosmos-sdk/MsgCreateGroupPolicy") + legacy.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyAdmin{}, "cosmos-sdk/MsgUpdateGroupPolicyAdmin") + legacy.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyDecisionPolicy{}, "cosmos-sdk/MsgUpdateGroupDecisionPolicy") + legacy.RegisterAminoMsg(cdc, &MsgUpdateGroupPolicyMetadata{}, "cosmos-sdk/MsgUpdateGroupPolicyMetadata") + legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "cosmos-sdk/group/MsgSubmitProposal") + legacy.RegisterAminoMsg(cdc, &MsgWithdrawProposal{}, "cosmos-sdk/group/MsgWithdrawProposal") + legacy.RegisterAminoMsg(cdc, &MsgVote{}, "cosmos-sdk/group/MsgVote") + legacy.RegisterAminoMsg(cdc, &MsgExec{}, "cosmos-sdk/group/MsgExec") + legacy.RegisterAminoMsg(cdc, &MsgLeaveGroup{}, "cosmos-sdk/group/MsgLeaveGroup") } func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { diff --git a/x/slashing/types/codec.go b/x/slashing/types/codec.go index 72735977ec40..ec1b44ec559d 100644 --- a/x/slashing/types/codec.go +++ b/x/slashing/types/codec.go @@ -10,7 +10,7 @@ import ( // RegisterLegacyAminoCodec registers concrete types on LegacyAmino codec func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgUnjail{}, "cosmos-sdk/MsgUnjail") + legacy.RegisterAminoMsg(cdc, &MsgUnjail{}, "cosmos-sdk/MsgUnjail") } func RegisterInterfaces(registry types.InterfaceRegistry) { diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 50c007317a4e..4efb2d3aa212 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -12,11 +12,11 @@ import ( // RegisterLegacyAminoCodec registers the necessary x/staking interfaces and concrete types // on the provided LegacyAmino codec. These types are used for Amino JSON serialization. func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { - codec.RegisterAminoMsg(cdc, &MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator") - codec.RegisterAminoMsg(cdc, &MsgEditValidator{}, "cosmos-sdk/MsgEditValidator") - codec.RegisterAminoMsg(cdc, &MsgDelegate{}, "cosmos-sdk/MsgDelegate") - codec.RegisterAminoMsg(cdc, &MsgUndelegate{}, "cosmos-sdk/MsgUndelegate") - codec.RegisterAminoMsg(cdc, &MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate") + legacy.RegisterAminoMsg(cdc, &MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator") + legacy.RegisterAminoMsg(cdc, &MsgEditValidator{}, "cosmos-sdk/MsgEditValidator") + legacy.RegisterAminoMsg(cdc, &MsgDelegate{}, "cosmos-sdk/MsgDelegate") + legacy.RegisterAminoMsg(cdc, &MsgUndelegate{}, "cosmos-sdk/MsgUndelegate") + legacy.RegisterAminoMsg(cdc, &MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate") cdc.RegisterInterface((*isStakeAuthorization_Validators)(nil), nil) cdc.RegisterConcrete(&StakeAuthorization_AllowList{}, "cosmos-sdk/StakeAuthorization/AllowList", nil) diff --git a/x/upgrade/types/codec.go b/x/upgrade/types/codec.go index 38c1a13372e0..4acdc05944ab 100644 --- a/x/upgrade/types/codec.go +++ b/x/upgrade/types/codec.go @@ -18,8 +18,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(Plan{}, "cosmos-sdk/Plan", nil) cdc.RegisterConcrete(&SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal", nil) cdc.RegisterConcrete(&CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal", nil) - codec.RegisterAminoMsg(cdc, &MsgSoftwareUpgrade{}, "cosmos-sdk/MsgSoftwareUpgrade") - codec.RegisterAminoMsg(cdc, &MsgCancelUpgrade{}, "cosmos-sdk/MsgCancelUpgrade") + legacy.RegisterAminoMsg(cdc, &MsgSoftwareUpgrade{}, "cosmos-sdk/MsgSoftwareUpgrade") + legacy.RegisterAminoMsg(cdc, &MsgCancelUpgrade{}, "cosmos-sdk/MsgCancelUpgrade") } func RegisterInterfaces(registry types.InterfaceRegistry) { From 3f55a3e5e90239107bf209f7e3a38a9f8ae775aa Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 11 Mar 2022 11:26:28 +0100 Subject: [PATCH 5/7] Add go doc --- codec/legacy/doc.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codec/legacy/doc.go b/codec/legacy/doc.go index d89944f3df42..b9d45b502c51 100644 --- a/codec/legacy/doc.go +++ b/codec/legacy/doc.go @@ -1,4 +1,6 @@ // Package legacy contains a global amino Cdc which is deprecated but // still used in several places within the SDK. This package is intended // to be removed at some point in the future when the global Cdc is removed. +// It also contains a util function RegisterAminoMsg that checks a msg name length +// and registers the concrete msg type with amino. package legacy From 5a0836fbb4036c39d66ce265ac17248347603651 Mon Sep 17 00:00:00 2001 From: blushi Date: Fri, 11 Mar 2022 11:26:59 +0100 Subject: [PATCH 6/7] Update go doc --- codec/legacy/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec/legacy/doc.go b/codec/legacy/doc.go index b9d45b502c51..f3976d871ffb 100644 --- a/codec/legacy/doc.go +++ b/codec/legacy/doc.go @@ -2,5 +2,5 @@ // still used in several places within the SDK. This package is intended // to be removed at some point in the future when the global Cdc is removed. // It also contains a util function RegisterAminoMsg that checks a msg name length -// and registers the concrete msg type with amino. +// before registering the concrete msg type with amino. package legacy From 1c50161a06136ad252f00c4818fd5b61c955233e Mon Sep 17 00:00:00 2001 From: blushi Date: Wed, 16 Mar 2022 13:57:12 +0100 Subject: [PATCH 7/7] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4312fe32d5d7..40bcadd76420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -160,6 +160,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [\#11349](https://github.com/cosmos/cosmos-sdk/pull/11349) Add `RegisterAminoMsg` function that checks that a msg name is <40 chars (else this would break ledger nano signing) then registers the concrete msg type with amino, it should be used for registering `sdk.Msg`s with amino instead of `cdc.RegisterConcrete`. * [\#11089](https://github.com/cosmos/cosmos-sdk/pull/11089]) Now cosmos-sdk consumers can upgrade gRPC to its newest versions. * [\#10439](https://github.com/cosmos/cosmos-sdk/pull/10439) Check error for `RegisterQueryHandlerClient` in all modules `RegisterGRPCGatewayRoutes`. * [\#9780](https://github.com/cosmos/cosmos-sdk/pull/9780) Remove gogoproto `moretags` YAML annotations and add `sigs.k8s.io/yaml` for YAML marshalling.