diff --git a/tools/cosmovisor/CHANGELOG.md b/tools/cosmovisor/CHANGELOG.md index 6746a05126..cf739974f7 100644 --- a/tools/cosmovisor/CHANGELOG.md +++ b/tools/cosmovisor/CHANGELOG.md @@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* [#23720](https://github.com/cosmos/cosmos-sdk/pull/23720) Get block height from db after node execution fails + ## v1.7.1 - 2025-01-12 ### Bug Fixes diff --git a/tools/cosmovisor/go.mod b/tools/cosmovisor/go.mod index b8c2c5a4d2..1644116411 100644 --- a/tools/cosmovisor/go.mod +++ b/tools/cosmovisor/go.mod @@ -5,6 +5,8 @@ go 1.23.0 require ( cosmossdk.io/log v1.5.0 cosmossdk.io/x/upgrade v0.1.4 + github.com/cometbft/cometbft v0.38.17 + github.com/cometbft/cometbft-db v0.14.1 github.com/cosmos/cosmos-sdk v0.50.13 github.com/fsnotify/fsnotify v1.8.0 github.com/otiai10/copy v1.14.1 @@ -58,8 +60,6 @@ require ( github.com/cockroachdb/pebble v1.1.2 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect - github.com/cometbft/cometbft v0.38.17 // indirect - github.com/cometbft/cometbft-db v0.14.1 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.1 // indirect github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect @@ -118,6 +118,7 @@ require ( github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/yamux v0.1.2 // indirect github.com/hdevalence/ed25519consensus v0.2.0 // indirect github.com/huandu/skiplist v1.2.1 // indirect diff --git a/tools/cosmovisor/scanner.go b/tools/cosmovisor/scanner.go index 008c573570..4f7af045a6 100644 --- a/tools/cosmovisor/scanner.go +++ b/tools/cosmovisor/scanner.go @@ -12,6 +12,9 @@ import ( "testing" "time" + dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/store" + upgradetypes "cosmossdk.io/x/upgrade/types" ) @@ -74,6 +77,15 @@ func (fw *fileWatcher) Stop() { fw.ticker.Stop() } +func (fw *fileWatcher) IsStop() bool { + select { + case <-fw.cancel: + return true + default: + return false + } +} + // MonitorUpdate pools the filesystem to check for new upgrade currentInfo. // currentName is the name of currently running upgrade. The check is rejected if it finds // an upgrade with the same name. @@ -187,6 +199,19 @@ func (fw *fileWatcher) checkHeight() (int64, error) { return 0, errUntestAble } + if fw.IsStop() { + result, err := exec.Command(fw.currentBin, "config", "get", "config", "db_backend", "--home", fw.daemonHome).CombinedOutput() //nolint:gosec // we want to execute the config command + if err != nil { + result = []byte("goleveldb") // set default value, old version may not have config command + } + blockStoreDB, err := dbm.NewDB("blockstore", dbm.BackendType(result), filepath.Join(fw.daemonHome, "data")) + if err != nil { + return 0, err + } + defer blockStoreDB.Close() + return store.NewBlockStore(blockStoreDB).Height(), nil + } + result, err := exec.Command(fw.currentBin, "status", "--home", fw.daemonHome).CombinedOutput() //nolint:gosec // we want to execute the status command if err != nil { return 0, err