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: Integrate ICS Provider #1938

Merged
merged 52 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b0a2cc0
Update dependencies and compile
Dec 4, 2022
18ce46d
Add ICS
Dec 4, 2022
7cb04f2
Add gov prop
Dec 4, 2022
b206190
Fix lint
Dec 5, 2022
e4907c0
Merge branch 'main' into glnro/ics-v45
glnro Dec 5, 2022
5edbc63
Fix commenting
Dec 5, 2022
a539f3e
Fix commenting
Dec 5, 2022
aec5b30
Add GetStakingKeeper for ICS e2e test
Dec 5, 2022
3a9bf13
Gaia implements ibc TestingApp
Dec 5, 2022
4ee8c07
Update correct return type for GetStakingKeeper
Dec 5, 2022
00643a4
Fix ibc import
Dec 5, 2022
81f918d
Fix linting
Dec 6, 2022
7437c41
Comment back LoadStreamingServices
Dec 6, 2022
4cc2502
Merge branch 'main' into glnro/ics-v45
mmulji-ic Dec 6, 2022
c6a8425
Merge branch 'main' into glnro/ics-v45
glnro Dec 7, 2022
2669bc2
Change IBC back to v3.4
Dec 7, 2022
528e87a
Merge branch 'main' into glnro/ics-v45
glnro Dec 7, 2022
135f4a3
Merge branch 'main' into glnro/ics-v45
Dec 9, 2022
338c2c2
Fix ics post merge
Dec 9, 2022
f73f975
Replace ibc with informal/ibc for e2e/ibctesting compatibility
Dec 9, 2022
95af2dd
Merge branch 'main' into glnro/ics-v45
Dec 9, 2022
6d810f5
Merge branch 'main' into glnro/ics-v45
Dec 12, 2022
ffa5464
Merge branch 'main' into glnro/ics-v45
glnro Dec 13, 2022
4761d5a
Update ibc to 3.4.0
Dec 13, 2022
b5ecda1
Merge branch 'main' into glnro/ics-v45
glnro Dec 14, 2022
786d432
Merge branch 'main' into glnro/ics-v45
Dec 15, 2022
2aff0ee
Merge branch 'main' into glnro/ics-v45
Dec 20, 2022
699f403
Fix linting
Dec 20, 2022
d3cc7ee
Merge branch 'main' into glnro/ics-v45
Dec 26, 2022
920a5da
Update gaia with new ics keeper interface
Dec 27, 2022
d80e0d2
Add provider module to simulationModules
Jan 4, 2023
c6d5c5a
Merge branch 'main' into glnro/ics-v45
glnro Jan 4, 2023
347d8fc
Bump ics
Jan 5, 2023
d9d916e
Fix sdk import
Jan 5, 2023
b51d0a5
Resolve conflicts
Jan 6, 2023
b43a8a7
Update sdk to tagged release
Jan 6, 2023
6e94762
Merge branch 'main' into glnro/ics-v45
Jan 6, 2023
8150927
Merge branch 'main' into glnro/ics-v45
glnro Jan 6, 2023
65737b9
Fix simapp dependence (#1983)
glnro Jan 6, 2023
d09a941
Update codecov rules
Jan 6, 2023
67beb00
Merge branch 'main' into glnro/ics-v45
glnro Jan 6, 2023
6b3e169
Merge branch 'main' into glnro/ics-v45
glnro Jan 6, 2023
c3c3586
Update ics dependency
Jan 8, 2023
a07d2bd
Update ICS dependency
Jan 10, 2023
7f64668
Update code cov
Jan 14, 2023
ddfb8d7
Merge branch 'main' into glnro/ics-v45
Jan 16, 2023
2897762
Update ICS to tagged version
Jan 16, 2023
f3e7890
Update codecov
Jan 16, 2023
8ac9165
Add imported ICS test
Jan 16, 2023
dd66079
Merge branch 'main' into glnro/ics-v45
Jan 17, 2023
963219d
Make requested test comment changes
Jan 17, 2023
90977e3
Remove commented code
Jan 17, 2023
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
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