Skip to content

Commit

Permalink
fix(gov): don't export deprecated params (backport #14408) (#14413)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
mergify[bot] and julienrbrt authored Dec 24, 2022
1 parent 3552202 commit c727ee7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
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

0 comments on commit c727ee7

Please sign in to comment.