Skip to content

Commit

Permalink
Merge pull request #718 from neutron-org/feat/rate-limit-params
Browse files Browse the repository at this point in the history
rate limit params
  • Loading branch information
quasisamurai authored Sep 16, 2024
2 parents 0c0dffb + 81f6303 commit d0c167f
Show file tree
Hide file tree
Showing 21 changed files with 946 additions and 100 deletions.
11 changes: 7 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ import (
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"

ibcratelimit "github.com/neutron-org/neutron/v4/x/ibc-rate-limit"
ibcratelimitkeeper "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/keeper"
ibcratelimittypes "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types"

//nolint:staticcheck
ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down Expand Up @@ -276,6 +276,7 @@ var (
),
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
ibcratelimitmodule.AppModuleBasic{},
auction.AppModuleBasic{},
globalfee.AppModule{},
feemarket.AppModuleBasic{},
Expand Down Expand Up @@ -875,7 +876,7 @@ func New(
)
interchainTxsModule := interchaintxs.NewAppModule(appCodec, app.InterchainTxsKeeper, app.AccountKeeper, app.BankKeeper)
contractManagerModule := contractmanager.NewAppModule(appCodec, app.ContractManagerKeeper)
ibcRateLimitmodule := ibcratelimitmodule.NewAppModule(*app.RateLimitingICS4Wrapper)
ibcRateLimitmodule := ibcratelimitmodule.NewAppModule(appCodec, *app.RateLimitingICS4Wrapper.IbcratelimitKeeper, *app.RateLimitingICS4Wrapper)
ibcHooksModule := ibchooks.NewAppModule(app.AccountKeeper)

transferModule := transferSudo.NewAppModule(app.TransferKeeper)
Expand Down Expand Up @@ -1093,6 +1094,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
ibcRateLimitmodule,
consumerModule,
icaModule,
app.PFMModule,
Expand Down Expand Up @@ -1600,7 +1602,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(tokenfactorytypes.StoreKey).WithKeyTable(tokenfactorytypes.ParamKeyTable())
paramsKeeper.Subspace(interchainqueriesmoduletypes.StoreKey).WithKeyTable(interchainqueriesmoduletypes.ParamKeyTable())
paramsKeeper.Subspace(interchaintxstypes.StoreKey).WithKeyTable(interchaintxstypes.ParamKeyTable())
paramsKeeper.Subspace(ibcratelimittypes.ModuleName)
// paramsKeeper.Subspace(ibcratelimittypes.ModuleName)

return paramsKeeper
}
Expand Down Expand Up @@ -1683,14 +1685,15 @@ func (app *App) WireICS20PreWasmKeeper(
&wasmHooks,
)

ibcratelimitKeeper := ibcratelimitkeeper.NewKeeper(appCodec, app.keys[ibcratelimittypes.ModuleName], authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String())
// ChannelKeeper wrapper for rate limiting SendPacket(). The wasmKeeper needs to be added after it's created
rateLimitingICS4Wrapper := ibcratelimit.NewICS4Middleware(
app.HooksICS4Wrapper,
&app.AccountKeeper,
// wasm keeper we set later.
nil,
&app.BankKeeper,
app.GetSubspace(ibcratelimittypes.ModuleName),
&ibcratelimitKeeper,
)
app.RateLimitingICS4Wrapper = &rateLimitingICS4Wrapper

Expand Down
2 changes: 1 addition & 1 deletion proto/osmosis/ibcratelimit/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "osmosis/ibcratelimit/v1beta1/params.proto";

option go_package = "github.com/osmosis-labs/osmosis/v26/x/ibc-rate-limit/types";
option go_package = "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types";

