Skip to content

Commit

Permalink
move downgrade verification after store migration
Browse files Browse the repository at this point in the history
otherwise, it panic because it expect the key is migrated
Closes: cosmos#12904
  • Loading branch information
yihuang committed Aug 11, 2022
1 parent 69c88ad commit ef8c1f4
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions x/upgrade/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ef8c1f4

Please sign in to comment.