Skip to content

Commit

Permalink
refactor update gov params to update params
Browse files Browse the repository at this point in the history
  • Loading branch information
nullpointer0x00 committed May 20, 2024
1 parent d3f50fa commit 4a06642
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 40 deletions.
4 changes: 2 additions & 2 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ const (
// Oracle
DefaultWeightUpdateOracle int = 25
DefaultWeightSendOracleQuery int = 75
// Rate Limiter
DefaultWeightGovUpdateParams int = 100
// Ibc Rate Limiter
DefaultWeightUpdateParams int = 100
)
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105881,6 +105881,13 @@ definitions:
description: >-
MsgGovUpdateParamsResponse is a response message for the GovUpdateParams
endpoint.

Deprecated: Use MsgUpdateParamsResponse instead.
provenance.ibcratelimit.v1.MsgUpdateParamsResponse:
type: object
description: >-
MsgUpdateParamsResponse is a response message for the UpdateParams
endpoint.
provenance.marker.v1.Access:
type: string
enum:
Expand Down
2 changes: 2 additions & 0 deletions proto/provenance/attribute/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ service Msg {

// SetAccountData defines a method for setting/updating an account's accountdata attribute.
rpc SetAccountData(MsgSetAccountDataRequest) returns (MsgSetAccountDataResponse);

// TODO add update params
}

// MsgAddAttributeRequest defines an sdk.Msg type that is used to add a new attribute to an account.
Expand Down
31 changes: 28 additions & 3 deletions proto/provenance/ibcratelimit/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,44 @@ import "provenance/ibcratelimit/v1/params.proto";
// Msg is the service for ibcratelimit module's tx endpoints.
service Msg {
// GovUpdateParams is a governance proposal endpoint for updating the exchange module's params.
rpc GovUpdateParams(MsgGovUpdateParamsRequest) returns (MsgGovUpdateParamsResponse);
// Deprecated: Use UpdateParams instead.
rpc GovUpdateParams(MsgGovUpdateParamsRequest) returns (MsgGovUpdateParamsResponse) {
option deprecated = true;
}

// UpdateParams is a governance proposal endpoint for updating the exchange module's params.
rpc UpdateParams(MsgUpdateParamsRequest) returns (MsgUpdateParamsResponse);
}

