Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make downgrade verification work again #13936

Merged
merged 8 commits into from
Nov 23, 2022

Conversation

0Tech
Copy link
Contributor

@0Tech 0Tech commented Nov 21, 2022

Description

In the current BeginBlocker() of x/upgrade, the downgrade verification logic would not work when no upgrade plan is on the state. It's because the if !found check is in front of the validation, and if it is, the function returns.

This patch would relocate the logic to the front again, but there is little difference from the previous logic. The GetLastCompletedUpgrade() is now only invoked where the migration would not needed, so it would not cause the issue #12904 to recur.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Copy link
Contributor Author

@0Tech 0Tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I provided the supplement comments.

// 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())) {
lastAppliedPlan, _ := k.GetLastCompletedUpgrade(ctx)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now GetLastCompletedUpgrade() is inside of the if !found... block.

}
}
}

if !found {
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function returns here, where no upgrade plan is on the chain.

@0Tech 0Tech marked this pull request as ready for review November 21, 2022 05:09
@0Tech 0Tech requested a review from a team as a code owner November 21, 2022 05:09
@julienrbrt julienrbrt added the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Nov 21, 2022
@julienrbrt
Copy link
Member

Can we add a test case?

@0Tech
Copy link
Contributor Author

0Tech commented Nov 22, 2022

Can we add a test case?

Of course, we can. I added the corresponding unit test. One can check whether the test works as expected:

  1. Checkout this branch
  2. Run the test. Confirm that it passes.
  3. Revert the fix (e44626f).
  4. Run the test. Confirm that it catches the bug.

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, lgtm

@julienrbrt julienrbrt enabled auto-merge (squash) November 22, 2022 21:21
@julienrbrt julienrbrt merged commit b585d17 into cosmos:main Nov 23, 2022
mergify bot pushed a commit that referenced this pull request Nov 23, 2022
(cherry picked from commit b585d17)

# Conflicts:
#	CHANGELOG.md
tac0turtle pushed a commit that referenced this pull request Nov 23, 2022
* fix: make downgrade verification work again (#13936)

(cherry picked from commit b585d17)

# Conflicts:
#	CHANGELOG.md

* fix changelog

Co-authored-by: Youngtaek Yoon <noreply@yoon.anonaddy.me>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release C:x/upgrade
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants