Skip to content

Commit

Permalink
Merge pull request #706 from neutron-org/feat/ibc-rate-limit
Browse files Browse the repository at this point in the history
ibc rate limit module NTRN-393
  • Loading branch information
pr0n00gler authored Oct 2, 2024
2 parents 36b8736 + 772156b commit d943d12
Show file tree
Hide file tree
Showing 44 changed files with 4,746 additions and 102 deletions.
222 changes: 138 additions & 84 deletions app/app.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/proposals_allowlisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
ccvconsumertypes "github.com/cosmos/interchain-security/v5/x/ccv/consumer/types"
ibcratelimittypes "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
marketmaptypes "github.com/skip-mev/slinky/x/marketmap/types"

Expand Down Expand Up @@ -93,7 +94,8 @@ func isSdkMessageWhitelisted(msg sdk.Msg) bool {
*feemarkettypes.MsgParams,
*dynamicfeestypes.MsgUpdateParams,
*ibctransfertypes.MsgUpdateParams,
*globalfeetypes.MsgUpdateParams:
*globalfeetypes.MsgUpdateParams,
*ibcratelimittypes.MsgUpdateParams:
return true
}
return false
Expand Down
5 changes: 3 additions & 2 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v5/x/ccv/consumer/keeper"
dexkeeper "github.com/neutron-org/neutron/v5/x/dex/keeper"
ibcratelimitkeeper "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/keeper"
auctionkeeper "github.com/skip-mev/block-sdk/v2/x/auction/keeper"
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper"
marketmapkeeper "github.com/skip-mev/slinky/x/marketmap/keeper"

dexkeeper "github.com/neutron-org/neutron/v5/x/dex/keeper"

dynamicfeeskeeper "github.com/neutron-org/neutron/v5/x/dynamicfees/keeper"

contractmanagerkeeper "github.com/neutron-org/neutron/v5/x/contractmanager/keeper"
Expand Down Expand Up @@ -67,6 +67,7 @@ type UpgradeKeepers struct {
FeeMarketKeeper *feemarketkeeper.Keeper
DynamicfeesKeeper *dynamicfeeskeeper.Keeper
DexKeeper *dexkeeper.Keeper
IbcRateLimitKeeper *ibcratelimitkeeper.Keeper
// subspaces
GlobalFeeSubspace paramtypes.Subspace
CcvConsumerSubspace paramtypes.Subspace
Expand Down
6 changes: 5 additions & 1 deletion app/upgrades/v5.0.0/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import (
storetypes "cosmossdk.io/store/types"

"github.com/neutron-org/neutron/v5/app/upgrades"
ibcratelimittypes "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types"
)

const (
// UpgradeName defines the on-chain upgrade name.
UpgradeName = "v5.0.0"

MarketMapAuthorityMultisig = "neutron1anjpluecd0tdc0n8xzc3l5hua4h93wyq0x7v56"
// RateLimitContract defines the RL contract addr which we set as a contract address in ibc-rate-limit middleware
// https://neutron.celat.one/neutron-1/contracts/neutron15aqgplxcavqhurr0g5wwtdw6025dknkqwkfh0n46gp2qjl6236cs2yd3nl
RateLimitContract = "neutron15aqgplxcavqhurr0g5wwtdw6025dknkqwkfh0n46gp2qjl6236cs2yd3nl"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{},
Added: []string{ibcratelimittypes.ModuleName},
},
}
24 changes: 24 additions & 0 deletions app/upgrades/v5.0.0/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"github.com/neutron-org/neutron/v5/app/upgrades"
dexkeeper "github.com/neutron-org/neutron/v5/x/dex/keeper"
ibcratelimitkeeper "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/keeper"
ibcratelimittypes "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types"
)

func CreateUpgradeHandler(
Expand Down Expand Up @@ -47,6 +49,15 @@ func CreateUpgradeHandler(
return nil, err
}

ctx.Logger().Info("Running ibc-rate-limit upgrades...")
// Only set rate limit contract for mainnet
if ctx.ChainID() == "neutron-1" {
err = upgradeIbcRateLimitSetContract(ctx, *keepers.IbcRateLimitKeeper)
if err != nil {
return nil, err
}
}

ctx.Logger().Info(fmt.Sprintf("Migration {%s} applied", UpgradeName))
return vm, nil
}
Expand All @@ -68,6 +79,19 @@ func upgradeDexPause(ctx sdk.Context, k dexkeeper.Keeper) error {
return nil
}

