# Validator bandwidth test

## Overview

| Check            | Purpose                                     |
| ---------------- | ------------------------------------------- |
| Download Speed   | Measures max download capacity (Mbps)       |
| Upload Speed     | Measures max upload capacity (Mbps)         |
| Interface Stats  | Shows current throughput on network adapter |
| RPC Connectivity | Tests latency to `rpc.mainnet.x1.xyz`       |
| Recommendations  | Analyzes if bandwidth meets validator needs |

***

## Requirements

### Official X1 Specifications

| Metric       | Minimum             | Recommended         | Notes                      |
| ------------ | ------------------- | ------------------- | -------------------------- |
| **Speed**    | 1 Gbps symmetric    | 10 Gbps symmetric   | Upload must equal download |
| **Type**     | Committed/sustained | Committed/sustained | NOT burst capacity         |
| **Data Cap** | Unmetered           | Unmetered           | No monthly limits          |
| **Latency**  | <20ms               | <5ms                | To RPC endpoints           |

### Real-World X1 Validator Usage

Based on production validators (Nov 2025):

* **Average usage**: 150-200 Mbps sustained
* **Peak usage**: 300-700 Mbps during high activity
* **Growth rate**: Doubling every 1-2 months
* **Network trend**: Approaching 1 Gbps per validator

**Bottom line**: 1 Gbps minimum today, plan for 10 Gbps within 6-12 months.

***

## ⚠️ CRITICAL: Committed vs Burst Bandwidth

### Common ISP Gotcha

**Your ISP might advertise "1 Gbps Unmetered" but actually provide:**

```
Port Speed:        1 Gbps (can burst to this temporarily)
Committed Rate:    200-500 Mbps (what you can sustain 24/7)
Billing:           95th percentile on committed rate
```

### How to Check

1. **Run this bandwidth test** — Shows maximum capacity
2. **Check your hosting provider's graphs** — Shows actual usage vs thresholds

**Example**: InterServer "1 Gbps Unmetered" was actually 200 Mbps committed with red thresholds at \~180-200 Mbps.

### Questions to Ask Your ISP

* "What is my **committed information rate (CIR)**?"
* "Is this **sustained** bandwidth or burst?"
* "What happens if my 95th percentile exceeds X Mbps?"
* "Can I sustain 500-1000 Mbps continuously?"

***

## Usage

1. Install dependencies:

   ```bash
   sudo apt update
   sudo apt install -y speedtest-cli bc curl ethtool
   ```
2. Copy the full script below into a file named `x1_bandwidth.sh`:

   ```bash
   nano x1_bandwidth.sh
   ```
3. Make it executable:

   ```bash
   chmod +x x1_bandwidth.sh
   ```
4. Run:

   ```bash
   ./x1_bandwidth.sh
   ```

***

## Full Script

```bash
#!/bin/bash
# === X1 Validator Bandwidth Test ===
# Tests download/upload speed, interface throughput, and RPC connectivity
# Author: X1 Labs / Xen Tzu

set -euo pipefail

echo "=============================================="
echo "🌐 X1 Validator Bandwidth Test"
echo "=============================================="
echo ""

# --- Check for speedtest-cli ---
if ! command -v speedtest-cli &> /dev/null; then
    echo "⚠️  speedtest-cli not found. Installing..."
    sudo apt update && sudo apt install -y speedtest-cli
    echo ""
fi

# --- Detect primary network interface ---
echo "🔹 Network Interface"
IFACE=$(ip route | grep default | awk '{print $5}' | head -1)
if [ -z "$IFACE" ]; then
    echo "⚠️  Could not detect network interface"
    IFACE="eth0"
fi
echo "   Interface: $IFACE"

# Get interface speed capability
LINK_SPEED=$(ethtool "$IFACE" 2>/dev/null | grep "Speed:" | awk '{print $2}' || echo "Unknown")
echo "   Link Speed: $LINK_SPEED"
echo ""

# --- Current Interface Throughput (5s sample) ---
echo "🔹 Current Throughput (5-second sample)"
echo "   Measuring live traffic on $IFACE..."

# Get initial bytes
RX1=$(cat /sys/class/net/"$IFACE"/statistics/rx_bytes)
TX1=$(cat /sys/class/net/"$IFACE"/statistics/tx_bytes)

sleep 5

# Get final bytes
RX2=$(cat /sys/class/net/"$IFACE"/statistics/rx_bytes)
TX2=$(cat /sys/class/net/"$IFACE"/statistics/tx_bytes)

# Calculate Mbps
RX_MBPS=$(awk "BEGIN {printf \"%.2f\", ($RX2 - $RX1) * 8 / 5 / 1000000}")
TX_MBPS=$(awk "BEGIN {printf \"%.2f\", ($TX2 - $TX1) * 8 / 5 / 1000000}")

echo "   Current Download: ${RX_MBPS} Mbps"
echo "   Current Upload: ${TX_MBPS} Mbps"
echo ""

# --- Speedtest (Maximum Capacity) ---
echo "🔹 Speedtest (Maximum Capacity)"
echo "   Testing connection speed (this takes ~30 seconds)..."

SPEEDTEST_OUTPUT=$(speedtest-cli --simple 2>&1)
PING=$(echo "$SPEEDTEST_OUTPUT" | grep "Ping:" | awk '{print $2}')
DOWNLOAD=$(echo "$SPEEDTEST_OUTPUT" | grep "Download:" | awk '{print $2}')
UPLOAD=$(echo "$SPEEDTEST_OUTPUT" | grep "Upload:" | awk '{print $2}')

echo "   Ping: ${PING} ms"
echo "   Download: ${DOWNLOAD} Mbps"
echo "   Upload: ${UPLOAD} Mbps"
echo ""

# --- RPC Connectivity ---
echo "🔹 RPC Connectivity"
echo "   Testing connection to rpc.mainnet.x1.xyz..."

RPC_START=$(date +%s%N)
RPC_STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 https://rpc.mainnet.x1.xyz || echo "000")
RPC_END=$(date +%s%N)
RPC_LATENCY=$(awk "BEGIN {printf \"%.3f\", ($RPC_END - $RPC_START) / 1000000}")

if [ "$RPC_STATUS" = "200" ] || [ "$RPC_STATUS" = "405" ]; then
    echo "   RPC Latency: ${RPC_LATENCY} ms"
    echo "   RPC Status: ✅ Connected"
    RPC_OK=true
else
    echo "   RPC Status: ❌ Failed (HTTP $RPC_STATUS)"
    RPC_OK=false
fi
echo ""

# --- Analysis ---
echo "=============================================="
echo "📊 BANDWIDTH ANALYSIS"
echo "=============================================="

# Convert speeds to numbers for comparison
DL_NUM=$(echo "$DOWNLOAD" | cut -d. -f1)
UP_NUM=$(echo "$UPLOAD" | cut -d. -f1)
RPC_LAT_NUM=$(echo "$RPC_LATENCY" | cut -d. -f1)

# Analyze download
if [ "$DL_NUM" -ge 1000 ]; then
    DL_STATUS="✅ Excellent (1Gbps+)"
elif [ "$DL_NUM" -ge 500 ]; then
    DL_STATUS="⚠️  Acceptable (500Mbps+)"
else
    DL_STATUS="❌ Insufficient (<500Mbps)"
fi

# Analyze upload
if [ "$UP_NUM" -ge 1000 ]; then
    UP_STATUS="✅ Excellent (1Gbps+)"
elif [ "$UP_NUM" -ge 500 ]; then
    UP_STATUS="⚠️  Acceptable (500Mbps+)"
else
    UP_STATUS="❌ Insufficient (<500Mbps)"
fi

# Analyze RPC latency
if [ "$RPC_LAT_NUM" -lt 20 ]; then
    LAT_STATUS="✅ Excellent (<20ms)"
elif [ "$RPC_LAT_NUM" -lt 50 ]; then
    LAT_STATUS="⚠️  Acceptable (<50ms)"
else
    LAT_STATUS="❌ High (>50ms)"
fi

echo "Download Capacity:  $DL_STATUS"
echo "Upload Capacity:    $UP_STATUS"
echo "RPC Latency:        $LAT_STATUS"
if $RPC_OK; then
    echo "RPC Connection:     ✅ OK"
else
    echo "RPC Connection:     ❌ Failed"
fi
echo ""

# --- Recommendations ---
echo "=============================================="
echo "📋 RECOMMENDATIONS"
echo "=============================================="

# Check if symmetric
SYMMETRIC=false
DIFF=$((DL_NUM - UP_NUM))
if [ ${DIFF#-} -lt 100 ]; then
    SYMMETRIC=true
fi

if [ "$DL_NUM" -ge 1000 ] && [ "$UP_NUM" -ge 1000 ]; then
    echo "✅ Your bandwidth meets Solana/X1 minimum requirements."
    echo ""
    echo "   Current capacity: ${DOWNLOAD}/${UPLOAD} Mbps"
    echo "   Minimum required: 1000/1000 Mbps (symmetric)"
    echo ""
    if [ "$DL_NUM" -lt 10000 ]; then
        echo "💡 Consider upgrading to 10 Gbps for future growth."
        echo "   X1 network usage is increasing and may approach"
        echo "   1 Gbps per validator within 6-12 months."
    fi
elif [ "$DL_NUM" -ge 500 ] && [ "$UP_NUM" -ge 500 ]; then
    echo "⚠️  Your bandwidth is below recommended levels."
    echo ""
    echo "   Current capacity: ${DOWNLOAD}/${UPLOAD} Mbps"
    echo "   Minimum required: 1000/1000 Mbps (symmetric)"
    echo ""
    echo "📌 UPGRADE RECOMMENDED:"
    echo "   • Contact your ISP for 1 Gbps symmetric upgrade"
    echo "   • Ask specifically for COMMITTED rate, not burst"
    echo "   • Verify it's truly symmetric (upload = download)"
else
    echo "❌ Your bandwidth is insufficient for validator operations."
    echo ""
    echo "   Current capacity: ${DOWNLOAD}/${UPLOAD} Mbps"
    echo "   Minimum required: 1000/1000 Mbps (symmetric)"
    echo ""
    echo "🚨 URGENT UPGRADE NEEDED:"
    echo "   • Current bandwidth may cause missed votes"
    echo "   • Upgrade to at least 1 Gbps symmetric immediately"
    echo "   • Consider 10 Gbps for optimal performance"
fi

# Check symmetry - only warn if upload is below 1 Gbps
if ! $SYMMETRIC && [ "$UP_NUM" -lt 1000 ]; then
    echo ""
    echo "⚠️  ASYMMETRIC CONNECTION DETECTED"
    echo "   Download: ${DOWNLOAD} Mbps"
    echo "   Upload:   ${UPLOAD} Mbps"
    echo ""
    echo "   Validators require SYMMETRIC bandwidth (equal up/down)."
    echo "   Contact your ISP for symmetric fiber connection."
fi

# Current usage vs capacity
echo ""
echo "=============================================="
echo "📈 USAGE vs CAPACITY"
echo "=============================================="
echo "Current Usage:   ${RX_MBPS} Mbps down / ${TX_MBPS} Mbps up"
echo "Max Capacity:    ${DOWNLOAD} Mbps down / ${UPLOAD} Mbps up"

USAGE_PERCENT=$(awk "BEGIN {printf \"%.1f\", ($RX_MBPS / $DOWNLOAD) * 100}")
echo "Utilization:     ${USAGE_PERCENT}%"
echo ""

if (( $(echo "$USAGE_PERCENT > 70" | bc -l) )); then
    echo "⚠️  HIGH UTILIZATION (>70%)"
    echo "   You're using most of your available bandwidth."
    echo "   Consider upgrading before you hit capacity limits."
elif (( $(echo "$USAGE_PERCENT > 50" | bc -l) )); then
    echo "💡 MODERATE UTILIZATION (50-70%)"
    echo "   Monitor your usage trends. Plan upgrade if growing."
else
    echo "✅ GOOD HEADROOM (<50%)"
    echo "   Plenty of capacity available for growth."
fi

# Final critical check
echo ""
echo "=============================================="
echo "⚠️  CRITICAL: Verify With Your Provider"
echo "=============================================="
echo ""
echo "This test shows your PORT SPEED (burst capacity)."
echo "Your ISP may have a lower COMMITTED RATE."
echo ""
echo "🔍 Next Steps:"
echo "   1. Check your hosting provider's bandwidth graphs"
echo "   2. Look for 'red threshold lines' around 200-500 Mbps"
echo "   3. Ask your ISP: 'What is my committed information rate?'"
echo "   4. Verify sustained usage vs provider thresholds"
echo ""
echo "Example: '1 Gbps Unmetered' might mean:"
echo "   • Port: 1000 Mbps (burst)"
echo "   • Committed: 200 Mbps (sustained)"
echo "   • Billing: 95th percentile"
echo ""
echo "=============================================="
echo "Test Complete"
echo "=============================================="
```

***

## Example Output

```
==============================================
🌐 X1 Validator Bandwidth Test
==============================================

🔹 Network Interface
   Interface: enp4s0
   Link Speed: 1000Mb/s

🔹 Current Throughput (5-second sample)
   Current Download: 189.45 Mbps
   Current Upload: 142.67 Mbps

🔹 Speedtest (Maximum Capacity)
   Ping: 2.26 ms
   Download: 814.00 Mbps
   Upload: 766.28 Mbps

🔹 RPC Connectivity
   RPC Latency: 12.345 ms
   RPC Status: ✅ Connected

==============================================
📊 BANDWIDTH ANALYSIS
==============================================
Download Capacity:  ⚠️  Acceptable (500Mbps+)
Upload Capacity:    ⚠️  Acceptable (500Mbps+)
RPC Latency:        ✅ Excellent (<20ms)
RPC Connection:     ✅ OK

==============================================
📋 RECOMMENDATIONS
==============================================
⚠️  Your bandwidth is below recommended levels.

   Current capacity: 814.00/766.28 Mbps
   Minimum required: 1000/1000 Mbps (symmetric)

📌 UPGRADE RECOMMENDED:
   • Contact your ISP for 1 Gbps symmetric upgrade
   • Ask specifically for COMMITTED rate, not burst
   • Verify it's truly symmetric (upload = download)

==============================================
📈 USAGE vs CAPACITY
==============================================
Current Usage:   189.45 Mbps down / 142.67 Mbps up
Max Capacity:    814.00 Mbps down / 766.28 Mbps up
Utilization:     23.3%

✅ GOOD HEADROOM (<50%)
   Plenty of capacity available for growth.

==============================================
⚠️  CRITICAL: Verify With Your Provider
==============================================

This test shows your PORT SPEED (burst capacity).
Your ISP may have a lower COMMITTED RATE.

🔍 Next Steps:
   1. Check your hosting provider's bandwidth graphs
   2. Look for 'red threshold lines' around 200-500 Mbps
   3. Ask your ISP: 'What is my committed information rate?'
   4. Verify sustained usage vs provider thresholds

Example: '1 Gbps Unmetered' might mean:
   • Port: 1000 Mbps (burst)
   • Committed: 200 Mbps (sustained)
   • Billing: 95th percentile

==============================================
Test Complete
==============================================
```

