Skip to content

Commit

Permalink
gov change by sdk47
Browse files Browse the repository at this point in the history
  • Loading branch information
vuong177 committed Apr 22, 2023
1 parent 7ff4cfe commit 591f182
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 39 deletions.
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"
"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 v1beta1.Content) bool {
switch c := content.(type) {
case *proposal.ParameterChangeProposal:
return isParamChangeWhitelisted(c.Changes)
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/consumer/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestValidateInitialGenesisState(t *testing.T) {
valHash := valSet.Hash()
valUpdates := tmtypes.TM2PB.ValidatorUpdates(valSet)

cs := ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false)
cs := ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath)
consensusState := ibctmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), valHash)

params := types.DefaultParams()
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestValidateRestartGenesisState(t *testing.T) {
SlashPacketData: ccv.NewSlashPacketData(
abci.Validator{Address: pubKey.Address(), Power: int64(1)},
1,
stakingtypes.Downtime),
stakingtypes.Infraction_INFRACTION_DOWNTIME),
},
}

Expand All @@ -273,7 +273,7 @@ func TestValidateRestartGenesisState(t *testing.T) {
{Height: 0, ValsetUpdateId: 0},
}

cs := ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false)
cs := ibctmtypes.NewClientState(chainID, ibctmtypes.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath)
consensusState := ibctmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte("apphash")), valHash)

