Skip to content

Commit

Permalink
refactor(consensus): move ValidateBasic logic to msgServer (#15758)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Apr 9, 2023
1 parent cdc03fa commit ec6af61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 5 additions & 5 deletions x/consensus/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types

var _ types.MsgServer = Keeper{}

func (k Keeper) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != req.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
func (k Keeper) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != msg.Authority {
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), msg.Authority)
}

consensusParams := req.ToProtoConsensusParams()
consensusParams := msg.ToProtoConsensusParams()
if err := cmttypes.ConsensusParamsFromProto(consensusParams).ValidateBasic(); err != nil {
return nil, err
}
Expand All @@ -76,7 +76,7 @@ func (k Keeper) UpdateParams(ctx context.Context, req *types.MsgUpdateParams) (*
if err := k.event.EventManager(ctx).EmitKV(
ctx,
"update_consensus_params",
event.Attribute{Key: "authority", Value: req.Authority},
event.Attribute{Key: "authority", Value: msg.Authority},
event.Attribute{Key: "parameters", Value: consensusParams.String()}); err != nil {
return nil, err
}
Expand Down
6 changes: 0 additions & 6 deletions x/consensus/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ func (msg MsgUpdateParams) GetSignBytes() []byte {
return sdk.MustSortJSON(amino.MustMarshalJSON(&msg))
}

// ValidateBasic performs basic MsgUpdateParams message validation.
func (msg MsgUpdateParams) ValidateBasic() error {
params := cmttypes.ConsensusParamsFromProto(msg.ToProtoConsensusParams())
return params.ValidateBasic()
}

func (msg MsgUpdateParams) ToProtoConsensusParams() cmtproto.ConsensusParams {
return cmtproto.ConsensusParams{
Block: &cmtproto.BlockParams{
Expand Down

0 comments on commit ec6af61

Please sign in to comment.