#!/usr/bin/env bash # Confirm Besu version >= 24.1.0 on selected nodes (required for EIP-7702 / Cancun) # Usage: # bash scripts/check-besu-version-all-nodes.sh # bash scripts/check-besu-version-all-nodes.sh --vmid 2301 set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" MIN_VERSION="24.1.0" TARGET_VMIDS=() usage() { cat <<'EOF' Usage: bash scripts/check-besu-version-all-nodes.sh [--vmid ] Options: --vmid Limit to one VMID; repeatable EOF } while [[ $# -gt 0 ]]; do case "$1" in --vmid) [[ $# -ge 2 ]] || { usage >&2; exit 2; } TARGET_VMIDS+=("$2") shift 2 ;; -h|--help) usage exit 0 ;; *) echo "Unknown argument: $1" >&2 usage >&2 exit 2 ;; esac done BESU_VMIDS=(1000 1001 1002 1003 1004 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 2101 2102 2103 2201 2301 2303 2304 2305 2306 2307 2308 2400 2401 2402 2403 2420 2430 2440 2460 2470 2480) selected_vmid() { local vmid="$1" [[ ${#TARGET_VMIDS[@]} -eq 0 ]] && return 0 local wanted for wanted in "${TARGET_VMIDS[@]}"; do [[ "$vmid" == "$wanted" ]] && return 0 done return 1 } RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' log_info() { echo -e "${BLUE}[INFO]${NC} $1"; } log_ok() { echo -e "${GREEN}[OK]${NC} $1"; } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } log_fail() { echo -e "${RED}[FAIL]${NC} $1"; } # Compare semantic versions: return 0 if $1 >= $2, else 1 version_gte() { local a="${1:-0}" local b="${2:-0}" [ "$a" = "$b" ] && return 0 local win win=$(echo -e "${a}\n${b}" | sort -V | tail -n1) [ "$win" = "$a" ] && return 0 return 1 } # Get Besu version from node: try RPC web3_clientVersion first, then CLI get_besu_version() { local vmid=$1 local host=$2 local version="" local raw # 1) RPC (actual running client) raw=$(ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=accept-new root@"$host" \ "pct exec $vmid -- curl -s -m 3 -X POST -H 'Content-Type: application/json' \ --data '{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":1}' \ http://127.0.0.1:8545 2>/dev/null" || true) if [ -n "$raw" ]; then if echo "$raw" | grep -q '"result"'; then version=$(echo "$raw" | sed -n 's/.*"result":"[^/]*\/v\([^\/"]*\).*/\1/p') [ -z "$version" ] && version=$(echo "$raw" | sed -n 's/.*"result":"\([^"]*\)".*/\1/p') fi fi # 2) CLI fallback if [ -z "$version" ]; then raw=$(ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=accept-new root@"$host" \ "pct exec $vmid -- /opt/besu/bin/besu --version 2>/dev/null || pct exec $vmid -- besu --version 2>/dev/null" || true) if [ -n "$raw" ]; then version=$(echo "$raw" | sed -n 's/.*[Bb]esu\/\?v\?\([0-9][0-9.]*\).*/\1/p') fi fi echo "$version" } # Check if container exists and is running on host is_running() { local vmid=$1 local host=$2 ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=accept-new root@"$host" \ "pct status $vmid 2>/dev/null" | grep -q running } echo "" log_info "Besu version check (>= ${MIN_VERSION}) on selected nodes" log_info "EIP-7702 / Cancun requires Besu >= 24.1.0" echo "" PASS=0 FAIL=0 SKIP=0 declare -a FAILED_VMIDS declare -a FAILED_VERSIONS for vmid in "${BESU_VMIDS[@]}"; do selected_vmid "$vmid" || continue host="$(get_host_for_vmid "$vmid")" if ! is_running "$vmid" "$host"; then printf " VMID %-5s %-12s %s\n" "$vmid" "—" "(container not running)" ((SKIP++)) || true continue fi version=$(get_besu_version "$vmid" "$host") if [ -z "$version" ]; then printf " VMID %-5s %-12s " "$vmid" "—" log_fail "no Besu version (RPC/CLI failed)" FAILED_VMIDS+=("$vmid") FAILED_VERSIONS+=("?") ((FAIL++)) || true continue fi if version_gte "$version" "$MIN_VERSION"; then printf " VMID %-5s %-12s " "$vmid" "$version" log_ok ">= $MIN_VERSION" ((PASS++)) || true else printf " VMID %-5s %-12s " "$vmid" "$version" log_fail "< $MIN_VERSION (upgrade required)" FAILED_VMIDS+=("$vmid") FAILED_VERSIONS+=("$version") ((FAIL++)) || true fi done echo "" echo "────────────────────────────────────────────────────────────" printf " Passed: %s Failed: %s Skipped (not running): %s\n" "$PASS" "$FAIL" "$SKIP" echo "────────────────────────────────────────────────────────────" if [ ${#FAILED_VMIDS[@]} -gt 0 ]; then echo "" log_warn "Nodes below minimum version ($MIN_VERSION):" for i in "${!FAILED_VMIDS[@]}"; do echo " VMID ${FAILED_VMIDS[$i]} version ${FAILED_VERSIONS[$i]}" done echo "" log_info "Upgrade: install Besu 24.1.0+ (e.g. from https://github.com/hyperledger/besu/releases) and restart besu service." exit 1 fi if [ "$PASS" -gt 0 ]; then log_ok "All checked nodes run Besu >= $MIN_VERSION (EIP-7702 / Cancun OK)." exit 0 fi log_warn "No Besu nodes could be checked (all skipped or failed)." exit 0