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

[v12] packet forward middleware #513

Merged
merged 3 commits into from
Jan 17, 2023
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
93 changes: 61 additions & 32 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ import (
ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"
ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"

packetforward "github.com/strangelove-ventures/packet-forward-middleware/v4/router"
packetforwardkeeper "github.com/strangelove-ventures/packet-forward-middleware/v4/router/keeper"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"

"github.com/CosmWasm/token-factory/x/tokenfactory/bindings"
tokenfactorykeeper "github.com/CosmWasm/token-factory/x/tokenfactory/keeper"
tokenfactorytypes "github.com/CosmWasm/token-factory/x/tokenfactory/types"
Expand Down Expand Up @@ -88,26 +92,27 @@ type AppKeepers struct {
memKeys map[string]*sdk.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.BaseKeeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
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
IBCFeeKeeper ibcfeekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.BaseKeeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
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
IBCFeeKeeper ibcfeekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
ContractKeeper *wasmkeeper.PermissionedKeeper

OracleKeeper oraclekeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
Expand Down Expand Up @@ -261,16 +266,6 @@ func NewAppKeepers(
scopedIBCKeeper,
)

appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, appKeepers.keys[ibcfeetypes.StoreKey],
appKeepers.GetSubspace(ibcfeetypes.ModuleName), // this isn't even used in the keeper but is required?
appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
)

appKeepers.FeeGrantKeeper = feegrantkeeper.NewKeeper(
appCodec,
appKeepers.keys[feegrant.StoreKey],
Expand Down Expand Up @@ -305,20 +300,45 @@ func NewAppKeepers(
appKeepers.Ics20WasmHooks,
)

// Initialize packet forward middleware router
appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec, appKeepers.keys[packetforwardtypes.StoreKey],
appKeepers.GetSubspace(packetforwardtypes.ModuleName),
appKeepers.TransferKeeper, // Will be zero-value here. Reference is set later on with SetTransferKeeper.
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
&appKeepers.IBCKeeper.PortKeeper,
// The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
&appKeepers.HooksICS4Wrapper,
faddat marked this conversation as resolved.
Show resolved Hide resolved
)

appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
appCodec, appKeepers.keys[ibcfeetypes.StoreKey],
appKeepers.GetSubspace(ibcfeetypes.ModuleName), // this isn't even used in the keeper but is required?
appKeepers.PacketForwardKeeper, // replaced with IBC middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
)

// Create Transfer Keepers
appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
// The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
appKeepers.HooksICS4Wrapper,
faddat marked this conversation as resolved.
Show resolved Hide resolved
// The ICS4Wrapper is replaced by the PacketForwardKeeper instead of the channel so that sending can be overridden by the middleware
appKeepers.PacketForwardKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
scopedTransferKeeper,
)

appKeepers.PacketForwardKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
appKeepers.keys[icahosttypes.StoreKey],
Expand Down Expand Up @@ -440,8 +460,16 @@ func NewAppKeepers(
// Create Transfer Stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(appKeepers.TransferKeeper)
transferStack = packetforward.NewIBCMiddleware(
transferStack,
appKeepers.PacketForwardKeeper,
0,
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
transferStack = ibcfee.NewIBCMiddleware(transferStack, appKeepers.IBCFeeKeeper)
transferStack = ibchooks.NewIBCMiddleware(transferStack, &appKeepers.HooksICS4Wrapper)

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
icaHostStack := ibcfee.NewIBCMiddleware(icaHostIBCModule, appKeepers.IBCFeeKeeper)
Expand Down Expand Up @@ -493,6 +521,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
Expand Down
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
)

func (appKeepers *AppKeepers) GenerateKeys() {
Expand All @@ -37,7 +38,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey,
tokenfactorytypes.StoreKey, feesharetypes.StoreKey, wasm.StoreKey, intertxtypes.StoreKey,
icacontrollertypes.StoreKey, oracletypes.StoreKey, ibchookstypes.StoreKey,
icacontrollertypes.StoreKey, oracletypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey,
)

appKeepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down
7 changes: 7 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import (
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"
ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"
packetforward "github.com/strangelove-ventures/packet-forward-middleware/v4/router"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
)

// module account permissions
Expand Down Expand Up @@ -106,6 +108,7 @@ var ModuleBasics = module.NewBasicManager(
feeshare.AppModuleBasic{},
globalfee.AppModuleBasic{},
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
)

func appModules(
Expand Down Expand Up @@ -146,6 +149,7 @@ func appModules(
intertx.NewAppModule(appCodec, app.InterTxKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper),
}
}

Expand Down Expand Up @@ -204,6 +208,7 @@ func orderBeginBlockers() []string {
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
packetforwardtypes.ModuleName,
intertxtypes.ModuleName,
ibcfeetypes.ModuleName,
oracletypes.ModuleName,
Expand Down Expand Up @@ -237,6 +242,7 @@ func orderEndBlockers() []string {
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
packetforwardtypes.ModuleName,
intertxtypes.ModuleName,
ibcfeetypes.ModuleName,
oracletypes.ModuleName,
Expand Down Expand Up @@ -270,6 +276,7 @@ func orderInitBlockers() []string {
ibchost.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
packetforwardtypes.ModuleName,
oracletypes.ModuleName,
intertxtypes.ModuleName,
ibcfeetypes.ModuleName,
Expand Down
12 changes: 11 additions & 1 deletion app/upgrades/v12/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
)

// UpgradeName defines the on-chain upgrade name for the Juno v12 upgrade.
Expand All @@ -19,6 +20,15 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV12UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{tokenfactorytypes.ModuleName, oracletypes.ModuleName, feesharetypes.ModuleName, globalfee.ModuleName, ibcfeetypes.ModuleName, intertxtypes.ModuleName, ibchookstypes.StoreKey},
Added: []string{
tokenfactorytypes.ModuleName,
oracletypes.ModuleName,
feesharetypes.ModuleName,
globalfee.ModuleName,
ibcfeetypes.ModuleName,
intertxtypes.ModuleName,
ibchookstypes.StoreKey,
packetforwardtypes.StoreKey,
},
},
}
5 changes: 5 additions & 0 deletions app/upgrades/v12/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types"

packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
)

// Returns "ujunox" if the chain is uni, else returns the standard ujuno token denom.
Expand Down Expand Up @@ -172,6 +174,9 @@ func CreateV12UpgradeHandler(
keepers.FeeShareKeeper.SetParams(ctx, newFeeShareParams)
logger.Info("set feeshare params")

// Packet Forward middleware initial params
keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams())

return versionMap, err
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.1-0.20230115230008-9d283c08227d
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.24
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.14.0 h1:Rg7d3Lo706X9tHsJMUjdiwMpHB7W8WnSVOssIY+JElU=
github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+egj8As=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.1-0.20230115230008-9d283c08227d h1:9ZUFA1o5r/3T2vV0QwTJAo3LnuILaLsZRAPHrR11tP8=
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.1-0.20230115230008-9d283c08227d/go.mod h1:zDsRdoeNhwyQ9j9984HDCZgUZneHklUCz/J9mj5ll5I=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down