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

fix(gov): don't export deprecated params #14408

Merged
merged 4 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 7 deletions x/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v1.GenesisState {
proposals := k.GetProposals(ctx)
params := k.GetParams(ctx)

depositParams := v1.NewDepositParams(params.MinDeposit, params.MaxDepositPeriod) //nolint:staticcheck
votingParams := v1.NewVotingParams(params.VotingPeriod) //nolint:staticcheck
tallyParams := v1.NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold) //nolint:staticcheck

var proposalsDeposits v1.Deposits
var proposalsVotes v1.Votes
for _, proposal := range proposals {
Expand All @@ -77,9 +73,6 @@ func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) *v1.GenesisState {
Deposits: proposalsDeposits,
Votes: proposalsVotes,
Proposals: proposals,
DepositParams: &depositParams,
VotingParams: &votingParams,
TallyParams: &tallyParams,
Params: &params,
}
}
21 changes: 20 additions & 1 deletion x/gov/migrations/v4/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,28 @@ func TestMigrateJSON(t *testing.T) {
WithCodec(encodingConfig.Codec)

govGenState := v1.DefaultGenesisState()
oldGovState := &v1.GenesisState{
StartingProposalId: govGenState.StartingProposalId,
Deposits: govGenState.Deposits,
Votes: govGenState.Votes,
Proposals: govGenState.Proposals,
DepositParams: &v1.DepositParams{
MinDeposit: govGenState.Params.MinDeposit,
MaxDepositPeriod: govGenState.Params.MaxDepositPeriod,
},
VotingParams: &v1.VotingParams{
VotingPeriod: govGenState.Params.VotingPeriod,
},
TallyParams: &v1.TallyParams{
Quorum: govGenState.Params.Quorum,
Threshold: govGenState.Params.Threshold,
VetoThreshold: govGenState.Params.VetoThreshold,
},
}

migrated, err := v4.MigrateJSON(govGenState)
migrated, err := v4.MigrateJSON(oldGovState)
require.NoError(t, err)
require.Equal(t, migrated, govGenState)

bz, err := clientCtx.Codec.MarshalJSON(migrated)
require.NoError(t, err)
Expand Down
20 changes: 0 additions & 20 deletions x/gov/types/v1/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@ package v1

import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/codec/types"
)

// NewGenesisState creates a new genesis state for the governance module
func NewGenesisState(startingProposalID uint64, params Params) *GenesisState {
dp := NewDepositParams(params.MinDeposit, params.MaxDepositPeriod)
vp := NewVotingParams(params.VotingPeriod)
tp := NewTallyParams(params.Quorum, params.Threshold, params.VetoThreshold)

return &GenesisState{
StartingProposalId: startingProposalID,
DepositParams: &dp,
VotingParams: &vp,
TallyParams: &tp,
Params: &params,
}
}
Expand All @@ -41,18 +33,6 @@ func ValidateGenesis(data *GenesisState) error {
return errors.New("starting proposal id must be greater than 0")
}

if err := validateTallyParams(*data.TallyParams); err != nil {
return fmt.Errorf("invalid tally params: %w", err)
}

if err := validateVotingParams(*data.VotingParams); err != nil {
return fmt.Errorf("invalid voting params: %w", err)
}

if err := validateDepositParams(*data.DepositParams); err != nil {
return fmt.Errorf("invalid deposit params: %w", err)
}

return data.Params.ValidateBasic()
}

Expand Down