forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: expedited proposals parameter migrations (#303)
* migration to v4 * added value & migrated params * Test additions and CI fixes * additional fixes * table mismatch fixes * feedback implemented * feedback implemented * Apply suggestions from code review Co-authored-by: Adam Tucker <[email protected]>
- Loading branch information
1 parent
6fcd25f
commit 02273b8
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package v4 | ||
|
||
var ( | ||
MinExpeditedDeposit = minExpeditedDeposit | ||
ExpeditedVotingPeriod = expeditedVotingPeriod | ||
ExpeditedThreshold = expeditedThreshold | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package v4 | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
) | ||
|
||
// If expedited, the deposit to enter voting period will be | ||
// increased to 5000 OSMO. The proposal will have 24 hours to achieve | ||
// a two-thirds majority of all staked OSMO voting power voting YES. | ||
|
||
var ( | ||
minExpeditedDeposit = sdk.NewCoins(sdk.NewCoin("uosmo", sdk.NewInt(5000 * 1_000_000))) | ||
expeditedVotingPeriod = time.Duration(time.Hour * 24) | ||
expeditedThreshold = sdk.NewDec(2).Quo(sdk.NewDec(3)) | ||
) | ||
|
||
// MigrateStore performs in-place store migrations for consensus version 4 | ||
// in the gov module. | ||
// The migration includes: | ||
// | ||
// - Setting the expedited proposals params in the paramstore. | ||
func MigrateStore(ctx sdk.Context, paramstore types.ParamSubspace) error { | ||
migrateParamsStore(ctx, paramstore) | ||
return nil | ||
} | ||
|
||
func migrateParamsStore(ctx sdk.Context, paramstore types.ParamSubspace) { | ||
var ( | ||
depositParams types.DepositParams | ||
votingParams types.VotingParams | ||
tallyParams types.TallyParams | ||
) | ||
|
||
// Set depositParams | ||
paramstore.Get(ctx, types.ParamStoreKeyDepositParams, &depositParams) | ||
depositParams.MinExpeditedDeposit = minExpeditedDeposit | ||
paramstore.Set(ctx, types.ParamStoreKeyDepositParams, depositParams) | ||
|
||
// Set votingParams | ||
paramstore.Get(ctx, types.ParamStoreKeyVotingParams, &votingParams) | ||
votingParams.ExpeditedVotingPeriod = expeditedVotingPeriod | ||
paramstore.Set(ctx, types.ParamStoreKeyVotingParams, votingParams) | ||
|
||
// Set tallyParams | ||
paramstore.Get(ctx, types.ParamStoreKeyTallyParams, &tallyParams) | ||
tallyParams.ExpeditedThreshold = expeditedThreshold | ||
paramstore.Set(ctx, types.ParamStoreKeyTallyParams, tallyParams) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package v4_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
"github.com/cosmos/cosmos-sdk/testutil" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
v4 "github.com/cosmos/cosmos-sdk/x/gov/legacy/v4" | ||
"github.com/cosmos/cosmos-sdk/x/gov/types" | ||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
) | ||
|
||
func TestGovStoreMigrationToV4ConsensusVersion(t *testing.T) { | ||
encCfg := simapp.MakeTestEncodingConfig() | ||
govKey := sdk.NewKVStoreKey("gov") | ||
transientTestKey := sdk.NewTransientStoreKey("transient_test") | ||
ctx := testutil.DefaultContext(govKey, transientTestKey) | ||
paramstore := paramtypes.NewSubspace(encCfg.Marshaler, encCfg.Amino, govKey, transientTestKey, "gov") | ||
|
||
paramstore = paramstore.WithKeyTable(types.ParamKeyTable()) | ||
|
||
// We assume that all deposit params are set besides the MinInitialDepositRatio | ||
originalDepositParams := types.DefaultDepositParams() | ||
originalDepositParams.MinExpeditedDeposit = sdk.NewCoins() | ||
paramstore.Set(ctx, types.ParamStoreKeyDepositParams, originalDepositParams) | ||
|
||
originalVotingParams := types.DefaultVotingParams() | ||
originalVotingParams.ExpeditedVotingPeriod = time.Duration(0) | ||
paramstore.Set(ctx, types.ParamStoreKeyVotingParams, originalVotingParams) | ||
|
||
originalTallyParams := types.DefaultTallyParams() | ||
originalTallyParams.ExpeditedThreshold = sdk.ZeroDec() | ||
paramstore.Set(ctx, types.ParamStoreKeyTallyParams, originalTallyParams) | ||
|
||
// Run migrations. | ||
err := v4.MigrateStore(ctx, paramstore) | ||
require.NoError(t, err) | ||
|
||
// Make sure the new params are set. | ||
var depositParams types.DepositParams | ||
paramstore.Get(ctx, types.ParamStoreKeyDepositParams, &depositParams) | ||
require.Equal(t, v4.MinExpeditedDeposit, depositParams.MinExpeditedDeposit) | ||
|
||
var votingParams types.VotingParams | ||
paramstore.Get(ctx, types.ParamStoreKeyVotingParams, &votingParams) | ||
require.Equal(t, v4.ExpeditedVotingPeriod, votingParams.ExpeditedVotingPeriod) | ||
|
||
var tallyParams types.TallyParams | ||
paramstore.Get(ctx, types.ParamStoreKeyTallyParams, &tallyParams) | ||
require.Equal(t, v4.ExpeditedThreshold, tallyParams.ExpeditedThreshold) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters