Skip to content

Commit

Permalink
feat!: wire ibcfee module (#3038)
Browse files Browse the repository at this point in the history
* feat!: wire ibcfee module

* docs: add changelogs

* chore: update e2e ICA test; correctly wire IBCFee with ICA and PFM

* uncomment tests

* tests: add IBC fee integration tests

* chore: appease linter

* nit: rm printline from test

* apply comment suggestion

* Update app/keepers/keepers.go

Co-authored-by: bernd-m <[email protected]>

---------

Co-authored-by: bernd-m <[email protected]>
  • Loading branch information
MSalopek and bermuell authored Apr 15, 2024
1 parent 9be4525 commit 6c6a514
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/dependencies/3038-ibc-fee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Add the [IBC Fee Module](https://ibc.cosmos.network/v7/middleware/ics29-fee/overview)
[v7.3.2](https://github.com/cosmos/ibc-go/releases/tag/v7.3.2).
([\#3038](https://github.com/cosmos/gaia/pull/3038))
3 changes: 3 additions & 0 deletions .changelog/unreleased/features/3038-ibc-fee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Add the [IBC Fee Module](https://ibc.cosmos.network/v7/middleware/ics29-fee/overview)
[v7.3.2](https://github.com/cosmos/ibc-go/releases/tag/v7.3.2).
([\#3038](https://github.com/cosmos/gaia/pull/3038))
3 changes: 3 additions & 0 deletions .changelog/unreleased/state-breaking/3038-ibc-fee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Add the [IBC Fee Module](https://ibc.cosmos.network/v7/middleware/ics29-fee/overview)
[v7.3.2](https://github.com/cosmos/ibc-go/releases/tag/v7.3.2).
([\#3038](https://github.com/cosmos/gaia/pull/3038))
26 changes: 23 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand Down Expand Up @@ -114,6 +117,7 @@ type AppKeepers struct {

// Modules
ICAModule ica.AppModule
IBCFeeKeeper ibcfeekeeper.Keeper
TransferModule transfer.AppModule
PFMRouterModule pfmrouter.AppModule
RateLimitModule ratelimit.AppModule
Expand Down Expand Up @@ -358,12 +362,19 @@ func NewAppKeeper(
// If evidence needs to be handled for the app, set routes in router here and seal
appKeepers.EvidenceKeeper = *evidenceKeeper

appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, appKeepers.keys[ibcfeetypes.StoreKey],
appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper,
)

// ICA Host keeper
appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
appKeepers.keys[icahosttypes.StoreKey],
appKeepers.GetSubspace(icahosttypes.SubModuleName),
appKeepers.IBCKeeper.ChannelKeeper, // ICS4Wrapper
appKeepers.IBCFeeKeeper, // ICS4Wrapper
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
Expand All @@ -381,15 +392,15 @@ func NewAppKeeper(
govAuthority, // authority
appKeepers.BankKeeper,
appKeepers.IBCKeeper.ChannelKeeper, // ChannelKeeper
appKeepers.IBCKeeper.ChannelKeeper, // ICS4Wrapper
appKeepers.IBCFeeKeeper, // ICS4Wrapper
)

// ICA Controller keeper
appKeepers.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec,
appKeepers.keys[icacontrollertypes.StoreKey],
appKeepers.GetSubspace(icacontrollertypes.SubModuleName),
appKeepers.IBCKeeper.ChannelKeeper, // ICS4Wrapper
appKeepers.IBCFeeKeeper, // ICS4Wrapper
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedICAControllerKeeper,
Expand Down Expand Up @@ -419,6 +430,7 @@ func NewAppKeeper(
appKeepers.BankKeeper,
appKeepers.ScopedTransferKeeper,
)

// Must be called on PFMRouter AFTER TransferKeeper initialized
appKeepers.PFMRouterKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

Expand All @@ -430,9 +442,14 @@ func NewAppKeeper(

// Create Transfer Stack (from bottom to top of stack)
// - core IBC
// - ibcfee
// - ratelimit
// - pfm
// - transfer
//
// This is how transfer stack will work in the end:
// * RecvPacket -> IBC core -> Fee -> RateLimit -> PFM -> Transfer (AddRoute)
// * SendPacket -> Transfer -> PFM -> RateLimit -> Fee -> IBC core (ICS4Wrapper)
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(appKeepers.TransferKeeper)
transferStack = pfmrouter.NewIBCMiddleware(
Expand All @@ -443,12 +460,15 @@ func NewAppKeeper(
pfmrouterkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
transferStack = ratelimit.NewIBCMiddleware(appKeepers.RatelimitKeeper, transferStack)
transferStack = ibcfee.NewIBCMiddleware(transferStack, appKeepers.IBCFeeKeeper)

// Create ICAHost Stack
var icaHostStack porttypes.IBCModule = icahost.NewIBCModule(appKeepers.ICAHostKeeper)
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, appKeepers.IBCFeeKeeper)

// Create Interchain Accounts Controller Stack
var icaControllerStack porttypes.IBCModule = icacontroller.NewIBCMiddleware(nil, appKeepers.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, appKeepers.IBCFeeKeeper)

// Create IBC Router & seal
ibcRouter := porttypes.NewRouter().
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
routertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
providertypes "github.com/cosmos/interchain-security/v4/x/ccv/provider/types"
Expand Down Expand Up @@ -46,6 +47,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
upgradetypes.StoreKey,
evidencetypes.StoreKey,
ibctransfertypes.StoreKey,
ibcfeetypes.StoreKey,
icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
capabilitytypes.StoreKey,
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
pfmroutertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v7/modules/apps/29-fee"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
Expand Down Expand Up @@ -74,6 +76,7 @@ var maccPerms = map[string][]string{
govtypes.ModuleName: {authtypes.Burner},
// liquiditytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibcfeetypes.ModuleName: nil,
providertypes.ConsumerRewardsPool: nil,
}

Expand Down Expand Up @@ -107,6 +110,7 @@ var ModuleBasics = module.NewBasicManager(
authzmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
ibcfee.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
Expand Down Expand Up @@ -152,6 +156,7 @@ func appModules(
sdkparams.NewAppModule(app.ParamsKeeper),
globalfee.NewAppModule(app.GetSubspace(globalfee.ModuleName)),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
app.TransferModule,
app.ICAModule,
app.PFMRouterModule,
Expand Down Expand Up @@ -221,6 +226,7 @@ func orderBeginBlockers() []string {
icatypes.ModuleName,
pfmroutertypes.ModuleName,
ratelimittypes.ModuleName,
ibcfeetypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
Expand Down Expand Up @@ -252,6 +258,7 @@ func orderEndBlockers() []string {
pfmroutertypes.ModuleName,
ratelimittypes.ModuleName,
capabilitytypes.ModuleName,
ibcfeetypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
Expand Down Expand Up @@ -294,6 +301,7 @@ func orderInitBlockers() []string {
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades/v16/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"

icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
ibcfeetypes "github.com/cosmos/ibc-go/v7/modules/apps/29-fee/types"

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

Expand All @@ -25,6 +26,7 @@ var Upgrade = upgrades.Upgrade{
Added: []string{
ratelimittypes.ModuleName,
icacontrollertypes.SubModuleName,
ibcfeetypes.ModuleName,
},
},
}
1 change: 1 addition & 0 deletions tests/e2e/e2e_ica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (s *IntegrationTestSuite) registerICAAccount(c *chain, valIdx int, sender,
fmt.Sprintf("--from=%s", sender),
fmt.Sprintf("--%s=%s", flags.FlagFees, fees),
fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id),
"--gas=250000", // default 200_000 is not enough; gas fees increased after adding IBC fee middleware
"--keyring-backend=test",
"--broadcast-mode=sync",
"--output=json",
Expand Down
Loading

0 comments on commit 6c6a514

Please sign in to comment.