diff --git a/app/upgrades/v2_0/upgrade.go b/app/upgrades/v2_0/upgrade.go index c910fc64..2b2b1a18 100644 --- a/app/upgrades/v2_0/upgrade.go +++ b/app/upgrades/v2_0/upgrade.go @@ -45,8 +45,6 @@ func CreateUpgradeHandler( // Run KYVE migrations migrateProtocolStakers(sdkCtx, delegationKeeper, stakersKeeper, stakingKeeper, bankKeeper) - // TODO: migrate slash params, commission change queues - return migratedVersionMap, err } } @@ -59,9 +57,13 @@ func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.K // Process current unbonding queue delegationKeeper.FullyProcessDelegatorUnbondingQueue(ctx) + validatorMapping := ValidatorMappingsMainnet + if ctx.ChainID() == "kaon-1" { + validatorMapping = ValidatorMappingsKaon + } + totalMigratedStake := uint64(0) - for _, mapping := range ValidatorMappings { - // TODO check if staker exists + for _, mapping := range validatorMapping { delegators := delegationKeeper.GetDelegatorsByStaker(ctx, mapping.ProtocolAddress) for _, delegator := range delegators { @@ -101,5 +103,16 @@ func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.K }) } - // TODO delete staker object + // Delete all legacy stakers objects + stakersKeeper.Migration_ResetOldState(ctx) + + // Migrate Params + delegationParams := delegationKeeper.GetParams(ctx) + stakersParams := stakersKeeper.GetParams(ctx) + + stakersParams.TimeoutSlash = delegationParams.TimeoutSlash + stakersParams.UploadSlash = delegationParams.UploadSlash + stakersParams.VoteSlash = delegationParams.VoteSlash + + stakersKeeper.SetParams(ctx, stakersParams) } diff --git a/app/upgrades/v2_0/validator_mapping.go b/app/upgrades/v2_0/validator_mapping.go index 49cc1118..fdab3ef2 100644 --- a/app/upgrades/v2_0/validator_mapping.go +++ b/app/upgrades/v2_0/validator_mapping.go @@ -1,15 +1,59 @@ package v2_0 +/* + +Protocol-Consensus Validator Linking: + +1. Fill out the entry below following the example. + +2. Send 1$KYVE from the protocol-address to the consensus-validator-operator address using the memo "Shared-Staking" + and put the tx-hash in Proof1. + +3. Send 1$KYVE from the consensus-validator-operator address to the protocol address using the memo "Shared-Staking" + and put the tx-hash in Proof2. + +4. Submit a Pull-Request to https://github.com/KYVENetwork/chain + +*/ + type ValidatorMapping struct { Name string ConsensusAddress string ProtocolAddress string + Proof1 string + Proof2 string +} + +var ValidatorMappingsMainnet = []ValidatorMapping{ + { + // human-readable name, only used for logging + Name: "", + // kyvevaloper... address of the chain node + ConsensusAddress: "", + // kyve... address of the protocol node + ProtocolAddress: "", + // Proof TX-Hash 1, transferring 1 $KYVE from the protocol-address to the operator address + // using "Shared Staking" as memo. + Proof1: "", + // Proof TX-Hash 2, transferring 1 $KYVE from the operator address to the protocol-address + // using "Shared Staking" as memo. + Proof2: "", + }, } -var ValidatorMappings = []ValidatorMapping{ +var ValidatorMappingsKaon = []ValidatorMapping{ { - Name: "", + // human-readable name, only used for logging + Name: "", + // kyvevaloper... address of the chain node ConsensusAddress: "", - ProtocolAddress: "", + // kyve... address of the protocol node + ProtocolAddress: "", + // Proof TX-Hash 1, transferring 1 $KYVE from the protocol-address to the operator address + // using "Shared Staking" as memo. + Proof1: "", + // Proof TX-Hash 2, transferring 1 $KYVE from the operator address to the protocol-address + // using "Shared Staking" as memo. + Proof2: "", }, } diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index 7a8585f5..d6134c86 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -287,7 +287,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) // calculate voter slashes - fraction := s.App().DelegationKeeper.GetVoteSlash(s.Ctx()) + fraction := s.App().StakersKeeper.GetVoteSlash(s.Ctx()) slashAmountVoter := uint64(math.LegacyNewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(Equal(0*i.KYVE - slashAmountVoter)) @@ -615,7 +615,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // calculate uploader slashes - fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) + fraction := s.App().StakersKeeper.GetUploadSlash(s.Ctx()) slashAmount := uint64(math.LegacyNewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) Expect(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(0*i.KYVE - slashAmount)) @@ -753,7 +753,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(valaccountActive).To(BeFalse()) // check if voter got slashed - slashAmountRatio := s.App().DelegationKeeper.GetTimeoutSlash(s.Ctx()) + slashAmountRatio := s.App().StakersKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 0*i.KYVE - uint64(math.LegacyNewDec(int64(0*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) Expect(expectedBalance).To(Equal(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) diff --git a/x/delegation/genesis.go b/x/delegation/genesis.go index 31a78091..ad77f6ee 100644 --- a/x/delegation/genesis.go +++ b/x/delegation/genesis.go @@ -9,7 +9,6 @@ import ( // InitGenesis initializes the capability module's state from a provided genesis // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { - } // ExportGenesis returns the capability module's exported genesis. diff --git a/x/stakers/keeper/migration.go b/x/stakers/keeper/migration.go new file mode 100644 index 00000000..39b119fb --- /dev/null +++ b/x/stakers/keeper/migration.go @@ -0,0 +1,56 @@ +package keeper + +import ( + "cosmossdk.io/store/prefix" + storeTypes "cosmossdk.io/store/types" + "github.com/KYVENetwork/chain/x/stakers/types" + "github.com/cosmos/cosmos-sdk/runtime" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) migration_RemoveBranch(ctx sdk.Context, keyPrefix []byte) { + storeAdapter := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx)) + store := prefix.NewStore(storeAdapter, keyPrefix) + iterator := storeTypes.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + keys := make([][]byte, 0) + for ; iterator.Valid(); iterator.Next() { + keys = append(keys, iterator.Key()) + } + + for _, key := range keys { + store.Delete(key) + } +} + +func (k Keeper) Migration_ResetOldState(ctx sdk.Context) { + k.migration_RemoveBranch(ctx, types.StakerKeyPrefix) + + k.migration_RemoveBranch(ctx, types.ValaccountPrefix) + k.migration_RemoveBranch(ctx, types.ValaccountPrefixIndex2) + + k.migration_RemoveBranch(ctx, types.CommissionChangeEntryKeyPrefix) + k.migration_RemoveBranch(ctx, types.CommissionChangeEntryKeyPrefixIndex2) + + k.migration_RemoveBranch(ctx, types.LeavePoolEntryKeyPrefix) + k.migration_RemoveBranch(ctx, types.LeavePoolEntryKeyPrefixIndex2) + + k.migration_RemoveBranch(ctx, types.ActiveStakerIndex) + + k.SetQueueState(ctx, types.QUEUE_IDENTIFIER_COMMISSION, types.QueueState{ + LowIndex: 0, + HighIndex: 0, + }) + + k.SetQueueState(ctx, types.QUEUE_IDENTIFIER_LEAVE, types.QueueState{ + LowIndex: 0, + HighIndex: 0, + }) + + k.SetQueueState(ctx, types.QUEUE_IDENTIFIER_STAKE_FRACTION, types.QueueState{ + LowIndex: 0, + HighIndex: 0, + }) +} diff --git a/x/stakers/types/keys.go b/x/stakers/types/keys.go index 6607fef1..cc4279a7 100644 --- a/x/stakers/types/keys.go +++ b/x/stakers/types/keys.go @@ -1,7 +1,6 @@ package types import ( - "cosmossdk.io/math" "github.com/KYVENetwork/chain/util" ) @@ -68,8 +67,6 @@ var ( const MaxStakers = 50 -var DefaultCommission = math.LegacyMustNewDecFromStr("0.1") - // StakerKey returns the store Key to retrieve a Staker from the index fields func StakerKey(staker string) []byte { return util.GetByteKey(staker)