Skip to content

Commit

Permalink
feat: add custom middleware for packet forward
Browse files Browse the repository at this point in the history
  • Loading branch information
soring323 committed Feb 26, 2024
1 parent c56014d commit e4e2be3
Show file tree
Hide file tree
Showing 6 changed files with 13,751 additions and 75,613 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import (
// upgrades
"github.com/sideprotocol/side/app/keepers"
v1 "github.com/sideprotocol/side/app/upgrades/v1"
// packet forward module
)

const (
Expand Down
38 changes: 35 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

"github.com/sideprotocol/packet-forward-middleware/v7/packetforward"
packetforwardkeeper "github.com/sideprotocol/packet-forward-middleware/v7/packetforward/keeper"
packetforwardtypes "github.com/sideprotocol/packet-forward-middleware/v7/packetforward/types"
)

const (
Expand Down Expand Up @@ -125,6 +129,8 @@ type AppKeepers struct {

YieldKeeper yieldmodulekeeper.Keeper

PacketForwardKeeper *packetforwardkeeper.Keeper

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
Expand Down Expand Up @@ -314,6 +320,19 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
scopedICAControllerKeeper, bApp.MsgServiceRouter(),
)

// Initialize the packet forward middleware Keeper
// It's important to note that the PFM Keeper must be initialized before the Transfer Keeper
appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec,
appKeepers.keys[packetforwardtypes.StoreKey],
nil, // will be zero-value here, reference is set later on with SetTransferKeeper.
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Create Transfer Keepers
appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -417,11 +436,22 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.CapabilityKeeper.Seal()
// wire up x/wasm to IBC
// Create static IBC router, add transfer route, then set and seal it

var ics101WasmStack ibcporttypes.IBCModule
ics101WasmStack = wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCKeeper.ChannelKeeper)
ics101WasmStack = packetforward.NewIBCMiddleware(
ics101WasmStack,
appKeepers.PacketForwardKeeper,
0, // retries on timeout
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)

ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(wasm.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCKeeper.ChannelKeeper))

AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
//.AddRoute(wasm.ModuleName, wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCKeeper.ChannelKeeper))

Check failure on line 453 in app/keepers/keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
ibcRouter.AddRoute(wasm.ModuleName, ics101WasmStack)
// this line is used by starport scaffolding # ibc/app/router
appKeepers.IBCKeeper.SetRouter(ibcRouter)
}
Expand All @@ -444,6 +474,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(gmmmoduletypes.ModuleName)
paramsKeeper.Subspace(yieldmoduletypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down Expand Up @@ -476,6 +507,7 @@ func KVStoreKeys() []string {
capabilitytypes.StoreKey, group.StoreKey, icacontrollertypes.StoreKey, consensusparamtypes.StoreKey, wasmtypes.StoreKey, ibcfeetypes.StoreKey,
gmmmoduletypes.StoreKey,
yieldmoduletypes.StoreKey,
packetforwardtypes.StoreKey,
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
// wasmd module integrate
"github.com/CosmWasm/wasmd/x/wasm"
// upgrades
"github.com/sideprotocol/packet-forward-middleware/v7/packetforward"
)

// AppModuleBasics returns ModuleBasics for the module BasicManager.
Expand Down Expand Up @@ -74,6 +75,7 @@ var AppModuleBasics = module.NewBasicManager(
wasm.AppModuleBasic{},
gmmmodule.AppModuleBasic{},
yieldmodule.AppModuleBasic{},
packetforward.AppModuleBasic{},
)

func getGovProposalHandlers() []govclient.ProposalHandler {
Expand Down
Loading

0 comments on commit e4e2be3

Please sign in to comment.