Skip to content

Commit fbd725d

Browse files
fix(cosmovisor): premature upgrade on restart (#22528)
1 parent 005ecad commit fbd725d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

tools/cosmovisor/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,22 @@ Ref: https://keepachangelog.com/en/1.0.0/
3636

3737
## [Unreleased]
3838

39+
## v1.7.0 - 2024-11-18
40+
3941
### Features
4042

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

4447
### Improvements
4548

4649
* [#21891](https://github.com/cosmos/cosmos-sdk/pull/21891) create `current` symlink as relative
4750
* [#21462](https://github.com/cosmos/cosmos-sdk/pull/21462) Pass `stdin` to binary.
51+
52+
### Bug Fixes
4853

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

5356
## v1.6.0 - 2024-08-12
5457

tools/cosmovisor/scanner.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
upgradetypes "cosmossdk.io/x/upgrade/types"
1616
)
1717

18+
var errUntestAble = errors.New("untestable")
19+
1820
type fileWatcher struct {
1921
daemonHome string
2022
filename string // full path to a watched file
@@ -149,8 +151,8 @@ func (fw *fileWatcher) CheckUpdate(currentUpgrade upgradetypes.Plan) bool {
149151
}
150152

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

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

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

0 commit comments

Comments
 (0)