From d34f50bc6c27e51fd2087a67b1354f9fe84a6e22 Mon Sep 17 00:00:00 2001 From: mbreithecker Date: Mon, 23 Dec 2024 17:19:43 +0100 Subject: [PATCH] chore: use json format for migration proofs --- app/upgrades/v2_0/upgrade.go | 15 +-- app/upgrades/v2_0/validator-proofs/Readme.md | 31 ++++++ .../kaon/example-validator.json | 7 ++ .../mainnet/example-validator.json | 7 ++ app/upgrades/v2_0/validator_mapping.go | 94 +++++++++---------- 5 files changed, 95 insertions(+), 59 deletions(-) create mode 100644 app/upgrades/v2_0/validator-proofs/Readme.md create mode 100644 app/upgrades/v2_0/validator-proofs/kaon/example-validator.json create mode 100644 app/upgrades/v2_0/validator-proofs/mainnet/example-validator.json diff --git a/app/upgrades/v2_0/upgrade.go b/app/upgrades/v2_0/upgrade.go index 2b2b1a18..2cd5346e 100644 --- a/app/upgrades/v2_0/upgrade.go +++ b/app/upgrades/v2_0/upgrade.go @@ -9,7 +9,7 @@ import ( delegationkeeper "github.com/KYVENetwork/chain/x/delegation/keeper" globalTypes "github.com/KYVENetwork/chain/x/global/types" - stakersKeeper "github.com/KYVENetwork/chain/x/stakers/keeper" + stakerskeeper "github.com/KYVENetwork/chain/x/stakers/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -30,7 +30,7 @@ func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, delegationKeeper delegationkeeper.Keeper, - stakersKeeper *stakersKeeper.Keeper, + stakersKeeper *stakerskeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, bankKeeper bankkeeper.Keeper, ) upgradetypes.UpgradeHandler { @@ -45,12 +45,14 @@ func CreateUpgradeHandler( // Run KYVE migrations migrateProtocolStakers(sdkCtx, delegationKeeper, stakersKeeper, stakingKeeper, bankKeeper) + logger.Info(fmt.Sprintf("finished upgrade %v", UpgradeName)) + return migratedVersionMap, err } } func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.Keeper, - stakersKeeper *stakersKeeper.Keeper, + stakersKeeper *stakerskeeper.Keeper, stakingKeeper *stakingkeeper.Keeper, bankKeeper bankkeeper.Keeper, ) { @@ -77,12 +79,11 @@ func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.K sdk.NewInt64Coin(globalTypes.Denom, int64(amount)), )) if err != nil { - // TODO how to handle - return + panic(err) } } } - logger.Info("migrated %d ukyve from protocol to chain", totalMigratedStake) + logger.Info(fmt.Sprintf("migrated %d ukyve from protocol to chain", totalMigratedStake)) // Undelegate Remaining totalReturnedStake := uint64(0) @@ -90,7 +91,7 @@ func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.K amount := delegationKeeper.PerformFullUndelegation(ctx, delegator.Staker, delegator.Delegator) totalReturnedStake += amount } - logger.Info("returned %d ukyve from protocol to users", totalReturnedStake) + logger.Info(fmt.Sprintf("returned %d ukyve from protocol to users", totalReturnedStake)) // Withdraw Pending Commissions for _, staker := range stakersKeeper.GetAllLegacyStakers(ctx) { diff --git a/app/upgrades/v2_0/validator-proofs/Readme.md b/app/upgrades/v2_0/validator-proofs/Readme.md new file mode 100644 index 00000000..a896070f --- /dev/null +++ b/app/upgrades/v2_0/validator-proofs/Readme.md @@ -0,0 +1,31 @@ +## Protocol-Consensus Validator Linking + +For the Shared Staking update [https://www.mintscan.io/kyve/proposals/43](https://www.mintscan.io/kyve/proposals/43) +it is necessary that every validator links their protocol and consensus validator. + +All delegators are then transferred from the protocol validator to the consensus +validator during the upgrade. + +If a protocol validator does not link to a chain validator before the upgrade is finalized, +all stake is returned to the original delegators during the migration. + +### Steps + +1. Enter the `mainnet`-directory and copy the `example-validator.json` config file and name it after your validator. + +2. Fill out the `name`, `protocol_address` and `consensus_address` + +3. Send 1 $KYVE from the protocol-address to the consensus-validator-operator address using the memo "Shared-Staking" + and put the tx-hash in proof_1. + +4. Send 1 $KYVE from the consensus-validator-operator address to the protocol address using the memo "Shared-Staking" + and put the tx-hash in proof_2. + +5. Submit a Pull-Request to https://github.com/KYVENetwork/chain + +6. (Optional) Perform the same steps for the `kaon` directory with your Kaon validators. + +## Questions + +If you have any questions feel free to submit an issue or ask them directly while +creating the pull-request. diff --git a/app/upgrades/v2_0/validator-proofs/kaon/example-validator.json b/app/upgrades/v2_0/validator-proofs/kaon/example-validator.json new file mode 100644 index 00000000..7a533ce9 --- /dev/null +++ b/app/upgrades/v2_0/validator-proofs/kaon/example-validator.json @@ -0,0 +1,7 @@ +{ + "name": "My example Kaon validator name - this is just for human-readability", + "consensus_address": "kyvevaloper...", + "protocol_address": "kyve...", + "proof_1": "89644D8598D007F7B744E91BA4490C11513860046C257F29CFAF41EAE37FAE9C", + "proof_2": "36A1110532EC28C4BEDA610720CA31DD1B14D4A49772F8890EB5C62B417D253B" +} \ No newline at end of file diff --git a/app/upgrades/v2_0/validator-proofs/mainnet/example-validator.json b/app/upgrades/v2_0/validator-proofs/mainnet/example-validator.json new file mode 100644 index 00000000..6d2d84ce --- /dev/null +++ b/app/upgrades/v2_0/validator-proofs/mainnet/example-validator.json @@ -0,0 +1,7 @@ +{ + "name": "My example validator name - this is just for human-readability", + "consensus_address": "kyvevaloper...", + "protocol_address": "kyve...", + "proof_1": "EEA08DDDA94434BBE1FA25AB941B58D85FC5EE48E866B602549CA194CAB41B11", + "proof_2": "21771F8B4B2F72D0F292F3517051FD6D8CAA5BB9EC83B906F2BF38684F1E624E" +} \ No newline at end of file diff --git a/app/upgrades/v2_0/validator_mapping.go b/app/upgrades/v2_0/validator_mapping.go index fdab3ef2..9691ddd3 100644 --- a/app/upgrades/v2_0/validator_mapping.go +++ b/app/upgrades/v2_0/validator_mapping.go @@ -1,59 +1,49 @@ 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 - -*/ +import ( + "embed" + "encoding/json" + "fmt" +) + +//go:embed validator-proofs/* +var validatorProofs embed.FS + +func init() { + parseDirectory := func(directory string) []ValidatorMapping { + dir, err := validatorProofs.ReadDir(directory) + if err != nil { + panic(err) + } + + result := make([]ValidatorMapping, 0) + for _, file := range dir { + readFile, err := validatorProofs.ReadFile(fmt.Sprintf("%s/%s", directory, file.Name())) + if err != nil { + panic(err) + } + + var proof ValidatorMapping + if err = json.Unmarshal(readFile, &proof); err != nil { + panic(err) + } + result = append(result, proof) + } + return result + } + + ValidatorMappingsMainnet = parseDirectory("validator-proofs/mainnet") + ValidatorMappingsKaon = parseDirectory("validator-proofs/kaon") +} type ValidatorMapping struct { - Name string - ConsensusAddress string - ProtocolAddress string - Proof1 string - Proof2 string + Name string `json:"name"` + ConsensusAddress string `json:"consensus_address"` + ProtocolAddress string `json:"protocol_address"` + Proof1 string `json:"proof_1"` + Proof2 string `json:"proof_2"` } -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 ValidatorMappingsMainnet []ValidatorMapping -var ValidatorMappingsKaon = []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 ValidatorMappingsKaon []ValidatorMapping