Skip to content

Commit

Permalink
Add support for IBC packet forward
Browse files Browse the repository at this point in the history
  • Loading branch information
luckychess committed Sep 12, 2024
1 parent f3da26c commit 29e8166
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
47 changes: 36 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ import (
"github.com/ignite/cli/ignite/pkg/openapiconsole"
"github.com/spf13/cast"

"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -195,6 +198,7 @@ var (
feegrantmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
packetforward.AppModuleBasic{},
ibctm.AppModuleBasic{},
solomachine.AppModuleBasic{},
upgrade.AppModuleBasic{},
Expand Down Expand Up @@ -279,6 +283,7 @@ type App struct {
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
PacketForwardKeeper *packetforwardkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
ProviderKeeper ccvproviderkeeper.Keeper
Expand Down Expand Up @@ -342,16 +347,11 @@ func New(
authtypes.StoreKey, authz.ModuleName, banktypes.StoreKey, stakingtypes.StoreKey,
crisistypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, icahosttypes.StoreKey,
capabilitytypes.StoreKey, group.StoreKey, icacontrollertypes.StoreKey, consensusparamtypes.StoreKey,
sscmoduletypes.StoreKey,
chainletmoduletypes.StoreKey,
epochstypes.StoreKey,
escrowmoduletypes.StoreKey,
billingmoduletypes.StoreKey,
acltypes.StoreKey,
peerstypes.StoreKey,
ccvprovidertypes.StoreKey,
feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, packetforwardtypes.StoreKey,
icahosttypes.StoreKey, capabilitytypes.StoreKey, group.StoreKey, icacontrollertypes.StoreKey,
consensusparamtypes.StoreKey, sscmoduletypes.StoreKey, chainletmoduletypes.StoreKey,
epochstypes.StoreKey, escrowmoduletypes.StoreKey, billingmoduletypes.StoreKey, acltypes.StoreKey,
peerstypes.StoreKey, ccvprovidertypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -516,6 +516,17 @@ func New(
scopedIBCKeeper,
)

app.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec,
keys[packetforwardtypes.StoreKey],
app.TransferKeeper, // will be zero-value here, reference is set later on with SetTransferKeeper.
app.IBCKeeper.ChannelKeeper,
app.DistrKeeper,
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
app.GovKeeper.GetAuthority(),
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
Expand All @@ -529,7 +540,16 @@ func New(
scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)
var transferIBCModule ibcporttypes.IBCModule
transferIBCModule = transfer.NewIBCModule(app.TransferKeeper)
transferIBCModule = packetforward.NewIBCMiddleware(
transferIBCModule,
app.PacketForwardKeeper,
0, // retries on timeout
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)
app.PacketForwardKeeper.SetTransferKeeper(app.TransferKeeper)

app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey],
Expand Down Expand Up @@ -739,6 +759,7 @@ func New(
evidence.NewAppModule(app.EvidenceKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
ibc.NewAppModule(app.IBCKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper, nil),
params.NewAppModule(app.ParamsKeeper),
transferModule,
providerModule,
Expand Down Expand Up @@ -768,6 +789,7 @@ func New(
evidencetypes.ModuleName,
stakingtypes.ModuleName,
ibcexported.ModuleName,
packetforwardtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
Expand Down Expand Up @@ -798,6 +820,7 @@ func New(
stakingtypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
packetforwardtypes.ModuleName,
ccvprovidertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
Expand Down Expand Up @@ -842,6 +865,7 @@ func New(
minttypes.ModuleName,
crisistypes.ModuleName,
ibcexported.ModuleName,
packetforwardtypes.ModuleName,
genutiltypes.ModuleName,
ibctransfertypes.ModuleName,
ccvprovidertypes.ModuleName,
Expand Down Expand Up @@ -1118,6 +1142,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ccvprovidertypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(ibcfeetypes.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.47.11
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3
github.com/cosmos/ibc-go/v7 v7.4.0
github.com/cosmos/interchain-security/v4 v4.1.1
github.com/gogo/protobuf v1.3.2
Expand Down Expand Up @@ -121,6 +122,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK
github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek=
github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg=
github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3 h1:MZGDMETv72suFpTAD6VPGqSIm1FJcChtk2HmVh9D+Bo=
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.3/go.mod h1:UvDmcGIWJPIytq+Q78/ff5NTOsuX/7IrNgEugTW5i0s=
github.com/cosmos/ibc-go/v7 v7.4.0 h1:8FqYMptvksgMvlbN4UW9jFxTXzsPyfAzEZurujXac8M=
github.com/cosmos/ibc-go/v7 v7.4.0/go.mod h1:L/KaEhzV5TGUCTfGysVgMBQtl5Dm7hHitfpk+GIeoAo=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down Expand Up @@ -685,6 +687,8 @@ github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0Jr
github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw=
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ignite/cli v0.27.2 h1:NFzZqQrt8vhRQeStSvAMhpq65ag+lEAVP5ulw7cu3Y4=
Expand Down

0 comments on commit 29e8166

Please sign in to comment.