@@ -54,6 +54,9 @@ import (
5454 ibchooks "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8"
5555 ibchookskeeper "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/keeper"
5656 ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v8/types"
57+ ratelimit "github.com/cosmos/ibc-apps/modules/rate-limiting/v8"
58+ ratelimitkeeper "github.com/cosmos/ibc-apps/modules/rate-limiting/v8/keeper"
59+ ratelimittypes "github.com/cosmos/ibc-apps/modules/rate-limiting/v8/types"
5760 capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
5861 capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
5962 icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
@@ -173,6 +176,7 @@ type AppKeepers struct {
173176 HooksICS4Wrapper ibchooks.ICS4Middleware
174177 Ics20WasmHooks * ibchooks.WasmHooks
175178 PacketForwardKeeper * packetforwardkeeper.Keeper
179+ RatelimitKeeper ratelimitkeeper.Keeper
176180}
177181
178182func (appKeepers AppKeepers ) GetKVStoreKeys () map [string ]* storetypes.KVStoreKey {
@@ -395,19 +399,6 @@ func NewAppKeeper(
395399 authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
396400 )
397401
398- // Configure the hooks keeper
399- hooksKeeper := ibchookskeeper .NewKeeper (
400- app .keys [ibchookstypes .StoreKey ],
401- )
402- app .IBCHooksKeeper = & hooksKeeper
403-
404- wasmHooks := ibchooks .NewWasmHooks (app .IBCHooksKeeper , & app .WasmKeeper , AccountAddressPrefix )
405- app .Ics20WasmHooks = & wasmHooks
406- app .HooksICS4Wrapper = ibchooks .NewICS4Middleware (
407- app .IBCKeeper .ChannelKeeper ,
408- app .Ics20WasmHooks ,
409- )
410-
411402 transferKeeper := ibctransferkeeper .NewKeeper (
412403 appCodec ,
413404 app .keys [ibctransfertypes .StoreKey ],
@@ -422,17 +413,6 @@ func NewAppKeeper(
422413 )
423414 app .TransferKeeper = & transferKeeper
424415
425- app .PacketForwardKeeper = packetforwardkeeper .NewKeeper (
426- appCodec ,
427- app .keys [packetforwardtypes .StoreKey ],
428- app .TransferKeeper ,
429- app .IBCKeeper .ChannelKeeper ,
430- app .BankKeeper ,
431- // The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
432- app .HooksICS4Wrapper ,
433- authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
434- )
435-
436416 app .ICAHostKeeper = icahostkeeper .NewKeeper (
437417 appCodec ,
438418 app .keys [icahosttypes .StoreKey ],
@@ -449,6 +429,16 @@ func NewAppKeeper(
449429 // required since ibc-go v7.5.0
450430 app .ICAHostKeeper .WithQueryRouter (bApp .GRPCQueryRouter ())
451431
432+ app .RatelimitKeeper = * ratelimitkeeper .NewKeeper (
433+ appCodec , // BinaryCodec
434+ runtime .NewKVStoreService (app .keys [ratelimittypes .StoreKey ]), // StoreKey
435+ app .GetSubspace (ratelimittypes .ModuleName ), // param Subspace
436+ authtypes .NewModuleAddress (govtypes .ModuleName ).String (), // authority
437+ app .BankKeeper ,
438+ app .IBCKeeper .ChannelKeeper , // ChannelKeeper
439+ app .IBCKeeper .ChannelKeeper , // ICS4Wrapper
440+ )
441+
452442 app .ICAControllerKeeper = icacontrollerkeeper .NewKeeper (
453443 appCodec ,
454444 app .keys [icacontrollertypes .StoreKey ],
@@ -461,6 +451,33 @@ func NewAppKeeper(
461451 authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
462452 )
463453
454+ // Configure the hooks keeper
455+ hooksKeeper := ibchookskeeper .NewKeeper (
456+ app .keys [ibchookstypes .StoreKey ],
457+ )
458+ app .IBCHooksKeeper = & hooksKeeper
459+
460+ wasmHooks := ibchooks .NewWasmHooks (app .IBCHooksKeeper , & app .WasmKeeper , AccountAddressPrefix )
461+ app .Ics20WasmHooks = & wasmHooks
462+ app .HooksICS4Wrapper = ibchooks .NewICS4Middleware (
463+ app .IBCKeeper .ChannelKeeper ,
464+ app .Ics20WasmHooks ,
465+ )
466+ // intentionally sending itself to wrap HooksICS4Wrapper with rate limiter
467+ // Note app.HooksICS4Wrapper is used in transfer stack as well
468+ app .HooksICS4Wrapper = ibchooks .NewICS4Middleware (app .HooksICS4Wrapper , app .RatelimitKeeper )
469+
470+ app .PacketForwardKeeper = packetforwardkeeper .NewKeeper (
471+ appCodec ,
472+ app .keys [packetforwardtypes .StoreKey ],
473+ app .TransferKeeper ,
474+ app .IBCKeeper .ChannelKeeper ,
475+ app .BankKeeper ,
476+ // The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
477+ app .HooksICS4Wrapper ,
478+ authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
479+ )
480+
464481 wasmDir := filepath .Join (homePath , "wasm" )
465482 wasmConfig , err := wasm .ReadWasmConfig (appOpts )
466483 if err != nil {
@@ -733,14 +750,13 @@ func NewAppKeeper(
733750
734751 // Create Transfer Stack (from bottom to top of stack)
735752 // - core IBC
736- // - ibcfee
737753 // - ratelimit
738754 // - pfm
739755 // - provider
740756 // - transfer
741757 //
742758 // This is how transfer stack will work in the end:
743- // * RecvPacket -> IBC core -> Fee -> RateLimit -> PFM -> Provider -> Transfer (AddRoute)
759+ // * RecvPacket -> IBC core -> RateLimit -> PFM -> Provider -> Transfer (AddRoute)
744760 // * SendPacket -> Transfer -> Provider -> PFM -> RateLimit -> Fee -> IBC core (ICS4Wrapper)
745761
746762 var transferStack porttypes.IBCModule
@@ -752,6 +768,7 @@ func NewAppKeeper(
752768 0 , // retries on timeout
753769 packetforwardkeeper .DefaultForwardTransferPacketTimeoutTimestamp ,
754770 )
771+ transferStack = ratelimit .NewIBCMiddleware (app .RatelimitKeeper , transferStack )
755772 transferICS4Wrapper := transferStack .(porttypes.ICS4Wrapper )
756773 app .TransferKeeper .WithICS4Wrapper (transferICS4Wrapper )
757774
@@ -868,6 +885,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
868885 paramsKeeper .Subspace (icahosttypes .SubModuleName ).WithKeyTable (icahosttypes .ParamKeyTable ())
869886 paramsKeeper .Subspace (ccvconsumertypes .ModuleName ).WithKeyTable (ccv .ParamKeyTable ())
870887 paramsKeeper .Subspace (ibchookstypes .ModuleName )
888+ paramsKeeper .Subspace (ratelimittypes .ModuleName ).WithKeyTable (ratelimittypes .ParamKeyTable ())
871889
872890 // Can be removed as we are not using param subspace anymore anywhere
873891 paramsKeeper .Subspace (assetprofilemoduletypes .ModuleName )
0 commit comments