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(cosmovisor): premature upgrade on restart #22528

Merged
merged 8 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tools/cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#21790](https://github.com/cosmos/cosmos-sdk/pull/21790) Add `add-batch-upgrade` command.
* [#21972](https://github.com/cosmos/cosmos-sdk/pull/21972) Add `prepare-upgrade` command
* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout.

### Improvements

* [#21891](https://github.com/cosmos/cosmos-sdk/pull/21891) create `current` symlink as relative
* [#21462](https://github.com/cosmos/cosmos-sdk/pull/21462) Pass `stdin` to binary.

### Bug Fixes

### Features

* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout.
* [#22528](https://github.com/cosmos/cosmos-sdk/pull/22528) Fix premature upgrades on restarting cosmovisor.

## v1.6.0 - 2024-08-12

Expand Down
8 changes: 5 additions & 3 deletions tools/cosmovisor/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
)

var errUntestAble = errors.New("untestable")
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

type fileWatcher struct {
daemonHome string
filename string // full path to a watched file
Expand Down Expand Up @@ -149,8 +151,8 @@ func (fw *fileWatcher) CheckUpdate(currentUpgrade upgradetypes.Plan) bool {
}

// file exist but too early in height
currentHeight, _ := fw.checkHeight()
if currentHeight != 0 && currentHeight < info.Height {
currentHeight, err := fw.checkHeight()
if (err != nil || currentHeight < info.Height) && !errors.Is(err, errUntestAble) { // ignore this check for tests
return false
}

Expand Down Expand Up @@ -182,7 +184,7 @@ func (fw *fileWatcher) CheckUpdate(currentUpgrade upgradetypes.Plan) bool {
// checkHeight checks if the current block height
func (fw *fileWatcher) checkHeight() (int64, error) {
if testing.Testing() { // we cannot test the command in the test environment
return 0, nil
return 0, errUntestAble
}

result, err := exec.Command(fw.currentBin, "status", "--home", fw.daemonHome).CombinedOutput() //nolint:gosec // we want to execute the status command
Expand Down
Loading