Skip to content

Commit

Permalink
chore: added protocol runtime upgrades to 1.5 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler committed Jun 20, 2024
1 parent 94719ab commit e44e37a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions app/upgrades/v1_5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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,
})
}
}

0 comments on commit e44e37a

Please sign in to comment.