Skip to content

Commit e8acc45

Browse files
mergify[bot]JeancarloBarrios
authored andcommitted
fix: move downgrade verification after store migration (cosmos#12906) (cosmos#12907)
1 parent cc2aa23 commit e8acc45

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4848
### Bug Fixes
4949

5050
* (x/group) [#12888](https://github.com/cosmos/cosmos-sdk/pull/12888) Fix event propagation to the current context of `x/group` message execution `[]sdk.Result`.
51+
* (x/upgrade) [#12906](https://github.com/cosmos/cosmos-sdk/pull/12906) Fix upgrade failure by moving downgrade verification logic after store migration.
5152

5253
## [v0.46.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0) - 2022-07-26
5354

x/upgrade/keeper/abci.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,6 @@ func (k Keeper) PreBlocker(ctx context.Context) error {
2929
}
3030
found := err == nil
3131

32-
if !k.DowngradeVerified() {
33-
k.SetDowngradeVerified(true)
34-
// This check will make sure that we are using a valid binary.
35-
// It'll panic in these cases if there is no upgrade handler registered for the last applied upgrade.
36-
// 1. If there is no scheduled upgrade.
37-
// 2. If the plan is not ready.
38-
// 3. If the plan is ready and skip upgrade height is set for current height.
39-
if !found || !plan.ShouldExecute(blockHeight) || (plan.ShouldExecute(blockHeight) && k.IsSkipHeight(blockHeight)) {
40-
lastAppliedPlan, _, err := k.GetLastCompletedUpgrade(ctx)
41-
if err != nil {
42-
return err
43-
}
44-
45-
if lastAppliedPlan != "" && !k.HasHandler(lastAppliedPlan) {
46-
appVersion, err := k.consensusKeeper.AppVersion(ctx)
47-
if err != nil {
48-
return err
49-
}
50-
51-
return fmt.Errorf("wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan)
52-
}
53-
}
54-
}
55-
5632
if !found {
5733
return nil
5834
}
@@ -104,7 +80,28 @@ func (k Keeper) PreBlocker(ctx context.Context) error {
10480
// Returning an error will end up in a panic
10581
return errors.New(downgradeMsg)
10682
}
107-
return nil
83+
84+
if !k.DowngradeVerified() {
85+
k.SetDowngradeVerified(true)
86+
lastAppliedPlan, _ := k.GetLastCompletedUpgrade(ctx)
87+
// This check will make sure that we are using a valid binary.
88+
// It'll panic in these cases if there is no upgrade handler registered for the last applied upgrade.
89+
// 1. If there is no scheduled upgrade.
90+
// 2. If the plan is not ready.
91+
// 3. If the plan is ready and skip upgrade height is set for current height.
92+
if !found || !plan.ShouldExecute(ctx) || (plan.ShouldExecute(ctx) && k.IsSkipHeight(ctx.BlockHeight())) {
93+
if lastAppliedPlan != "" && !k.HasHandler(lastAppliedPlan) {
94+
var appVersion uint64
95+
96+
cp := ctx.ConsensusParams()
97+
if cp != nil && cp.Version != nil {
98+
appVersion = cp.Version.AppVersion
99+
}
100+
101+
panic(fmt.Sprintf("Wrong app version %d, upgrade handler is missing for %s upgrade plan", appVersion, lastAppliedPlan))
102+
}
103+
}
104+
}
108105
}
109106

110107
// BuildUpgradeNeededMsg prints the message that notifies that an upgrade is needed.

0 commit comments

Comments
 (0)