Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom middleware for packet forward #62

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 34 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,21 @@ 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)
ibcRouter.AddRoute(wasm.ModuleName, ics101WasmStack)
// this line is used by starport scaffolding # ibc/app/router
appKeepers.IBCKeeper.SetRouter(ibcRouter)
}
Expand All @@ -444,6 +473,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 +506,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
Loading