Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
b3417a3
feature: push node manager
mohammeds1992 Aug 12, 2025
8fa24b7
fix: nginx tests
mohammeds1992 Aug 12, 2025
f67d8a4
fix: ubuntu error fix for netcat
mohammeds1992 Aug 12, 2025
11544d5
Update README.md
mohammeds1992 Aug 12, 2025
dc9f910
fix: virtual python env
mohammeds1992 Aug 12, 2025
f688c71
Update setup-dependencies.sh
mohammeds1992 Aug 13, 2025
0843919
fixes
mohammeds1992 Aug 13, 2025
80ce768
fixes
mohammeds1992 Aug 13, 2025
3aeb70a
Update install.sh
mohammeds1992 Aug 13, 2025
abf70ac
fixes
mohammeds1992 Aug 13, 2025
98fc8e0
Update setup-dependencies.sh
mohammeds1992 Aug 13, 2025
fab1368
log fixes
mohammeds1992 Aug 13, 2025
1df14da
Update install.sh
mohammeds1992 Aug 13, 2025
8222d4c
Update setup-dependencies.sh
mohammeds1992 Aug 13, 2025
1e6ecde
fixes
mohammeds1992 Aug 13, 2025
d1ba0c5
fixes
mohammeds1992 Aug 13, 2025
8f56fdd
Update install.sh
mohammeds1992 Aug 13, 2025
54c710e
Update install.sh
mohammeds1992 Aug 13, 2025
4038ef2
Update install.sh
mohammeds1992 Aug 13, 2025
7e739e6
Update install.sh
mohammeds1992 Aug 13, 2025
27e6df2
fixes
mohammeds1992 Aug 13, 2025
0d924b5
Update push-node-manager
mohammeds1992 Aug 13, 2025
ed5be7b
Update push-node-manager
mohammeds1992 Aug 13, 2025
5b0d664
Update push-node-manager
mohammeds1992 Aug 13, 2025
b52697f
Update push-node-manager
mohammeds1992 Aug 13, 2025
b0b9af2
Update push-node-manager
mohammeds1992 Aug 13, 2025
a323fcc
Update push-node-manager
mohammeds1992 Aug 14, 2025
22a736f
fix: updated push-validator-manger from push-node-manager
mohammeds1992 Sep 3, 2025
d342611
fix: reduce logs clutter
mohammeds1992 Sep 3, 2025
99dd4c7
fix: more logs cleanup
mohammeds1992 Sep 3, 2025
3f1302a
fix: flicker issue
mohammeds1992 Sep 3, 2025
389a412
fix: flicker issue
mohammeds1992 Sep 3, 2025
24007b2
fix: reset data
mohammeds1992 Sep 4, 2025
82bb4a4
Update install.sh
mohammeds1992 Sep 4, 2025
2c5e6a5
fixes
mohammeds1992 Sep 4, 2025
e4d1678
fix: logging fixes
mohammeds1992 Sep 4, 2025
cf0b89a
feature: ws logic to block sync
mohammeds1992 Sep 4, 2025
cefe15d
fix: wscat auto install
mohammeds1992 Sep 4, 2025
3d1e989
fix: remove brew logs
mohammeds1992 Sep 4, 2025
1fe9f6b
fix: progress bar logic
mohammeds1992 Sep 4, 2025
8a8ee3a
fix: status check
mohammeds1992 Sep 4, 2025
4a90dce
fix: progress bar fixes
mohammeds1992 Sep 4, 2025
37dfd87
fix: more fixes
mohammeds1992 Sep 4, 2025
65524e8
fix: progress bar issues
mohammeds1992 Sep 4, 2025
334a19c
fix: pchaind fix
mohammeds1992 Sep 4, 2025
c681e8d
fix: start pchaind in background fix
mohammeds1992 Sep 4, 2025
2898863
fix: added daemon launcher
mohammeds1992 Sep 4, 2025
d4ad313
fix: log fixes
mohammeds1992 Sep 4, 2025
41f475c
fix: add state sync functionality
mohammeds1992 Sep 15, 2025
5441f6c
fix: read me fixes
mohammeds1992 Sep 15, 2025
8254497
fix: variable fix
mohammeds1992 Sep 15, 2025
9579533
fix: few code fixes
mohammeds1992 Sep 15, 2025
b826062
fix: minor sed fixes
mohammeds1992 Sep 15, 2025
77fa964
fixes
mohammeds1992 Sep 15, 2025
b921e63
fix: installer fixes
mohammeds1992 Sep 15, 2025
6a57835
fix: prevent installer hanging during node start with state sync
mohammeds1992 Sep 15, 2025
5a5b214
Update install.sh
mohammeds1992 Sep 15, 2025
5133630
Update push-validator-manager
mohammeds1992 Sep 15, 2025
cfef217
Update install.sh
mohammeds1992 Sep 15, 2025
96780b0
fix: more fixes
mohammeds1992 Sep 15, 2025
a64b914
Update install.sh
mohammeds1992 Sep 15, 2025
cb8ae7d
Update push-validator-manager
mohammeds1992 Sep 15, 2025
bda4411
Update push-validator-manager
mohammeds1992 Sep 15, 2025
2c2e1aa
fix: state sync progress bar
mohammeds1992 Sep 15, 2025
380a195
Update install.sh
mohammeds1992 Sep 15, 2025
4d99e4d
Update install.sh
mohammeds1992 Sep 15, 2025
62df99d
fixes
mohammeds1992 Sep 15, 2025
495abdf
Update install.sh
mohammeds1992 Sep 15, 2025
70a869f
fixes
mohammeds1992 Sep 15, 2025
21353c9
Update install.sh
mohammeds1992 Sep 15, 2025
37d7d87
fixes
mohammeds1992 Sep 15, 2025
1e18434
Update install.sh
mohammeds1992 Sep 15, 2025
bdb9538
Update install.sh
mohammeds1992 Sep 15, 2025
dfb8fb7
fixes
mohammeds1992 Sep 15, 2025
f29bc2b
feat: add extensive debug logging to diagnose installer startup issue
mohammeds1992 Sep 15, 2025
be15ed7
fix: redirect pchaind init output to stderr to maintain pipe connection
mohammeds1992 Sep 15, 2025
d69c30c
fix: add --overwrite flag to pchaind init to handle existing genesis.…
mohammeds1992 Sep 15, 2025
d668344
fix: state sync progress calculation and remove debug logs
mohammeds1992 Sep 15, 2025
a8dff55
fix: improve state sync progress calculation
mohammeds1992 Sep 15, 2025
4c4b878
fix: show actual state sync progress instead of phase-divided progress
mohammeds1992 Sep 15, 2025
e085ca0
Update push-validator-manager
mohammeds1992 Sep 15, 2025
cc70c38
Update push-validator-manager
mohammeds1992 Sep 15, 2025
183ecd0
Update push-validator-manager
mohammeds1992 Sep 15, 2025
48c315f
Update push-validator-manager
mohammeds1992 Sep 15, 2025
8dcebb2
Update push-validator-manager
mohammeds1992 Sep 15, 2025
77bd911
Update push-validator-manager
mohammeds1992 Sep 15, 2025
556365e
Update push-validator-manager
mohammeds1992 Sep 15, 2025
dc09baa
Update push-validator-manager
mohammeds1992 Sep 15, 2025
3408946
Update push-validator-manager
mohammeds1992 Sep 15, 2025
e797eba
Update push-validator-manager
mohammeds1992 Sep 15, 2025
28c23af
Update push-validator-manager
mohammeds1992 Sep 15, 2025
36f9493
Update push-validator-manager
mohammeds1992 Sep 15, 2025
a21e234
Update push-validator-manager
mohammeds1992 Sep 15, 2025
ef0775e
Update push-validator-manager
mohammeds1992 Sep 15, 2025
1a736f3
fixes
mohammeds1992 Sep 15, 2025
320d417
Update install.sh
mohammeds1992 Sep 15, 2025
0525567
Update push-validator-manager
mohammeds1992 Sep 15, 2025
db2431c
Update push-validator-manager
mohammeds1992 Sep 15, 2025
ee49ac3
fixes
mohammeds1992 Sep 15, 2025
c8235dd
Update push-validator-manager
mohammeds1992 Sep 15, 2025
6a39770
fix: remove fallback monitoring and restore detect_state_sync_phase f…
mohammeds1992 Sep 15, 2025
65a6c9f
fix: prevent SYNC_COMPLETE from being reset after state sync
mohammeds1992 Sep 15, 2025
8dffe5f
fix: make monitor-state-sync exit after sync completes
mohammeds1992 Sep 15, 2025
47ede71
fix: use catching_up API field to detect sync completion
mohammeds1992 Sep 15, 2025
30ace68
fix: initialize SYNC_COMPLETE variable to prevent unbound error
mohammeds1992 Sep 15, 2025
ecc2573
fix: prevent premature exit when checking catching_up before state sy…
mohammeds1992 Sep 15, 2025
c56f20b
fix: ensure monitor exits all loops when sync completes
mohammeds1992 Sep 15, 2025
f304ecf
fix: remove 'Fetching network height' message display
mohammeds1992 Sep 15, 2025
c47dd66
Update push-validator-manager
mohammeds1992 Sep 15, 2025
963e829
Update push-validator-manager
mohammeds1992 Sep 15, 2025
62134b2
Update push-validator-manager
mohammeds1992 Sep 15, 2025
6fd8692
fix: remove subshells from monitor_sync_auto to fix exit issue
mohammeds1992 Sep 15, 2025
658a44e
fix: make monitor_sync exit when node is synced in state sync mode
mohammeds1992 Sep 15, 2025
b7ff85f
Update install.sh
mohammeds1992 Sep 15, 2025
04d6bee
fix: cleanup background process when WebSocket monitor falls back
mohammeds1992 Sep 15, 2025
8bb6b11
fix: initialize LOCAL_HEIGHT with actual node height to show correct …
mohammeds1992 Sep 15, 2025
df1c17c
Update push-validator-manager
mohammeds1992 Sep 15, 2025
55a4f58
Update push-validator-manager
mohammeds1992 Sep 15, 2025
7364471
Update push-validator-manager
mohammeds1992 Sep 15, 2025
b62dffd
Update push-validator-manager
mohammeds1992 Sep 15, 2025
ae9d43a
fixes
mohammeds1992 Sep 15, 2025
8634c5f
Update install.sh
mohammeds1992 Sep 15, 2025
ca959fa
Update install.sh
mohammeds1992 Sep 15, 2025
73b66e7
fixes
mohammeds1992 Sep 15, 2025
e6c73e4
Update install.sh
mohammeds1992 Sep 15, 2025
8013c14
fix: more cleanup
mohammeds1992 Sep 15, 2025
735d449
Update push-validator-manager
mohammeds1992 Sep 15, 2025
e51b366
Update install.sh
mohammeds1992 Sep 15, 2025
42985c7
fixes
mohammeds1992 Sep 15, 2025
d2d6e65
Update register-validator.sh
mohammeds1992 Sep 16, 2025
0c6f5ca
fixes
mohammeds1992 Sep 16, 2025
3f0e386
Update install.sh
mohammeds1992 Sep 16, 2025
2532f02
Update install.sh
mohammeds1992 Sep 16, 2025
3f21937
fixes
mohammeds1992 Sep 16, 2025
5157754
fix: clean UX
mohammeds1992 Sep 16, 2025
62543a3
fix: more fixes
mohammeds1992 Sep 16, 2025
500b5ad
Update install.sh
mohammeds1992 Sep 16, 2025
9b30526
Update install.sh
mohammeds1992 Sep 16, 2025
a549e47
Update install.sh
mohammeds1992 Sep 16, 2025
eee59f4
Update install.sh
mohammeds1992 Sep 16, 2025
d69c135
Update install.sh
mohammeds1992 Sep 16, 2025
286bc8e
Update register-validator.sh
mohammeds1992 Sep 16, 2025
152535e
feat: go implementation
mohammeds1992 Sep 17, 2025
d4a4fb9
fix: cleanup and cmd fixes
mohammeds1992 Sep 17, 2025
16c292b
fix: validator UX changes
mohammeds1992 Sep 17, 2025
92b48cd
fix: UI fixes
mohammeds1992 Sep 17, 2025
f5965bd
Merge branch 'feat/universal-validator' into feature/pnm
mohammeds1992 Sep 17, 2025
1f599bd
Merge branch 'main' into feature/pnm
mohammeds1992 Oct 8, 2025
9970ee1
fix: polish pnm
mohammeds1992 Oct 8, 2025
3212185
fix: log viewer fixes
mohammeds1992 Oct 9, 2025
a302811
fix: more fixes related to help
mohammeds1992 Oct 9, 2025
6c1b275
fix: more fixes
mohammeds1992 Oct 9, 2025
925db27
fix: add more fixes
mohammeds1992 Oct 9, 2025
fc2ad19
fix: install.sh fixes
mohammeds1992 Oct 9, 2025
ed9a7e7
fix: admin fixes
mohammeds1992 Oct 9, 2025
39d51a6
Update install.sh
mohammeds1992 Oct 9, 2025
f68725c
fix: bug fixes
mohammeds1992 Oct 9, 2025
ee7c51c
Update install.sh
mohammeds1992 Oct 9, 2025
9bf85f0
fix: add footer message when stopping logs in non-interactive mode
mohammeds1992 Oct 9, 2025
5a472a9
fix: enable interactive logs for remote installer by checking stderr TTY
mohammeds1992 Oct 9, 2025
997f336
fix: use /dev/tty for interactive detection in remote installer
mohammeds1992 Oct 9, 2025
1158709
fixes
mohammeds1992 Oct 9, 2025
f75cd61
Update cmd_register.go
mohammeds1992 Oct 9, 2025
336d64f
Update install.sh
mohammeds1992 Oct 9, 2025
37f6d04
fixes
mohammeds1992 Oct 9, 2025
1575bd2
fix: testing bug fixes
mohammeds1992 Oct 9, 2025
6699387
Update logtui_v2.go
mohammeds1992 Oct 9, 2025
44506f6
fixes
mohammeds1992 Oct 9, 2025
9c2e9b8
fix: added read me file
mohammeds1992 Oct 9, 2025
4c5df76
fix: advanced setup
mohammeds1992 Oct 9, 2025
f21177c
fix: log fixes
mohammeds1992 Oct 10, 2025
5bffab5
Merge branch 'main' into feature/pnm
mohammeds1992 Oct 10, 2025
e5f3b7f
fix: eta fixes
mohammeds1992 Oct 11, 2025
be848a7
error handling
mohammeds1992 Oct 11, 2025
1d2c79e
Update install.sh
mohammeds1992 Oct 11, 2025
bf31fb2
Update monitor.go
mohammeds1992 Oct 11, 2025
a5a5564
fix: dashboard implementation
mohammeds1992 Oct 13, 2025
82d5941
Merge branch 'main' into feature/pnm
mohammeds1992 Oct 17, 2025
987221e
fix: dashboard changes
mohammeds1992 Oct 18, 2025
ceb4613
fixes
mohammeds1992 Oct 18, 2025
1af9da6
fixes
mohammeds1992 Oct 18, 2025
ccb6ecb
Update install.sh
mohammeds1992 Oct 18, 2025
566263b
fix: logs viewer, pagination to validators
mohammeds1992 Oct 19, 2025
19ee2b8
fixes
mohammeds1992 Oct 21, 2025
01de801
fixes
mohammeds1992 Oct 22, 2025
f12060c
fixes
mohammeds1992 Oct 22, 2025
0faf709
Update dashboard.go
mohammeds1992 Oct 22, 2025
ab601f2
Update dashboard.go
mohammeds1992 Oct 22, 2025
0700489
fix: deleted older version of push-validator-manager
mohammeds1992 Oct 27, 2025
fbb99c7
fix: folder name simplification and command simplification
mohammeds1992 Oct 27, 2025
be2851d
fix: UX issues
mohammeds1992 Oct 27, 2025
b81bc47
fix: Resolve memory issue in push-validator status command
mohammeds1992 Oct 27, 2025
9d21519
fix: Resolve memory issue in push-validator status command
mohammeds1992 Oct 27, 2025
e58efd7
fix: Resolve memory issue in push-validator status command
mohammeds1992 Oct 27, 2025
8f1e48d
fixes
mohammeds1992 Oct 27, 2025
0ec0185
feat: Show initialization progress logs in push-validator start
mohammeds1992 Oct 27, 2025
6313842
feat: Show sync completion status in push-validator start output
mohammeds1992 Oct 27, 2025
2fb2166
fixes
mohammeds1992 Oct 28, 2025
1f73312
fixes
mohammeds1992 Oct 28, 2025
f929a24
Update app.go
mohammeds1992 Oct 28, 2025
1b5bc5d
fixes
mohammeds1992 Oct 28, 2025
8d590fd
Update README.md
mohammeds1992 Oct 28, 2025
8eb8764
fixes
mohammeds1992 Oct 28, 2025
fd2c927
Merge branch 'main' into feature/pnm
mohammeds1992 Oct 30, 2025
a2be313
fixes
mohammeds1992 Oct 30, 2025
8b134dd
Update install.sh
mohammeds1992 Oct 30, 2025
2c5db55
Update install.sh
mohammeds1992 Oct 30, 2025
682d62b
Update install.sh
mohammeds1992 Oct 30, 2025
8dede69
Update install.sh
mohammeds1992 Oct 30, 2025
306f131
fixes
mohammeds1992 Oct 30, 2025
82b6ec8
Update .gitignore
mohammeds1992 Oct 30, 2025
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
129 changes: 129 additions & 0 deletions push-validator-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Push Validator Manager

