From aa3cf667071c32a80cd7f9b7ae21eacea5343b87 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Mon, 22 Feb 2021 14:15:10 -0700 Subject: [PATCH] add validator vesting migrations (#845) --- migrate/v0_13/migrate.go | 23 +++++++++++++++++++++-- migrate/v0_13/migrate_test.go | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/migrate/v0_13/migrate.go b/migrate/v0_13/migrate.go index 4a01e737..048974e5 100644 --- a/migrate/v0_13/migrate.go +++ b/migrate/v0_13/migrate.go @@ -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) } diff --git a/migrate/v0_13/migrate_test.go b/migrate/v0_13/migrate_test.go index eda58a07..8ff05d1a 100644 --- a/migrate/v0_13/migrate_test.go +++ b/migrate/v0_13/migrate_test.go @@ -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)