Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions tools/cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Bug Fixes

* [#26819](https://github.com/cosmos/cosmos-sdk/pull/26819) Fix the inverted retry condition when `upgrade-info.json` is still empty: the watcher now keeps waiting (up to 10 × 2 ms) until the write lands instead of giving up after the first empty stat.

### Improvements

* [#23720](https://github.com/cosmos/cosmos-sdk/pull/23720) Get block height from db after node execution fails
Expand Down
3 changes: 2 additions & 1 deletion tools/cosmovisor/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ func (fw *fileWatcher) CheckUpdate(currentUpgrade upgradetypes.Plan) bool {
panic(fmt.Errorf("failed to stat upgrade info file: %w", err))
}
}
if stat.Size() == 0 {
// stop waiting as soon as the write has landed
if stat.Size() != 0 {
break
}
}
Expand Down
25 changes: 25 additions & 0 deletions tools/cosmovisor/scanner_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cosmovisor

import (
"os"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -90,3 +92,26 @@ func TestParseUpgradeInfoFile(t *testing.T) {
})
}
}

func TestCheckUpdateWaitsForEmptyFileWrite(t *testing.T) {
filename := filepath.Join(t.TempDir(), "upgrade-info.json")
require.NoError(t, os.WriteFile(filename, nil, 0o600))

fw := &fileWatcher{
filename: filename,
currentInfo: upgradetypes.Plan{Name: "upgrade1", Height: 1},
initialized: true,
}

// Simulate the daemon finishing its write a few milliseconds after the
// watcher observed the empty file; CheckUpdate should keep waiting instead
// of giving up after the first still-empty stat.
go func() {
time.Sleep(5 * time.Millisecond)
_ = os.WriteFile(filename, []byte(`{"name":"upgrade2","height":10}`), 0o600)
}()

require.True(t, fw.CheckUpdate(upgradetypes.Plan{Name: "upgrade1"}))
require.Equal(t, "upgrade2", fw.currentInfo.Name)
require.Equal(t, int64(10), fw.currentInfo.Height)
}