Skip to content

Commit

Permalink
fix(exomint): stateful validation add
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 committed Jun 11, 2024
1 parent c616fa1 commit 0fbc063
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 3 additions & 6 deletions x/exomint/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func CmdUpdateParams() *cobra.Command {
return err
}

msg, err := newBuildUpdateParamsMsg(clientCtx, cmd.Flags())
if err != nil {
return err
}
msg := newBuildUpdateParamsMsg(clientCtx, cmd.Flags())

// this calls ValidateBasic internally so we don't need to do that.
return tx.GenerateOrBroadcastTxWithFactory(clientCtx, txf, msg)
Expand All @@ -79,7 +76,7 @@ func CmdUpdateParams() *cobra.Command {

func newBuildUpdateParamsMsg(
clientCtx client.Context, fs *pflag.FlagSet,
) (*types.MsgUpdateParams, error) {
) *types.MsgUpdateParams {
sender := clientCtx.GetFromAddress()
// #nosec G703 // this only errors if the flag isn't defined.
mintDenom, _ := fs.GetString(FlagMintDenom)
Expand All @@ -99,5 +96,5 @@ func newBuildUpdateParamsMsg(
EpochIdentifier: epochIdentifier,
},
}
return msg, nil
return msg
}
9 changes: 9 additions & 0 deletions x/exomint/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ func (k Keeper) UpdateParams(
logger.Info("UpdateParams", "overriding EpochIdentifier with value", prevParams.EpochIdentifier)
nextParams.EpochIdentifier = prevParams.EpochIdentifier
}
// stateful validations
// no need to check if MintDenom is registered in BankKeeper, since it does not
// itself perform such checks.
// the reward is already guaranteed to be positive and fits in the bit length.
// we just have to check epoch here.
if _, found := k.epochsKeeper.GetEpochInfo(c, nextParams.EpochIdentifier); !found {
logger.Info("UpdateParams", "overriding EpochIdentifier with value", prevParams.EpochIdentifier)
nextParams.EpochIdentifier = prevParams.EpochIdentifier
}
k.SetParams(c, msg.Params)
return nil, nil
}

0 comments on commit 0fbc063

Please sign in to comment.