From ef8c1f4e5d33be8251d08d68a43facf0e03621f9 Mon Sep 17 00:00:00 2001 From: HuangYi Date: Thu, 11 Aug 2022 17:14:13 +0800 Subject: [PATCH] move downgrade verification after store migration otherwise, it panic because it expect the key is migrated Closes: #12904 --- x/upgrade/abci.go | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/x/upgrade/abci.go b/x/upgrade/abci.go index 5212cd9e2ed5..f0214751422c 100644 --- a/x/upgrade/abci.go +++ b/x/upgrade/abci.go @@ -25,28 +25,6 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { plan, found := k.GetUpgradePlan(ctx) - if !k.DowngradeVerified() { - k.SetDowngradeVerified(true) - lastAppliedPlan, _ := k.GetLastCompletedUpgrade(ctx) - // This check will make sure that we are using a valid binary. - // It'll panic in these cases if there is no upgrade handler registered for the last applied upgrade. - // 1. If there is no scheduled upgrade. - // 2. If the plan is not ready. - // 3. If the plan is ready and skip upgrade height is set for current height. - if !found || !plan.ShouldExecute(ctx) || (plan.ShouldExecute(ctx) && k.IsSkipHeight(ctx.BlockHeight())) { - if lastAppliedPlan != "" && !k.HasHandler(lastAppliedPlan) { - var appVersion uint64 - - cp := ctx.ConsensusParams() - if cp != nil && cp.Version != nil { - appVersion = cp.Version.AppVersion - } - - panic(fmt.Sprintf("Wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan)) - } - } - } - if !found { return } @@ -92,6 +70,28 @@ func BeginBlocker(k keeper.Keeper, ctx sdk.Context, _ abci.RequestBeginBlock) { ctx.Logger().Error(downgradeMsg) panic(downgradeMsg) } + + if !k.DowngradeVerified() { + k.SetDowngradeVerified(true) + lastAppliedPlan, _ := k.GetLastCompletedUpgrade(ctx) + // This check will make sure that we are using a valid binary. + // It'll panic in these cases if there is no upgrade handler registered for the last applied upgrade. + // 1. If there is no scheduled upgrade. + // 2. If the plan is not ready. + // 3. If the plan is ready and skip upgrade height is set for current height. + if !found || !plan.ShouldExecute(ctx) || (plan.ShouldExecute(ctx) && k.IsSkipHeight(ctx.BlockHeight())) { + if lastAppliedPlan != "" && !k.HasHandler(lastAppliedPlan) { + var appVersion uint64 + + cp := ctx.ConsensusParams() + if cp != nil && cp.Version != nil { + appVersion = cp.Version.AppVersion + } + + panic(fmt.Sprintf("Wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan)) + } + } + } } // BuildUpgradeNeededMsg prints the message that notifies that an upgrade is needed.