Skip to content

Commit

Permalink
migrate gov
Browse files Browse the repository at this point in the history
  • Loading branch information
tbruyelle committed Apr 13, 2023
1 parent 15e5bde commit 20514fb
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion app/consumer-democracy/ante/forbidden_proposals_ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

type ForbiddenProposalsDecorator struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/params/types/proposal"
app "github.com/cosmos/interchain-security/app/consumer-democracy"
"github.com/cosmos/interchain-security/app/consumer-democracy/ante"
Expand Down
2 changes: 1 addition & 1 deletion app/consumer-democracy/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
Expand Down
22 changes: 12 additions & 10 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/feegrant"
feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/params"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
Expand Down Expand Up @@ -83,8 +84,6 @@ import (
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"

distr "github.com/cosmos/cosmos-sdk/x/distribution"

distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
testutil "github.com/cosmos/interchain-security/testutil/integration"
Expand All @@ -97,6 +96,7 @@ import (
gov "github.com/cosmos/cosmos-sdk/x/gov"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
ccvgov "github.com/cosmos/interchain-security/x/ccv/democracy/governance"

// add mint
Expand Down Expand Up @@ -135,7 +135,9 @@ var (
ccvdistr.AppModuleBasic{},
gov.NewAppModuleBasic(
// TODO: eventually remove upgrade proposal handler and cancel proposal handler
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
[]govclient.ProposalHandler{
paramsclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler,
},
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down Expand Up @@ -381,15 +383,15 @@ func New(
)

// register the proposal types
ccvgovRouter := govtypes.NewRouter()
ccvgovRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
ccvgovRouter := govv1beta1.NewRouter()
ccvgovRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
// TODO: remove upgrade handler from gov once admin module or decision for only signaling proposal is made.
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper))
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.UpgradeKeeper))
govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, ccvgovRouter,
appCodec, keys[govtypes.StoreKey], app.AccountKeeper, app.BankKeeper,
stakingKeeper, app.MsgServiceRouter(),
govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.GovKeeper = *govKeeper.SetHooks(
Expand Down Expand Up @@ -925,7 +927,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(gov.ProvideKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
Expand Down
3 changes: 2 additions & 1 deletion app/consumer-democracy/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ 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"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
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"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
)

func IsProposalWhitelisted(content govtypes.Content) bool {
func IsProposalWhitelisted(content govv1beta1.Content) bool {
switch c := content.(type) {
case *proposal.ParameterChangeProposal:
return isParamChangeWhitelisted(c.Changes)
Expand Down
39 changes: 22 additions & 17 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand Down Expand Up @@ -128,14 +130,16 @@ var (
mint.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler,
upgradeclient.ProposalHandler,
upgradeclient.CancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
ibcproviderclient.ConsumerAdditionProposalHandler,
ibcproviderclient.ConsumerRemovalProposalHandler,
ibcproviderclient.EquivocationProposalHandler,
[]govclient.ProposalHandler{
paramsclient.ProposalHandler,
upgradeclient.LegacyProposalHandler,
upgradeclient.LegacyCancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler,
ibcclientclient.UpgradeProposalHandler,
ibcproviderclient.ConsumerAdditionProposalHandler,
ibcproviderclient.ConsumerRemovalProposalHandler,
ibcproviderclient.EquivocationProposalHandler,
},
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down Expand Up @@ -411,25 +415,26 @@ func New(
providerModule := ibcprovider.NewAppModule(&app.ProviderKeeper)

// register the proposal types
govRouter := govtypes.NewRouter()
govRouter := govv1beta1.NewRouter()
govRouter.
AddRoute(govtypes.RouterKey, govtypes.ProposalHandler).
AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler).
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)).
AddRoute(providertypes.RouterKey, ibcprovider.NewProviderProposalHandler(app.ProviderKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

app.GovKeeper = govkeeper.NewKeeper(
govKeeper := govkeeper.NewKeeper(
appCodec,
keys[govtypes.StoreKey],
app.GetSubspace(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&stakingKeeper,
govRouter,
stakingKeeper,
app.MsgServiceRouter(),
govtypes.DefaultConfig(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.GovKeeper = *govKeeper

app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -860,7 +865,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(minttypes.ModuleName)
paramsKeeper.Subspace(distrtypes.ModuleName)
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(gov.ProvideKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/democracy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
icstestingutils "github.com/cosmos/interchain-security/testutil/ibc_testing"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
testutil "github.com/cosmos/interchain-security/testutil/integration"
Expand Down
3 changes: 2 additions & 1 deletion testutil/integration/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
Expand Down Expand Up @@ -139,6 +139,7 @@ type TestMintKeeper interface {
}

type TestGovKeeper interface {
// TODO fix methods here
GetDepositParams(ctx sdk.Context) govtypes.DepositParams
GetVotingParams(ctx sdk.Context) govtypes.VotingParams
SetVotingParams(ctx sdk.Context, votingParams govtypes.VotingParams)
Expand Down
20 changes: 11 additions & 9 deletions x/ccv/democracy/governance/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
gov "github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
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"
)

const (
Expand All @@ -28,11 +30,11 @@ type AppModule struct {
gov.AppModule

keeper keeper.Keeper
isProposalWhitelisted func(govtypes.Content) bool
isProposalWhitelisted func(govv1beta1.Content) bool
}

// NewAppModule creates a new AppModule object using the native x/governance module AppModule constructor.
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak govtypes.AccountKeeper, bk govtypes.BankKeeper, isProposalWhitelisted func(govtypes.Content) bool) AppModule {
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak govtypes.AccountKeeper, bk govtypes.BankKeeper, isProposalWhitelisted func(govv1beta1.Content) bool) AppModule {
govAppModule := gov.NewAppModule(cdc, keeper, ak, bk)
return AppModule{
AppModule: govAppModule,
Expand All @@ -42,7 +44,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak govtypes.AccountKeep
}

func (am AppModule) EndBlock(ctx sdk.Context, request abci.RequestEndBlock) []abci.ValidatorUpdate {
am.keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal govtypes.Proposal) bool {
am.keeper.IterateActiveProposalsQueue(ctx, ctx.BlockHeader().Time, func(proposal govv1.Proposal) bool {
// if there are forbidden proposals in active proposals queue, refund deposit, delete votes for that proposal
// and delete proposal from all storages
deleteForbiddenProposal(ctx, am, proposal)
Expand All @@ -52,7 +54,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, request abci.RequestEndBlock) []ab
return am.AppModule.EndBlock(ctx, request)
}

func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal govtypes.Proposal) {
func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal govv1.Proposal) {
if am.isProposalWhitelisted(proposal.GetContent()) {
return
}
Expand All @@ -63,21 +65,21 @@ func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal govtypes.Pr
// private and cannot be called directly from the overridden app module
am.keeper.Tally(ctx, proposal)

am.keeper.DeleteProposal(ctx, proposal.ProposalId)
am.keeper.RefundDeposits(ctx, proposal.ProposalId)
am.keeper.DeleteProposal(ctx, proposal.Id)
am.keeper.RefundAndDeleteDeposits(ctx, proposal.Id)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
govtypes.EventTypeActiveProposal,
sdk.NewAttribute(govtypes.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.ProposalId)),
sdk.NewAttribute(govtypes.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.Id)),
sdk.NewAttribute(govtypes.AttributeKeyProposalResult, AttributeValueProposalForbidden),
),
)

logger := am.keeper.Logger(ctx)
logger.Info(
"proposal is not whitelisted; deleted",
"proposal", proposal.ProposalId,
"proposal", proposal.Id,
"title", proposal.GetTitle(),
"total_deposit", proposal.TotalDeposit.String())
"total_deposit", proposal.TotalDeposit)
}
14 changes: 2 additions & 12 deletions x/ccv/provider/client/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/interchain-security/x/ccv/provider/types"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -224,8 +224,8 @@ type ConsumerAdditionProposalJSON struct {
Deposit string `json:"deposit"`
}

// TODO remove ?
type ConsumerAdditionProposalReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Proposer sdk.AccAddress `json:"proposer"`

Title string `json:"title"`
Expand Down Expand Up @@ -270,7 +270,6 @@ type ConsumerRemovalProposalJSON struct {
}

type ConsumerRemovalProposalReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Proposer sdk.AccAddress `json:"proposer"`

Title string `json:"title"`
Expand All @@ -289,7 +288,6 @@ type EquivocationProposalJSON struct {
}

type EquivocationProposalReq struct {
BaseReq rest.BaseReq `json:"base_req"`
Proposer sdk.AccAddress `json:"proposer"`

// evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand All @@ -313,14 +311,6 @@ func ParseEquivocationProposalJSON(proposalFile string) (EquivocationProposalJSO
return proposal, nil
}

// EquivocationProposalRESTHandler returns a ProposalRESTHandler that exposes the equivocation rest handler.
func EquivocationProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler {
return govrest.ProposalRESTHandler{
SubRoute: "equivocation",
Handler: postEquivocationProposalHandlerFn(clientCtx),
}
}

func ParseConsumerRemovalProposalJSON(proposalFile string) (ConsumerRemovalProposalJSON, error) {
proposal := ConsumerRemovalProposalJSON{}

Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package provider
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/interchain-security/x/ccv/provider/keeper"
"github.com/cosmos/interchain-security/x/ccv/provider/types"
)
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
testkeeper "github.com/cosmos/interchain-security/testutil/keeper"
"github.com/cosmos/interchain-security/x/ccv/provider"
providertypes "github.com/cosmos/interchain-security/x/ccv/provider/types"
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

// RegisterLegacyAminoCodec registers the necessary x/ibc transfer interfaces and concrete types
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ccvtypes "github.com/cosmos/interchain-security/x/ccv/types"
)
Expand Down
2 changes: 1 addition & 1 deletion x/ccv/provider/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
Expand Down

0 comments on commit 20514fb

Please sign in to comment.