add validator vesting migrations (#845)

This commit is contained in:
Kevin Davis 2021-02-22 14:15:10 -07:00 committed by GitHub
parent 0865e40553
commit aa3cf66707
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -19,10 +19,11 @@ import (
v0_13incentive "github.com/kava-labs/kava/x/incentive"
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
"github.com/kava-labs/kava/x/kavadist"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
)
var (
GenesisTime = time.Date(2021, 3, 4, 14, 0, 0, 0, time.UTC)
GenesisTime = time.Date(2021, 3, 4, 15, 0, 0, 0, time.UTC)
RewardEndTime = time.Date(2022, 2, 25, 14, 0, 0, 0, time.UTC)
ClaimEndTime = time.Date(2026, 2, 25, 14, 0, 0, 0, time.UTC)
)
@ -309,6 +310,15 @@ func Incentive(hardGS v0_11hard.GenesisState, incentiveGS v0_11incentive.Genesis
// Auth migrates from a v0.11 auth genesis state to a v0.13
func Auth(genesisState auth.GenesisState) auth.GenesisState {
validatorVestingChangeAddress, err := sdk.AccAddressFromBech32("kava1a3qmze57knfj29a5knqs5ptewh76v4fg23xsvn")
if err != nil {
panic(err)
}
validatorVestingUpdatedValAddress, err := sdk.ConsAddressFromBech32("kavavalcons1ucxhn6zh7y2zun49m36psjffrhmux7ukqxdcte")
if err != nil {
panic(err)
}
savingsRateMaccCoins := sdk.NewCoins()
savingsMaccAddr := supply.NewModuleAddress(v0_11cdp.SavingsRateMacc)
savingsRateMaccIndex := 0
@ -329,6 +339,15 @@ func Auth(genesisState auth.GenesisState) auth.GenesisState {
kavaDistIdx := 0
for idx, acc := range genesisState.Accounts {
// reset validator vesting missed blocks to zero (due to ongoing network issues in kava-4)
vvacc, ok := acc.(*validatorvesting.ValidatorVestingAccount)
if ok {
vvacc.CurrentPeriodProgress.MissedBlocks = 0
if vvacc.GetAddress().Equals(validatorVestingChangeAddress) {
// update validator vesting validator address for shiprekt
vvacc.ValidatorAddress = validatorVestingUpdatedValAddress
}
}
if acc.GetAddress().Equals(savingsMaccAddr) {
savingsRateMaccCoins = acc.GetCoins()
savingsRateMaccIndex = idx
@ -358,7 +377,7 @@ func Auth(genesisState auth.GenesisState) auth.GenesisState {
}
// move remaining cdp savings to liquidator account
liquidatorAcc := genesisState.Accounts[liquidatorMaccIndex]
err := liquidatorAcc.SetCoins(liquidatorAcc.GetCoins().Add(savingsRateMaccCoins...))
err = liquidatorAcc.SetCoins(liquidatorAcc.GetCoins().Add(savingsRateMaccCoins...))
if err != nil {
panic(err)
}

View File

@ -22,6 +22,7 @@ import (
v0_11hard "github.com/kava-labs/kava/x/hard/legacy/v0_11"
v0_13incentive "github.com/kava-labs/kava/x/incentive"
v0_11incentive "github.com/kava-labs/kava/x/incentive/legacy/v0_11"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
"github.com/stretchr/testify/require"
)
@ -55,6 +56,14 @@ func TestCDP(t *testing.T) {
}
func TestAuth(t *testing.T) {
validatorVestingChangeAddress, err := sdk.AccAddressFromBech32("kava1a3qmze57knfj29a5knqs5ptewh76v4fg23xsvn")
if err != nil {
panic(err)
}
validatorVestingUpdatedValAddress, err := sdk.ConsAddressFromBech32("kavavalcons1ucxhn6zh7y2zun49m36psjffrhmux7ukqxdcte")
if err != nil {
panic(err)
}
bz, err := ioutil.ReadFile(filepath.Join("testdata", "kava-4-auth-state-block-500000.json"))
require.NoError(t, err)
var oldGenState auth.GenesisState
@ -65,6 +74,13 @@ func TestAuth(t *testing.T) {
harvestCoins := getModuleAccount(oldGenState.Accounts, "harvest").GetCoins()
newGenState := Auth(oldGenState)
for _, acc := range newGenState.Accounts {
if acc.GetAddress().Equals(validatorVestingChangeAddress) {
vacc := acc.(*validatorvesting.ValidatorVestingAccount)
require.Equal(t, int64(0), vacc.CurrentPeriodProgress.MissedBlocks)
require.Equal(t, validatorVestingUpdatedValAddress, vacc.ValidatorAddress)
}
}
err = auth.ValidateGenesis(newGenState)
require.NoError(t, err)