***

## Interpreting Results

### ✅ Good Result

```
Download: 1200 Mbps
Upload:   1150 Mbps
Symmetric: Yes
Utilization: 35%
```

**Action**: You're good. Monitor trends monthly.

### ⚠️ Warning Result

```
Download: 850 Mbps
Upload:   780 Mbps
Symmetric: Yes
Utilization: 55%
```

**Action**: Plan upgrade to 1 Gbps committed soon.

### ❌ Critical Result

```
Download: 950 Mbps
Upload:   180 Mbps
Symmetric: No
Utilization: 85%
```

**Action**: Upgrade immediately. Asymmetric connection will cause issues.

***

## Continuous Monitoring

### Run Periodically

Add to cron for weekly reports:

```bash
# Run bandwidth test every Sunday at 3 AM
0 3 * * 0 /home/validator/x1_bandwidth.sh >> /var/log/x1_bandwidth.log 2>&1
```

### Check Provider Graphs

Don't just rely on speedtest — check your hosting provider's actual usage graphs:

1. Look for 95th percentile metrics
2. Check for red warning thresholds
3. Compare current usage vs thresholds
4. Monitor growth trends month-over-month

***

## FAQ

**Q: I have "1 Gbps" but speedtest shows 800 Mbps. Why?**

A: TCP/IP overhead, network congestion, or provider throttling. Also verify if it's committed vs burst.

**Q: My upload is lower than download. Is that OK?**

A: No. Validators need symmetric bandwidth. Upgrade to fiber with equal upload/download.

**Q: I'm at 60% utilization. Should I upgrade?**

A: Yes. X1 network usage is growing. Upgrade before you hit 80-90%.

**Q: What's the difference between committed and burst?**

A: Committed = sustained 24/7. Burst = temporary spikes allowed. Validators need committed.

**Q: Can I run a validator on cable internet?**

A: No. Cable is asymmetric (low upload). You need symmetric fiber.

***

## Notes

* Run during normal validator operation to see real-world throughput alongside capacity tests.
* Speedtest results may vary — run multiple times for accurate average.
* For continuous monitoring, consider setting up a cron job to log results.
* Requires: `speedtest-cli`, `bc`, `curl`, `ethtool`.\
  Install with:

  ```bash
  sudo apt install -y speedtest-cli bc curl ethtool
  ```
