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 12 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
36 changes: 36 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ 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/ibc-go/v3/testing"
"github.com/cosmos/interchain-security/testutil/e2e"
ibcproviderkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -58,6 +61,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 +283,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 Expand Up @@ -403,3 +412,30 @@ type EmptyAppOptions struct{}
func (ao EmptyAppOptions) Get(o string) interface{} {
return nil
}

// ProviderApp interface implementations for e2e tests

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

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

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

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

// GetE2eDistributionKeeper implements the ProviderApp interface.
func (app *GaiaApp) GetE2eDistributionKeeper() e2e.E2eDistributionKeeper {
return app.DistrKeeper
}
66 changes: 49 additions & 17 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -22,6 +21,7 @@ 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"

govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand All @@ -39,6 +39,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"
icacontrollerkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
Expand All @@ -53,14 +54,13 @@ 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"
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 @@ -94,18 +94,23 @@ 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
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedIBCProviderKeeper capabilitykeeper.ScopedKeeper
}

func NewAppKeeper(
Expand All @@ -125,11 +130,14 @@ 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
if _, _, err := streaming.LoadStreamingServices(bApp, appOpts, appCodec, appKeepers.keys); err != nil {
tmos.Exit(err.Error())
}
/*
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())
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comment out this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was temporarily removed due to a previous version conflict...bringing it back in


appKeepers.ParamsKeeper = initParamsKeeper(
appCodec,
Expand All @@ -149,6 +157,7 @@ func NewAppKeeper(
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedICAControllerKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedIBCProviderKeeper = appKeepers.CapabilityKeeper.ScopeToModule(providertypes.ModuleName)

appKeepers.CapabilityKeeper.Seal()

Expand Down Expand Up @@ -232,7 +241,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 @@ -254,13 +267,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 @@ -326,7 +357,8 @@ func NewAppKeeper(
// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
AddRoute(ibctransfertypes.ModuleName, transferIBCModule).
AddRoute(providertypes.ModuleName, appKeepers.ProviderModule)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -366,15 +398,15 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(providertypes.ModuleName)

return paramsKeeper
}

// TODO: find out why GetStakingKeeper was being written here,
// // GetStakingKeeper implements the TestingApp interface.
// func (appKeepers *AppKeepers) GetStakingKeeper() ibctestingtypes.StakingKeeper {
// return appKeepers.StakingKeeper
// }
// GetStakingKeeper implements the TestingApp interface. Needed for ICS.
func (appKeepers *AppKeepers) GetStakingKeeper() ibcclienttypes.StakingKeeper {
return appKeepers.StakingKeeper
}

// GetIBCKeeper implements the TestingApp interface.
func (appKeepers *AppKeepers) GetIBCKeeper() *ibckeeper.Keeper {
Expand Down
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -33,7 +34,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,
icacontrollertypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, icahosttypes.StoreKey, providertypes.StoreKey,
)

// Define transient store keys
Expand Down
42 changes: 39 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 @@ -167,8 +174,18 @@ func simulationModules(
}
}

// 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 @@ -195,9 +212,18 @@ func orderBeginBlockers() []string {
vestingtypes.ModuleName,
icatypes.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 @@ -223,18 +249,27 @@ func orderEndBlockers() []string {
vestingtypes.ModuleName,
icatypes.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 @@ -251,5 +286,6 @@ func orderInitBlockers() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
globalfee.ModuleName,
providertypes.ModuleName,
}
}
Loading