From bfb96e32e9bb3fd178e58e029a99d63c53ac11d4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 8 Apr 2023 17:52:20 +0200 Subject: [PATCH] refactor(consensus): move `ValidateBasic` logic to `msgServer` --- x/consensus/keeper/keeper.go | 10 +++++----- x/consensus/types/msgs.go | 6 ------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index bbb0a299eeb9..837ced7e05c4 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -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 } @@ -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 } diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 8ac148dfbc38..c04ac71da713 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -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{