**Fast validator setup for Push Chain**

## 🚀 Quick Start (1-2 minutes)

### Step 1: Install & Start
```bash
curl -fsSL https://get.push.network/node/install.sh | bash
```
Automatically installs and starts your validator using state sync (no full sync needed).

> **Note:** Restart terminal or run `source ~/.bashrc` to use `push-validator` from anywhere.

### Step 2: Verify Sync
```bash
push-validator status
```
Wait for: `✅ Catching Up: false` (takes ~1-2 minutes with state sync)

### Step 3: Register Validator
```bash
push-validator register-validator
```
**Requirements:** 2+ PC tokens from [faucet](https://faucet.push.org)

**Done! Your validator is running with automatic recovery enabled! 🎉**

## 📊 Dashboard

Monitor your validator in real-time with an interactive dashboard:

```bash
push-validator dashboard
```

**Features:**
- **Node Status** - Process state, RPC connectivity, resource usage (CPU, memory, disk)
- **Chain Sync** - Real-time block height, sync progress with ETA, network latency
- **Validator Metrics** - Bonding status, voting power, commission rate, accumulated rewards
- **Network Overview** - Connected peers, chain ID, active validators list
- **Live Logs** - Stream node activity with search and filtering
- **Auto-Refresh** - Updates every 2 seconds for real-time monitoring

The dashboard provides everything you need to monitor validator health and performance at a glance.

## 📖 Commands

### Core
```bash
push-validator start # Start with state sync (2-3 min)
push-validator stop # Stop node
push-validator status # Check sync & validator status
push-validator dashboard # Live interactive monitoring dashboard
push-validator register-validator # Register as validator
push-validator logs # View logs
```

### Validator Operations
```bash
push-validator increase-stake # Increase validator stake and voting power
push-validator unjail # Restore jailed validator to active status
push-validator withdraw-rewards # Withdraw validator rewards and commission
push-validator restake # Auto-withdraw and restake all rewards to increase validator power
```

### Monitoring
```bash
push-validator sync # Monitor sync progress
push-validator peers # Show peer connections (from local RPC)
push-validator doctor # Run diagnostic checks on validator setup
```

### Management
```bash
push-validator restart # Restart node
push-validator validators # List validators (supports --output json)
push-validator balance # Check balance (defaults to validator key)
push-validator reset # Reset chain data (keeps address book)
push-validator full-reset # ⚠️ Complete reset (deletes ALL keys and data)
push-validator backup # Backup config and validator state
```

## ⚡ Features

- **State Sync**: 1-2 minute setup (no full blockchain download)
- **Interactive Logs**: Real-time log viewer with search and filtering
- **Smart Detection**: Monitors for sync stalls and network issues
- **Reliable Snapshots**: Uses trusted RPC nodes for recovery
- **Multiple Outputs**: JSON, YAML, or text format support

## 📊 Network

- **Chain**: `push_42101-1` (Testnet)
- **Min Stake**: 1.5 PC
- **Faucet**: https://faucet.push.org
- **Explorer**: https://donut.push.network


## 🔧 Advanced Setup (Optional)

### Setup NGINX with SSL
```bash
bash scripts/setup-nginx.sh yourdomain.com
```
**Creates:**
- `https://yourdomain.com` - Cosmos RPC endpoint
- `https://evm.yourdomain.com` - EVM RPC endpoint
- Automatic SSL certificates via Let's Encrypt
- Rate limiting and security headers

**Requirements:**
- Domain pointing to your server IP
- Ports 80/443 open
- Ubuntu/Debian system

### Log Rotation
```bash
bash scripts/setup-log-rotation.sh
```
Configures daily rotation with 14-day retention and compression.

### File Locations
- **Manager**: `~/.local/bin/push-validator`
- **Binary**: `~/.local/bin/pchaind`
- **Config**: `~/.pchain/config/`
- **Data**: `~/.pchain/data/`
- **Logs**: `~/.pchain/logs/pchaind.log`
- **Backups**: `~/push-node-backups/`
20 changes: 20 additions & 0 deletions push-validator-manager/cmd/push-validator/cmd_backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"fmt"

"github.com/pushchain/push-chain-node/push-validator-manager/internal/admin"
"github.com/pushchain/push-chain-node/push-validator-manager/internal/config"
)

// handleBackup creates a backup archive of the node configuration and
// prints the resulting path, or a JSON object when --output=json.
func handleBackup(cfg config.Config) error {
path, err := admin.Backup(admin.BackupOptions{HomeDir: cfg.HomeDir})
if err != nil {
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": false, "error": err.Error()}) } else { getPrinter().Error(fmt.Sprintf("backup error: %v", err)) }
return err
}
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": true, "backup_path": path}) } else { getPrinter().Success(fmt.Sprintf("backup created: %s", path)) }
return nil
}
55 changes: 55 additions & 0 deletions push-validator-manager/cmd/push-validator/cmd_balance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"context"
"fmt"
"os"
"os/exec"
"strings"
"time"

"github.com/pushchain/push-chain-node/push-validator-manager/internal/config"
"github.com/pushchain/push-chain-node/push-validator-manager/internal/validator"
)

// handleBalance prints an account balance. It resolves the address from
// either a positional argument or KEY_NAME when --address/arg is omitted.
// When --output=json is set, it emits a structured object.
func handleBalance(cfg config.Config, args []string) error {
var addr string
if len(args) > 0 { addr = args[0] }
if addr == "" {
key := os.Getenv("KEY_NAME")
if key == "" {
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": false, "error": "address not provided; set KEY_NAME or pass --address"}) } else { fmt.Println("usage: push-validator balance <address> (or set KEY_NAME)") }
return fmt.Errorf("address not provided")
}
out, err := exec.Command(findPchaind(), "keys", "show", key, "-a", "--keyring-backend", cfg.KeyringBackend, "--home", cfg.HomeDir).Output()
if err != nil {
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": false, "error": err.Error()}) } else { fmt.Printf("resolve address error: %v\n", err) }
return fmt.Errorf("resolve address: %w", err)
}
addr = strings.TrimSpace(string(out))
}

// Convert hex address (0x...) to bech32 if needed
if strings.HasPrefix(addr, "0x") || strings.HasPrefix(addr, "0X") {
bech32Addr, convErr := hexToBech32Address(addr)
if convErr != nil {
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": false, "error": convErr.Error(), "address": addr}) } else { getPrinter().Error(fmt.Sprintf("address conversion error: %v", convErr)) }
return convErr
}
addr = bech32Addr
}

v := validator.NewWith(validator.Options{BinPath: findPchaind(), HomeDir: cfg.HomeDir, ChainID: cfg.ChainID, Keyring: cfg.KeyringBackend, GenesisDomain: cfg.GenesisDomain, Denom: cfg.Denom})
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
bal, err := v.Balance(ctx, addr)
if err != nil {
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": false, "error": err.Error(), "address": addr}) } else { getPrinter().Error(fmt.Sprintf("balance error: %v", err)) }
return err
}
if flagOutput == "json" { getPrinter().JSON(map[string]any{"ok": true, "address": addr, "balance": bal, "denom": cfg.Denom}) } else { getPrinter().Info(fmt.Sprintf("%s %s", bal, cfg.Denom)) }
return nil
}
157 changes: 157 additions & 0 deletions push-validator-manager/cmd/push-validator/cmd_dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package main

import (
"context"
"fmt"
"os"
"strings"
"time"

tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
"golang.org/x/term"

"github.com/pushchain/push-chain-node/push-validator-manager/internal/dashboard"
)

// dashboardCmd provides an interactive TUI dashboard for monitoring validator status
func createDashboardCmd() *cobra.Command {
var (
refreshInterval time.Duration
rpcTimeout time.Duration
debugMode bool
)

cmd := &cobra.Command{
Use: "dashboard",
Short: "Interactive dashboard for monitoring validator status",
Long: `Launch an interactive terminal dashboard showing real-time validator metrics:

• Node process status (running/stopped, PID, version)
• Chain sync progress with ETA calculation
• Network connectivity (peers, latency)
• Validator consensus power and status

The dashboard auto-refreshes every 2 seconds by default. Press '?' for help.

For non-interactive environments (CI/pipes), dashboard automatically falls back
to a static text snapshot.`,
RunE: func(cmd *cobra.Command, args []string) error {
// Load configuration
cfg := loadCfg()

// Build dashboard options
opts := dashboard.Options{
Config: cfg,
RefreshInterval: refreshInterval,
RPCTimeout: rpcTimeout,
NoColor: flagNoColor,
NoEmoji: flagNoEmoji,
Debug: debugMode,
}
opts = normalizeDashboardOptions(opts)

// Check if we're in a TTY environment
isTTY := term.IsTerminal(int(os.Stdout.Fd()))

if !isTTY {
// Non-TTY environment (CI/pipes): use static mode
if debugMode {
fmt.Fprintln(os.Stderr, "Debug: Non-TTY detected, using static mode")
}
return runDashboardStatic(cmd.Context(), opts)
}

// TTY environment: use interactive Bubble Tea dashboard
if debugMode {
fmt.Fprintln(os.Stderr, "Debug: TTY detected, using interactive mode")
}
return runDashboardInteractive(opts)
},
}

// Flags
cmd.Flags().DurationVar(&refreshInterval, "refresh-interval", 2*time.Second, "Dashboard refresh interval")
cmd.Flags().DurationVar(&rpcTimeout, "rpc-timeout", 15*time.Second, "RPC request timeout")
cmd.Flags().BoolVar(&debugMode, "debug", false, "Enable debug mode for troubleshooting")

return cmd
}