func upgradeIbcRateLimitSetContract(ctx sdk.Context, k ibcratelimitkeeper.Keeper) error {
// Set the dex to paused
ctx.Logger().Info("Setting ibc rate limiting contract...")

if err := k.SetParams(ctx, ibcratelimittypes.Params{ContractAddress: RateLimitContract}); err != nil {
return err
}

ctx.Logger().Info("Rate limit contract is set")

return nil
}

func setMarketMapParams(ctx sdk.Context, marketmapKeeper *marketmapkeeper.Keeper) error {
marketmapParams := marketmaptypes.Params{
MarketAuthorities: []string{authtypes.NewModuleAddress(adminmoduletypes.ModuleName).String(), MarketMapAuthorityMultisig},
Expand Down
22 changes: 22 additions & 0 deletions app/upgrades/v5.0.0/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,25 @@ func (suite *UpgradeTestSuite) TestUpgradeDexPause() {

suite.ErrorIs(err, dextypes.ErrDexPaused)
}

func (suite *UpgradeTestSuite) TestUpgradeSetRateLimitContract() {
var (
app = suite.GetNeutronZoneApp(suite.ChainA)
ctx = suite.ChainA.GetContext().WithChainID("neutron-1")
)

params := app.RateLimitingICS4Wrapper.IbcratelimitKeeper.GetParams(ctx)

suite.Equal(params.ContractAddress, "")

upgrade := upgradetypes.Plan{
Name: v500.UpgradeName,
Info: "some text here",
Height: 100,
}
suite.NoError(app.UpgradeKeeper.ApplyUpgrade(ctx, upgrade))

params = app.RateLimitingICS4Wrapper.IbcratelimitKeeper.GetParams(ctx)

suite.Equal(params.ContractAddress, v500.RateLimitContract)
}
15 changes: 15 additions & 0 deletions proto/neutron/ibcratelimit/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
package neutron.ibcratelimit.v1beta1;

import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "neutron/ibcratelimit/v1beta1/params.proto";

option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types";

// GenesisState defines the ibc-rate-limit module's genesis state.
message GenesisState {
// params are all the parameters of the module
Params params = 1 [(gogoproto.nullable) = false];
}
14 changes: 14 additions & 0 deletions proto/neutron/ibcratelimit/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
syntax = "proto3";
package neutron.ibcratelimit.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types";

// Params defines the parameters for the ibc-rate-limit module.
message Params {
string contract_address = 1 [
(gogoproto.moretags) = "yaml:\"contract_address\"",
(gogoproto.nullable) = true
];
}
27 changes: 27 additions & 0 deletions proto/neutron/ibcratelimit/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";
package neutron.ibcratelimit.v1beta1;

import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "neutron/ibcratelimit/v1beta1/params.proto";

option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types";

// Query defines the gRPC querier service.
service Query {
// Params defines a gRPC query method that returns the ibc-rate-limit module's
// parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/neutron/ibc-rate-limit/v1beta1/params";
}
}

// ParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// aramsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
43 changes: 43 additions & 0 deletions proto/neutron/ibcratelimit/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
syntax = "proto3";
package neutron.ibcratelimit.v1beta1;

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 "neutron/ibcratelimit/v1beta1/params.proto";

option go_package = "github.com/neutron-org/neutron/v5/x/ibc-rate-limit/types";

// Msg defines the tokefactory module's gRPC message service.
service Msg {
option (cosmos.msg.v1.service) = true;
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgUpdateParams is the MsgUpdateParams request type.
//
// Since: 0.47
message MsgUpdateParams {
option (amino.name) = "neutron/ibc-rate-limit/MsgUpdateParams";
option (cosmos.msg.v1.signer) = "authority";

// Authority is the address of the governance account.
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// params defines the x/tokenfactory parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}

// MsgUpdateParamsResponse defines the response structure for executing a
// MsgUpdateParams message.
//
// Since: 0.47
message MsgUpdateParamsResponse {}
Loading

0 comments on commit d943d12

Please sign in to comment.