Skip to content

feat: IBC V2 #49

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v10/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
)

// NewAnteHandler extends the default AnteHandler with custom decorators.
Expand Down
24 changes: 6 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
_ "github.com/cosmos/ibc-go/modules/capability" // import for side-effects
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
icacontrollerkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v10/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
abci "github.com/skip-mev/block-sdk/v2/abci"
"github.com/skip-mev/block-sdk/v2/block"
"github.com/skip-mev/block-sdk/v2/block/base"
Expand All @@ -76,8 +75,6 @@ import (
tierkeeper "github.com/sourcenetwork/sourcehub/x/tier/keeper"
tiertypes "github.com/sourcenetwork/sourcehub/x/tier/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

"github.com/sourcenetwork/sourcehub/docs"
)

Expand Down Expand Up @@ -123,26 +120,18 @@ type App struct {
GroupKeeper groupkeeper.Keeper
ConsensusParamsKeeper consensuskeeper.Keeper
CircuitBreakerKeeper circuitkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper

// IBC
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
CapabilityKeeper *capabilitykeeper.Keeper
IBCFeeKeeper ibcfeekeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouterV2 on it correctly
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper

// Scoped IBC
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedIBCTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

AcpKeeper *acpkeeper.Keeper
BulletinKeeper *bulletinkeeper.Keeper
EpochsKeeper *epochskeeper.Keeper
TierKeeper *tierkeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// simulation manager
sm *module.SimulationManager
Expand Down Expand Up @@ -271,7 +260,6 @@ func New(
&app.BulletinKeeper,
&app.EpochsKeeper,
&app.TierKeeper,
// this line is used by starport scaffolding # stargate/app/keeperDefinition
); err != nil {
panic(err)
}
Expand Down
14 changes: 4 additions & 10 deletions app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ import (
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
_ "github.com/cosmos/ibc-go/modules/capability" // import for side-effects
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
_ "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts" // import for side-effects
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
_ "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" // import for side-effects
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
_ "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts" // import for side-effects
icatypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/types"
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
"google.golang.org/protobuf/types/known/durationpb"

epochsmodulev1 "github.com/sourcenetwork/sourcehub/api/osmosis/epochs/module/v1beta1"
Expand Down Expand Up @@ -109,7 +107,6 @@ var (
authz.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
Expand Down Expand Up @@ -145,7 +142,6 @@ var (
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// chain modules
acptypes.ModuleName,
bulletintypes.ModuleName,
Expand All @@ -167,7 +163,6 @@ var (
ibctransfertypes.ModuleName,
capabilitytypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
// chain modules
acptypes.ModuleName,
bulletintypes.ModuleName,
Expand All @@ -190,7 +185,6 @@ var (
{Account: stakingtypes.NotBondedPoolName, Permissions: []string{authtypes.Burner, stakingtypes.ModuleName}},
{Account: govtypes.ModuleName, Permissions: []string{authtypes.Burner}},
{Account: ibctransfertypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner}},
{Account: ibcfeetypes.ModuleName},
{Account: icatypes.ModuleName},
{Account: tiertypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner, authtypes.Staking}},
{Account: tiertypes.DeveloperPoolName},
Expand Down
156 changes: 67 additions & 89 deletions app/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,39 @@ import (
"cosmossdk.io/core/appmodule"
storetypes "cosmossdk.io/store/types"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/params"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/cosmos/ibc-go/modules/capability"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
icamodule "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee"
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
// this line is used by starport scaffolding # ibc/app/import
icamodule "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts"
icacontroller "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v10/modules/apps/transfer"
ibctransfer "github.com/cosmos/ibc-go/v10/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v10/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types"
transferv2 "github.com/cosmos/ibc-go/v10/modules/apps/transfer/v2"
ibc "github.com/cosmos/ibc-go/v10/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
ibcconnectiontypes "github.com/cosmos/ibc-go/v10/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v10/modules/core/05-port/types"
ibcapi "github.com/cosmos/ibc-go/v10/modules/core/api"
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"
solomachine "github.com/cosmos/ibc-go/v10/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v10/modules/light-clients/07-tendermint"
)

// registerIBCModules register IBC keepers and non dependency inject modules.
Expand All @@ -45,7 +46,6 @@ func (app *App) registerIBCModules() {
storetypes.NewKVStoreKey(capabilitytypes.StoreKey),
storetypes.NewKVStoreKey(ibcexported.StoreKey),
storetypes.NewKVStoreKey(ibctransfertypes.StoreKey),
storetypes.NewKVStoreKey(ibcfeetypes.StoreKey),
storetypes.NewKVStoreKey(icahosttypes.StoreKey),
storetypes.NewKVStoreKey(icacontrollertypes.StoreKey),
storetypes.NewMemoryStoreKey(capabilitytypes.MemStoreKey),
Expand All @@ -62,27 +62,21 @@ func (app *App) registerIBCModules() {
app.ParamsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
app.ParamsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())

// add capability keeper and ScopeToModule for ibc module
// Set capability keeper before GetCapabilityScopedKeeper
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
app.AppCodec(),
app.GetKey(capabilitytypes.StoreKey),
app.GetMemKey(capabilitytypes.MemStoreKey),
)

// add capability keeper and ScopeToModule for ibc module
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedIBCTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
keys := app.kvStoreKeys()

// Create IBC keeper
app.IBCKeeper = ibckeeper.NewKeeper(
app.appCodec,
app.GetKey(ibcexported.StoreKey),
runtime.NewKVStoreService(keys[ibcexported.StoreKey]),
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand All @@ -91,93 +85,79 @@ func (app *App) registerIBCModules() {
// by granting the governance module the right to execute the message.
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
govRouter := govv1beta1.NewRouter()
govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler)
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper))

app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
app.appCodec, app.GetKey(ibcfeetypes.StoreKey),
app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper,
)

// Create IBC transfer keeper
app.TransferKeeper = ibctransferkeeper.NewKeeper(
app.appCodec,
app.GetKey(ibctransfertypes.StoreKey),
app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCFeeKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
scopedIBCTransferKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

// Create interchain account keepers
app.ICAHostKeeper = icahostkeeper.NewKeeper(
app.appCodec,
app.GetKey(icahosttypes.StoreKey),
runtime.NewKVStoreService(keys[icahosttypes.StoreKey]),
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
app.IBCKeeper.ChannelKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
// Fixes "panic: query router must not be nil" introduced in ibc-go v8.3.1
app.ICAHostKeeper.WithQueryRouter(app.GRPCQueryRouter())

app.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
app.appCodec,
app.GetKey(icacontrollertypes.StoreKey),
runtime.NewKVStoreService(keys[icacontrollertypes.StoreKey]),
app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper,
app.IBCKeeper.ChannelKeeper,
app.MsgServiceRouter(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.GovKeeper.SetLegacyRouter(govRouter)

// Create IBC modules with ibcfee middleware
transferIBCModule := ibcfee.NewIBCMiddleware(ibctransfer.NewIBCModule(app.TransferKeeper), app.IBCFeeKeeper)

// integration point for custom authentication modules
var noAuthzModule porttypes.IBCModule
icaControllerIBCModule := ibcfee.NewIBCMiddleware(
icacontroller.NewIBCMiddleware(noAuthzModule, app.ICAControllerKeeper),
app.IBCFeeKeeper,
// Create IBC transfer keeper
app.TransferKeeper = ibctransferkeeper.NewKeeper(
app.appCodec,
runtime.NewKVStoreService(keys[ibctransfertypes.StoreKey]),
app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
app.MsgServiceRouter(),
app.AccountKeeper,
app.BankKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

icaHostIBCModule := ibcfee.NewIBCMiddleware(icahost.NewIBCModule(app.ICAHostKeeper), app.IBCFeeKeeper)
icaHostStack := icahost.NewIBCModule(app.ICAHostKeeper)
icaControllerStack := icacontroller.NewIBCMiddleware(app.ICAControllerKeeper)
transferStack := transfer.NewIBCModule(app.TransferKeeper)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(icacontrollertypes.SubModuleName, icaControllerIBCModule).
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)

// this line is used by starport scaffolding # ibc/app/module
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(ibctransfertypes.ModuleName, transferStack)

app.IBCKeeper.SetRouter(ibcRouter)

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedIBCTransferKeeper = scopedIBCTransferKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
// Create IBC v2 transfer middleware stack
var ibcv2TransferStack ibcapi.IBCModule
ibcv2TransferStack = transferv2.NewIBCModule(app.TransferKeeper)
ibcv2Router := ibcapi.NewRouter().AddRoute(ibctransfertypes.PortID, ibcv2TransferStack)
app.IBCKeeper.SetRouterV2(ibcv2Router)

// Light client modules
clientKeeper := app.IBCKeeper.ClientKeeper
storeProvider := app.IBCKeeper.ClientKeeper.GetStoreProvider()
tmLightClientModule := ibctm.NewLightClientModule(app.appCodec, storeProvider)
clientKeeper.AddRoute(ibctm.ModuleName, &tmLightClientModule)

// register IBC modules
if err := app.RegisterModules(
ibc.NewAppModule(app.IBCKeeper),
ibctransfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
icamodule.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
capability.NewAppModule(app.appCodec, *app.CapabilityKeeper, false),
ibctm.AppModule{},
ibctm.NewAppModule(tmLightClientModule),
solomachine.AppModule{},
); err != nil {
panic(err)
Expand All @@ -191,7 +171,6 @@ func (app *App) setDefaultIBCParams(ctx sdk.Context) {
app.IBCKeeper.ChannelKeeper.SetNextChannelSequence(ctx, 0)
app.IBCKeeper.ClientKeeper.SetParams(ctx, ibcclienttypes.DefaultParams())
app.IBCKeeper.ConnectionKeeper.SetParams(ctx, ibcconnectiontypes.DefaultParams())
app.IBCKeeper.ChannelKeeper.SetParams(ctx, ibcchanneltypes.DefaultParams())
app.ICAControllerKeeper.SetParams(ctx, icacontrollertypes.DefaultParams())
app.ICAHostKeeper.SetParams(ctx, icahosttypes.DefaultParams())
app.TransferKeeper.SetParams(ctx, ibctransfertypes.DefaultParams())
Expand All @@ -204,7 +183,6 @@ func RegisterIBC(registry cdctypes.InterfaceRegistry) map[string]appmodule.AppMo
modules := map[string]appmodule.AppModule{
ibcexported.ModuleName: ibc.AppModule{},
ibctransfertypes.ModuleName: ibctransfer.AppModule{},
ibcfeetypes.ModuleName: ibcfee.AppModule{},
icatypes.ModuleName: icamodule.AppModule{},
capabilitytypes.ModuleName: capability.AppModule{},
ibctm.ModuleName: ibctm.AppModule{},
Expand Down
Loading