// runDashboardStatic performs a single fetch and prints static output for non-TTY
func runDashboardStatic(ctx context.Context, opts dashboard.Options) error {
// Print debug info BEFORE dashboard output
if opts.Debug {
fmt.Fprintln(os.Stderr, "Debug: Starting dashboard...")
fmt.Fprintf(os.Stderr, "Debug: Config loaded - HomeDir: %s, RPC: %s\n", opts.Config.HomeDir, opts.Config.RPCLocal)
fmt.Fprintln(os.Stderr, "Debug: Running in static mode")
fmt.Fprintln(os.Stderr, "---") // Separator
}

d := dashboard.New(opts)

// Apply RPC timeout to context (prevents hung RPCs in CI/pipes)
ctx, cancel := context.WithTimeout(ctx, opts.RPCTimeout)
defer cancel()

// Fetch data once with timeout
data, err := d.FetchDataOnce(ctx)
if err != nil {
return fmt.Errorf("failed to fetch dashboard data: %w", err)
}

// Render static text snapshot to stdout
fmt.Print(d.RenderStatic(data))
return nil
}

// runDashboardInteractive launches the Bubble Tea TUI program
func runDashboardInteractive(opts dashboard.Options) error {
d := dashboard.New(opts)
if d == nil {
return fmt.Errorf("failed to create dashboard instance")
}

// Create Bubble Tea program with proper TTY configuration
// Key fix: Use stdin/stdout explicitly instead of /dev/tty
p := tea.NewProgram(
d,
tea.WithAltScreen(), // Use alternate screen buffer (clean display)
tea.WithInput(os.Stdin), // Use stdin instead of trying to open /dev/tty
tea.WithOutput(os.Stdout), // Use stdout instead of trying to open /dev/tty
)

// Run program - blocks until quit
if _, err := p.Run(); err != nil {
// If TTY error, fall back to static mode
if strings.Contains(err.Error(), "tty") || strings.Contains(err.Error(), "device not configured") {
if opts.Debug {
fmt.Fprintf(os.Stderr, "Debug: TTY error, falling back to static mode: %v\n", err)
}
return runDashboardStatic(context.Background(), opts)
}
return fmt.Errorf("dashboard error: %w", err)
}

return nil
}

// normalizeDashboardOptions applies default refresh/timeout values to keep behaviour
// consistent between interactive and static dashboard modes.
func normalizeDashboardOptions(opts dashboard.Options) dashboard.Options {
if opts.RefreshInterval <= 0 {
opts.RefreshInterval = 2 * time.Second
}
if opts.RPCTimeout <= 0 {
// Default to 15s but cap at twice the refresh interval so the UI remains responsive.
timeout := 15 * time.Second
if opts.RefreshInterval > 0 {
candidate := 2 * opts.RefreshInterval
if candidate < timeout {
timeout = candidate
}
}
opts.RPCTimeout = timeout
}
return opts
}
Loading
Loading