Skip to content

Commit aa21564

Browse files
crodriguezvegamergify[bot]
authored andcommitted
add missing set order functions for ica (#2740)
Co-authored-by: Carlos Rodriguez <crodveg@gmail.com> (cherry picked from commit f54143e) # Conflicts: # docs/middleware/ics29-fee/integration.md
1 parent 2d2dedc commit aa21564

File tree

2 files changed

+184
-1
lines changed

2 files changed

+184
-1
lines changed

docs/apps/interchain-accounts/integration.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,22 @@ app.moduleManager = module.NewManager(
116116

117117
...
118118

119+
// Add fee middleware to begin blocker logic
120+
app.moduleManager.SetOrderBeginBlockers(
121+
...
122+
icatypes.ModuleName,
123+
...
124+
)
125+
126+
// Add fee middleware to end blocker logic
127+
app.moduleManager.SetOrderEndBlockers(
128+
...
129+
icatypes.ModuleName,
130+
...
131+
)
132+
119133
// Add Interchain Accounts module InitGenesis logic
120-
app.mm.SetOrderInitGenesis(
134+
app.moduleManager.SetOrderInitGenesis(
121135
...
122136
icatypes.ModuleName,
123137
...
+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<!--
2+
order: 2
3+
-->
4+
5+
# Integration
6+
7+
Learn how to configure the Fee Middleware module with IBC applications. The following document is intended for developers building on top of the Cosmos SDK and only applies for Cosmos SDK chains. {synopsis}
8+
9+
## Pre-requisite Readings
10+
11+
* [IBC middleware development](../../ibc/middleware/develop.md) {prereq}
12+
* [IBC middleware integration](../../ibc/middleware/integration.md) {prereq}
13+
14+
The Fee Middleware module, as the name suggests, plays the role of an IBC middleware and as such must be configured by chain developers to route and handle IBC messages correctly.
15+
For Cosmos SDK chains this setup is done via the `app/app.go` file, where modules are constructed and configured in order to bootstrap the blockchain application.
16+
17+
## Example integration of the Fee Middleware module
18+
19+
```
20+
// app.go
21+
22+
// Register the AppModule for the fee middleware module
23+
ModuleBasics = module.NewBasicManager(
24+
...
25+
ibcfee.AppModuleBasic{},
26+
...
27+
)
28+
29+
...
30+
31+
// Add module account permissions for the fee middleware module
32+
maccPerms = map[string][]string{
33+
...
34+
ibcfeetypes.ModuleName: nil,
35+
}
36+
37+
...
38+
39+
// Add fee middleware Keeper
40+
type App struct {
41+
...
42+
43+
IBCFeeKeeper ibcfeekeeper.Keeper
44+
45+
...
46+
}
47+
48+
...
49+
50+
// Create store keys
51+
keys := sdk.NewKVStoreKeys(
52+
...
53+
ibcfeetypes.StoreKey,
54+
...
55+
)
56+
57+
...
58+
59+
app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
60+
appCodec, keys[ibcfeetypes.StoreKey],
61+
app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
62+
app.IBCKeeper.ChannelKeeper,
63+
&app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper,
64+
)
65+
66+
67+
// See the section below for configuring an application stack with the fee middleware module
68+
69+
...
70+
71+
// Register fee middleware AppModule
72+
app.moduleManager = module.NewManager(
73+
...
74+
ibcfee.NewAppModule(app.IBCFeeKeeper),
75+
)
76+
77+
...
78+
79+
// Add fee middleware to begin blocker logic
80+
app.moduleManager.SetOrderBeginBlockers(
81+
...
82+
ibcfeetypes.ModuleName,
83+
...
84+
)
85+
86+
// Add fee middleware to end blocker logic
87+
app.moduleManager.SetOrderEndBlockers(
88+
...
89+
ibcfeetypes.ModuleName,
90+
...
91+
)
92+
93+
// Add fee middleware to init genesis logic
94+
app.moduleManager.SetOrderInitGenesis(
95+
...
96+
ibcfeetypes.ModuleName,
97+
...
98+
)
99+
```
100+
101+
## Configuring an application stack with Fee Middleware
102+
103+
As mentioned in [IBC middleware development](../../ibc/middleware/develop.md) an application stack may be composed of many or no middlewares that nest a base application.
104+
These layers form the complete set of application logic that enable developers to build composable and flexible IBC application stacks.
105+
For example, an application stack may be just a single base application like `transfer`, however, the same application stack composed with `29-fee` will nest the `transfer` base application
106+
by wrapping it with the Fee Middleware module.
107+
108+
109+
### Transfer
110+
111+
See below for an example of how to create an application stack using `transfer` and `29-fee`.
112+
The following `transferStack` is configured in `app/app.go` and added to the IBC `Router`.
113+
The in-line comments describe the execution flow of packets between the application stack and IBC core.
114+
115+
```go
116+
// Create Transfer Stack
117+
// SendPacket, since it is originating from the application to core IBC:
118+
// transferKeeper.SendPacket -> fee.SendPacket -> channel.SendPacket
119+
120+
// RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way
121+
// channel.RecvPacket -> fee.OnRecvPacket -> transfer.OnRecvPacket
122+
123+
// transfer stack contains (from top to bottom):
124+
// - IBC Fee Middleware
125+
// - Transfer
126+
127+
// create IBC module from bottom to top of stack
128+
var transferStack porttypes.IBCModule
129+
transferStack = transfer.NewIBCModule(app.TransferKeeper)
130+
transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper)
131+
132+
// Add transfer stack to IBC Router
133+
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
134+
```
135+
136+
### Interchain Accounts
137+
138+
See below for an example of how to create an application stack using `27-interchain-accounts` and `29-fee`.
139+
The following `icaControllerStack` and `icaHostStack` are configured in `app/app.go` and added to the IBC `Router` with the associated authentication module.
140+
The in-line comments describe the execution flow of packets between the application stack and IBC core.
141+
142+
```go
143+
// Create Interchain Accounts Stack
144+
// SendPacket, since it is originating from the application to core IBC:
145+
// icaAuthModuleKeeper.SendTx -> icaController.SendPacket -> fee.SendPacket -> channel.SendPacket
146+
147+
// initialize ICA module with mock module as the authentication module on the controller side
148+
var icaControllerStack porttypes.IBCModule
149+
icaControllerStack = ibcmock.NewIBCModule(&mockModule, ibcmock.NewMockIBCApp("", scopedICAMockKeeper))
150+
app.ICAAuthModule = icaControllerStack.(ibcmock.IBCModule)
151+
icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper)
152+
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
153+
154+
// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
155+
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
156+
157+
var icaHostStack porttypes.IBCModule
158+
icaHostStack = icahost.NewIBCModule(app.ICAHostKeeper)
159+
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, app.IBCFeeKeeper)
160+
161+
// Add authentication module, controller and host to IBC router
162+
ibcRouter.
163+
// the ICA Controller middleware needs to be explicitly added to the IBC Router because the
164+
// ICA controller module owns the port capability for ICA. The ICA authentication module
165+
// owns the channel capability.
166+
AddRoute(ibcmock.ModuleName+icacontrollertypes.SubModuleName, icaControllerStack) // ica with mock auth module stack route to ica (top level of middleware stack)
167+
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
168+
AddRoute(icahosttypes.SubModuleName, icaHostStack).
169+
```

0 commit comments

Comments
 (0)