Skip to content

Commit

Permalink
chore: remove ibc, ibc-middleware, ica and ics
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Aug 20, 2024
1 parent 797c135 commit 9e75d78
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 424 deletions.
9 changes: 0 additions & 9 deletions ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ante

import (
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -19,7 +16,6 @@ import (
type HandlerOptions struct {
ante.HandlerOptions
Codec codec.BinaryCodec
IBCkeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
TxFeeChecker ante.TxFeeChecker
}
Expand All @@ -34,10 +30,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
if opts.SignModeHandler == nil {
return nil, errorsmod.Wrap(atomoneerrors.ErrLogic, "sign mode handler is required for AnteHandler")
}
if opts.IBCkeeper == nil {
return nil, errorsmod.Wrap(atomoneerrors.ErrLogic, "IBC keeper is required for AnteHandler")
}

if opts.StakingKeeper == nil {
return nil, errorsmod.Wrap(atomoneerrors.ErrNotFound, "staking param store is required for AnteHandler")
}
Expand All @@ -60,7 +52,6 @@ func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
ante.NewIncrementSequenceDecorator(opts.AccountKeeper),
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
8 changes: 0 additions & 8 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"github.com/cometbft/cometbft/libs/log"
tmos "github.com/cometbft/cometbft/libs/os"

ibctesting "github.com/cosmos/ibc-go/v7/testing"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -67,7 +64,6 @@ var (
var (
_ runtime.AppI = (*AtomOneApp)(nil)
_ servertypes.Application = (*AtomOneApp)(nil)
_ ibctesting.TestingApp = (*AtomOneApp)(nil)
)

// AtomOneApp extends an ABCI application, but with most of its parameters exported.
Expand Down Expand Up @@ -222,7 +218,6 @@ func NewAtomOneApp(
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
Codec: appCodec,
IBCkeeper: app.IBCKeeper,
StakingKeeper: app.StakingKeeper,
// If TxFeeChecker is nil the default ante TxFeeChecker is used
TxFeeChecker: nil,
Expand Down Expand Up @@ -295,9 +290,6 @@ func (app *AtomOneApp) BlockedModuleAccountAddrs(modAccAddrs map[string]bool) ma
// remove module accounts that are ALLOWED to received funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())

// Remove the ConsumerRewardsPool from the group of blocked recipient addresses in bank
delete(modAccAddrs, authtypes.NewModuleAddress(providertypes.ConsumerRewardsPool).String())

return modAccAddrs
}

Expand Down
56 changes: 0 additions & 56 deletions app/app_helpers.go

This file was deleted.

186 changes: 16 additions & 170 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ import (

"github.com/cometbft/cometbft/libs/log"

pfmrouter "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
pfmrouterkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
pfmroutertypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcprovider "github.com/cosmos/interchain-security/v3/x/ccv/provider"
ibcproviderkeeper "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper"
providertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -77,42 +57,21 @@ type AppKeepers struct {
memKeys map[string]*storetypes.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
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
// IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCKeeper *ibckeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
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
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

// ICS
ProviderKeeper ibcproviderkeeper.Keeper

PFMRouterKeeper *pfmrouterkeeper.Keeper

// Modules
ICAModule ica.AppModule
TransferModule transfer.AppModule
PFMRouterModule pfmrouter.AppModule
ProviderModule ibcprovider.AppModule

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedIBCProviderKeeper capabilitykeeper.ScopedKeeper
}

func NewAppKeeper(
Expand Down Expand Up @@ -160,17 +119,13 @@ func NewAppKeeper(
bApp.SetParamStore(&appKeepers.ConsensusParamsKeeper)

// add capability keeper and ScopeToModule for ibc module
// TODO remove if no IBC ?
appKeepers.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec,
appKeepers.keys[capabilitytypes.StoreKey],
appKeepers.memKeys[capabilitytypes.MemStoreKey],
)

appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedIBCProviderKeeper = appKeepers.CapabilityKeeper.ScopeToModule(providertypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
appKeepers.CapabilityKeeper.Seal()
Expand Down Expand Up @@ -257,7 +212,6 @@ func NewAppKeeper(
stakingtypes.NewMultiStakingHooks(
appKeepers.DistrKeeper.Hooks(),
appKeepers.SlashingKeeper.Hooks(),
appKeepers.ProviderKeeper.Hooks(),
),
)

Expand All @@ -271,16 +225,6 @@ func NewAppKeeper(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// UpgradeKeeper must be created before IBCKeeper
appKeepers.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
appKeepers.keys[ibcexported.StoreKey],
appKeepers.GetSubspace(ibcexported.ModuleName),
appKeepers.StakingKeeper,
appKeepers.UpgradeKeeper,
appKeepers.ScopedIBCKeeper,
)

// provider depends on gov, so gov must be registered first
govConfig := govtypes.DefaultConfig()
// set the MaxMetadataLen for proposals to the same value as it was pre-sdk v0.47.x
Expand All @@ -295,47 +239,23 @@ func NewAppKeeper(
govConfig,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
appKeepers.ProviderKeeper = ibcproviderkeeper.NewKeeper(
appCodec,
appKeepers.keys[providertypes.StoreKey],
appKeepers.GetSubspace(providertypes.ModuleName),
appKeepers.ScopedIBCProviderKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.IBCKeeper.ConnectionKeeper,
appKeepers.IBCKeeper.ClientKeeper,
appKeepers.StakingKeeper,
appKeepers.SlashingKeeper,
appKeepers.AccountKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
appKeepers.GovKeeper,
authtypes.FeeCollectorName,
)

appKeepers.ProviderModule = ibcprovider.NewAppModule(&appKeepers.ProviderKeeper, appKeepers.GetSubspace(providertypes.ModuleName))

// Register the proposal types
// Deprecated: Avoid adding new handlers, instead use the new proposal flow
// by granting the governance module the right to execute the message.
// See: https://docs.cosmos.network/main/modules/gov#proposal-messages
//
// TODO(tb): remove completely govRouter and rely only on proposals that
// embed sdk.Msg ?
govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(appKeepers.ProviderKeeper))
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper))

// Set legacy router for backwards compatibility with gov v1beta1
appKeepers.GovKeeper.SetLegacyRouter(govRouter)

appKeepers.GovKeeper = appKeepers.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
appKeepers.ProviderKeeper.Hooks(),
),
)

evidenceKeeper := evidencekeeper.NewKeeper(
appCodec,
appKeepers.keys[evidencetypes.StoreKey],
Expand All @@ -345,75 +265,6 @@ func NewAppKeeper(
// If evidence needs to be handled for the app, set routes in router here and seal
appKeepers.EvidenceKeeper = *evidenceKeeper

// ICA Host keeper
appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
appKeepers.keys[icahosttypes.StoreKey],
appKeepers.GetSubspace(icahosttypes.SubModuleName),
appKeepers.IBCKeeper.ChannelKeeper, // ICS4Wrapper
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.ScopedICAHostKeeper,
bApp.MsgServiceRouter(),
)

// PFMRouterKeeper must be created before TransferKeeper
authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()
appKeepers.PFMRouterKeeper = pfmrouterkeeper.NewKeeper(
appCodec,
appKeepers.keys[pfmroutertypes.StoreKey],
nil, // Will be zero-value here. Reference is set later on with SetTransferKeeper.
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
authority,
)

appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
appKeepers.PFMRouterKeeper, // ISC4 Wrapper: PFM Router middleware
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.ScopedTransferKeeper,
)
// Must be called on PFMRouter AFTER TransferKeeper initialized
appKeepers.PFMRouterKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

// Middleware Stacks
appKeepers.ICAModule = ica.NewAppModule(nil, &appKeepers.ICAHostKeeper)
appKeepers.TransferModule = transfer.NewAppModule(appKeepers.TransferKeeper)
appKeepers.PFMRouterModule = pfmrouter.NewAppModule(appKeepers.PFMRouterKeeper, appKeepers.GetSubspace(pfmroutertypes.ModuleName))

// create IBC module from bottom to top of stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(appKeepers.TransferKeeper)
transferStack = pfmrouter.NewIBCMiddleware(
transferStack,
appKeepers.PFMRouterKeeper,
0,
pfmrouterkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
pfmrouterkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)

// Add transfer stack to IBC Router

// Create Interchain Accounts Stack
var icaHostStack porttypes.IBCModule = icahost.NewIBCModule(appKeepers.ICAHostKeeper)

// Create IBC Router & seal
ibcRouter := porttypes.NewRouter().
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(providertypes.ModuleName, appKeepers.ProviderModule)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

return appKeepers
}

Expand All @@ -439,11 +290,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable()) //nolint: staticcheck // SA1019
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint: staticcheck // SA1019
paramsKeeper.Subspace(crisistypes.ModuleName).WithKeyTable(crisistypes.ParamKeyTable()) //nolint: staticcheck // SA1019
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(pfmroutertypes.ModuleName).WithKeyTable(pfmroutertypes.ParamKeyTable())
paramsKeeper.Subspace(providertypes.ModuleName)

return paramsKeeper
}
Loading

0 comments on commit 9e75d78

Please sign in to comment.