Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: check for nil params #18041

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also add the unit tests if any of block, validator is missing.

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
13 changes: 11 additions & 2 deletions x/consensus/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package types

import (
"errors"
fmt "fmt"

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

Expand All @@ -9,7 +12,13 @@ import (

var _ sdk.Msg = &MsgUpdateParams{}

func (msg MsgUpdateParams) ToProtoConsensusParams() cmtproto.ConsensusParams {
func (msg MsgUpdateParams) ToProtoConsensusParams() (cmtproto.ConsensusParams, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be a api breaking change?

if msg.Evidence == nil || msg.Block == nil || msg.Validator == nil {
return cmtproto.ConsensusParams{}, errors.New("all parameters must be present")
}

fmt.Println(msg.Evidence)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt.Println(msg.Evidence)


cp := cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
MaxBytes: msg.Block.MaxBytes,
Expand All @@ -32,5 +41,5 @@ func (msg MsgUpdateParams) ToProtoConsensusParams() cmtproto.ConsensusParams {
}
}

return cp
return cp, nil
}
Loading