diff --git a/proto/cosmos/consensus/v1/tx.proto b/proto/cosmos/consensus/v1/tx.proto index ae0473a0a410..481aa14bb6e1 100644 --- a/proto/cosmos/consensus/v1/tx.proto +++ b/proto/cosmos/consensus/v1/tx.proto @@ -25,6 +25,8 @@ message MsgUpdateParams { string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; // params defines the x/consensus_params parameters to update. + // VersionsParams is not included in this Msg because it is tracked + // separarately in x/upgrade. // // NOTE: All parameters must be supplied. tendermint.types.BlockParams block = 2; diff --git a/x/consensus/exported/exported.go b/x/consensus/exported/exported.go index 5b626a119baf..0312fbdfad9f 100644 --- a/x/consensus/exported/exported.go +++ b/x/consensus/exported/exported.go @@ -14,8 +14,8 @@ type ( Get(ctx sdk.Context, key []byte, ptr interface{}) } - // ConsensusParamSetter defines the interface fulfilled by BaseApp - // which allows setting its appVersion field. + // ConsensusParamSetter defines the interface fulfilled by BaseApp's + // ParamStore which allows setting its appVersion field. ConsensusParamSetter interface { Get(ctx sdk.Context) (*tmproto.ConsensusParams, error) Has(ctx sdk.Context) bool diff --git a/x/consensus/keeper/msg_server.go b/x/consensus/keeper/msg_server.go index 66fb2a14e230..96a49b00e517 100644 --- a/x/consensus/keeper/msg_server.go +++ b/x/consensus/keeper/msg_server.go @@ -31,7 +31,7 @@ func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam ctx := sdk.UnwrapSDKContext(goCtx) consensusParams := req.ToProtoConsensusParams() - if err := types.Validate(tmtypes.ConsensusParamsFromProto(consensusParams)); err != nil { + if err := tmtypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil { return nil, err } diff --git a/x/consensus/keeper/msg_server_test.go b/x/consensus/keeper/msg_server_test.go index e61d0debe4bf..eaef548a460c 100644 --- a/x/consensus/keeper/msg_server_test.go +++ b/x/consensus/keeper/msg_server_test.go @@ -37,7 +37,7 @@ func (s *KeeperTestSuite) TestUpdateParams() { expErrMsg: "block.MaxBytes must be greater than 0. Got -10", }, { - name: "invalid authority", + name: "invalid authority", input: &types.MsgUpdateParams{ Authority: "invalid", Block: defaultConsensusParams.Block, diff --git a/x/consensus/module.go b/x/consensus/module.go index dc72c6f34520..56d7cd5b080e 100644 --- a/x/consensus/module.go +++ b/x/consensus/module.go @@ -25,7 +25,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -// ConsensusVersion defines the current x/bank module consensus version. +// ConsensusVersion defines the current x/consensus module consensus version. const ConsensusVersion = 1 var ( @@ -42,7 +42,9 @@ type AppModuleBasic struct { func (AppModuleBasic) Name() string { return types.ModuleName } // RegisterLegacyAminoCodec registers the consensus_param module's types on the LegacyAmino codec. -func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterLegacyAminoCodec(cdc) +} // DefaultGenesis returns default genesis state as raw bytes for the consensus_param // module. diff --git a/x/consensus/types/codec.go b/x/consensus/types/codec.go index 0b9e9b507f13..205596743fa1 100644 --- a/x/consensus/types/codec.go +++ b/x/consensus/types/codec.go @@ -1,9 +1,15 @@ package types import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" + govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec" + groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec" ) func RegisterInterfaces(registry types.InterfaceRegistry) { @@ -14,3 +20,26 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } + +// RegisterLegacyAminoCodec registers the necessary x/consensus interfaces and concrete types +// on the provided LegacyAmino codec. These types are used for Amino JSON serialization. +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "cosmos-sdk/x/consensus/MsgUpdateParams") +} + +var ( + amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewAminoCodec(amino) +) + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be + // used to properly serialize MsgUpdate instances + RegisterLegacyAminoCodec(authzcodec.Amino) + RegisterLegacyAminoCodec(govcodec.Amino) + RegisterLegacyAminoCodec(groupcodec.Amino) +} diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 3f5cbfe4c4b3..96bdceb055bf 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -5,6 +5,7 @@ import ( tmtypes "github.com/tendermint/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // bank message types @@ -12,7 +13,7 @@ const ( TypeMsgUpdateParams = "update_params" ) -var _ sdk.Msg = &MsgUpdateParams{} +var _ legacytx.LegacyMsg = &MsgUpdateParams{} // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. @@ -24,13 +25,21 @@ func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { // GetSignBytes returns the raw bytes for a MsgUpdateParams message that // the expected signer needs to sign. func (msg MsgUpdateParams) GetSignBytes() []byte { - return []byte{} + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) +} + +func (msg MsgUpdateParams) Route() string { + return sdk.MsgTypeURL(&msg) +} + +func (msg MsgUpdateParams) Type() string { + return sdk.MsgTypeURL(&msg) } // ValidateBasic performs basic MsgUpdateParams message validation. func (msg MsgUpdateParams) ValidateBasic() error { params := tmtypes.ConsensusParamsFromProto(msg.ToProtoConsensusParams()) - return Validate(params) + return params.ValidateBasic() } func (msg MsgUpdateParams) ToProtoConsensusParams() tmproto.ConsensusParams { @@ -47,6 +56,6 @@ func (msg MsgUpdateParams) ToProtoConsensusParams() tmproto.ConsensusParams { Validator: &tmproto.ValidatorParams{ PubKeyTypes: msg.Validator.PubKeyTypes, }, - Version: tmtypes.DefaultConsensusParams().ToProto().Version, + Version: tmtypes.DefaultConsensusParams().ToProto().Version, // Version is stored in x/upgrade } } diff --git a/x/consensus/types/params.go b/x/consensus/types/params.go deleted file mode 100644 index 5ecf68d9c9fa..000000000000 --- a/x/consensus/types/params.go +++ /dev/null @@ -1,11 +0,0 @@ -package types - -import ( - tmtypes "github.com/tendermint/tendermint/types" -) - -// Validate performs basic validation of ConsensusParams returning an error upon -// failure. -func Validate(p tmtypes.ConsensusParams) error { - return p.ValidateBasic() -} diff --git a/x/consensus/types/util.go b/x/consensus/types/util.go deleted file mode 100644 index 8e911d92efe0..000000000000 --- a/x/consensus/types/util.go +++ /dev/null @@ -1,17 +0,0 @@ -package types - -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// Sentinel errors for the x/consensus module. -var ( - ErrUnauthorized = sdkerrors.Register(ModuleName, 2, "unauthorized action") -) - -// Events -const ( - EventTypeUpdateParam = "update_param" - - AttributeKeyParamUpdater = "param_updater" -)