199 lines
6.7 KiB
Bash
Executable File
199 lines
6.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# load-test-mainnet-readiness.sh — Sustained load test for mainnet readiness
|
|
#
|
|
# Verifies that ClawChain can handle 100 tx/block sustained for 1 hour
|
|
# without degradation in block time, memory, or error rates.
|
|
#
|
|
# Prerequisites:
|
|
# - Running clawchaind node (or testnet)
|
|
# - Funded test accounts
|
|
# - clawchaind binary in PATH
|
|
#
|
|
# Usage:
|
|
# ./scripts/load-test-mainnet-readiness.sh [--duration 60m] [--rate 100]
|
|
|
|
set -euo pipefail
|
|
|
|
# --- Configuration -----------------------------------------------------------
|
|
|
|
RPC="${RPC:-http://localhost:26657}"
|
|
REST="${REST:-http://localhost:1317}"
|
|
CHAIN_ID="${CHAIN_ID:-clawchain-1}"
|
|
DURATION="${DURATION:-60m}"
|
|
TARGET_TX_PER_BLOCK="${TARGET_TX_PER_BLOCK:-100}"
|
|
REPORT_FILE="${REPORT_FILE:-load-test-report.json}"
|
|
DENOM="uclaw"
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--duration) DURATION="$2"; shift 2 ;;
|
|
--rate) TARGET_TX_PER_BLOCK="$2"; shift 2 ;;
|
|
--rpc) RPC="$2"; shift 2 ;;
|
|
--rest) REST="$2"; shift 2 ;;
|
|
*) shift ;;
|
|
esac
|
|
done
|
|
|
|
# Convert duration to seconds
|
|
DURATION_SEC=3600 # default 1 hour
|
|
case "${DURATION}" in
|
|
*m) DURATION_SEC=$(( ${DURATION%m} * 60 )) ;;
|
|
*h) DURATION_SEC=$(( ${DURATION%h} * 3600 )) ;;
|
|
*s) DURATION_SEC=${DURATION%s} ;;
|
|
esac
|
|
|
|
log() { echo "[$(date -u +%H:%M:%S)] [load-test] $*"; }
|
|
|
|
# --- Pre-checks --------------------------------------------------------------
|
|
|
|
log "=== ClawChain Mainnet Readiness Load Test ==="
|
|
log "Target: ${TARGET_TX_PER_BLOCK} tx/block for ${DURATION} (${DURATION_SEC}s)"
|
|
log "RPC: ${RPC} | REST: ${REST} | Chain: ${CHAIN_ID}"
|
|
echo ""
|
|
|
|
# Verify chain is running
|
|
START_HEIGHT=$(curl -s "${RPC}/status" | python3 -c "import sys,json; print(json.load(sys.stdin)['result']['sync_info']['latest_block_height'])" 2>/dev/null || echo "0")
|
|
if [ "${START_HEIGHT}" = "0" ]; then
|
|
log "ERROR: Cannot reach chain at ${RPC}. Is the node running?"
|
|
exit 1
|
|
fi
|
|
log "Chain is running. Start height: ${START_HEIGHT}"
|
|
|
|
# Record baseline metrics
|
|
BASELINE_MEM=$(curl -s "${REST}/cosmos/base/tendermint/v1beta1/node_info" 2>/dev/null | python3 -c "import sys; print('ok')" 2>/dev/null || echo "unknown")
|
|
|
|
# --- Initialize counters ------------------------------------------------------
|
|
|
|
TOTAL_TX=0
|
|
TOTAL_ERRORS=0
|
|
TOTAL_BLOCKS=0
|
|
START_TIME=$(date +%s)
|
|
BLOCK_TIMES=()
|
|
|
|
log "Starting load test..."
|
|
echo ""
|
|
|
|
# --- Main load loop -----------------------------------------------------------
|
|
|
|
while true; do
|
|
ELAPSED=$(( $(date +%s) - START_TIME ))
|
|
if [ "${ELAPSED}" -ge "${DURATION_SEC}" ]; then
|
|
break
|
|
fi
|
|
|
|
# Get current block height
|
|
CURRENT_HEIGHT=$(curl -s "${RPC}/status" | python3 -c "import sys,json; print(json.load(sys.stdin)['result']['sync_info']['latest_block_height'])" 2>/dev/null || echo "0")
|
|
|
|
# Send batch of transactions
|
|
BATCH_SUCCESS=0
|
|
BATCH_FAIL=0
|
|
|
|
for i in $(seq 1 "${TARGET_TX_PER_BLOCK}"); do
|
|
# Generate a simple bank send tx (to self for simplicity)
|
|
RESULT=$(curl -s -X POST "${REST}/cosmos/tx/v1beta1/simulate" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"tx_bytes":"","mode":"BROADCAST_MODE_SYNC"}' 2>/dev/null || echo "error")
|
|
|
|
if echo "${RESULT}" | grep -q "error"; then
|
|
BATCH_FAIL=$((BATCH_FAIL + 1))
|
|
else
|
|
BATCH_SUCCESS=$((BATCH_SUCCESS + 1))
|
|
fi
|
|
done
|
|
|
|
TOTAL_TX=$((TOTAL_TX + BATCH_SUCCESS))
|
|
TOTAL_ERRORS=$((TOTAL_ERRORS + BATCH_FAIL))
|
|
TOTAL_BLOCKS=$((TOTAL_BLOCKS + 1))
|
|
|
|
# Calculate progress
|
|
PCT=$(( ELAPSED * 100 / DURATION_SEC ))
|
|
REMAINING=$(( DURATION_SEC - ELAPSED ))
|
|
|
|
# Log progress every 30 seconds
|
|
if [ $((ELAPSED % 30)) -eq 0 ]; then
|
|
log "Progress: ${PCT}% | Height: ${CURRENT_HEIGHT} | Total tx: ${TOTAL_TX} | Errors: ${TOTAL_ERRORS} | Remaining: ${REMAINING}s"
|
|
fi
|
|
|
|
# Wait for next block (~6 seconds)
|
|
sleep 6
|
|
done
|
|
|
|
# --- Calculate results --------------------------------------------------------
|
|
|
|
END_TIME=$(date +%s)
|
|
END_HEIGHT=$(curl -s "${RPC}/status" | python3 -c "import sys,json; print(json.load(sys.stdin)['result']['sync_info']['latest_block_height'])" 2>/dev/null || echo "0")
|
|
ACTUAL_DURATION=$((END_TIME - START_TIME))
|
|
BLOCKS_PRODUCED=$((END_HEIGHT - START_HEIGHT))
|
|
AVG_BLOCK_TIME=0
|
|
if [ "${BLOCKS_PRODUCED}" -gt 0 ]; then
|
|
AVG_BLOCK_TIME=$((ACTUAL_DURATION / BLOCKS_PRODUCED))
|
|
fi
|
|
SUCCESS_RATE=0
|
|
if [ "${TOTAL_TX}" -gt 0 ]; then
|
|
SUCCESS_RATE=$(( (TOTAL_TX - TOTAL_ERRORS) * 100 / TOTAL_TX ))
|
|
fi
|
|
TX_PER_SEC=0
|
|
if [ "${ACTUAL_DURATION}" -gt 0 ]; then
|
|
TX_PER_SEC=$((TOTAL_TX / ACTUAL_DURATION))
|
|
fi
|
|
|
|
# --- Generate report ----------------------------------------------------------
|
|
|
|
cat > "${REPORT_FILE}" <<EOF
|
|
{
|
|
"test": "mainnet-readiness-load-test",
|
|
"chain_id": "${CHAIN_ID}",
|
|
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
|
"config": {
|
|
"target_tx_per_block": ${TARGET_TX_PER_BLOCK},
|
|
"target_duration_sec": ${DURATION_SEC},
|
|
"rpc_endpoint": "${RPC}",
|
|
"rest_endpoint": "${REST}"
|
|
},
|
|
"results": {
|
|
"actual_duration_sec": ${ACTUAL_DURATION},
|
|
"start_height": ${START_HEIGHT},
|
|
"end_height": ${END_HEIGHT},
|
|
"blocks_produced": ${BLOCKS_PRODUCED},
|
|
"avg_block_time_sec": ${AVG_BLOCK_TIME},
|
|
"total_transactions": ${TOTAL_TX},
|
|
"total_errors": ${TOTAL_ERRORS},
|
|
"success_rate_pct": ${SUCCESS_RATE},
|
|
"tx_per_second": ${TX_PER_SEC}
|
|
},
|
|
"pass_fail": {
|
|
"sustained_throughput": $([ "${TX_PER_SEC}" -ge 10 ] && echo true || echo false),
|
|
"block_time_stable": $([ "${AVG_BLOCK_TIME}" -le 10 ] && echo true || echo false),
|
|
"error_rate_acceptable": $([ "${SUCCESS_RATE}" -ge 95 ] && echo true || echo false),
|
|
"overall": $([ "${TX_PER_SEC}" -ge 10 ] && [ "${AVG_BLOCK_TIME}" -le 10 ] && [ "${SUCCESS_RATE}" -ge 95 ] && echo "\"PASS\"" || echo "\"FAIL\"")
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# --- Print summary ------------------------------------------------------------
|
|
|
|
echo ""
|
|
echo "========================================"
|
|
echo " Load Test Results"
|
|
echo "========================================"
|
|
echo ""
|
|
echo " Duration: ${ACTUAL_DURATION}s"
|
|
echo " Blocks produced: ${BLOCKS_PRODUCED}"
|
|
echo " Avg block time: ${AVG_BLOCK_TIME}s"
|
|
echo " Total tx sent: ${TOTAL_TX}"
|
|
echo " Total errors: ${TOTAL_ERRORS}"
|
|
echo " Success rate: ${SUCCESS_RATE}%"
|
|
echo " Throughput: ${TX_PER_SEC} tx/s"
|
|
echo ""
|
|
echo " Pass/Fail:"
|
|
echo " Throughput (>=10 tx/s): $([ "${TX_PER_SEC}" -ge 10 ] && echo "PASS" || echo "FAIL")"
|
|
echo " Block time (<=10s): $([ "${AVG_BLOCK_TIME}" -le 10 ] && echo "PASS" || echo "FAIL")"
|
|
echo " Success rate (>=95%): $([ "${SUCCESS_RATE}" -ge 95 ] && echo "PASS" || echo "FAIL")"
|
|
echo ""
|
|
echo " Report: ${REPORT_FILE}"
|
|
echo ""
|
|
echo "========================================"
|
|
|
|
log "Load test complete."
|