Skip to content

Commit

Permalink
chore: prepare v2 upgrade (#245)
Browse files Browse the repository at this point in the history
Co-authored-by: Troy Kessler <[email protected]>
  • Loading branch information
mbreithecker and troykessler authored Feb 18, 2025
1 parent 82e8799 commit 279189c
Show file tree
Hide file tree
Showing 19 changed files with 539 additions and 233 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ An '!' indicates a state machine breaking change.

### Features

- ! (`x/bundles`) [#236](https://github.com/KYVENetwork/chain/pull/236) merkle_root bundles migration
- ! (`x/stakers`) [#209](https://github.com/KYVENetwork/chain/pull/209) Shared Staking: Consensus-validator stake is now used for the protocol.
- ! (`x/stakers`) [#210](https://github.com/KYVENetwork/chain/pull/210) Shared Staking: Pool specific commission and stake fraction.
- ! (`x/stakers`) [#211](https://github.com/KYVENetwork/chain/pull/211) Shared Staking: Maximum voting power per pool.

### Improvements

- (`x/stakers`) [#232](https://github.com/KYVENetwork/chain/pull/232) Shared Staking: Update stakers queries
- (deps) [#213](https://github.com/KYVENetwork/chain/pull/213) Bump to CosmosSDK v0.50.11 and cleanup deps.
- (deps) [#246](https://github.com/KYVENetwork/chain/pull/246) Bump stakers module version from v1beta1 to v1

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ COMMIT := $(shell git log -1 --format='%H')
GO_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1,2)

# VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
VERSION := v1.5.0
VERSION := v2.0.0

BUILD_TIME := 202407040800.00 # format [[CC]YY]MMDDhhmm[.ss]
BUILD_TIME := 202502100800.00 # format [[CC]YY]MMDDhhmm[.ss]

TEAM_ALLOCATION := 165000000000000
ifeq ($(ENV),kaon)
Expand All @@ -30,7 +30,8 @@ ldflags += -X github.com/cosmos/cosmos-sdk/version.Name=kyve \
-X github.com/KYVENetwork/chain/x/team/types.TEAM_FOUNDATION_STRING=$(TEAM_FOUNDATION_ADDRESS) \
-X github.com/KYVENetwork/chain/x/team/types.TEAM_BCP_STRING=$(TEAM_BCP_ADDRESS) \
-X github.com/KYVENetwork/chain/x/team/types.TEAM_ALLOCATION_STRING=$(TEAM_ALLOCATION) \
-X github.com/KYVENetwork/chain/x/team/types.TGE_STRING=$(TEAM_TGE)
-X github.com/KYVENetwork/chain/x/team/types.TGE_STRING=$(TEAM_TGE) \
-w -s
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -ldflags '$(ldflags)' -tags 'ledger' -trimpath -buildvcs=false
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
| Version | Supported |
|---------|--------------------|
| main | :white_check_mark: |
| v1.4.x | :white_check_mark: |
| < v1.4 | :x: |
| v1.5.x | :white_check_mark: |
| < v1.5 | :x: |

## Reporting a Vulnerability

Expand Down
5 changes: 4 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ import (
bundleskeeper "github.com/KYVENetwork/chain/x/bundles/keeper"
_ "github.com/KYVENetwork/chain/x/delegation" // import for side-effects
delegationkeeper "github.com/KYVENetwork/chain/x/delegation/keeper"
_ "github.com/KYVENetwork/chain/x/funders" // import for side-effects
_ "github.com/KYVENetwork/chain/x/delegation/types" // import for side-effects
_ "github.com/KYVENetwork/chain/x/funders" // import for side-effects
funderskeeper "github.com/KYVENetwork/chain/x/funders/keeper"
_ "github.com/KYVENetwork/chain/x/global" // import for side-effects
globalkeeper "github.com/KYVENetwork/chain/x/global/keeper"
Expand Down Expand Up @@ -416,7 +417,9 @@ func New(
app.StakingKeeper,
app.BankKeeper,
app.BundlesKeeper,
app.GlobalKeeper,
app.MultiCoinRewardsKeeper,
app.PoolKeeper,
app.DistributionKeeper,
),
)
Expand Down
235 changes: 224 additions & 11 deletions app/upgrades/v2_0/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"context"
"fmt"

poolTypes "github.com/KYVENetwork/chain/x/pool/types"

poolkeeper "github.com/KYVENetwork/chain/x/pool/keeper"

multicoinrewardskeeper "github.com/KYVENetwork/chain/x/multi_coin_rewards/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"

Expand All @@ -14,6 +18,10 @@ import (

bundleskeeper "github.com/KYVENetwork/chain/x/bundles/keeper"

"cosmossdk.io/math"

globalkeeper "github.com/KYVENetwork/chain/x/global/keeper"

"github.com/KYVENetwork/chain/x/stakers/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

Expand Down Expand Up @@ -45,7 +53,9 @@ func CreateUpgradeHandler(
stakingKeeper *stakingkeeper.Keeper,
bankKeeper bankkeeper.Keeper,
bundlesKeeper bundleskeeper.Keeper,
globalKeeper globalkeeper.Keeper,
multiCoinRewardsKeeper multicoinrewardskeeper.Keeper,
poolKeeper *poolkeeper.Keeper,
distrKeeper *distrkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
Expand All @@ -58,12 +68,20 @@ func CreateUpgradeHandler(

// Run KYVE migrations
migrateProtocolStakers(sdkCtx, delegationKeeper, stakersKeeper, stakingKeeper, bankKeeper)
EnsureMultiCoinDistributionAccount(sdkCtx, accountKeeper)
EnsureMultiCoinDistributionAccount(sdkCtx, accountKeeper, multicoinrewardstypes.ModuleName)
EnsureMultiCoinDistributionAccount(sdkCtx, accountKeeper, multicoinrewardstypes.MultiCoinRewardsRedistributionAccountName)
AdjustGasConfig(sdkCtx, globalKeeper)

SetMultiCoinRewardsParams(sdkCtx, multiCoinRewardsKeeper)
if err := SetMultiCoinRewardsPolicy(sdkCtx, multiCoinRewardsKeeper); err != nil {
return migratedVersionMap, err
}

// TODO add new stakers types to gas refunds
SetPoolParams(sdkCtx, poolKeeper)

// Run Bundles Merkle Roots migrations
bundlesKeeper.SetBundlesMigrationUpgradeHeight(sdkCtx, uint64(sdkCtx.BlockHeight()))
UpgradeRuntimes(sdkCtx, poolKeeper)

// Set MultiCoinRewards and Withdraw address for the KYVE Foundation
if sdkCtx.ChainID() == "kyve-1" {
Expand Down Expand Up @@ -107,21 +125,150 @@ func SetWithdrawAddressAndMultiCoinRewards(
}
}

func EnsureMultiCoinDistributionAccount(ctx sdk.Context, ak authkeeper.AccountKeeper) {
address := authTypes.NewModuleAddress(multicoinrewardstypes.MultiCoinRewardsRedistributionAccountName)
func SetMultiCoinRewardsParams(ctx sdk.Context, multiCoinRewardsKeeper multicoinrewardskeeper.Keeper) {
params := multiCoinRewardsKeeper.GetParams(ctx)

if ctx.ChainID() == "kyve-1" {
params.MultiCoinDistributionPendingTime = 60 * 60 * 24 * 14
// KYVE Public Good Funding address
params.MultiCoinDistributionPolicyAdminAddress = "kyve1t0uez3nn28ljnzlwndzxffyjuhean3edhtjee8"
} else if ctx.ChainID() == "kaon-1" {
params.MultiCoinDistributionPendingTime = 60 * 60 * 24
// Kaon Ecosystem
params.MultiCoinDistributionPolicyAdminAddress = "kyve1z67jal9d9unjvmzsadps9jytzt9kx2m2vgc3wm"
} else if ctx.ChainID() == "korellia-2" {
params.MultiCoinDistributionPendingTime = 600
// Korellia Ecosystem
params.MultiCoinDistributionPolicyAdminAddress = "kyve1ygtqlzxhvp3t0wwcjd5lmq4zxl0qcck9g3mmgp"
}

multiCoinRewardsKeeper.SetParams(ctx, params)
}

func SetMultiCoinRewardsPolicy(ctx sdk.Context, multiCoinRewardsKeeper multicoinrewardskeeper.Keeper) error {
if ctx.ChainID() == "kyve-1" {
return multiCoinRewardsKeeper.MultiCoinDistributionPolicy.Set(ctx, multicoinrewardstypes.MultiCoinDistributionPolicy{
Entries: []*multicoinrewardstypes.MultiCoinDistributionDenomEntry{
{
Denom: "ibc/A59C9E368C043E72968615DE82D4AD4BC88E34E6F353262B6769781C07390E8A", // andromeda
PoolWeights: []*multicoinrewardstypes.MultiCoinDistributionPoolWeightEntry{
{
PoolId: 14,
Weight: math.LegacyMustNewDecFromStr("1"),
},
},
},
{
Denom: "ibc/F4E5517A3BA2E77906A0847014EBD39E010E28BEB4181378278144D22442DB91", // source
PoolWeights: []*multicoinrewardstypes.MultiCoinDistributionPoolWeightEntry{
{
PoolId: 11,
Weight: math.LegacyMustNewDecFromStr("1"),
},
{
PoolId: 12,
Weight: math.LegacyMustNewDecFromStr("1"),
},
},
},
{
Denom: "ibc/D0C5DCA29836D2FD5937714B21206DD8243E5E76B1D0F180741CCB43DCAC1584", // dydx
PoolWeights: []*multicoinrewardstypes.MultiCoinDistributionPoolWeightEntry{
{
PoolId: 13,
Weight: math.LegacyMustNewDecFromStr("1"),
},
},
},
{
Denom: "ibc/506478E08FB0A2D3B12D493E3B182572A3B0D7BD5DCBE71610D2F393DEDDF4CA", // xion
PoolWeights: []*multicoinrewardstypes.MultiCoinDistributionPoolWeightEntry{
{
PoolId: 16,
Weight: math.LegacyMustNewDecFromStr("1"),
},
{
PoolId: 17,
Weight: math.LegacyMustNewDecFromStr("1"),
},
},
},
{
Denom: "ibc/7D5A9AE91948931279BA58A04FBEB9BF4F7CA059F7D4BDFAC6C3C43705973E1E", // lava
PoolWeights: []*multicoinrewardstypes.MultiCoinDistributionPoolWeightEntry{
{
PoolId: 18,
Weight: math.LegacyMustNewDecFromStr("1"),
},
},
},
},
})
}

return multiCoinRewardsKeeper.MultiCoinDistributionPolicy.Set(ctx, multicoinrewardstypes.MultiCoinDistributionPolicy{
Entries: []*multicoinrewardstypes.MultiCoinDistributionDenomEntry{},
})
}

func SetPoolParams(ctx sdk.Context, poolKeeper *poolkeeper.Keeper) {
params := poolKeeper.GetParams(ctx)

if ctx.ChainID() == "kyve-1" {
params.ProtocolInflationShare = math.LegacyMustNewDecFromStr("0.4")
}

poolKeeper.SetParams(ctx, params)
}

func AdjustGasConfig(ctx sdk.Context, globalKeeper globalkeeper.Keeper) {
params := globalKeeper.GetParams(ctx)
params.MinGasPrice = math.LegacyMustNewDecFromStr("2")
params.GasAdjustments = []globalTypes.GasAdjustment{
{
Type: "/cosmos.staking.v1beta1.MsgCreateValidator",
Amount: 50000000,
},
{
Type: "/kyve.funders.v1beta1.MsgCreateFunder",
Amount: 50000000,
},
}
params.GasRefunds = []globalTypes.GasRefund{
{
Type: "/kyve.bundles.v1beta1.MsgSubmitBundleProposal",
Fraction: math.LegacyMustNewDecFromStr("0.99"),
},
{
Type: "/kyve.bundles.v1beta1.MsgVoteBundleProposal",
Fraction: math.LegacyMustNewDecFromStr("0.99"),
},
{
Type: "/kyve.bundles.v1beta1.MsgSkipUploaderRole",
Fraction: math.LegacyMustNewDecFromStr("0.99"),
},
{
Type: "/kyve.bundles.v1beta1.MsgClaimUploaderRole",
Fraction: math.LegacyMustNewDecFromStr("0.99"),
},
}
globalKeeper.SetParams(ctx, params)
}

func EnsureMultiCoinDistributionAccount(ctx sdk.Context, ak authkeeper.AccountKeeper, name string) {
address := authTypes.NewModuleAddress(name)
account := ak.GetAccount(ctx, address)

if account == nil {
// account doesn't exist, initialise a new module account.
newAcc := authTypes.NewEmptyModuleAccount(multicoinrewardstypes.MultiCoinRewardsRedistributionAccountName)
account = ak.NewAccountWithAddress(ctx, newAcc.GetAddress())
account = authTypes.NewEmptyModuleAccount(name)
ak.NewAccount(ctx, account)
} else {
// account exists, adjust it to a module account.
baseAccount := authTypes.NewBaseAccount(address, nil, account.GetAccountNumber(), 0)
account = authTypes.NewModuleAccount(baseAccount, multicoinrewardstypes.MultiCoinRewardsRedistributionAccountName)
account = authTypes.NewModuleAccount(baseAccount, name)
ak.SetAccount(ctx, account)
}

ak.SetAccount(ctx, account)
}

func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.Keeper,
Expand All @@ -132,9 +279,13 @@ func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.K
// Process current unbonding queue
delegationKeeper.FullyProcessDelegatorUnbondingQueue(ctx)

validatorMapping := ValidatorMappingsMainnet
if ctx.ChainID() == "kaon-1" {
var validatorMapping []ValidatorMapping
if ctx.ChainID() == "kyve-1" {
validatorMapping = ValidatorMappingsMainnet
} else if ctx.ChainID() == "kaon-1" {
validatorMapping = ValidatorMappingsKaon
} else if ctx.ChainID() == "korellia-2" {
validatorMapping = ValidatorMappingsKorellia
}

totalMigratedStake := uint64(0)
Expand Down Expand Up @@ -190,3 +341,65 @@ func migrateProtocolStakers(ctx sdk.Context, delegationKeeper delegationkeeper.K

stakersKeeper.SetParams(ctx, stakersParams)
}

func UpgradeRuntimes(sdkCtx sdk.Context, poolKeeper *poolkeeper.Keeper) {
// Upgrade duration set to 10mins
upgrades := []poolTypes.MsgScheduleRuntimeUpgrade{
{
Runtime: "@kyvejs/tendermint",
Version: "1.3.0",
ScheduledAt: uint64(sdkCtx.BlockTime().Unix()),
Duration: 600,
Binaries: "{\"kyve-linux-arm64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint%401.3.0/kyve-linux-arm64.zip\",\"kyve-linux-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint%401.3.0/kyve-linux-x64.zip\",\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint%401.3.0/kyve-macos-x64.zip\"}",
},
{
Runtime: "@kyvejs/tendermint-bsync",
Version: "1.2.9",
ScheduledAt: uint64(sdkCtx.BlockTime().Unix()),
Duration: 600,
Binaries: "{\"kyve-linux-arm64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.2.9/kyve-linux-arm64.zip\",\"kyve-linux-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.2.9/kyve-linux-x64.zip\",\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.2.9/kyve-macos-x64.zip\"}",
},
{
Runtime: "@kyvejs/tendermint-ssync",
Version: "1.3.0",
ScheduledAt: uint64(sdkCtx.BlockTime().Unix()),
Duration: 600,
Binaries: "{\"kyve-linux-arm64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-ssync%401.3.0/kyve-linux-arm64.zip\",\"kyve-linux-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-ssync%401.3.0/kyve-linux-x64.zip\",\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-ssync%401.3.0/kyve-macos-x64.zip\"}",
},
}

for _, upgrade := range upgrades {
affectedPools := make([]uint64, 0)
for _, pool := range poolKeeper.GetAllPools(sdkCtx) {
// only schedule upgrade if the runtime matches
if pool.Runtime != upgrade.Runtime {
continue
}

// only schedule upgrade if there is no upgrade already
if pool.UpgradePlan.ScheduledAt != 0 {
continue
}

pool.UpgradePlan = &poolTypes.UpgradePlan{
Version: upgrade.Version,
Binaries: upgrade.Binaries,
ScheduledAt: upgrade.ScheduledAt,
Duration: upgrade.Duration,
}

affectedPools = append(affectedPools, pool.Id)

poolKeeper.SetPool(sdkCtx, pool)
}

_ = sdkCtx.EventManager().EmitTypedEvent(&poolTypes.EventRuntimeUpgradeScheduled{
Runtime: upgrade.Runtime,
Version: upgrade.Version,
ScheduledAt: upgrade.ScheduledAt,
Duration: upgrade.Duration,
Binaries: upgrade.Binaries,
AffectedPools: affectedPools,
})
}
}
7 changes: 7 additions & 0 deletions app/upgrades/v2_0/validator-proofs/korellia/Validator-EU.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Validator-EU",
"consensus_address": "kyvevaloper1ghpmzfuggm7vcruyhfzrczl4aczy8gas8guslh",
"protocol_address": "kyve1zxlk3x50re5rhz985gcx8pm73whqnutg8ptnkz",
"proof_1": "A7A27728A03B1052B4B32D802920BBDB1E7B8FB549000A8ECE571F554513B59E",
"proof_2": "11B9EFAA0F3BF895F5E6D0FB4EAD66422552A31BADC1AE51C850AA1B8F59F518"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Validator-OVH",
"consensus_address": "kyvevaloper1af699xwpa6z6hek648p2c08hupd4j2knz22atl",
"protocol_address": "kyve1zuzyh0c0zvxry42dpqc79gu3ssukpfzg47uzrc",
"proof_1": "3131A86723482046AEA2034D23D4E125BDC749D72C00F16D47E99AD78CF6971A",
"proof_2": "54B6CC415720BD3FF573ACCC412043EF40399D5E1954ADA948F5044729B5436F"
}
7 changes: 7 additions & 0 deletions app/upgrades/v2_0/validator-proofs/korellia/Validator-US.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Validator-US",
"consensus_address": "kyvevaloper1p6ctexlukvllyruwnyfhh2cvdwqggz95yzqxe9",
"protocol_address": "kyve1tg9rc2rwzu3ytvkdjh4mpe4k46n2eykpdv46nw",
"proof_1": "C05CBE4E1FB1006C9FCF12713889D69012532C436C5CD3B96715143F8C5191B0",
"proof_2": "56C4CCDA3953388FCB26B7C8841B9F4D1718DA571B833E54FF6523B959A15C55"
}
Loading

0 comments on commit 279189c

Please sign in to comment.