Skip to content

Commit

Permalink
refactor(cosmovisor): get block height from db after node execution f…
Browse files Browse the repository at this point in the history
…ails
  • Loading branch information
zakir-code committed Feb 27, 2025
1 parent ff779ec commit b377562
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

0 comments on commit b377562

Please sign in to comment.