// GenesisState defines the ibc-rate-limit module's genesis state.
message GenesisState {
Expand Down
2 changes: 1 addition & 1 deletion proto/osmosis/ibcratelimit/v1beta1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package osmosis.ibcratelimit.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/osmosis-labs/osmosis/v26/x/ibc-rate-limit/types";
option go_package = "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types";

// Params defines the parameters for the ibc-rate-limit module.
message Params {
Expand Down
2 changes: 1 addition & 1 deletion proto/osmosis/ibcratelimit/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "osmosis/ibcratelimit/v1beta1/params.proto";

option go_package = "github.com/osmosis-labs/osmosis/v26/x/ibc-rate-limit/client/queryproto";
option go_package = "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/client/queryproto";

// Query defines the gRPC querier service.
service Query {
Expand Down
4 changes: 2 additions & 2 deletions proto/osmosis/ibcratelimit/v1beta1/query.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
keeper:
path: "github.com/osmosis-labs/osmosis/v26/x/ibc-rate-limit"
path: "github.com/neutron-org/neutron/v4/x/ibc-rate-limit"
struct: "Keeper"
client_path: "github.com/osmosis-labs/osmosis/v26/x/ibc-rate-limit/client"
client_path: "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/client"
queries:
Params:
proto_wrapper:
Expand Down
9 changes: 6 additions & 3 deletions proto/osmosis/ibcratelimit/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
syntax = "proto3";
package osmosis.ibcratelimit.v1beta1;

import "cosmos/base/query/v1beta1/pagination.proto";
import "amino/amino.proto";
import "cosmos/bank/v1beta1/bank.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "osmosis/ibcratelimit/v1beta1/params.proto";

option go_package = "github.com/osmosis-labs/osmosis/v26/x/ibc-rate-limit/types";
option go_package = "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types";

// Msg defines the tokefactory module's gRPC message service.
service Msg {
Expand Down
42 changes: 21 additions & 21 deletions x/ibc-rate-limit/client/queryproto/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion x/ibc-rate-limit/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import (
// InitGenesis initializes the x/ibc-rate-limit module's state from a provided genesis
// state, which includes the parameter for the contract address.
func (i *ICS4Wrapper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
i.SetParams(ctx, genState.Params)
err := i.IbcratelimitKeeper.SetParams(ctx, genState.Params)
if err != nil {
panic(err)
}
}

// ExportGenesis returns the x/ibc-rate-limit module's exported genesis.
Expand Down
15 changes: 4 additions & 11 deletions x/ibc-rate-limit/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,9 @@ func (suite *MiddlewareTestSuite) TestUnsetRateLimitingContract() {
app := suite.GetNeutronZoneApp(suite.ChainA)

// Unset the contract param
params, err := types.NewParams("")
err := app.RateLimitingICS4Wrapper.IbcratelimitKeeper.SetParams(suite.ChainA.GetContext(), types.Params{ContractAddress: ""})
suite.Require().NoError(err)
paramSpace, ok := app.ParamsKeeper.GetSubspace(types.ModuleName)
suite.Require().True(ok)
// N.B.: this panics if validation fails.
paramSpace.SetParamSet(suite.ChainA.GetContext(), &params)
}

// Test rate limits are reverted if a "send" fails
Expand Down Expand Up @@ -614,14 +611,10 @@ func (suite *MiddlewareTestSuite) InstantiateRLContract(quotas string) sdk.AccAd
}

func (suite *MiddlewareTestSuite) RegisterRateLimitingContract(addr []byte) {
addrStr, err := sdk.Bech32ifyAddressBytes("neutron", addr)
require.NoError(suite.ChainA.TB, err)
params, err := types.NewParams(addrStr)
require.NoError(suite.ChainA.TB, err)
addrStr, _ := sdk.Bech32ifyAddressBytes("neutron", addr)
app := suite.GetNeutronZoneApp(suite.ChainA)
paramSpace, ok := app.ParamsKeeper.GetSubspace(types.ModuleName)
require.True(suite.ChainA.TB, ok)
paramSpace.SetParamSet(suite.ChainA.GetContext(), &params)
_ = app.RateLimitingICS4Wrapper.SetParams(suite.ChainA.GetContext(), types.Params{ContractAddress: addrStr})
require.True(suite.ChainA.TB, true)
}

// AssertEventEmitted asserts that ctx's event manager has emitted the given number of events
Expand Down
26 changes: 21 additions & 5 deletions x/ibc-rate-limit/ibcratelimitmodule/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/neutron-org/neutron/v4/x/ibc-rate-limit/keeper"
"github.com/spf13/cobra"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
Expand Down Expand Up @@ -35,11 +36,18 @@ var (
_ module.HasServices = AppModule{}
)

type AppModuleBasic struct{}
type AppModuleBasic struct {
cdc codec.BinaryCodec
}

func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic {
return AppModuleBasic{cdc: cdc}
}

func (AppModuleBasic) Name() string { return types.ModuleName }

func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
types.RegisterCodec(cdc)
}

func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
Expand Down Expand Up @@ -70,7 +78,8 @@ func (b AppModuleBasic) GetQueryCmd() *cobra.Command {
}

// RegisterInterfaces registers interfaces and implementations of the ibc-rate-limit module.
func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {
func (AppModuleBasic) RegisterInterfaces(reg codectypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
}

// ----------------------------------------------------------------------------
Expand All @@ -82,11 +91,17 @@ type AppModule struct {
AppModuleBasic

ics4wrapper ibcratelimit.ICS4Wrapper
keeper keeper.Keeper
}

func NewAppModule(ics4wrapper ibcratelimit.ICS4Wrapper) AppModule {
func NewAppModule(
cdc codec.Codec,
keeper keeper.Keeper,
ics4wrapper ibcratelimit.ICS4Wrapper,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
ics4wrapper: ics4wrapper,
}
}
Expand All @@ -109,6 +124,7 @@ func (AppModule) QuerierRoute() string { return types.RouterKey }
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
queryproto.RegisterQueryServer(cfg.QueryServer(), grpc.Querier{Q: ibcratelimitclient.Querier{K: am.ics4wrapper}})
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
}

// RegisterInvariants registers the txfees module's invariants.
Expand Down
48 changes: 48 additions & 0 deletions x/ibc-rate-limit/ibcratelimitmodule/module_simulation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ibcratelimitmodule

import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/neutron-org/neutron/v4/testutil/common/sample"
ibcratelimitsimulation "github.com/neutron-org/neutron/v4/x/ibc-rate-limit/simulation"
"github.com/neutron-org/neutron/v4/x/ibc-rate-limit/types"
)

// avoid unused import issue
var (
_ = sample.AccAddress
_ = ibcratelimitsimulation.FindAccount
_ = sims.StakePerAccount
_ = simulation.MsgEntryKind
_ = baseapp.Paramspace
)

// GenerateGenesisState creates a randomized GenState of the module
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
accs := make([]string, len(simState.Accounts))
for i, acc := range simState.Accounts {
accs[i] = acc.Address.String()
}
interchainqueriesGenesis := types.GenesisState{
Params: types.DefaultParams(),
}
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&interchainqueriesGenesis)
}

// ProposalContents doesn't return any content functions for governance proposals
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
return nil
}

// RegisterStoreDecoder registers a decoder
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}

// WeightedOperations returns the all the gov module operations with their respective weights.
func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation {
operations := make([]simtypes.WeightedOperation, 0)

return operations
}
Loading

0 comments on commit d0c167f

Please sign in to comment.