revert: Turn staking power reduction into an on-chain param (#9495)
<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description Closes: #9447 This PR partially reverts #8505. Namely: - it removes PowerReduction as a staking on-chain param - however, it keeps #8505's API changes regarding adding a `powerReduction` function argument to staking functions. This allows us to rely less on global variables in said functions. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
179c819a9d
commit
5cd741a878
|
@ -86,6 +86,7 @@ if input key is empty, or input data contains empty key.
|
|||
* (x/gov) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the gov module account balance, coming from bank module state, does not match the one in gov module state, the initialization will panic.
|
||||
* (x/distribution) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the distribution module account balance, coming from bank module state, does not match the one in distribution module state, the initialization will panic.
|
||||
* (client/keys) [\#8500](https://github.com/cosmos/cosmos-sdk/pull/8500) `InfoImporter` interface is removed from legacy keybase.
|
||||
* (x/staking) [\#8505](https://github.com/cosmos/cosmos-sdk/pull/8505) `sdk.PowerReduction` has been renamed to `sdk.DefaultPowerReduction`, and most staking functions relying on power reduction take a new function argument, instead of relying on that global variable.
|
||||
* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Deprecated `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`.
|
||||
* (x/upgrade) [\#8673](https://github.com/cosmos/cosmos-sdk/pull/8673) Remove IBC logic from x/upgrade. Deprecates IBC fields in an Upgrade Plan. IBC upgrade logic moved to 02-client and an IBC UpgradeProposal is added.
|
||||
* (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) `SupplyI` interface and `Supply` are removed and uses `sdk.Coins` for supply tracking
|
||||
|
@ -126,7 +127,6 @@ if input key is empty, or input data contains empty key.
|
|||
* (x/bank) [\#8656](https://github.com/cosmos/cosmos-sdk/pull/8656) balance and supply are now correctly tracked via `coin_spent`, `coin_received`, `coinbase` and `burn` events.
|
||||
* (x/bank) [\#8517](https://github.com/cosmos/cosmos-sdk/pull/8517) Supply is now stored and tracked as `sdk.Coins`
|
||||
* (store) [\#8790](https://github.com/cosmos/cosmos-sdk/pull/8790) Reduce gas costs by 10x for transient store operations.
|
||||
* (x/staking) [\#8505](https://github.com/cosmos/cosmos-sdk/pull/8505) Convert staking power reduction into an on-chain parameter rather than a hardcoded in-code variable.
|
||||
* (x/bank) [\#9051](https://github.com/cosmos/cosmos-sdk/pull/9051) Supply value is stored as `sdk.Int` rather than `string`.
|
||||
|
||||
### Improvements
|
||||
|
|
|
@ -6394,7 +6394,6 @@ Params defines the parameters for the staking module.
|
|||
| `max_entries` | [uint32](#uint32) | | max_entries is the max entries for either unbonding delegation or redelegation (per pair/trio). |
|
||||
| `historical_entries` | [uint32](#uint32) | | historical_entries is the number of historical entries to persist. |
|
||||
| `bond_denom` | [string](#string) | | bond_denom defines the bondable coin denomination. |
|
||||
| `power_reduction` | [string](#string) | | power_reduction is the amount of staking tokens required for 1 unit of consensus-engine power |
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -282,12 +282,6 @@ message Params {
|
|||
uint32 historical_entries = 4 [(gogoproto.moretags) = "yaml:\"historical_entries\""];
|
||||
// bond_denom defines the bondable coin denomination.
|
||||
string bond_denom = 5 [(gogoproto.moretags) = "yaml:\"bond_denom\""];
|
||||
// power_reduction is the amount of staking tokens required for 1 unit of consensus-engine power
|
||||
string power_reduction = 6 [
|
||||
(gogoproto.moretags) = "yaml:\"power_reduction\"",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// DelegationResponse is equivalent to Delegation except that it contains a
|
||||
|
|
|
@ -867,13 +867,12 @@ func (s *IntegrationTestSuite) TestGetCmdQueryParams() {
|
|||
historical_entries: 10000
|
||||
max_entries: 7
|
||||
max_validators: 100
|
||||
power_reduction: "1000000"
|
||||
unbonding_time: 1814400s`,
|
||||
},
|
||||
{
|
||||
"with json output",
|
||||
[]string{fmt.Sprintf("--%s=json", tmcli.OutputFlag)},
|
||||
`{"unbonding_time":"1814400s","max_validators":100,"max_entries":7,"historical_entries":10000,"bond_denom":"stake","power_reduction":"1000000"}`,
|
||||
`{"unbonding_time":"1814400s","max_validators":100,"max_entries":7,"historical_entries":10000,"bond_denom":"stake"}`,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
|
|
|
@ -42,51 +42,6 @@ func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmo
|
|||
return app, ctx, addrDels, addrVals
|
||||
}
|
||||
|
||||
func TestPowerReductionChangeValidatorSetUpdates(t *testing.T) {
|
||||
initPower := int64(1000000)
|
||||
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 10, sdk.TokensFromConsensusPower(initPower, sdk.DefaultPowerReduction))
|
||||
validatorAddr, validatorAddr3 := valAddrs[0], valAddrs[1]
|
||||
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
|
||||
|
||||
// create validator
|
||||
tstaking.CreateValidatorWithValPower(validatorAddr, PKs[0], initPower, true)
|
||||
|
||||
// must end-block
|
||||
updates, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(updates))
|
||||
|
||||
// create a second validator keep it bonded
|
||||
tstaking.CreateValidatorWithValPower(validatorAddr3, PKs[2], initPower, true)
|
||||
|
||||
// must end-block
|
||||
updates, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(updates))
|
||||
|
||||
// modify power reduction to 10 times bigger one
|
||||
params := app.StakingKeeper.GetParams(ctx)
|
||||
params.PowerReduction = sdk.DefaultPowerReduction.Mul(sdk.NewInt(10))
|
||||
app.StakingKeeper.SetParams(ctx, params)
|
||||
|
||||
// validator updates for tendermint power
|
||||
updates, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(updates))
|
||||
require.Equal(t, updates[0].Power, initPower/10)
|
||||
require.Equal(t, updates[1].Power, initPower/10)
|
||||
|
||||
// power reduction back to default
|
||||
params = app.StakingKeeper.GetParams(ctx)
|
||||
params.PowerReduction = sdk.DefaultPowerReduction
|
||||
app.StakingKeeper.SetParams(ctx, params)
|
||||
|
||||
// validator updates for tendermint power
|
||||
updates, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 2, len(updates))
|
||||
}
|
||||
|
||||
func TestValidatorByPowerIndex(t *testing.T) {
|
||||
initPower := int64(1000000)
|
||||
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 10, sdk.TokensFromConsensusPower(initPower, sdk.DefaultPowerReduction))
|
||||
|
|
|
@ -17,5 +17,5 @@ func NewMigrator(keeper Keeper) Migrator {
|
|||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
return v043.MigrateStore(ctx, m.keeper.storeKey, m.keeper.paramstore)
|
||||
return v043.MigrateStore(ctx, m.keeper.storeKey)
|
||||
}
|
||||
|
|
|
@ -39,11 +39,12 @@ func (k Keeper) BondDenom(ctx sdk.Context) (res string) {
|
|||
return
|
||||
}
|
||||
|
||||
// PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power
|
||||
// governance can update it on a running chain
|
||||
func (k Keeper) PowerReduction(ctx sdk.Context) (res sdk.Int) {
|
||||
k.paramstore.Get(ctx, types.KeyPowerReduction, &res)
|
||||
return
|
||||
// PowerReduction - is the amount of staking tokens required for 1 unit of consensus-engine power.
|
||||
// Currently, this returns a global variable that the app developer can tweak.
|
||||
// TODO: we might turn this into an on-chain param:
|
||||
// https://github.com/cosmos/cosmos-sdk/issues/8365
|
||||
func (k Keeper) PowerReduction(ctx sdk.Context) sdk.Int {
|
||||
return sdk.DefaultPowerReduction
|
||||
}
|
||||
|
||||
// Get all parameteras as types.Params
|
||||
|
@ -54,7 +55,6 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params {
|
|||
k.MaxEntries(ctx),
|
||||
k.HistoricalEntries(ctx),
|
||||
k.BondDenom(ctx),
|
||||
k.PowerReduction(ctx),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
package keeper_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func (suite *KeeperTestSuite) TestPowerReductionChange() {
|
||||
// modify power reduction
|
||||
newPowerReduction := sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(12), nil))
|
||||
params := suite.app.StakingKeeper.GetParams(suite.ctx)
|
||||
params.PowerReduction = newPowerReduction
|
||||
suite.app.StakingKeeper.SetParams(suite.ctx, params)
|
||||
|
||||
// check power reduction change
|
||||
suite.Require().Equal(newPowerReduction, suite.app.StakingKeeper.PowerReduction(suite.ctx))
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestTokensToConsensusPower() {
|
||||
suite.Require().Equal(int64(0), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, sdk.DefaultPowerReduction.Sub(sdk.NewInt(1))))
|
||||
suite.Require().Equal(int64(1), suite.app.StakingKeeper.TokensToConsensusPower(suite.ctx, sdk.DefaultPowerReduction))
|
||||
|
|
|
@ -112,7 +112,7 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context) []abci.ValidatorUpdate {
|
|||
func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []abci.ValidatorUpdate, err error) {
|
||||
params := k.GetParams(ctx)
|
||||
maxValidators := params.MaxValidators
|
||||
powerReduction := params.PowerReduction
|
||||
powerReduction := k.PowerReduction(ctx)
|
||||
totalPower := sdk.ZeroInt()
|
||||
amtFromBondedToNotBonded, amtFromNotBondedToBonded := sdk.ZeroInt(), sdk.ZeroInt()
|
||||
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
package v043
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v043staking "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// MigrateJSON accepts exported v0.40 x/gov genesis state and migrates it to
|
||||
// v0.43 x/gov genesis state. The migration includes:
|
||||
//
|
||||
// - Gov weighted votes.
|
||||
func MigrateJSON(oldState *v040staking.GenesisState) *v043staking.GenesisState {
|
||||
return &v043staking.GenesisState{
|
||||
Params: migrateParams(oldState.Params),
|
||||
LastTotalPower: oldState.LastTotalPower,
|
||||
LastValidatorPowers: migrateLastValidatorPowers(oldState.LastValidatorPowers),
|
||||
Validators: migrateValidators(oldState.Validators),
|
||||
Delegations: migrateDelegations(oldState.Delegations),
|
||||
UnbondingDelegations: migrateUnbondingDelegations(oldState.UnbondingDelegations),
|
||||
Redelegations: migrateRedelegations(oldState.Redelegations),
|
||||
Exported: oldState.Exported,
|
||||
}
|
||||
}
|
||||
|
||||
func migrateParams(oldParams v040staking.Params) v043staking.Params {
|
||||
return v043staking.NewParams(
|
||||
oldParams.UnbondingTime,
|
||||
oldParams.MaxValidators,
|
||||
oldParams.MaxEntries,
|
||||
oldParams.HistoricalEntries,
|
||||
oldParams.BondDenom,
|
||||
sdk.DefaultPowerReduction,
|
||||
)
|
||||
}
|
||||
|
||||
func migrateLastValidatorPowers(oldLastValidatorPowers []v040staking.LastValidatorPower) []v043staking.LastValidatorPower {
|
||||
newLastValidatorPowers := make([]v043staking.LastValidatorPower, len(oldLastValidatorPowers))
|
||||
for i, oldLastValidatorPower := range oldLastValidatorPowers {
|
||||
newLastValidatorPowers[i] = v043staking.LastValidatorPower{
|
||||
Address: oldLastValidatorPower.Address,
|
||||
Power: oldLastValidatorPower.Power,
|
||||
}
|
||||
}
|
||||
return newLastValidatorPowers
|
||||
}
|
||||
|
||||
func migrateValidators(oldValidators []v040staking.Validator) []v043staking.Validator {
|
||||
newValidators := make([]v043staking.Validator, len(oldValidators))
|
||||
|
||||
for i, oldValidator := range oldValidators {
|
||||
newValidators[i] = v043staking.Validator{
|
||||
OperatorAddress: oldValidator.OperatorAddress,
|
||||
ConsensusPubkey: oldValidator.ConsensusPubkey,
|
||||
Jailed: oldValidator.Jailed,
|
||||
Status: v043staking.BondStatus(oldValidator.Status),
|
||||
Tokens: oldValidator.Tokens,
|
||||
DelegatorShares: oldValidator.DelegatorShares,
|
||||
Description: v043staking.Description{
|
||||
Moniker: oldValidator.Description.Moniker,
|
||||
Identity: oldValidator.Description.Identity,
|
||||
Website: oldValidator.Description.Website,
|
||||
SecurityContact: oldValidator.Description.SecurityContact,
|
||||
Details: oldValidator.Description.Details,
|
||||
},
|
||||
UnbondingHeight: oldValidator.UnbondingHeight,
|
||||
UnbondingTime: oldValidator.UnbondingTime,
|
||||
Commission: v043staking.Commission{
|
||||
CommissionRates: v043staking.CommissionRates{
|
||||
Rate: oldValidator.Commission.CommissionRates.Rate,
|
||||
MaxRate: oldValidator.Commission.CommissionRates.MaxRate,
|
||||
MaxChangeRate: oldValidator.Commission.CommissionRates.MaxChangeRate,
|
||||
},
|
||||
UpdateTime: oldValidator.Commission.UpdateTime,
|
||||
},
|
||||
MinSelfDelegation: oldValidator.MinSelfDelegation,
|
||||
}
|
||||
}
|
||||
|
||||
return newValidators
|
||||
}
|
||||
|
||||
func migrateDelegations(oldDelegations []v040staking.Delegation) []v043staking.Delegation {
|
||||
newDelegations := make([]v043staking.Delegation, len(oldDelegations))
|
||||
for i, oldDelegation := range oldDelegations {
|
||||
newDelegations[i] = v043staking.Delegation{
|
||||
DelegatorAddress: oldDelegation.DelegatorAddress,
|
||||
ValidatorAddress: oldDelegation.ValidatorAddress,
|
||||
Shares: oldDelegation.Shares,
|
||||
}
|
||||
}
|
||||
return newDelegations
|
||||
}
|
||||
|
||||
func migrateUnbondingDelegations(oldUnbondingDelegations []v040staking.UnbondingDelegation) []v043staking.UnbondingDelegation {
|
||||
newUnbondingDelegations := make([]v043staking.UnbondingDelegation, len(oldUnbondingDelegations))
|
||||
for i, oldUnbondingDelegation := range oldUnbondingDelegations {
|
||||
newEntries := make([]v043staking.UnbondingDelegationEntry, len(oldUnbondingDelegation.Entries))
|
||||
for j, oldEntry := range oldUnbondingDelegation.Entries {
|
||||
newEntries[j] = v043staking.UnbondingDelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
Balance: oldEntry.Balance,
|
||||
}
|
||||
}
|
||||
|
||||
newUnbondingDelegations[i] = v043staking.UnbondingDelegation{
|
||||
DelegatorAddress: oldUnbondingDelegation.DelegatorAddress,
|
||||
ValidatorAddress: oldUnbondingDelegation.ValidatorAddress,
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
return newUnbondingDelegations
|
||||
}
|
||||
|
||||
func migrateRedelegations(oldRedelegations []v040staking.Redelegation) []v043staking.Redelegation {
|
||||
newRedelegations := make([]v043staking.Redelegation, len(oldRedelegations))
|
||||
for i, oldRedelegation := range oldRedelegations {
|
||||
newEntries := make([]v043staking.RedelegationEntry, len(oldRedelegation.Entries))
|
||||
for j, oldEntry := range oldRedelegation.Entries {
|
||||
newEntries[j] = v043staking.RedelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
SharesDst: oldEntry.SharesDst,
|
||||
}
|
||||
}
|
||||
|
||||
newRedelegations[i] = v043staking.Redelegation{
|
||||
DelegatorAddress: oldRedelegation.DelegatorAddress,
|
||||
ValidatorSrcAddress: oldRedelegation.ValidatorSrcAddress,
|
||||
ValidatorDstAddress: oldRedelegation.ValidatorDstAddress,
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
return newRedelegations
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
package v043_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v043staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v043"
|
||||
)
|
||||
|
||||
func TestMigrateJSON(t *testing.T) {
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithJSONCodec(encodingConfig.Marshaler)
|
||||
|
||||
// voter, err := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh")
|
||||
// require.NoError(t, err)
|
||||
stakingGenState := &v040staking.GenesisState{
|
||||
Params: v040staking.DefaultParams(),
|
||||
}
|
||||
|
||||
migrated := v043staking.MigrateJSON(stakingGenState)
|
||||
|
||||
require.True(t, migrated.Params.PowerReduction.Equal(sdk.DefaultPowerReduction))
|
||||
|
||||
bz, err := clientCtx.Codec.MarshalJSON(migrated)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Indent the JSON bz correctly.
|
||||
var jsonObj map[string]interface{}
|
||||
err = json.Unmarshal(bz, &jsonObj)
|
||||
require.NoError(t, err)
|
||||
indentedBz, err := json.MarshalIndent(jsonObj, "", "\t")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure about:
|
||||
// - Votes are all ADR-037 weighted votes with weight 1.
|
||||
expected := `{
|
||||
"delegations": [],
|
||||
"exported": false,
|
||||
"last_total_power": "0",
|
||||
"last_validator_powers": [],
|
||||
"params": {
|
||||
"bond_denom": "stake",
|
||||
"historical_entries": 10000,
|
||||
"max_entries": 7,
|
||||
"max_validators": 100,
|
||||
"power_reduction": "1000000",
|
||||
"unbonding_time": "1814400s"
|
||||
},
|
||||
"redelegations": [],
|
||||
"unbonding_delegations": [],
|
||||
"validators": []
|
||||
}`
|
||||
|
||||
fmt.Println(string(indentedBz))
|
||||
|
||||
require.Equal(t, expected, string(indentedBz))
|
||||
}
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v040"
|
||||
v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v043"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
@ -55,20 +54,11 @@ func migrateValidatorsByPowerIndexKey(store sdk.KVStore) {
|
|||
}
|
||||
}
|
||||
|
||||
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
|
||||
if paramstore.HasKeyTable() {
|
||||
paramstore.Set(ctx, types.KeyPowerReduction, sdk.DefaultPowerReduction)
|
||||
} else {
|
||||
paramstore.WithKeyTable(types.ParamKeyTable())
|
||||
paramstore.Set(ctx, types.KeyPowerReduction, sdk.DefaultPowerReduction)
|
||||
}
|
||||
}
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The
|
||||
// migration includes:
|
||||
//
|
||||
// - Setting the Power Reduction param in the paramstore
|
||||
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, paramstore paramtypes.Subspace) error {
|
||||
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
|
||||
v043distribution.MigratePrefixAddress(store, v040staking.LastValidatorPowerKey)
|
||||
|
@ -84,7 +74,5 @@ func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, paramstore paramtypes.
|
|||
migratePrefixAddressAddressAddress(store, v040staking.RedelegationByValSrcIndexKey)
|
||||
migratePrefixAddressAddressAddress(store, v040staking.RedelegationByValDstIndexKey)
|
||||
|
||||
migrateParamsStore(ctx, paramstore)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,11 +7,9 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v043staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v043"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
|
||||
|
@ -19,14 +17,11 @@ import (
|
|||
)
|
||||
|
||||
func TestStoreMigration(t *testing.T) {
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
stakingKey := sdk.NewKVStoreKey("staking")
|
||||
tStakingKey := sdk.NewTransientStoreKey("transient_test")
|
||||
ctx := testutil.DefaultContext(stakingKey, tStakingKey)
|
||||
store := ctx.KVStore(stakingKey)
|
||||
|
||||
paramSubspace := paramtypes.NewSubspace(encCfg.Marshaler, encCfg.Amino, stakingKey, tStakingKey, types.ModuleName)
|
||||
|
||||
_, pk1, addr1 := testdata.KeyTestPubAddr()
|
||||
valAddr1 := sdk.ValAddress(addr1)
|
||||
val := teststaking.NewValidator(t, valAddr1, pk1)
|
||||
|
@ -127,7 +122,7 @@ func TestStoreMigration(t *testing.T) {
|
|||
}
|
||||
|
||||
// Run migrations.
|
||||
err := v043staking.MigrateStore(ctx, stakingKey, paramSubspace)
|
||||
err := v043staking.MigrateStore(ctx, stakingKey)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure the new keys are set and old keys are deleted.
|
||||
|
@ -140,8 +135,4 @@ func TestStoreMigration(t *testing.T) {
|
|||
require.Equal(t, value, store.Get(tc.newKey))
|
||||
})
|
||||
}
|
||||
|
||||
powerReduction := sdk.NewInt(0)
|
||||
paramSubspace.Get(ctx, types.KeyPowerReduction, &powerReduction)
|
||||
require.True(t, powerReduction.Equal(sdk.DefaultPowerReduction))
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func RandomizedGenState(simState *module.SimulationState) {
|
|||
// NOTE: the slashing module need to be defined after the staking module on the
|
||||
// NewSimulationManager constructor for this to work
|
||||
simState.UnbondTime = unbondTime
|
||||
params := types.NewParams(simState.UnbondTime, maxVals, 7, histEntries, sdk.DefaultBondDenom, sdk.DefaultPowerReduction)
|
||||
params := types.NewParams(simState.UnbondTime, maxVals, 7, histEntries, sdk.DefaultBondDenom)
|
||||
|
||||
// validators & delegations
|
||||
var (
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/simulation"
|
||||
|
@ -47,7 +46,6 @@ func TestRandomizedGenState(t *testing.T) {
|
|||
require.Equal(t, uint32(8687), stakingGenesis.Params.HistoricalEntries)
|
||||
require.Equal(t, "stake", stakingGenesis.Params.BondDenom)
|
||||
require.Equal(t, float64(238280), stakingGenesis.Params.UnbondingTime.Seconds())
|
||||
require.Equal(t, sdk.DefaultPowerReduction, stakingGenesis.Params.PowerReduction)
|
||||
// check numbers of Delegations and Validators
|
||||
require.Len(t, stakingGenesis.Delegations, 3)
|
||||
require.Len(t, stakingGenesis.Validators, 3)
|
||||
|
|
|
@ -49,14 +49,13 @@ func ParamKeyTable() paramtypes.KeyTable {
|
|||
}
|
||||
|
||||
// NewParams creates a new Params instance
|
||||
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string, powerReduction sdk.Int) Params {
|
||||
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string) Params {
|
||||
return Params{
|
||||
UnbondingTime: unbondingTime,
|
||||
MaxValidators: maxValidators,
|
||||
MaxEntries: maxEntries,
|
||||
HistoricalEntries: historicalEntries,
|
||||
BondDenom: bondDenom,
|
||||
PowerReduction: powerReduction,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +67,6 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
|||
paramtypes.NewParamSetPair(KeyMaxEntries, &p.MaxEntries, validateMaxEntries),
|
||||
paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries),
|
||||
paramtypes.NewParamSetPair(KeyBondDenom, &p.BondDenom, validateBondDenom),
|
||||
paramtypes.NewParamSetPair(KeyPowerReduction, &p.PowerReduction, ValidatePowerReduction),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +78,6 @@ func DefaultParams() Params {
|
|||
DefaultMaxEntries,
|
||||
DefaultHistoricalEntries,
|
||||
sdk.DefaultBondDenom,
|
||||
sdk.DefaultPowerReduction,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue