Skip to content

Commit 3d411fb

Browse files
committed
fix: cosmovisor integration
1 parent c8a47ac commit 3d411fb

10 files changed

Lines changed: 1213 additions & 286 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Configures daily rotation with 14-day retention and compression.
149149

150150
### File Locations
151151
- **Manager**: `~/.local/bin/push-validator`
152-
- **Binary**: `~/.local/bin/pchaind`
152+
- **Chain Binary**: `~/.pchain/cosmovisor/current/bin/pchaind` (managed by Cosmovisor)
153153
- **Config**: `~/.pchain/config/`
154154
- **Data**: `~/.pchain/data/`
155155
- **Logs**: `~/.pchain/logs/pchaind.log`

cmd/push-validator/cmd_doctor.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/pushchain/push-validator-cli/internal/config"
13+
"github.com/pushchain/push-validator-cli/internal/cosmovisor"
1314
"github.com/pushchain/push-validator-cli/internal/exitcodes"
1415
"github.com/pushchain/push-validator-cli/internal/node"
1516
"github.com/pushchain/push-validator-cli/internal/process"
@@ -60,6 +61,7 @@ func runDoctor(cmd *cobra.Command, args []string) error {
6061
results = append(results, checkDiskSpace(cfg, c))
6162
results = append(results, checkPermissions(cfg, c))
6263
results = append(results, checkSyncStatus(cfg, c))
64+
results = append(results, checkCosmovisor(cfg, c))
6365

6466
// Summary
6567
fmt.Println()
@@ -334,6 +336,34 @@ func checkSyncStatus(cfg config.Config, c *ui.ColorConfig) checkResult {
334336
return result
335337
}
336338

339+
func checkCosmovisor(cfg config.Config, c *ui.ColorConfig) checkResult {
340+
result := checkResult{Name: "Cosmovisor"}
341+
342+
detection := cosmovisor.Detect(cfg.HomeDir)
343+
344+
if !detection.Available {
345+
result.Status = "warn"
346+
result.Message = "Cosmovisor not installed (optional)"
347+
result.Details = []string{
348+
"Install with: go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest",
349+
"Cosmovisor enables automatic binary upgrades",
350+
}
351+
} else if !detection.SetupComplete {
352+
result.Status = "warn"
353+
result.Message = "Cosmovisor installed but not initialized"
354+
result.Details = []string{
355+
"Will auto-initialize on next 'push-validator start'",
356+
"Or check status with: push-validator cosmovisor status",
357+
}
358+
} else {
359+
result.Status = "pass"
360+
result.Message = "Cosmovisor configured and ready"
361+
}
362+
363+
printCheck(result, c)
364+
return result
365+
}
366+
337367
func printCheck(r checkResult, c *ui.ColorConfig) {
338368
icon := ""
339369
msg := ""

cmd/push-validator/cmd_update.go

Lines changed: 0 additions & 190 deletions
This file was deleted.

cmd/push-validator/helpers.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math/big"
99
"os"
1010
"os/exec"
11+
"path/filepath"
1112
"strings"
1213
"time"
1314

@@ -18,14 +19,38 @@ import (
1819
)
1920

2021
// findPchaind returns the path to the pchaind binary, resolving
21-
// either PCHAIND or PCHAIN_BIN environment variables, or falling
22-
// back to the literal "pchaind" on PATH.
22+
// either PCHAIND or PCHAIN_BIN environment variables, checking the
23+
// cosmovisor genesis directory, or falling back to PATH lookup.
2324
func findPchaind() string {
2425
if v := os.Getenv("PCHAIND"); v != "" { return v }
2526
if v := os.Getenv("PCHAIN_BIN"); v != "" { return v }
27+
28+
// Check cosmovisor genesis directory (primary location after install.sh)
29+
homeDir := os.Getenv("HOME_DIR")
30+
if homeDir == "" {
31+
if home, err := os.UserHomeDir(); err == nil {
32+
homeDir = filepath.Join(home, ".pchain")
33+
}
34+
}
35+
if homeDir != "" {
36+
cosmovisorPath := filepath.Join(homeDir, "cosmovisor", "genesis", "bin", "pchaind")
37+
if _, err := os.Stat(cosmovisorPath); err == nil {
38+
return cosmovisorPath
39+
}
40+
}
41+
2642
return "pchaind"
2743
}
2844

45+
// findCosmovisor returns the path to the cosmovisor binary, resolving
46+
// COSMOVISOR environment variable or falling back to PATH lookup.
47+
// Returns empty string if not found.
48+
func findCosmovisor() string {
49+
if v := os.Getenv("COSMOVISOR"); v != "" { return v }
50+
if path, err := exec.LookPath("cosmovisor"); err == nil { return path }
51+
return ""
52+
}
53+
2954
// getenvDefault returns the environment value for k, or default d
3055
// when k is not set.
3156
func getenvDefault(k, d string) string { if v := os.Getenv(k); v != "" { return v }; return d }

0 commit comments

Comments
 (0)