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

Add consumer module #237

Merged
merged 13 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 7 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
tfmwKeeper "github.com/notional-labs/centauri/v5/x/transfermiddleware/keeper"
txBoundaryAnte "github.com/notional-labs/centauri/v5/x/tx-boundary/ante"
txBoundaryKeeper "github.com/notional-labs/centauri/v5/x/tx-boundary/keeper"

democracyante "github.com/cosmos/interchain-security/v3/app/consumer-democracy/ante"
consumerante "github.com/cosmos/interchain-security/v3/app/consumer/ante"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
)

// Link to default ante handler used by cosmos sdk:
Expand All @@ -25,10 +29,13 @@ func NewAnteHandler(
channelKeeper *ibckeeper.Keeper,
tfmwKeeper tfmwKeeper.Keeper,
txBoundaryKeeper txBoundaryKeeper.Keeper,
consumerKeeper ccvconsumerkeeper.Keeper,
codec codec.BinaryCodec,
) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // // outermost AnteDecorator. SetUpContext must be called first
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
democracyante.NewForbiddenProposalsDecorator(IsProposalWhitelisted, IsModuleWhiteList),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(ak),
Expand Down
111 changes: 111 additions & 0 deletions app/ante/proposals_whitelist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package ante

import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvgov "github.com/cosmos/interchain-security/v3/x/ccv/democracy/governance"
)

var WhiteListModule = map[string]struct{}{
"/cosmos.gov.v1.MsgUpdateParams": {},
"/cosmos.bank.v1beta1.MsgUpdateParams": {},
"/cosmos.staking.v1beta1.MsgUpdateParams": {},
"/cosmos.distribution.v1beta1.MsgUpdateParams": {},
"/cosmos.mint.v1beta1.MsgUpdateParams": {},
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade": {},
"/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {},
"/centauri.transfermiddleware.v1beta1.MsgAddParachainIBCTokenInfo": {},
"/centauri.transfermiddleware.v1beta1.MsgRemoveParachainIBCTokenInfo": {},
"/centauri.transfermiddleware.v1beta1.MsgAddRlyAddress": {},
}

func IsModuleWhiteList(typeUrl string) bool {
_, found := WhiteListModule[typeUrl]
return found
}

func IsProposalWhitelisted(content govv1beta1.Content) bool {
switch c := content.(type) {
case *proposal.ParameterChangeProposal:
return isParamChangeWhitelisted(getParamChangesMapFromArray(c.Changes))
case *upgradetypes.SoftwareUpgradeProposal, //nolint:staticcheck
*upgradetypes.CancelSoftwareUpgradeProposal: //nolint:staticcheck
return true

default:
return false
}
}

func getParamChangesMapFromArray(paramChanges []proposal.ParamChange) map[ccvgov.ParamChangeKey]struct{} {
res := map[ccvgov.ParamChangeKey]struct{}{}
for _, paramChange := range paramChanges {
key := ccvgov.ParamChangeKey{
MsgType: paramChange.Subspace,
Key: paramChange.Key,
}

res[key] = struct{}{}
}

return res
}

func isParamChangeWhitelisted(paramChanges map[ccvgov.ParamChangeKey]struct{}) bool {
for paramChangeKey := range paramChanges {
_, found := WhitelistedParams[paramChangeKey]
if !found {
return false
}
}
Comment on lines +67 to +72

Check warning

Code scanning / CodeQL

Iteration over map

Iteration over map may be a possible source of non-determinism
return true
}

var WhitelistedParams = map[ccvgov.ParamChangeKey]struct{}{
//bank
{MsgType: banktypes.ModuleName, Key: string(banktypes.KeySendEnabled)}: {},
{MsgType: banktypes.ModuleName, Key: string(banktypes.KeyDefaultSendEnabled)}: {},
//governance
{MsgType: govtypes.ModuleName, Key: string(govv1.ParamStoreKeyDepositParams)}: {}, //min_deposit, max_deposit_period
{MsgType: govtypes.ModuleName, Key: string(govv1.ParamStoreKeyVotingParams)}: {}, //voting_period
{MsgType: govtypes.ModuleName, Key: string(govv1.ParamStoreKeyTallyParams)}: {}, //quorum,threshold,veto_threshold
//staking
{MsgType: stakingtypes.ModuleName, Key: string(stakingtypes.KeyUnbondingTime)}: {},
{MsgType: stakingtypes.ModuleName, Key: string(stakingtypes.KeyMaxValidators)}: {},
{MsgType: stakingtypes.ModuleName, Key: string(stakingtypes.KeyMaxEntries)}: {},
{MsgType: stakingtypes.ModuleName, Key: string(stakingtypes.KeyHistoricalEntries)}: {},
{MsgType: stakingtypes.ModuleName, Key: string(stakingtypes.KeyBondDenom)}: {},
{MsgType: stakingtypes.ModuleName, Key: string(stakingtypes.KeyMinCommissionRate)}: {},
//ccv consumer
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyRewardDenoms)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyEnabled)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyBlocksPerDistributionTransmission)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyDistributionTransmissionChannel)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyProviderFeePoolAddrStr)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyTransferTimeoutPeriod)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyConsumerRedistributionFrac)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyHistoricalEntries)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyConsumerUnbondingPeriod)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeySoftOptOutThreshold)}: {},
{MsgType: ccvconsumertypes.ModuleName, Key: string(ccvconsumertypes.KeyProviderRewardDenoms)}: {},
//distribution
{MsgType: distrtypes.ModuleName, Key: string(distrtypes.ParamStoreKeyCommunityTax)}: {},
{MsgType: distrtypes.ModuleName, Key: string(distrtypes.ParamStoreKeyWithdrawAddrEnabled)}: {},
//ibc transfer
{MsgType: ibctransfertypes.ModuleName, Key: string(ibctransfertypes.KeySendEnabled)}: {},
//ica
{MsgType: icahosttypes.SubModuleName, Key: string(icahosttypes.KeyHostEnabled)}: {},
{MsgType: icahosttypes.SubModuleName, Key: string(icahosttypes.KeyAllowMessages)}: {},
}
49 changes: 32 additions & 17 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/evidence"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand All @@ -68,7 +67,6 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/cosmos-sdk/x/upgrade"
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
Expand Down Expand Up @@ -123,6 +121,14 @@ import (
v5_1_0 "github.com/notional-labs/centauri/v5/app/upgrades/v5_1_0"

upgrades "github.com/notional-labs/centauri/v5/app/upgrades"

ccvdistr "github.com/cosmos/interchain-security/v3/x/ccv/democracy/distribution"
ccvgov "github.com/cosmos/interchain-security/v3/x/ccv/democracy/governance"
ccvstaking "github.com/cosmos/interchain-security/v3/x/ccv/democracy/staking"

ccvconsumer "github.com/cosmos/interchain-security/v3/x/ccv/consumer"
// ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)

const (
Expand Down Expand Up @@ -194,8 +200,8 @@ var (
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
ccvstaking.AppModuleBasic{},
ccvdistr.AppModuleBasic{},
gov.NewAppModuleBasic(getGovProposalHandlers()),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand All @@ -220,6 +226,7 @@ var (
ratelimitmodule.AppModuleBasic{},
consensus.AppModuleBasic{},
alliancemodule.AppModuleBasic{},
ccvconsumer.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -228,15 +235,17 @@ var (
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
// mint module needs burn access to remove excess validator tokens (it overallocates, then burns)
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
transfermiddlewaretypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.RewardsPoolName: nil,
icatypes.ModuleName: nil,
ccvconsumertypes.ConsumerRedistributeName: nil,
ccvconsumertypes.ConsumerToSendToProviderName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
transfermiddlewaretypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
alliancemoduletypes.RewardsPoolName: nil,
icatypes.ModuleName: nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -336,6 +345,7 @@ func NewCentauriApp(
icqModule := icq.NewAppModule(app.ICQKeeper)
ibcHooksModule := ibc_hooks.NewAppModule()
icaModule := ica.NewAppModule(nil, &app.ICAHostKeeper) // Only ICA Host
consumerModule := ccvconsumer.NewAppModule(app.ConsumerKeeper, app.GetSubspace(ccvconsumertypes.ModuleName))
/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand All @@ -357,11 +367,11 @@ func NewCentauriApp(
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
ccvgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, ante.IsProposalWhitelisted, app.GetSubspace(govtypes.ModuleName), func(_ string) bool { return true }),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.ConsumerKeeper, app.GetSubspace(slashingtypes.ModuleName)),
ccvdistr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, *app.StakingKeeper, authtypes.FeeCollectorName, app.GetSubspace(distrtypes.ModuleName)),
ccvstaking.NewAppModule(appCodec, *app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
Expand All @@ -377,6 +387,7 @@ func NewCentauriApp(
txBoundaryModule,
icaModule,
ratelimitModule,
consumerModule,
alliancemodule.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// this line is used by starport scaffolding # stargate/app/appModule
)
Expand Down Expand Up @@ -415,6 +426,7 @@ func NewCentauriApp(
icatypes.ModuleName,
wasm.ModuleName,
alliancemoduletypes.ModuleName,
ccvconsumertypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -448,6 +460,7 @@ func NewCentauriApp(
icatypes.ModuleName,
wasm.ModuleName,
alliancemoduletypes.ModuleName,
ccvconsumertypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -485,6 +498,7 @@ func NewCentauriApp(
icatypes.ModuleName,
wasm.ModuleName,
alliancemoduletypes.ModuleName,
ccvconsumertypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down Expand Up @@ -536,6 +550,7 @@ func NewCentauriApp(
app.IBCKeeper,
app.TransferMiddlewareKeeper,
app.TxBoundaryKeepper,
app.ConsumerKeeper,
appCodec,
))
app.SetEndBlocker(app.EndBlocker)
Expand Down
3 changes: 3 additions & 0 deletions app/ibctesting/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ import (
transfermiddleware "github.com/notional-labs/centauri/v5/x/transfermiddleware"
transfermiddlewarekeeper "github.com/notional-labs/centauri/v5/x/transfermiddleware/keeper"
transfermiddlewaretypes "github.com/notional-labs/centauri/v5/x/transfermiddleware/types"

ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
)

const appName = "SimApp"
Expand Down Expand Up @@ -949,6 +951,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(ccvconsumertypes.ModuleName)

return paramsKeeper
}
Expand Down
Loading