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

Provider-driven governance #416

Closed
wants to merge 8 commits into from
122 changes: 104 additions & 18 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"os"
"path/filepath"

govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
paramsrest "github.com/cosmos/cosmos-sdk/x/params/client/rest"
upgraderest "github.com/cosmos/cosmos-sdk/x/upgrade/client/rest"
adminmodulemodule "github.com/cosmos/interchain-security/x/ccv/adminmodule"
adminmodulecli "github.com/cosmos/interchain-security/x/ccv/adminmodule/client/cli"
adminmodulemodulekeeper "github.com/cosmos/interchain-security/x/ccv/adminmodule/keeper"
adminmodulemoduletypes "github.com/cosmos/interchain-security/x/ccv/adminmodule/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -61,6 +69,11 @@ 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"
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"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/types"
"github.com/cosmos/ibc-go/v3/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
Expand All @@ -82,6 +95,7 @@ import (

distr "github.com/cosmos/cosmos-sdk/x/distribution"
ccvdistrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
distrrest "github.com/cosmos/cosmos-sdk/x/distribution/client/rest"
ccvdistrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
ccvdistrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/interchain-security/testutil/e2e"
Expand Down Expand Up @@ -147,6 +161,25 @@ var (
vesting.AppModuleBasic{},
//router.AppModuleBasic{},
ibcconsumer.AppModuleBasic{},
ica.AppModuleBasic{},
adminmodulemodule.NewAppModuleBasic(
govclient.NewProposalHandler(
adminmodulecli.NewSubmitParamChangeProposalTxCmd,
paramsrest.ProposalRESTHandler,
),
govclient.NewProposalHandler(
adminmodulecli.NewSubmitPoolSpendProposalTxCmd,
distrrest.ProposalRESTHandler,
),
govclient.NewProposalHandler(
adminmodulecli.NewCmdSubmitUpgradeProposal,
upgraderest.ProposalRESTHandler,
),
govclient.NewProposalHandler(
adminmodulecli.NewCmdSubmitCancelUpgradeProposal,
upgraderest.ProposalCancelRESTHandler,
),
),
)

// module account permissions
Expand All @@ -158,6 +191,7 @@ var (
ccvminttypes.ModuleName: {authtypes.Minter},
ibcconsumertypes.ConsumerRedistributeName: nil,
ibcconsumertypes.ConsumerToSendToProviderName: nil,
icatypes.ModuleName: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ccvgovtypes.ModuleName: {authtypes.Burner},
}
Expand Down Expand Up @@ -187,28 +221,31 @@ type App struct { // nolint: golint
memKeys map[string]*sdk.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper ccvstakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper ccvmintkeeper.Keeper
DistrKeeper ccvdistrkeeper.Keeper
GovKeeper ccvgovkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsumerKeeper ibcconsumerkeeper.Keeper
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper ccvstakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper ccvmintkeeper.Keeper
DistrKeeper ccvdistrkeeper.Keeper
GovKeeper ccvgovkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsumerKeeper ibcconsumerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
AdminmoduleKeeper adminmodulemodulekeeper.Keeper

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

// the module manager
MM *module.Manager
Expand Down Expand Up @@ -256,7 +293,8 @@ func New(
ccvgovtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey,
capabilitytypes.StoreKey, authzkeeper.StoreKey,
ibcconsumertypes.StoreKey,
ibcconsumertypes.StoreKey, icahosttypes.StoreKey,
adminmodulemoduletypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -294,6 +332,7 @@ func New(
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedIBCConsumerKeeper := app.CapabilityKeeper.ScopeToModule(ibcconsumertypes.ModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
app.CapabilityKeeper.Seal()

// add keepers
Expand Down Expand Up @@ -452,10 +491,25 @@ func New(
transferModule := transfer.NewAppModule(app.TransferKeeper)
ibcmodule := transfer.NewIBCModule(app.TransferKeeper)

app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec,
keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
)

icaModule := ica.NewAppModule(nil, &app.ICAHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper)

// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, ibcmodule)
ibcRouter.AddRoute(ibcconsumertypes.ModuleName, consumerModule)
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule)
app.IBCKeeper.SetRouter(ibcRouter)

// create evidence keeper with router
Expand All @@ -468,6 +522,23 @@ func New(

app.EvidenceKeeper = *evidenceKeeper

adminRouter := ccvgovtypes.NewRouter()
adminRouter.AddRoute(ccvgovtypes.RouterKey, ccvgovtypes.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))

app.AdminmoduleKeeper = *adminmodulemodulekeeper.NewKeeper(
appCodec,
keys[adminmodulemoduletypes.StoreKey],
keys[adminmodulemoduletypes.MemStoreKey],
adminRouter,
// this allows any type of proposal to be submitted to the admin module (everything is whitelisted)
// projects will implement their functions to define what is allowed for provider and consumer admins
func(ccvgovtypes.Content) bool { return true },
func(ccvgovtypes.Content) bool { return true },
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice. Maybe an example of a switch statement with various proposal types to show how you'd include or exclude specific ones would be nice to have?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we already have similar function for democracy consumer chain that implements whitelisting based on proposal type. We will change this comment to make reference to that function.

)
adminModule := adminmodulemodule.NewAppModule(appCodec, app.AdminmoduleKeeper, app.ICAHostKeeper, app.ConsumerKeeper)

skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

// NOTE: Any module instantiated in the module manager that is later modified
Expand All @@ -491,6 +562,8 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
transferModule,
consumerModule,
icaModule,
adminModule,
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -517,7 +590,9 @@ func New(
vestingtypes.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
ibcconsumertypes.ModuleName,
adminmodulemoduletypes.ModuleName,
)
app.MM.SetOrderEndBlockers(
crisistypes.ModuleName,
Expand All @@ -537,7 +612,9 @@ func New(
vestingtypes.ModuleName,
ibctransfertypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
ibcconsumertypes.ModuleName,
adminmodulemoduletypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -563,8 +640,10 @@ func New(
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibchost.ModuleName,
icatypes.ModuleName,
ibctransfertypes.ModuleName,
ibcconsumertypes.ModuleName,
adminmodulemoduletypes.ModuleName,
)

app.MM.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -660,6 +739,7 @@ func New(
app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper
app.ScopedIBCConsumerKeeper = scopedIBCConsumerKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper

return app
}
Expand Down Expand Up @@ -817,6 +897,11 @@ func (app *App) GetStakingKeeper() ibcclienttypes.StakingKeeper {
return app.ConsumerKeeper
}

// GetICAHostKeeper implements the TestingApp interface.
func (app *App) GetICAHostKeeper() icahostkeeper.Keeper {
return app.ICAHostKeeper
}

// GetIBCKeeper implements the TestingApp interface.
func (app *App) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
Expand Down Expand Up @@ -899,6 +984,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
paramsKeeper.Subspace(ibcconsumertypes.ModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)

return paramsKeeper
}
5 changes: 4 additions & 1 deletion app/consumer-democracy/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
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"
)

Expand Down Expand Up @@ -64,5 +65,7 @@ var WhitelistedParams = map[paramChangeKey]struct{}{
//ibc transfer
{Subspace: ibctransfertypes.ModuleName, Key: "SendEnabled"}: {},
{Subspace: ibctransfertypes.ModuleName, Key: "ReceiveEnabled"}: {},
//add interchain account params(HostEnabled, AllowedMessages) once the module is added to the consumer app
//ica
{Subspace: icahosttypes.SubModuleName, Key: "HostEnabled"}: {},
{Subspace: icahosttypes.SubModuleName, Key: "AllowMessages"}: {},
}
Loading