// MsgGovUpdateParamsRequest is a request message for the GovUpdateParams endpoint.
// Deprecated: Use MsgUpdateParamsRequest instead.
message MsgGovUpdateParamsRequest {
option (cosmos.msg.v1.signer) = "authority";
option deprecated = true;

// authority should be the governance module account address.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params are the new param values to set
// params are the new param values to set.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgGovUpdateParamsResponse is a response message for the GovUpdateParams endpoint.
message MsgGovUpdateParamsResponse {}
// Deprecated: Use MsgUpdateParamsResponse instead.
message MsgGovUpdateParamsResponse {
option deprecated = true;
}

// MsgUpdateParamsRequest is a request message for the UpdateParams endpoint.
message MsgUpdateParamsRequest {
option (cosmos.msg.v1.signer) = "authority";

// authority should be the governance module account address.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params are the new param values to set.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse is a response message for the UpdateParams endpoint.
message MsgUpdateParamsResponse {}
2 changes: 2 additions & 0 deletions proto/provenance/marker/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ service Msg {
rpc WithdrawEscrowProposal(MsgWithdrawEscrowProposalRequest) returns (MsgWithdrawEscrowProposalResponse);
// SetDenomMetadataProposal is a governance proposal to set marker metadata
rpc SetDenomMetadataProposal(MsgSetDenomMetadataProposalRequest) returns (MsgSetDenomMetadataProposalResponse);

// TODO: UpdateParams
}

// MsgGrantAllowanceRequest validates permission to create a fee grant based on marker admin access. If
Expand Down
2 changes: 2 additions & 0 deletions proto/provenance/metadata/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ service Msg {

// AddNetAssetValues set the net asset value for a scope
rpc AddNetAssetValues(MsgAddNetAssetValuesRequest) returns (MsgAddNetAssetValuesResponse);

// TODO: add update params
}

// MsgWriteScopeRequest is the request type for the Msg/WriteScope RPC method.
Expand Down
2 changes: 2 additions & 0 deletions proto/provenance/msgfees/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ service Msg {
// UpdateConversionFeeDenomProposal defines a governance proposal to update the msg fee conversion denom
rpc UpdateConversionFeeDenomProposal(MsgUpdateConversionFeeDenomProposalRequest)
returns (MsgUpdateConversionFeeDenomProposalResponse);

// TODO: add update params
}

// MsgAssessCustomMsgFeeRequest defines an sdk.Msg type
Expand Down
2 changes: 2 additions & 0 deletions proto/provenance/name/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ service Msg {

// CreateRootName defines a governance method for creating a root name.
rpc CreateRootName(MsgCreateRootNameRequest) returns (MsgCreateRootNameResponse);

// TODO: add update params
}

// MsgBindNameRequest defines an sdk.Msg type that is used to add an address/name binding under an optional parent name.
Expand Down
2 changes: 1 addition & 1 deletion x/ibcratelimit/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetCmdParamsUpdate() *cobra.Command {

flagSet := cmd.Flags()
authority := provcli.GetAuthority(flagSet)
msg := ibcratelimit.NewMsgGovUpdateParamsRequest(authority, args[0])
msg := ibcratelimit.NewUpdateParamsRequest(authority, args[0])
return provcli.GenerateOrBroadcastTxCLIAsGovProp(clientCtx, flagSet, msg)
},
}
Expand Down
8 changes: 7 additions & 1 deletion x/ibcratelimit/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"errors"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -23,6 +24,11 @@ var _ ibcratelimit.MsgServer = MsgServer{}

// GovUpdateParams is a governance proposal endpoint for updating the ibcratelimit module's params.
func (k MsgServer) GovUpdateParams(goCtx context.Context, msg *ibcratelimit.MsgGovUpdateParamsRequest) (*ibcratelimit.MsgGovUpdateParamsResponse, error) {

Check failure on line 26 in x/ibcratelimit/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'goCtx' seems to be unused, consider removing or renaming it as _ (revive)
return nil, errors.New("deprecated and unusable")
}

// UpdateParams is a governance proposal endpoint for updating the ibcratelimit module's params.
func (k MsgServer) UpdateParams(goCtx context.Context, msg *ibcratelimit.MsgUpdateParamsRequest) (*ibcratelimit.MsgUpdateParamsResponse, error) {
if err := k.ValidateAuthority(msg.Authority); err != nil {
return nil, err
}
Expand All @@ -31,5 +37,5 @@ func (k MsgServer) GovUpdateParams(goCtx context.Context, msg *ibcratelimit.MsgG
k.SetParams(ctx, msg.Params)
k.emitEvent(ctx, ibcratelimit.NewEventParamsUpdated())

return &ibcratelimit.MsgGovUpdateParamsResponse{}, nil
return &ibcratelimit.MsgUpdateParamsResponse{}, nil
}
16 changes: 11 additions & 5 deletions x/ibcratelimit/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ibcratelimit

import (
"errors"
fmt "fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -9,18 +10,23 @@ import (
// AllRequestMsgs defines all the Msg*Request messages.
var AllRequestMsgs = []sdk.Msg{
(*MsgGovUpdateParamsRequest)(nil),
(*MsgUpdateParamsRequest)(nil),
}

// NewMsgGovUpdateParamsRequest creates a new GovUpdateParams message.
func NewMsgGovUpdateParamsRequest(authority, ratelimiter string) *MsgGovUpdateParamsRequest {
return &MsgGovUpdateParamsRequest{
// ValidateBasic runs stateless validation checks on the message.
func (m MsgGovUpdateParamsRequest) ValidateBasic() error {
return errors.New("deprecated and unusable")
}

// NewUpdateParamsRequest creates a new GovUpdateParams message.
func NewUpdateParamsRequest(authority, ratelimiter string) *MsgUpdateParamsRequest {
return &MsgUpdateParamsRequest{
Authority: authority,
Params: NewParams(ratelimiter),
}
}

// ValidateBasic runs stateless validation checks on the message.
func (m MsgGovUpdateParamsRequest) ValidateBasic() error {
func (m MsgUpdateParamsRequest) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil {
return fmt.Errorf("invalid authority: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions x/ibcratelimit/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@ import (
func TestAllMsgsGetSigners(t *testing.T) {
msgMakers := []testutil.MsgMaker{
func(signer string) sdk.Msg { return &MsgGovUpdateParamsRequest{Authority: signer} },
func(signer string) sdk.Msg { return &MsgUpdateParamsRequest{Authority: signer} },
}

testutil.RunGetSignersTests(t, AllRequestMsgs, msgMakers, nil)
}

func TestNewMsgGovUpdateParamsRequest(t *testing.T) {
expected := &MsgGovUpdateParamsRequest{
expected := &MsgUpdateParamsRequest{
Authority: "authority",
Params: NewParams("contract"),
}
event := NewMsgGovUpdateParamsRequest(expected.Authority, expected.Params.ContractAddress)
event := NewUpdateParamsRequest(expected.Authority, expected.Params.ContractAddress)
assert.Equal(t, expected, event, "should create the correct with correct content")
}

func TestNewMsgGovUpdateParamsValidateBasic(t *testing.T) {
func TestNewMsgUpdateParamsValidateBasic(t *testing.T) {
tests := []struct {
name string
authority string
Expand Down Expand Up @@ -62,7 +63,7 @@ func TestNewMsgGovUpdateParamsValidateBasic(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
msg := NewMsgGovUpdateParamsRequest(tc.authority, tc.contract)
msg := NewUpdateParamsRequest(tc.authority, tc.contract)
err := msg.ValidateBasic()

if len(tc.err) > 0 {
Expand Down
12 changes: 6 additions & 6 deletions x/ibcratelimit/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ func WeightedOperations(
)

simState.AppParams.GetOrGenerate(OpWeightMsgUpdateParams, &wMsgUpdateParams, nil,
func(_ *rand.Rand) { wMsgUpdateParams = simappparams.DefaultWeightGovUpdateParams })
func(_ *rand.Rand) { wMsgUpdateParams = simappparams.DefaultWeightUpdateParams })

return simulation.WeightedOperations{
simulation.NewWeightedOperation(wMsgUpdateParams, SimulateMsgGovUpdateParams(simState, k, ak, bk)),
simulation.NewWeightedOperation(wMsgUpdateParams, SimulateMsgUpdateParams(simState, k, ak, bk)),
}
}

// SimulateMsgGovUpdateParams sends a MsgUpdateParams.
func SimulateMsgGovUpdateParams(simState module.SimulationState, _ keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation {
// SimulateMsgUpdateParams sends a MsgUpdateParams.
func SimulateMsgUpdateParams(simState module.SimulationState, _ keeper.Keeper, ak authkeeper.AccountKeeperI, bk bankkeeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
raccs, err := RandomAccs(r, accs, uint64(len(accs)))
if err != nil {
return simtypes.NoOpMsg(ibcratelimit.ModuleName, sdk.MsgTypeURL(&ibcratelimit.MsgGovUpdateParamsRequest{}), err.Error()), nil, nil
return simtypes.NoOpMsg(ibcratelimit.ModuleName, sdk.MsgTypeURL(&ibcratelimit.MsgUpdateParamsRequest{}), err.Error()), nil, nil
}

// 50% chance to be from the module's authority
from := raccs[0]
to := raccs[1]

msg := ibcratelimit.NewMsgGovUpdateParamsRequest(from.Address.String(), to.Address.String())
msg := ibcratelimit.NewUpdateParamsRequest(from.Address.String(), to.Address.String())

// TODO[1760]: Refactor this to submit it as a gov prop and return futures for votes.
return Dispatch(r, app, ctx, simState, from, chainID, msg, ak, bk, nil)
Expand Down
10 changes: 5 additions & 5 deletions x/ibcratelimit/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *SimTestSuite) TestWeightedOperations() {
opMsgRoute string
opMsgName string
}{
{simappparams.DefaultWeightGovUpdateParams, ibcratelimit.ModuleName, sdk.MsgTypeURL(&ibcratelimit.MsgGovUpdateParamsRequest{})},
{simappparams.DefaultWeightUpdateParams, ibcratelimit.ModuleName, sdk.MsgTypeURL(&ibcratelimit.MsgUpdateParamsRequest{})},
}

expNames := make([]string, len(expected))
Expand Down Expand Up @@ -107,19 +107,19 @@ func (s *SimTestSuite) TestWeightedOperations() {
}
}

func (s *SimTestSuite) TestSimulateMsgGovUpdateParams() {
func (s *SimTestSuite) TestSimulateMsgUpdateParams() {
// setup 3 accounts
source := rand.NewSource(1)
r := rand.New(source)
accounts := s.getTestingAccounts(r, 3)

// execute operation
op := simulation.SimulateMsgGovUpdateParams(s.MakeTestSimState(), *s.app.RateLimitingKeeper, s.app.AccountKeeper, s.app.BankKeeper)
op := simulation.SimulateMsgUpdateParams(s.MakeTestSimState(), *s.app.RateLimitingKeeper, s.app.AccountKeeper, s.app.BankKeeper)
operationMsg, futureOperations, err := op(r, s.app.BaseApp, s.ctx, accounts, "")
s.Require().NoError(err, "SimulateMsgGovUpdateParams op(...) error")
s.Require().NoError(err, "SimulateMsgUpdateParams op(...) error")
s.LogOperationMsg(operationMsg, "good")

var msg ibcratelimit.MsgGovUpdateParamsRequest
var msg ibcratelimit.MsgUpdateParamsRequest
s.Require().NoError(s.app.AppCodec().Unmarshal(operationMsg.Msg, &msg), "UnmarshalJSON(operationMsg.Msg)")

s.Assert().True(operationMsg.OK, "operationMsg.OK")
Expand Down
Loading

0 comments on commit 4a06642

Please sign in to comment.