Skip to content

Commit

Permalink
chore: check for nil params (#18041)
Browse files Browse the repository at this point in the history
Co-authored-by: atheeshp <[email protected]>
  • Loading branch information
tac0turtle and atheeshp authored Oct 11, 2023
1 parent 758d3a1 commit ed14ec0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (types) [#17885](https://github.com/cosmos/cosmos-sdk/pull/17885) `InitGenesis` & `ExportGenesis` now take `context.Context` instead of `sdk.Context`
* (x/auth) [#17985](https://github.com/cosmos/cosmos-sdk/pull/17985) Remove `StdTxConfig`
* Remove depreacted `MakeTestingEncodingParams` from `simapp/params`
* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error

### CLI Breaking Changes

Expand Down
5 changes: 4 additions & 1 deletion x/consensus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*
return nil, fmt.Errorf("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
}
Expand Down
33 changes: 33 additions & 0 deletions x/consensus/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,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 {
Expand Down
10 changes: 8 additions & 2 deletions x/consensus/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"errors"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmttypes "github.com/cometbft/cometbft/types"

Expand All @@ -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,
Expand All @@ -32,5 +38,5 @@ func (msg MsgUpdateParams) ToProtoConsensusParams() cmtproto.ConsensusParams {
}
}

return cp
return cp, nil
}

0 comments on commit ed14ec0

Please sign in to comment.