From 6a28cf4dedc1954b8edd7c610dd75eaf4f6551f5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 8 Apr 2022 15:04:53 +0200 Subject: [PATCH] feat: `ScheduleUpgradeNoHeightValidation` for automated upgrades w/o gov proposal (backport #11551) (#11574) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: `ScheduleUpgradeNoHeightValidation` for automated upgrades w/o gov proposal (#11551) ## Description Implements a `ScheduleUpgradeNoHeightValidation` function for chains to schedule an automated upgrade (using the `x/upgrade` module) without having to go through a governance proposal. This is beneficial to coordinate upgrades without having to manually download the new version, do the migration and restart the chain. This is the procedure Evmos used for its automated upgrade. --- ### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) 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) (cherry picked from commit 5b02bf459f2da26202a7b661cbfaf54e1f7595f9) # Conflicts: # CHANGELOG.md # x/upgrade/abci_test.go # x/upgrade/keeper/keeper.go * fix conflicts * changelog * fix test Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Federico Kunze Küllmer --- CHANGELOG.md | 4 ++++ x/upgrade/keeper/keeper.go | 11 +++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c74cc5a2a19d..7f2e8885ab10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +* (x/upgrade) [\#11551](https://github.com/cosmos/cosmos-sdk/pull/11551) Update `ScheduleUpgrade` for chains to schedule an automated upgrade on `BeginBlock` without having to go though governance. + ## [v0.45.2](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.2) - 2022-04-05 ### Features diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index 9420cf968273..f20b6ad5c355 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -196,13 +196,8 @@ func (k Keeper) ScheduleUpgrade(ctx context.Context, plan types.Plan) error { // NOTE: allow for the possibility of chains to schedule upgrades in begin block of the same block // as a strategy for emergency hard fork recoveries - if plan.Height < k.HeaderService.HeaderInfo(ctx).Height { - return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past") - } - - doneHeight, err := k.GetDoneHeight(ctx, plan.Name) - if err != nil { - return err + if plan.Height < ctx.BlockHeight() { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "upgrade cannot be scheduled in the past") } if doneHeight != 0 { @@ -512,7 +507,7 @@ func (k Keeper) DumpUpgradeInfoWithInfoToDisk(height int64, name string, info st return err } - return ioutil.WriteFile(upgradeInfoFilePath, bz, 0600) + return os.WriteFile(upgradeInfoFilePath, bz, 0o600) } // GetUpgradeInfoPath returns the upgrade info file path