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

LSM staking migration #17

Merged
merged 22 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
40b8762
upgrade handler and test
riley-stride Jul 8, 2023
eec7bca
rm upgrade handler and move migration helpers from app/upgrades to x/…
riley-stride Jul 13, 2023
f649cff
rm BeforeTokenizeShareRecordRemoved hooks
riley-stride Jul 13, 2023
bcf3697
Revert "rm upgrade handler and move migration helpers from app/upgrad…
riley-stride Jul 13, 2023
230a866
rm upgrade handler and move migration helpers from app/upgrades to x/…
riley-stride Jul 13, 2023
5e6b974
Revert "rm BeforeTokenizeShareRecordRemoved hooks"
riley-stride Jul 13, 2023
2ee275d
lint/format
sampocs Jul 26, 2023
679cf5d
moved and renamed files
sampocs Aug 1, 2023
aa24023
refactored migrations
sampocs Aug 1, 2023
3082897
wired up migration
sampocs Aug 1, 2023
018ecc8
added legacy types
sampocs Aug 2, 2023
a7255b0
added validators and delegations unit tests, params test WIP
sampocs Aug 2, 2023
128be08
finished unit test for params
sampocs Aug 2, 2023
4d6ab68
Merge branch 'v0.45.16-ics-lsm' into v0.45.16-ics-lsm_upgrade-handler
sampocs Aug 3, 2023
a87d1a1
resolved conflicts
sampocs Aug 3, 2023
b75a00e
chore: add migrateUBDEntries to migration
riley-stride Aug 4, 2023
213f038
chore: call migrateUBDEntries from upgrade handler
riley-stride Aug 4, 2023
79044d1
test: tweak store, keys, migrations for UBD unit test
riley-stride Aug 8, 2023
0063de6
test: copy paste UBD unit test from https://github.com/cosmos/cosmos-…
riley-stride Aug 8, 2023
3d19da9
cleaned up UBD unit test and incremented consensus version
sampocs Aug 8, 2023
2967e8a
removed legacy subspace from migrator
sampocs Aug 8, 2023
63e834b
registered migration
sampocs Aug 9, 2023
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
39 changes: 39 additions & 0 deletions x/staking/legacy/v045/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v11

import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
)

// Set initial param values, based on https://github.com/iqlusioninc/liquidity-staking-module/blob/master/x/staking/spec/08_params.md
func SetParamsStaking(ctx sdk.Context, k stakingkeeper.Keeper) {
params := k.GetParams(ctx)

params.ValidatorBondFactor = sdk.Dec(sdk.NewInt(250))
params.GlobalLiquidStakingCap = sdk.Dec(sdk.NewInt(25).Quo(sdk.NewInt(100)))
params.ValidatorLiquidStakingCap = sdk.Dec(sdk.NewInt(50).Quo(sdk.NewInt(100)))

k.SetParams(ctx, params)
}

// Set each validator's TotalValidatorBondShares and TotalLiquidShares to 0
func SetAllValidatorBondAndLiquidSharesToZero(ctx sdk.Context, k stakingkeeper.Keeper) {

for _, Val := range k.GetAllValidators(ctx) {

Val.TotalValidatorBondShares = sdk.ZeroDec()
Val.TotalLiquidShares = sdk.ZeroDec()

k.SetValidator(ctx, Val)
}
}

// Set each validator's ValidatorBond to false
func SetAllDelegationValidatorBondsFalse(ctx sdk.Context, k stakingkeeper.Keeper) {
for _, Del := range k.GetAllDelegations(ctx) {

Del.ValidatorBond = false

k.SetDelegation(ctx, Del)
}
}
97 changes: 97 additions & 0 deletions x/staking/legacy/v045/migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package v11

import (
"testing"

"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

// Test setting params in the staking module
func TestSetParamsStaking(t *testing.T) {

app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

// set the params in the staking store; exclude the new v11 params
params := app.StakingKeeper.GetParams(ctx)
preUpgradeParams := stakingtypes.Params{
UnbondingTime: params.UnbondingTime,
MaxValidators: params.MaxValidators,
MaxEntries: params.MaxEntries,
HistoricalEntries: params.HistoricalEntries,
BondDenom: params.BondDenom,
}
app.StakingKeeper.SetParams(ctx, preUpgradeParams)

SetParamsStaking(ctx, app.StakingKeeper)

// check that the params were set correctly
params = app.StakingKeeper.GetParams(ctx)
require.Equal(t, sdk.NewDec(250), params.ValidatorBondFactor)
require.Equal(t, sdk.NewDec(25).Quo(sdk.NewDec(100)), params.GlobalLiquidStakingCap)
require.Equal(t, sdk.NewDec(50).Quo(sdk.NewDec(100)), params.ValidatorLiquidStakingCap)
}

// Test setting each validator's TotalValidatorBondShares and TotalLiquidShares to 0
func TestSetAllValidatorBondAndLiquidSharesToZero(t *testing.T) {

app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

for _, Val := range app.StakingKeeper.GetAllValidators(ctx) {

// set the validator attributes on each val; exclude the new v11 attributes
preUpgradeValidator := stakingtypes.Validator{
OperatorAddress: Val.OperatorAddress,
ConsensusPubkey: Val.ConsensusPubkey,
Jailed: Val.Jailed,
Status: Val.Status,
Tokens: Val.Tokens,
DelegatorShares: Val.DelegatorShares,
Description: Val.Description,
UnbondingHeight: Val.UnbondingHeight,
MinSelfDelegation: Val.MinSelfDelegation,
Commission: Val.Commission,
UnbondingTime: Val.UnbondingTime,
}
app.StakingKeeper.SetValidator(ctx, preUpgradeValidator)
}

SetAllValidatorBondAndLiquidSharesToZero(ctx, app.StakingKeeper)

// check that the validator TotalValidatorBondShares and TotalLiquidShares were correctly set to 0
for _, Val := range app.StakingKeeper.GetAllValidators(ctx) {
require.Equal(t, sdk.ZeroDec(), Val.TotalValidatorBondShares)
require.Equal(t, sdk.ZeroDec(), Val.TotalLiquidShares)
}
}

// Test setting each validator's TotalDelegatorBondShares to 0
func TestSetAllDelegatorBondSharesToZero(t *testing.T) {

app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

for _, Del := range app.StakingKeeper.GetAllDelegations(ctx) {

// set the delegation attributes on each del; exclude the new v11 attributes
preUpgradeDelegation := stakingtypes.Delegation{
DelegatorAddress: Del.DelegatorAddress,
ValidatorAddress: Del.ValidatorAddress,
Shares: Del.Shares,
}
app.StakingKeeper.SetDelegation(ctx, preUpgradeDelegation)
}

SetAllDelegationValidatorBondsFalse(ctx, app.StakingKeeper)

// check that the delegation ValidatorBond was correctly set to false
for _, Del := range app.StakingKeeper.GetAllDelegations(ctx) {
require.Equal(t, false, Del.ValidatorBond)
}

}