diff --git a/CHANGELOG.md b/CHANGELOG.md index 368fe0e59646..d70cc31b831d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/staking/keeper) [#18035](https://github.com/cosmos/cosmos-sdk/pull/18035) Hoisted out of the redelegation loop, the non-changing validator and delegator addresses parsing. * (keyring) [#17913](https://github.com/cosmos/cosmos-sdk/pull/17913) Add `NewAutoCLIKeyring` for creating an AutoCLI keyring from a SDK keyring. +* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) Let `ToProtoConsensusParams()` return an error. ### Bug Fixes diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index 6155f7130ec5..52dfd6740f6c 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -68,7 +68,10 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (* return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority) } - consensusParams := msg.ToProtoConsensusParams() + consensusParams, err := msg.ToProtoConsensusParams() + if err != nil { + return nil, err + } if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil { return nil, err } diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 6c36b1c45eeb..ce95158652bd 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -171,6 +171,39 @@ func (s *KeeperTestSuite) TestUpdateParams() { expErr: true, expErrMsg: "invalid authority", }, + { + name: "nil evidence params", + input: &types.MsgUpdateParams{ + Authority: s.consensusParamsKeeper.GetAuthority(), + Block: defaultConsensusParams.Block, + Validator: defaultConsensusParams.Validator, + Evidence: nil, + }, + expErr: true, + expErrMsg: "all parameters must be present", + }, + { + name: "nil block params", + input: &types.MsgUpdateParams{ + Authority: s.consensusParamsKeeper.GetAuthority(), + Block: nil, + Validator: defaultConsensusParams.Validator, + Evidence: defaultConsensusParams.Evidence, + }, + expErr: true, + expErrMsg: "all parameters must be present", + }, + { + name: "nil validator params", + input: &types.MsgUpdateParams{ + Authority: s.consensusParamsKeeper.GetAuthority(), + Block: defaultConsensusParams.Block, + Validator: nil, + Evidence: defaultConsensusParams.Evidence, + }, + expErr: true, + expErrMsg: "all parameters must be present", + }, } for _, tc := range testCases { diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 64307f4c3c9d..b62c0052f7cb 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -1,6 +1,8 @@ package types import ( + "errors" + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" cmttypes "github.com/cometbft/cometbft/types" @@ -9,7 +11,11 @@ import ( var _ sdk.Msg = &MsgUpdateParams{} -func (msg MsgUpdateParams) ToProtoConsensusParams() cmtproto.ConsensusParams { +func (msg MsgUpdateParams) ToProtoConsensusParams() (cmtproto.ConsensusParams, error) { + if msg.Evidence == nil || msg.Block == nil || msg.Validator == nil { + return cmtproto.ConsensusParams{}, errors.New("all parameters must be present") + } + cp := cmtproto.ConsensusParams{ Block: &cmtproto.BlockParams{ MaxBytes: msg.Block.MaxBytes, @@ -32,5 +38,5 @@ func (msg MsgUpdateParams) ToProtoConsensusParams() cmtproto.ConsensusParams { } } - return cp + return cp, nil }