Skip to content

Commit

Permalink
chore: use json format for migration proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
mbreithecker committed Dec 23, 2024
1 parent 1c80ec6 commit d34f50b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 59 deletions.
15 changes: 8 additions & 7 deletions app/upgrades/v2_0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 {
Expand All @@ -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,
) {
Expand All @@ -77,20 +79,19 @@ 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)
for _, delegator := range delegationKeeper.GetAllDelegators(ctx) {
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) {
Expand Down
31 changes: 31 additions & 0 deletions app/upgrades/v2_0/validator-proofs/Readme.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
94 changes: 42 additions & 52 deletions app/upgrades/v2_0/validator_mapping.go
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d34f50b

Please sign in to comment.