Skip to content

Commit 347cd81

Browse files
committed
bug fixes
1 parent 833b176 commit 347cd81

18 files changed

Lines changed: 147 additions & 58 deletions

cmd/push-validator/cmd_increase_stake.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,18 @@ func handleIncreaseStake(d *Deps) error {
142142
// Determine delegation amount
143143
delegationAmount := ""
144144
if !d.Prompter.IsInteractive() {
145-
// In non-interactive mode, use max delegatable amount
145+
// In non-interactive mode, require --yes to auto-delegate max amount
146+
if !flagYes {
147+
if flagOutput == "json" {
148+
getPrinter().JSON(map[string]any{"ok": false, "error": "non-interactive mode requires --yes to confirm delegation"})
149+
} else {
150+
fmt.Println(p.Colors.Error(p.Colors.Emoji("❌") + " Non-interactive mode requires --yes flag to confirm delegation"))
151+
fmt.Println()
152+
fmt.Printf(" This would delegate %s PC. Run with --yes to confirm.\n", fmt.Sprintf("%.6f", maxDelegatePC))
153+
fmt.Println()
154+
}
155+
return fmt.Errorf("non-interactive mode requires --yes to confirm delegation")
156+
}
146157
delegationAmount = maxDelegatable.String()
147158
} else {
148159
// Prompt for delegation amount

cmd/push-validator/cmd_increase_stake_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,19 @@ func TestHandleIncreaseStake_NonInteractive_Success(t *testing.T) {
205205
origNonInteractive := flagNonInteractive
206206
origNoColor := flagNoColor
207207
origNoEmoji := flagNoEmoji
208+
origYes := flagYes
208209
defer func() {
209210
flagOutput = origOutput
210211
flagNonInteractive = origNonInteractive
211212
flagNoColor = origNoColor
212213
flagNoEmoji = origNoEmoji
214+
flagYes = origYes
213215
}()
214216
flagOutput = "json"
215217
flagNonInteractive = true
216218
flagNoColor = true
217219
flagNoEmoji = true
220+
flagYes = true
218221

219222
runner := newMockRunner()
220223
binPath := findPchaind()
@@ -250,16 +253,19 @@ func TestHandleIncreaseStake_NonInteractive_DelegationFails(t *testing.T) {
250253
origNonInteractive := flagNonInteractive
251254
origNoColor := flagNoColor
252255
origNoEmoji := flagNoEmoji
256+
origYes := flagYes
253257
defer func() {
254258
flagOutput = origOutput
255259
flagNonInteractive = origNonInteractive
256260
flagNoColor = origNoColor
257261
flagNoEmoji = origNoEmoji
262+
flagYes = origYes
258263
}()
259264
flagOutput = "json"
260265
flagNonInteractive = true
261266
flagNoColor = true
262267
flagNoEmoji = true
268+
flagYes = true
263269

264270
runner := newMockRunner()
265271
binPath := findPchaind()
@@ -297,16 +303,19 @@ func TestHandleIncreaseStake_NonInteractive_TextSuccess(t *testing.T) {
297303
origNonInteractive := flagNonInteractive
298304
origNoColor := flagNoColor
299305
origNoEmoji := flagNoEmoji
306+
origYes := flagYes
300307
defer func() {
301308
flagOutput = origOutput
302309
flagNonInteractive = origNonInteractive
303310
flagNoColor = origNoColor
304311
flagNoEmoji = origNoEmoji
312+
flagYes = origYes
305313
}()
306314
flagOutput = "text"
307315
flagNonInteractive = true
308316
flagNoColor = true
309317
flagNoEmoji = true
318+
flagYes = true
310319

311320
runner := newMockRunner()
312321
binPath := findPchaind()
@@ -341,16 +350,19 @@ func TestHandleIncreaseStake_NonInteractive_KeyDerivationFallback(t *testing.T)
341350
origNonInteractive := flagNonInteractive
342351
origNoColor := flagNoColor
343352
origNoEmoji := flagNoEmoji
353+
origYes := flagYes
344354
defer func() {
345355
flagOutput = origOutput
346356
flagNonInteractive = origNonInteractive
347357
flagNoColor = origNoColor
348358
flagNoEmoji = origNoEmoji
359+
flagYes = origYes
349360
}()
350361
flagOutput = "json"
351362
flagNonInteractive = true
352363
flagNoColor = true
353364
flagNoEmoji = true
365+
flagYes = true
354366

355367
runner := newMockRunner()
356368
binPath := findPchaind()
@@ -617,16 +629,19 @@ func TestHandleIncreaseStake_NonInteractive_DelegationFails_Text(t *testing.T) {
617629
origNonInteractive := flagNonInteractive
618630
origNoColor := flagNoColor
619631
origNoEmoji := flagNoEmoji
632+
origYes := flagYes
620633
defer func() {
621634
flagOutput = origOutput
622635
flagNonInteractive = origNonInteractive
623636
flagNoColor = origNoColor
624637
flagNoEmoji = origNoEmoji
638+
flagYes = origYes
625639
}()
626640
flagOutput = "text"
627641
flagNonInteractive = true
628642
flagNoColor = true
629643
flagNoEmoji = true
644+
flagYes = true
630645

631646
runner := newMockRunner()
632647
binPath := findPchaind()

cmd/push-validator/cmd_register.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ var flagRegisterCheckOnly bool
242242
// handleRegisterValidator is the main entry point for registration.
243243
// It prompts interactively for moniker and key name if not set via env vars.
244244
func handleRegisterValidator(d *Deps) error {
245+
if err := checkNodeRunning(d.Sup); err != nil {
246+
return err
247+
}
248+
245249
cfg := d.Cfg
246250
// Get defaults from env or use hardcoded fallbacks
247251
defaultMoniker := getenvDefault("MONIKER", "push-validator")

cmd/push-validator/cmd_restake.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
// - submit delegation transaction
2222
// - display results
2323
func handleRestakeRewardsAll(d *Deps) error {
24+
if err := checkNodeRunning(d.Sup); err != nil {
25+
return err
26+
}
27+
2428
p := getPrinter()
2529
cfg := d.Cfg
2630

cmd/push-validator/cmd_start.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ func handlePostStartFlow(cfg config.Config, p *ui.Printer) bool {
293293
// Show status checking message
294294
fmt.Println(p.Colors.Info("▸ Checking Validator Status"))
295295

296-
// Give the node a moment to fully initialize RPC after sync check
297-
time.Sleep(2 * time.Second)
298-
299296
valResult := checkValidatorRegistration(v, 2)
300297

301298
if valResult.Error != nil {
@@ -378,6 +375,8 @@ func (prodDashboardRunner) Run(cfg config.Config) error {
378375
NoEmoji: flagNoEmoji,
379376
CLIVersion: Version,
380377
Debug: false,
378+
Supervisor: newSupervisor(cfg.HomeDir),
379+
BinPath: findPchaind(),
381380
}
382381
return runDashboardInteractive(opts)
383382
}

cmd/push-validator/cmd_status.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,22 @@ func computeStatus(d *Deps) statusResult {
206206
}
207207
}
208208

209+
// If validator info wasn't fetched (node stopped / RPC down), try via remote RPC
210+
if !res.IsValidator && res.ValidatorMoniker == "" {
211+
valCtx, valCancel := context.WithTimeout(context.Background(), 3*time.Second)
212+
myVal, _ := d.Fetcher.GetMyValidator(valCtx, cfg)
213+
valCancel()
214+
res.IsValidator = myVal.IsValidator
215+
if myVal.IsValidator {
216+
res.ValidatorMoniker = myVal.Moniker
217+
res.VotingPower = myVal.VotingPower
218+
res.VotingPct = myVal.VotingPct
219+
res.Commission = myVal.Commission
220+
res.ValidatorStatus = myVal.Status
221+
res.IsJailed = myVal.Jailed
222+
}
223+
}
224+
209225
// Fetch binary version (best-effort)
210226
res.BinaryVer = getBinaryVersion(cfg)
211227

@@ -263,7 +279,7 @@ func printStatusText(result statusResult) {
263279
}
264280

265281
syncIcon := c.StatusIcon("offline")
266-
syncVal := "N/A"
282+
syncVal := "Stopped"
267283
if result.RPCListening {
268284
if result.CatchingUp {
269285
syncIcon = c.StatusIcon("syncing")

cmd/push-validator/cmd_sync.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ func init() {
9898
syncRemote = cfg.RemoteRPCURL()
9999
}
100100
sup := newSupervisor(cfg.HomeDir)
101+
if err := checkNodeRunning(sup); err != nil {
102+
return err
103+
}
101104
return runSyncCore(cmd.Context(), prodSyncRunner{}, syncCoreOpts{
102105
rpc: syncRPC,
103106
remote: syncRemote,

cmd/push-validator/cmd_unjail.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
// - submit unjail transaction
1919
// - display results
2020
func handleUnjail(d *Deps) error {
21+
if err := checkNodeRunning(d.Sup); err != nil {
22+
return err
23+
}
24+
2125
p := getPrinter()
2226
cfg := d.Cfg
2327

cmd/push-validator/cmd_withdraw_rewards.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
// - submit withdraw transaction
2020
// - display results
2121
func handleWithdrawRewards(d *Deps) error {
22+
if err := checkNodeRunning(d.Sup); err != nil {
23+
return err
24+
}
25+
2226
p := getPrinter()
2327
cfg := d.Cfg
2428

cmd/push-validator/helpers.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ func newSupervisor(homeDir string) process.Supervisor {
2121
return process.NewCosmovisor(homeDir)
2222
}
2323

24+
// silentErr wraps an error that has already been displayed to the user.
25+
// Execute() checks for this type and skips re-printing.
26+
type silentErr struct{ error }
27+
28+
func (e silentErr) Unwrap() error { return e.error }
29+
30+
// checkNodeRunning verifies the node is running and prints a user-friendly
31+
// error if not. Returns a silentErr so the message is not repeated.
32+
func checkNodeRunning(sup process.Supervisor) error {
33+
if sup.IsRunning() {
34+
return nil
35+
}
36+
if flagOutput == "json" {
37+
getPrinter().JSON(map[string]any{"ok": false, "error": "node is not running"})
38+
} else {
39+
p := getPrinter()
40+
fmt.Println()
41+
fmt.Println(p.Colors.Error(p.Colors.Emoji("⚠️") + " Node is not running"))
42+
fmt.Println()
43+
fmt.Println(p.Colors.Info("Start the node with:"))
44+
fmt.Println(p.Colors.Apply(p.Colors.Theme.Command, " push-validator start"))
45+
fmt.Println()
46+
}
47+
return silentErr{fmt.Errorf("node is not running")}
48+
}
49+
2450
// findPchaind returns the path to the pchaind binary, resolving
2551
// either --bin flag, PCHAIND or PCHAIN_BIN environment variables, checking the
2652
// cosmovisor genesis directory, or falling back to PATH lookup.

0 commit comments

Comments
 (0)