From e44e37a07950d922b747d91b1c47b3916b25b858 Mon Sep 17 00:00:00 2001 From: Troy Kessler Date: Thu, 20 Jun 2024 17:21:37 +0200 Subject: [PATCH] chore: added protocol runtime upgrades to 1.5 migration --- app/upgrades/v1_5/upgrade.go | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/app/upgrades/v1_5/upgrade.go b/app/upgrades/v1_5/upgrade.go index a4f1b944..38d955a4 100644 --- a/app/upgrades/v1_5/upgrade.go +++ b/app/upgrades/v1_5/upgrade.go @@ -101,6 +101,9 @@ func CreateUpgradeHandler( // migrate old MsgCreatePool gov proposals migrateOldGovProposals(sdkCtx, cdc, MustGetStoreKey(storeKeys, govTypes.StoreKey)) + // upgrade protocol runtimes at last + upgradeRuntimes(sdkCtx, poolKeeper) + return migratedVersionMap, err } } @@ -390,3 +393,65 @@ func migratePoolModule(sdkCtx sdk.Context, cdc codec.Codec, poolStoreKey storety logger.Info("migrated Pool module") } + +func upgradeRuntimes(sdkCtx sdk.Context, poolKeeper *poolKeeper.Keeper) { + // TODO: define upgrade duration and submit download links for binaries + upgrades := []poolTypes.MsgScheduleRuntimeUpgrade{ + { + Runtime: "@kyvejs/tendermint", + Version: "1.2.0", + ScheduledAt: uint64(sdkCtx.BlockTime().Unix()), + Duration: 3600, + Binaries: "{}", + }, + { + Runtime: "@kyvejs/tendermint-bsync", + Version: "1.2.0", + ScheduledAt: uint64(sdkCtx.BlockTime().Unix()), + Duration: 3600, + Binaries: "{}", + }, + { + Runtime: "@kyvejs/tendermint-ssync", + Version: "1.2.0", + ScheduledAt: uint64(sdkCtx.BlockTime().Unix()), + Duration: 3600, + Binaries: "{}", + }, + } + + 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, + }) + } +}