params := types.DefaultParams()
Expand Down
5 changes: 3 additions & 2 deletions x/ccv/democracy/distribution/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
Expand Down Expand Up @@ -46,9 +47,9 @@ type AppModule struct {
// AppModule constructor.
func NewAppModule(
cdc codec.Codec, keeper keeper.Keeper, ak distrtypes.AccountKeeper,
bk distrtypes.BankKeeper, sk stakingkeeper.Keeper, feeCollectorName string,
bk distrtypes.BankKeeper, sk stakingkeeper.Keeper, feeCollectorName string, subspace exported.Subspace,
) AppModule {
distrAppMod := distr.NewAppModule(cdc, keeper, ak, bk, sk)
distrAppMod := distr.NewAppModule(cdc, keeper, ak, bk, sk, subspace)
return AppModule{
AppModule: distrAppMod,
keeper: keeper,
Expand Down
19 changes: 10 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"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

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

keeper keeper.Keeper
isProposalWhitelisted func(govtypes.Content) bool
isProposalWhitelisted func(v1beta1.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 {
govAppModule := gov.NewAppModule(cdc, keeper, ak, bk)
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak govtypes.AccountKeeper, bk govtypes.BankKeeper, isProposalWhitelisted func(v1beta1.Content) bool, ss govtypes.ParamSubspace) AppModule {
govAppModule := gov.NewAppModule(cdc, &keeper, ak, bk, ss)
return AppModule{
AppModule: govAppModule,
keeper: keeper,
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 v1.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,19 +54,18 @@ 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) {
if am.isProposalWhitelisted(proposal.GetContent()) {
func deleteForbiddenProposal(ctx sdk.Context, am AppModule, proposal v1.Proposal) {
if am.isProposalWhitelisted(proposal.Content) {
return
}

// delete the votes related to the proposal calling Tally
// Tally's return result won't be used in decision if the tokens will be burned or refunded (they are always refunded), but
// this function needs to be called to delete the votes related to the given proposal, since the deleteVote function is
// 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.DeleteAndBurnDeposits(ctx, proposal.Id)
am.keeper.RefundAndDeleteDeposits(ctx, proposal.Id)

ctx.EventManager().EmitEvent(
sdk.NewEvent(
Expand Down
2 changes: 0 additions & 2 deletions x/ccv/provider/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ func DefaultParams() Params {
clienttypes.Height{}, // latest(initial) height
commitmenttypes.GetSDKSpecs(),
[]string{"upgrade", "upgradedIBCState"},
true,
true,
),
DefaultTrustingPeriodFraction,
ccvtypes.DefaultCCVTimeoutPeriod,
Expand Down
16 changes: 8 additions & 8 deletions x/ccv/provider/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestValidateParams(t *testing.T) {
}{
{"default params", types.DefaultParams(), true},
{"custom valid params", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100), true},
{"custom invalid params", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
0, clienttypes.Height{}, nil, []string{"ibc", "upgradedIBCState"}, true, false),
Expand All @@ -30,25 +30,25 @@ func TestValidateParams(t *testing.T) {
{"nil client", types.NewParams(nil, "0.33", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100), false},
// Check if "0.00" is valid or if a zero dec TrustFraction needs to return an error
{"0 trusting period fraction", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.00", time.Hour, time.Hour, time.Hour, 30*time.Minute, "0.1", 100), true},
{"0 ccv timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", 0, time.Hour, time.Hour, 30*time.Minute, "0.1", 100), false},
{"0 init timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", time.Hour, 0, time.Hour, 30*time.Minute, "0.1", 100), false},
{"0 vsc timeout period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", time.Hour, time.Hour, 0, 30*time.Minute, "0.1", 100), false},
{"0 slash meter replenish period", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", time.Hour, time.Hour, 24*time.Hour, 0, "0.1", 100), false},
{"slash meter replenish fraction over 1", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "1.5", 100), false},
{"negative max pending slash packets", types.NewParams(ibctmtypes.NewClientState("", ibctmtypes.DefaultTrustLevel, 0, 0,
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}, true, false),
time.Second*40, clienttypes.Height{}, commitmenttypes.GetSDKSpecs(), []string{"ibc", "upgradedIBCState"}),
"0.33", time.Hour, time.Hour, 24*time.Hour, time.Hour, "0.1", -100), false},
}

Expand Down
26 changes: 13 additions & 13 deletions 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"
"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 All @@ -20,15 +20,15 @@ const (
)

var (
_ govtypes.Content = &ConsumerAdditionProposal{}
_ govtypes.Content = &ConsumerRemovalProposal{}
_ govtypes.Content = &EquivocationProposal{}
_ v1beta1.Content = &ConsumerAdditionProposal{}
_ v1beta1.Content = &ConsumerRemovalProposal{}
_ v1beta1.Content = &EquivocationProposal{}
)

func init() {
govtypes.RegisterProposalType(ProposalTypeConsumerAddition)
govtypes.RegisterProposalType(ProposalTypeConsumerRemoval)
govtypes.RegisterProposalType(ProposalTypeEquivocation)
v1beta1.RegisterProposalType(ProposalTypeConsumerAddition)
v1beta1.RegisterProposalType(ProposalTypeConsumerRemoval)
v1beta1.RegisterProposalType(ProposalTypeEquivocation)
}

// NewConsumerAdditionProposal creates a new consumer addition proposal.
Expand All @@ -41,7 +41,7 @@ func NewConsumerAdditionProposal(title, description, chainID string,
ccvTimeoutPeriod time.Duration,
transferTimeoutPeriod time.Duration,
unbondingPeriod time.Duration,
) govtypes.Content {
) v1beta1.Content {
return &ConsumerAdditionProposal{
Title: title,
Description: description,
Expand Down Expand Up @@ -75,7 +75,7 @@ func (cccp *ConsumerAdditionProposal) ProposalType() string {

// ValidateBasic runs basic stateless validity checks
func (cccp *ConsumerAdditionProposal) ValidateBasic() error {
if err := govtypes.ValidateAbstract(cccp); err != nil {
if err := v1beta1.ValidateAbstract(cccp); err != nil {
return err
}

Expand Down Expand Up @@ -157,7 +157,7 @@ func (cccp *ConsumerAdditionProposal) String() string {
}

// NewConsumerRemovalProposal creates a new consumer removal proposal.
func NewConsumerRemovalProposal(title, description, chainID string, stopTime time.Time) govtypes.Content {
func NewConsumerRemovalProposal(title, description, chainID string, stopTime time.Time) v1beta1.Content {
return &ConsumerRemovalProposal{
Title: title,
Description: description,
Expand All @@ -174,7 +174,7 @@ func (sccp *ConsumerRemovalProposal) ProposalType() string { return ProposalType

// ValidateBasic runs basic stateless validity checks
func (sccp *ConsumerRemovalProposal) ValidateBasic() error {
if err := govtypes.ValidateAbstract(sccp); err != nil {
if err := v1beta1.ValidateAbstract(sccp); err != nil {
return err
}

Expand All @@ -189,7 +189,7 @@ func (sccp *ConsumerRemovalProposal) ValidateBasic() error {
}

// NewEquivocationProposal creates a new equivocation proposal.
func NewEquivocationProposal(title, description string, equivocations []*evidencetypes.Equivocation) govtypes.Content {
func NewEquivocationProposal(title, description string, equivocations []*evidencetypes.Equivocation) v1beta1.Content {
return &EquivocationProposal{
Title: title,
Description: description,
Expand All @@ -207,7 +207,7 @@ func (sp *EquivocationProposal) ProposalType() string {

// ValidateBasic runs basic stateless validity checks
func (sp *EquivocationProposal) ValidateBasic() error {
if err := govtypes.ValidateAbstract(sp); err != nil {
if err := v1beta1.ValidateAbstract(sp); err != nil {
return err
}
if len(sp.Equivocations) == 0 {
Expand Down
3 changes: 2 additions & 1 deletion x/ccv/provider/types/proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibctmtypes "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
Expand All @@ -24,7 +25,7 @@ func TestConsumerAdditionProposalValidateBasic(t *testing.T) {

testCases := []struct {
name string
proposal govtypes.Content
proposal v1beta1.Content
expPass bool
}{
{
Expand Down

0 comments on commit 591f182

Please sign in to comment.