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

refactor(cosmovisor): get block height from db after node execution fails #23720

Open
wants to merge 3 commits into
base: release/v0.53.x
Choose a base branch
from
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]

### 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
Expand Down
5 changes: 3 additions & 2 deletions tools/cosmovisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ toolchain go1.24.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.12
github.com/fsnotify/fsnotify v1.8.0
github.com/otiai10/copy v1.14.1
Expand Down Expand Up @@ -60,8 +62,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
Expand Down Expand Up @@ -119,6 +119,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/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/hdevalence/ed25519consensus v0.2.0 // indirect
Expand Down
25 changes: 25 additions & 0 deletions tools/cosmovisor/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"testing"
"time"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/store"

upgradetypes "cosmossdk.io/x/upgrade/types"
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading