Skip to content

Commit 833b176

Browse files
committed
fixes
1 parent ff70ea6 commit 833b176

23 files changed

+127
-196
lines changed

cmd/push-validator/cmd_dashboard.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ to a static text snapshot.`,
7575
NoEmoji: flagNoEmoji,
7676
Debug: debugMode,
7777
CLIVersion: Version,
78+
Supervisor: newSupervisor(cfg.HomeDir),
79+
BinPath: findPchaind(),
7880
}
7981
opts = normalizeDashboardOptions(opts)
8082

cmd/push-validator/cmd_doctor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func runDoctor(cmd *cobra.Command, args []string) error {
4848
c := getPrinter().Colors
4949

5050
// Create dependencies for checks
51-
sup := process.New(cfg.HomeDir)
51+
sup := newSupervisor(cfg.HomeDir)
5252
rpc := cfg.RPCLocal
5353
if rpc == "" {
5454
rpc = "http://127.0.0.1:26657"

cmd/push-validator/cmd_register.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func handleRegisterValidator(d *Deps) error {
282282
}
283283
if isValAlready {
284284
if flagOutput == "json" {
285-
getPrinter().JSON(map[string]any{"ok": false, "error": "validator already registered"})
285+
getPrinter().JSON(map[string]any{"ok": true, "registered": true, "message": "validator already registered"})
286286
} else {
287287
p := getPrinter()
288288
fmt.Println()
@@ -299,7 +299,7 @@ func handleRegisterValidator(d *Deps) error {
299299
fmt.Println(p.Colors.Apply(p.Colors.Theme.Command, " push-validator status"))
300300
fmt.Println()
301301
}
302-
return fmt.Errorf("validator already registered")
302+
return nil
303303
}
304304

305305
// Check for moniker conflicts before prompting for registration

cmd/push-validator/cmd_register_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ func TestHandleRegisterValidator_AlreadyRegistered_JSON(t *testing.T) {
102102
})
103103

104104
err := handleRegisterValidator(d)
105-
if err == nil {
106-
t.Fatal("expected error")
107-
}
108-
if !containsSubstr(err.Error(), "validator already registered") {
109-
t.Errorf("unexpected error: %v", err)
105+
if err != nil {
106+
t.Fatalf("unexpected error: %v", err)
110107
}
111108
}
112109

@@ -131,11 +128,8 @@ func TestHandleRegisterValidator_AlreadyRegistered_Text(t *testing.T) {
131128
})
132129

133130
err := handleRegisterValidator(d)
134-
if err == nil {
135-
t.Fatal("expected error")
136-
}
137-
if !containsSubstr(err.Error(), "validator already registered") {
138-
t.Errorf("unexpected error: %v", err)
131+
if err != nil {
132+
t.Fatalf("unexpected error: %v", err)
139133
}
140134
}
141135

cmd/push-validator/cmd_restake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ func handleRestakeRewardsAll(d *Deps) error {
152152

153153
if totalRewards < rewardThreshold {
154154
if flagOutput == "json" {
155-
getPrinter().JSON(map[string]any{"ok": false, "error": "no significant rewards available"})
155+
getPrinter().JSON(map[string]any{"ok": true, "rewards_available": false, "message": "no significant rewards available"})
156156
} else {
157157
fmt.Println(p.Colors.Warning(p.Colors.Emoji("⚠️") + " No significant rewards available (less than 0.01 PC)"))
158158
fmt.Println()
159159
fmt.Println(p.Colors.Info("Nothing to restake. Continue earning rewards and try again later."))
160160
fmt.Println()
161161
}
162-
return fmt.Errorf("no significant rewards available")
162+
return nil
163163
}
164164

165165
// Step 4: Auto-detect key name from validator

cmd/push-validator/cmd_restake_extra_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,8 @@ func TestHandleRestakeRewardsAll_JSON_NoSignificantRewards(t *testing.T) {
200200
})
201201

202202
err := handleRestakeRewardsAll(d)
203-
if err == nil {
204-
t.Fatal("expected error")
205-
}
206-
if !containsSubstr(err.Error(), "no significant rewards") {
207-
t.Errorf("unexpected error: %v", err)
203+
if err != nil {
204+
t.Fatalf("unexpected error: %v", err)
208205
}
209206
}
210207

cmd/push-validator/cmd_restake_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ func TestHandleRestakeRewardsAll_NoSignificantRewards(t *testing.T) {
116116
})
117117

118118
err := handleRestakeRewardsAll(d)
119-
if err == nil {
120-
t.Fatal("expected error")
121-
}
122-
if !containsSubstr(err.Error(), "no significant rewards") {
123-
t.Errorf("unexpected error: %v", err)
119+
if err != nil {
120+
t.Fatalf("unexpected error: %v", err)
124121
}
125122
}
126123

@@ -473,11 +470,8 @@ func TestHandleRestakeRewardsAll_TextOutput_NoSignificantRewards(t *testing.T) {
473470
})
474471

475472
err := handleRestakeRewardsAll(d)
476-
if err == nil {
477-
t.Fatal("expected error")
478-
}
479-
if !containsSubstr(err.Error(), "no significant rewards") {
480-
t.Errorf("unexpected error: %v", err)
473+
if err != nil {
474+
t.Fatalf("unexpected error: %v", err)
481475
}
482476
}
483477

cmd/push-validator/cmd_restart.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212
)
1313

1414
var (
15-
restartBin string
16-
restartNoCosmovisor bool
15+
restartBin string
1716
)
1817

1918
var restartCmd = &cobra.Command{
@@ -26,19 +25,12 @@ var restartCmd = &cobra.Command{
2625
_ = os.Setenv("PCHAIND", restartBin)
2726
}
2827

29-
// Determine which supervisor to use
30-
var sup process.Supervisor
31-
useCosmovisor := false
32-
33-
if !restartNoCosmovisor {
34-
detection := cosmovisor.Detect(cfg.HomeDir)
35-
if detection.Available {
36-
useCosmovisor = true
37-
}
38-
sup = newSupervisor(cfg.HomeDir)
39-
} else {
40-
sup = process.New(cfg.HomeDir)
28+
// Verify cosmovisor is available
29+
detection := cosmovisor.Detect(cfg.HomeDir)
30+
if !detection.Available {
31+
return fmt.Errorf("cosmovisor binary not found; install it or ensure it's in PATH")
4132
}
33+
sup := newSupervisor(cfg.HomeDir)
4234

4335
_, err := sup.Restart(process.StartOpts{HomeDir: cfg.HomeDir, Moniker: os.Getenv("MONIKER"), BinPath: findPchaind()})
4436
if err != nil {
@@ -56,13 +48,9 @@ var restartCmd = &cobra.Command{
5648
return err
5749
}
5850
if flagOutput == "json" {
59-
p.JSON(map[string]any{"ok": true, "action": "restart", "cosmovisor": useCosmovisor})
51+
p.JSON(map[string]any{"ok": true, "action": "restart", "cosmovisor": true})
6052
} else {
61-
if useCosmovisor {
62-
p.Success("✓ Node restarted with Cosmovisor")
63-
} else {
64-
p.Success("✓ Node restarted")
65-
}
53+
p.Success("✓ Node restarted with Cosmovisor")
6654
fmt.Println()
6755
fmt.Println(p.Colors.Info("Useful commands:"))
6856
fmt.Println(p.Colors.Apply(p.Colors.Theme.Command, " push-validator status"))
@@ -78,6 +66,5 @@ var restartCmd = &cobra.Command{
7866

7967
func init() {
8068
restartCmd.Flags().StringVar(&restartBin, "bin", "", "Path to pchaind binary")
81-
restartCmd.Flags().BoolVar(&restartNoCosmovisor, "no-cosmovisor", false, "Use direct pchaind instead of Cosmovisor")
8269
rootCmd.AddCommand(restartCmd)
8370
}

cmd/push-validator/cmd_start.go

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ import (
2525
)
2626

2727
var (
28-
startBin string
29-
startNoPrompt bool
30-
startNoCosmovisor bool
28+
startBin string
29+
startNoPrompt bool
3130
)
3231

3332
var startCmd = &cobra.Command{
@@ -102,22 +101,15 @@ var startCmd = &cobra.Command{
102101
}
103102
}
104103

105-
// Determine which supervisor to use (Cosmovisor or direct pchaind)
106-
var sup process.Supervisor
107-
useCosmovisor := false
108-
109-
if !startNoCosmovisor {
110-
detection := cosmovisor.Detect(cfg.HomeDir)
111-
if detection.Available {
112-
useCosmovisor = true
113-
if flagOutput != "json" && !detection.SetupComplete {
114-
p.Info("Initializing Cosmovisor...")
115-
}
116-
}
117-
sup = newSupervisor(cfg.HomeDir)
118-
} else {
119-
sup = process.New(cfg.HomeDir)
104+
// Verify cosmovisor is available
105+
detection := cosmovisor.Detect(cfg.HomeDir)
106+
if !detection.Available {
107+
return fmt.Errorf("cosmovisor binary not found; install it or ensure it's in PATH")
108+
}
109+
if flagOutput != "json" && !detection.SetupComplete {
110+
p.Info("Initializing Cosmovisor...")
120111
}
112+
sup := newSupervisor(cfg.HomeDir)
121113

122114
// Check if node is already running
123115
isAlreadyRunning := sup.IsRunning()
@@ -130,11 +122,7 @@ var startCmd = &cobra.Command{
130122
p.Success("Node is running")
131123
}
132124
} else {
133-
if useCosmovisor {
134-
fmt.Println("→ Starting node with Cosmovisor...")
135-
} else {
136-
fmt.Println("→ Starting node...")
137-
}
125+
fmt.Println("→ Starting node with Cosmovisor...")
138126
}
139127
}
140128

@@ -160,14 +148,10 @@ var startCmd = &cobra.Command{
160148
return err
161149
}
162150
if flagOutput == "json" {
163-
p.JSON(map[string]any{"ok": true, "action": "start", "already_running": isAlreadyRunning, "cosmovisor": useCosmovisor})
151+
p.JSON(map[string]any{"ok": true, "action": "start", "already_running": isAlreadyRunning, "cosmovisor": true})
164152
} else {
165153
if !isAlreadyRunning {
166-
if useCosmovisor {
167-
p.Success("Node started with Cosmovisor")
168-
} else {
169-
p.Success("Node started successfully")
170-
}
154+
p.Success("Node started with Cosmovisor")
171155
}
172156

173157
// Check validator status and show appropriate next steps (skip if --no-prompt)
@@ -186,7 +170,6 @@ var startCmd = &cobra.Command{
186170
func init() {
187171
startCmd.Flags().StringVar(&startBin, "bin", "", "Path to pchaind binary")
188172
startCmd.Flags().BoolVar(&startNoPrompt, "no-prompt", false, "Skip post-start prompts (for use in scripts)")
189-
startCmd.Flags().BoolVar(&startNoCosmovisor, "no-cosmovisor", false, "Use direct pchaind instead of Cosmovisor")
190173
rootCmd.AddCommand(startCmd)
191174
}
192175

cmd/push-validator/cmd_stop.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,14 @@ var stopCmd = &cobra.Command{
1515
cfg := loadCfg()
1616
p := getPrinter()
1717

18-
// Try to stop Cosmovisor first (it will also handle direct pchaind if running)
19-
cosmoSup := process.NewCosmovisor(cfg.HomeDir)
20-
if cosmoSup.IsRunning() {
21-
if err := cosmoSup.Stop(); err != nil {
22-
if flagOutput == "json" {
23-
p.JSON(map[string]any{"ok": false, "error": err.Error()})
24-
} else {
25-
p.Error(fmt.Sprintf("stop error: %v", err))
26-
}
27-
return err
28-
}
29-
} else {
30-
// Fall back to direct pchaind supervisor
31-
sup := process.New(cfg.HomeDir)
32-
if err := sup.Stop(); err != nil {
33-
if flagOutput == "json" {
34-
p.JSON(map[string]any{"ok": false, "error": err.Error()})
35-
} else {
36-
p.Error(fmt.Sprintf("stop error: %v", err))
37-
}
38-
return err
18+
sup := process.NewCosmovisor(cfg.HomeDir)
19+
if err := sup.Stop(); err != nil {
20+
if flagOutput == "json" {
21+
p.JSON(map[string]any{"ok": false, "error": err.Error()})
22+
} else {
23+
p.Error(fmt.Sprintf("stop error: %v", err))
3924
}
25+
return err
4026
}
4127

4228
if flagOutput == "json" {

0 commit comments

Comments
 (0)