Skip to content

Commit

Permalink
feat: Integrate ICS Provider (#1938)
Browse files Browse the repository at this point in the history
* Update dependencies and compile

* Add ICS

* Add gov prop

* Fix lint

* Fix commenting

* Fix commenting

* Add GetStakingKeeper for ICS e2e test

* Gaia implements ibc TestingApp

* Update correct return type for GetStakingKeeper

* Fix ibc import

* Fix linting

* Comment back LoadStreamingServices

* Change IBC back to v3.4

* Fix ics post merge

* Replace ibc with informal/ibc for e2e/ibctesting compatibility

* Update ibc to 3.4.0

* Fix linting

* Update gaia with new ics keeper interface

* Add provider module to simulationModules

* Bump ics

* Fix sdk import

* Update sdk to tagged release

* Fix simapp dependence (#1983)

* Fix simapp dependence

* Fix coverage and linting

* Update sim ignore

* Update codecov rules

* Update ics dependency

* Update ICS dependency

* Update code cov

* Update ICS to tagged version

* Update codecov

* Add imported ICS test

* Make requested test comment changes

* Remove commented code

Co-authored-by: Milan Mulji <98309852+mmulji-ic@users.noreply.github.com>
  • Loading branch information
glnro and mmulji-ic authored Jan 17, 2023
1 parent a005a85 commit e665d82
Show file tree
Hide file tree
Showing 13 changed files with 2,504 additions and 54 deletions.
5 changes: 4 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ coverage:
threshold: 1% # allow this much decrease on project
app:
target: 80%
paths: "app/"
paths: # this must be a list type
- "app/"
changes: false

comment:
Expand All @@ -27,3 +28,5 @@ ignore:
- "docs"
- "proto"
- "tests/e2e"
- "app/app_helpers.go"
- "app/sim"
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
ibctesting "github.com/cosmos/interchain-security/legacy_ibc_testing/testing"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -58,6 +59,7 @@ var (
var (
_ simapp.App = (*GaiaApp)(nil)
_ servertypes.Application = (*GaiaApp)(nil)
_ ibctesting.TestingApp = (*GaiaApp)(nil)
)

// GaiaApp extends an ABCI application, but with most of its parameters exported.
Expand Down Expand Up @@ -279,6 +281,11 @@ func (app *GaiaApp) BlockedModuleAccountAddrs(modAccAddrs map[string]bool) map[s
// remove module accounts that are ALLOWED to received funds
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())

// Remove the fee-pool from the group of blocked recipient addresses in bank
// this is required for the provider chain to be able to receive tokens from
// the consumer chain
delete(modAccAddrs, authtypes.NewModuleAddress(authtypes.FeeCollectorName).String())

return modAccAddrs
}

Expand Down
33 changes: 33 additions & 0 deletions app/app_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package gaia

import (
"github.com/cosmos/interchain-security/testutil/e2e"
ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"
)

// ProviderApp interface implementations for e2e tests

// GetProviderKeeper implements the ProviderApp interface.
func (app *GaiaApp) GetProviderKeeper() ibcproviderkeeper.Keeper { //nolint:nolintlint
return app.ProviderKeeper
}

// GetE2eStakingKeeper implements the ProviderApp interface.
func (app *GaiaApp) GetE2eStakingKeeper() e2e.E2eStakingKeeper { //nolint:nolintlint
return app.StakingKeeper
}

// GetE2eBankKeeper implements the ProviderApp interface.
func (app *GaiaApp) GetE2eBankKeeper() e2e.E2eBankKeeper { //nolint:nolintlint
return app.BankKeeper
}

// GetE2eSlashingKeeper implements the ProviderApp interface.
func (app *GaiaApp) GetE2eSlashingKeeper() e2e.E2eSlashingKeeper { //nolint:nolintlint
return app.SlashingKeeper
}

// GetE2eDistributionKeeper implements the ProviderApp interface.
func (app *GaiaApp) GetE2eDistributionKeeper() e2e.E2eDistributionKeeper { //nolint:nolintlint
return app.DistrKeeper
}
66 changes: 53 additions & 13 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"
tmos "github.com/tendermint/tendermint/libs/os"

govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand All @@ -39,6 +41,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/gaia/v8/x/globalfee"
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
icahost "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
Expand All @@ -51,14 +54,14 @@ import (
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
ibcstakinginterface "github.com/cosmos/interchain-security/legacy_ibc_testing/core"
ibcprovider "github.com/cosmos/interchain-security/x/ccv/provider"
ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"
liquiditykeeper "github.com/gravity-devs/liquidity/x/liquidity/keeper"
liquiditytypes "github.com/gravity-devs/liquidity/x/liquidity/types"
"github.com/strangelove-ventures/packet-forward-middleware/v3/router"
routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v3/router/keeper"
routertypes "github.com/strangelove-ventures/packet-forward-middleware/v3/router/types"
tmos "github.com/tendermint/tendermint/libs/os"

"github.com/cosmos/gaia/v8/x/globalfee"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
Expand Down Expand Up @@ -91,17 +94,22 @@ type AppKeepers struct {
AuthzKeeper authzkeeper.Keeper
LiquidityKeeper liquiditykeeper.Keeper

// ICS
ProviderKeeper ibcproviderkeeper.Keeper

RouterKeeper *routerkeeper.Keeper

// Modules
ICAModule ica.AppModule
TransferModule transfer.AppModule
RouterModule router.AppModule
ProviderModule ibcprovider.AppModule

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

func NewAppKeeper(
Expand All @@ -121,8 +129,10 @@ func NewAppKeeper(
// Set keys KVStoreKey, TransientStoreKey, MemoryStoreKey
appKeepers.GenerateKeys()

// configure state listening capabilities using AppOptions
// we are doing nothing with the returned streamingServices and waitGroup in this case
/*
configure state listening capabilities using AppOptions
we are doing nothing with the returned streamingServices and waitGroup in this case
*/
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, appKeepers.keys); err != nil {
tmos.Exit(err.Error())
}
Expand All @@ -144,6 +154,7 @@ func NewAppKeeper(
appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedIBCProviderKeeper = appKeepers.CapabilityKeeper.ScopeToModule(providertypes.ModuleName)

appKeepers.CapabilityKeeper.Seal()

Expand Down Expand Up @@ -227,7 +238,11 @@ func NewAppKeeper(
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
appKeepers.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(appKeepers.DistrKeeper.Hooks(), appKeepers.SlashingKeeper.Hooks()),
stakingtypes.NewMultiStakingHooks(
appKeepers.DistrKeeper.Hooks(),
appKeepers.SlashingKeeper.Hooks(),
appKeepers.ProviderKeeper.Hooks(),
),
)

// UpgradeKeeper must be created before IBCKeeper
Expand All @@ -249,13 +264,31 @@ func NewAppKeeper(
appKeepers.ScopedIBCKeeper,
)

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,
authtypes.FeeCollectorName,
)

appKeepers.ProviderModule = ibcprovider.NewAppModule(&appKeepers.ProviderKeeper)

govRouter := govtypes.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(appKeepers.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(appKeepers.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(appKeepers.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(appKeepers.IBCKeeper.ClientKeeper)).
AddRoute(providertypes.RouterKey, ibcprovider.NewConsumerChainProposalHandler(appKeepers.ProviderKeeper))

/*
Example of setting gov params:
Expand Down Expand Up @@ -328,7 +361,8 @@ func NewAppKeeper(
// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, ibcStack)
AddRoute(ibctransfertypes.ModuleName, ibcStack).
AddRoute(providertypes.ModuleName, appKeepers.ProviderModule)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -367,16 +401,22 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(routertypes.ModuleName).WithKeyTable(routertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(providertypes.ModuleName)

return paramsKeeper
}

// GetStakingKeeper implements the TestingApp interface. Needed for ICS.
func (appKeepers *AppKeepers) GetStakingKeeper() ibcstakinginterface.StakingKeeper { //nolint:nolintlint
return appKeepers.StakingKeeper
}

// GetIBCKeeper implements the TestingApp interface.
func (appKeepers *AppKeepers) GetIBCKeeper() *ibckeeper.Keeper {
func (appKeepers *AppKeepers) GetIBCKeeper() *ibckeeper.Keeper { //nolint:nolintlint
return appKeepers.IBCKeeper
}

// GetScopedIBCKeeper implements the TestingApp interface.
func (appKeepers *AppKeepers) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
func (appKeepers *AppKeepers) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { //nolint:nolintlint
return appKeepers.ScopedIBCKeeper
}
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"
liquiditytypes "github.com/gravity-devs/liquidity/x/liquidity/types"
routertypes "github.com/strangelove-ventures/packet-forward-middleware/v3/router/types"
)
Expand All @@ -32,7 +33,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, liquiditytypes.StoreKey, ibctransfertypes.StoreKey,
capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, routertypes.StoreKey,
icahosttypes.StoreKey,
icahosttypes.StoreKey, providertypes.StoreKey,
)

// Define transient store keys
Expand Down
43 changes: 40 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import (
ibc "github.com/cosmos/ibc-go/v3/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v3/modules/core/02-client/client"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibcprovider "github.com/cosmos/interchain-security/x/ccv/provider"
ibcproviderclient "github.com/cosmos/interchain-security/x/ccv/provider/client"
providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"
"github.com/gravity-devs/liquidity/x/liquidity"
liquiditytypes "github.com/gravity-devs/liquidity/x/liquidity/types"
"github.com/strangelove-ventures/packet-forward-middleware/v3/router"
Expand Down Expand Up @@ -84,6 +87,8 @@ var ModuleBasics = module.NewBasicManager(
upgradeclient.CancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
ibcproviderclient.ConsumerAdditionProposalHandler,
ibcproviderclient.ConsumerRemovalProposalHandler,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -99,6 +104,7 @@ var ModuleBasics = module.NewBasicManager(
router.AppModuleBasic{},
ica.AppModuleBasic{},
globalfee.AppModule{},
ibcprovider.AppModuleBasic{},
)

func appModules(
Expand Down Expand Up @@ -136,6 +142,7 @@ func appModules(
app.TransferModule,
app.ICAModule,
app.RouterModule,
app.ProviderModule,
}
}

Expand Down Expand Up @@ -164,11 +171,22 @@ func simulationModules(
liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.BankKeeper, app.DistrKeeper),
ibc.NewAppModule(app.IBCKeeper),
app.TransferModule,
app.ProviderModule,
}
}

// orderBeginBlockers Tell the app's module manager how to set the order of
// BeginBlockers, which are run at the beginning of every block.
/*
orderBeginBlockers tells the app's module manager how to set the order of
BeginBlockers, which are run at the beginning of every block.
Interchain Security Requirements:
During begin block slashing happens after distr.BeginBlocker so that
there is nothing left over in the validator fee pool, so as to keep the
CanWithdrawInvariant invariant.
NOTE: staking module is required if HistoricalEntries param > 0
NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
*/

func orderBeginBlockers() []string {
return []string{
// upgrades should be run first
Expand All @@ -194,9 +212,18 @@ func orderBeginBlockers() []string {
paramstypes.ModuleName,
vestingtypes.ModuleName,
globalfee.ModuleName,
providertypes.ModuleName,
}
}

/*
Interchain Security Requirements:
- provider.EndBlock gets validator updates from the staking module;
thus, staking.EndBlock must be executed before provider.EndBlock;
- creating a new consumer chain requires the following order,
CreateChildClient(), staking.EndBlock, provider.EndBlock;
thus, gov.EndBlock must be executed before staking.EndBlock
*/
func orderEndBlockers() []string {
return []string{
crisistypes.ModuleName,
Expand All @@ -221,18 +248,27 @@ func orderEndBlockers() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
globalfee.ModuleName,
providertypes.ModuleName,
}
}

/*
NOTE: The genutils module must occur after staking so that pools are
properly initialized with tokens from genesis accounts.
NOTE: The genutils module must also occur after auth so that it can access the params from auth.
NOTE: Capability module must occur first so that it can initialize any capabilities
so that other modules that want to create or claim capabilities afterwards in InitChain
can do so safely.
*/
func orderInitBlockers() []string {
return []string{
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
Expand All @@ -248,5 +284,6 @@ func orderInitBlockers() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
globalfee.ModuleName,
providertypes.ModuleName,
}
}
Loading

0 comments on commit e665d82

Please sign in to comment.