#!/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 "=============================================="