205 lines
8.2 KiB
Bash
Executable File
205 lines
8.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Upgrade the public Chain 138 RPC node (VMID 2201) to a Besu version that supports
|
|
# eth_maxPriorityFeePerGas. Default target is the current fleet baseline.
|
|
#
|
|
# Usage:
|
|
# bash scripts/besu/upgrade-public-rpc-vmid2201.sh
|
|
# bash scripts/besu/upgrade-public-rpc-vmid2201.sh --dry-run
|
|
# BESU_VERSION=25.12.0 bash scripts/besu/upgrade-public-rpc-vmid2201.sh
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
VMID="${RPC_VMID_2201:-2201}"
|
|
RPC_HOST="${RPC_VM_2201_HOST:-root@${PROXMOX_R630_02:-192.168.11.12}}"
|
|
[[ "$RPC_HOST" != *"@"* ]] && RPC_HOST="root@$RPC_HOST"
|
|
|
|
BESU_VERSION="${BESU_VERSION:-25.12.0}"
|
|
BESU_TAR="besu-${BESU_VERSION}.tar.gz"
|
|
BESU_DIR="/opt/besu-${BESU_VERSION}"
|
|
DOWNLOAD_URL="${BESU_DOWNLOAD_URL:-https://github.com/hyperledger/besu/releases/download/${BESU_VERSION}/${BESU_TAR}}"
|
|
JAVA21_FALLBACK_URL="${JAVA21_FALLBACK_URL:-https://api.adoptium.net/v3/binary/latest/21/ga/linux/x64/jre/hotspot/normal/eclipse}"
|
|
RPC_HTTP_MAX_ACTIVE_CONNECTIONS="${RPC_HTTP_MAX_ACTIVE_CONNECTIONS:-256}"
|
|
RPC_WS_MAX_ACTIVE_CONNECTIONS="${RPC_WS_MAX_ACTIVE_CONNECTIONS:-256}"
|
|
LOCAL_CACHE="${LOCAL_CACHE:-/tmp}"
|
|
DRY_RUN=false
|
|
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
|
|
|
|
SSH_OPTS=(-o StrictHostKeyChecking=accept-new -o ConnectTimeout=15)
|
|
RPC_IP="${RPC_PUBLIC_1:-192.168.11.221}"
|
|
|
|
run_on_host() {
|
|
ssh "${SSH_OPTS[@]}" "$RPC_HOST" "$@"
|
|
}
|
|
|
|
run_in_vmid() {
|
|
local cmd="$1"
|
|
if command -v pct >/dev/null 2>&1 && pct list 2>/dev/null | grep -q "^${VMID} "; then
|
|
pct exec "$VMID" -- bash -lc "$cmd"
|
|
else
|
|
run_on_host "pct exec ${VMID} -- bash -lc $(printf '%q' "$cmd")"
|
|
fi
|
|
}
|
|
|
|
push_to_vmid() {
|
|
local src="$1"
|
|
local dest="$2"
|
|
if command -v pct >/dev/null 2>&1 && pct list 2>/dev/null | grep -q "^${VMID} "; then
|
|
pct push "$VMID" "$src" "$dest"
|
|
else
|
|
local host_tmp="/tmp/$(basename "$src")"
|
|
scp "${SSH_OPTS[@]}" "$src" "${RPC_HOST}:${host_tmp}"
|
|
run_on_host "pct push ${VMID} $(printf '%q' "$host_tmp") $(printf '%q' "$dest") && rm -f $(printf '%q' "$host_tmp")"
|
|
fi
|
|
}
|
|
|
|
rpc_request() {
|
|
local method="$1"
|
|
local params="${2:-[]}"
|
|
curl -sS --max-time 20 -X POST "http://${RPC_IP}:8545" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"jsonrpc\":\"2.0\",\"method\":\"${method}\",\"params\":${params},\"id\":1}"
|
|
}
|
|
|
|
echo "=============================================="
|
|
echo "Upgrade public Chain 138 RPC (VMID ${VMID})"
|
|
echo "Host: ${RPC_HOST}"
|
|
echo "Target Besu version: ${BESU_VERSION}"
|
|
echo "=============================================="
|
|
if $DRY_RUN; then
|
|
echo "[dry-run] No changes will be made."
|
|
fi
|
|
|
|
run_on_host "echo connected >/dev/null"
|
|
|
|
run_in_vmid "
|
|
set -euo pipefail
|
|
if [[ ! -e /opt/besu ]]; then
|
|
fallback=\$(find /opt -maxdepth 1 -type d -name 'besu-*' | sort -V | tail -1)
|
|
if [[ -n \"\${fallback:-}\" ]]; then
|
|
ln -sfn \"\$fallback\" /opt/besu
|
|
chown -h besu:besu /opt/besu 2>/dev/null || true
|
|
fi
|
|
fi
|
|
"
|
|
|
|
CURRENT_VERSION="$(run_in_vmid '/opt/besu/bin/besu --version 2>/dev/null || besu --version 2>/dev/null || true' | head -1 || true)"
|
|
JAVA_VERSION_RAW="$(run_in_vmid 'java -version 2>&1 | head -1' || true)"
|
|
echo "Current version: ${CURRENT_VERSION:-unknown}"
|
|
echo "Current Java: ${JAVA_VERSION_RAW:-unknown}"
|
|
|
|
if $DRY_RUN; then
|
|
echo "[dry-run] Would download ${DOWNLOAD_URL}"
|
|
echo "[dry-run] Would stage ${BESU_TAR} in VMID ${VMID}, extract to ${BESU_DIR}, switch /opt/besu, restart besu-rpc."
|
|
exit 0
|
|
fi
|
|
|
|
mkdir -p "$LOCAL_CACHE"
|
|
if [[ ! -f "${LOCAL_CACHE}/${BESU_TAR}" ]]; then
|
|
echo "Downloading ${DOWNLOAD_URL} ..."
|
|
curl -fsSL -o "${LOCAL_CACHE}/${BESU_TAR}" "${DOWNLOAD_URL}"
|
|
fi
|
|
|
|
echo "Pushing tarball into VMID ${VMID} ..."
|
|
push_to_vmid "${LOCAL_CACHE}/${BESU_TAR}" "/tmp/${BESU_TAR}"
|
|
|
|
echo "Ensuring Java 21 runtime is present ..."
|
|
run_in_vmid "
|
|
set -euo pipefail
|
|
java_major=\$(java -version 2>&1 | sed -n '1s/.*version \"\\([0-9][0-9]*\\).*/\\1/p')
|
|
if [[ -z \"\${java_major:-}\" || \"\$java_major\" -lt 21 ]]; then
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update -qq
|
|
apt-get install -y -qq openjdk-21-jre-headless || true
|
|
java_major=\$(java -version 2>&1 | sed -n '1s/.*version \"\\([0-9][0-9]*\\).*/\\1/p')
|
|
if [[ -z \"\${java_major:-}\" || \"\$java_major\" -lt 21 ]]; then
|
|
command -v curl >/dev/null 2>&1 || apt-get install -y -qq curl ca-certificates
|
|
tmp_jre=/tmp/java21-jre.tar.gz
|
|
curl -fsSL -o \"\$tmp_jre\" '${JAVA21_FALLBACK_URL}'
|
|
tar -tzf \"\$tmp_jre\" > /tmp/java21-jre.list
|
|
extracted_dir=\$(head -1 /tmp/java21-jre.list | cut -d/ -f1)
|
|
rm -f /tmp/java21-jre.list
|
|
tar -xzf \"\$tmp_jre\" -C /opt
|
|
rm -f \"\$tmp_jre\"
|
|
ln -sfn \"/opt/\${extracted_dir}\" /opt/java-21
|
|
update-alternatives --install /usr/bin/java java /opt/java-21/bin/java 2100
|
|
fi
|
|
fi
|
|
config_file=\$(systemctl cat besu-rpc.service | sed -n 's/.*--config-file=\\([^ ]*\\).*/\\1/p' | tail -1)
|
|
if [[ -n \"\${config_file:-}\" && -f \"\$config_file\" ]]; then
|
|
find /etc/besu -maxdepth 1 -type f -name '*.toml' -print0 2>/dev/null | while IFS= read -r -d '' toml; do
|
|
sed -i \
|
|
-e '/^[[:space:]]*miner-enabled[[:space:]]*=.*/d' \
|
|
-e '/^[[:space:]]*privacy-enabled[[:space:]]*=.*/d' \
|
|
\"\$toml\"
|
|
if grep -q '^rpc-http-enabled=true' \"\$toml\" && ! grep -q '^rpc-http-max-active-connections=' \"\$toml\"; then
|
|
tmp=\$(mktemp)
|
|
awk '1; /^rpc-http-port=/{print \"rpc-http-max-active-connections=${RPC_HTTP_MAX_ACTIVE_CONNECTIONS}\"}' \"\$toml\" > \"\$tmp\"
|
|
cat \"\$tmp\" > \"\$toml\"
|
|
rm -f \"\$tmp\"
|
|
fi
|
|
if grep -q '^rpc-ws-enabled=true' \"\$toml\" && ! grep -q '^rpc-ws-max-active-connections=' \"\$toml\"; then
|
|
tmp=\$(mktemp)
|
|
awk '1; /^rpc-ws-port=/{print \"rpc-ws-max-active-connections=${RPC_WS_MAX_ACTIVE_CONNECTIONS}\"}' \"\$toml\" > \"\$tmp\"
|
|
cat \"\$tmp\" > \"\$toml\"
|
|
rm -f \"\$tmp\"
|
|
fi
|
|
done
|
|
if ! grep -q '^data-storage-format=' \"\$config_file\"; then
|
|
tmp=\$(mktemp)
|
|
awk '1; /^sync-mode=/{print \"data-storage-format=\\\"FOREST\\\"\"}' \"\$config_file\" > \"\$tmp\"
|
|
cat \"\$tmp\" > \"\$config_file\"
|
|
rm -f \"\$tmp\"
|
|
fi
|
|
fi
|
|
"
|
|
|
|
echo "Installing Besu ${BESU_VERSION} inside VMID ${VMID} ..."
|
|
run_in_vmid "
|
|
set -euo pipefail
|
|
cd /opt
|
|
if [[ -L /opt/besu ]]; then
|
|
current_target=\$(readlink -f /opt/besu)
|
|
current_version=\$(basename \"\$current_target\")
|
|
else
|
|
current_version=\$(/opt/besu/bin/besu --version 2>/dev/null | head -1 | sed -E 's#^.*/(v)?([0-9.]+).*\$#besu-\\2#')
|
|
[[ -z \"\$current_version\" ]] && current_version=besu-backup-pre-${BESU_VERSION}
|
|
mv /opt/besu \"/opt/\${current_version}\"
|
|
fi
|
|
rm -rf '${BESU_DIR}'
|
|
tar -xzf '/tmp/${BESU_TAR}' -C /opt
|
|
rm -f '/tmp/${BESU_TAR}'
|
|
ln -sfn '${BESU_DIR}' /opt/besu
|
|
chown -h besu:besu /opt/besu
|
|
chown -R besu:besu '${BESU_DIR}' /opt/besu-* 2>/dev/null || true
|
|
"
|
|
|
|
echo "Restarting besu-rpc.service ..."
|
|
run_in_vmid "systemctl restart besu-rpc.service"
|
|
for _ in $(seq 1 24); do
|
|
ACTIVE_STATE="$(run_in_vmid 'systemctl is-active besu-rpc.service' || true)"
|
|
[[ "$ACTIVE_STATE" == "active" ]] && break
|
|
sleep 5
|
|
done
|
|
NEW_VERSION="$(run_in_vmid '/opt/besu/bin/besu --version 2>/dev/null | grep -m1 "besu/" || true' | head -1 || true)"
|
|
echo "Service state: ${ACTIVE_STATE:-unknown}"
|
|
echo "New version: ${NEW_VERSION:-unknown}"
|
|
|
|
echo "Verifying live RPC methods ..."
|
|
CHAIN_ID="$(rpc_request eth_chainId | jq -r '.result // empty' 2>/dev/null || true)"
|
|
PRIORITY_FEE="$(curl -sS --max-time 20 -X POST 'https://rpc-http-pub.d-bis.org' -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"method\":\"eth_maxPriorityFeePerGas\",\"params\":[],\"id\":1}' | jq -r '.result // empty' 2>/dev/null || true)"
|
|
TRACE_OK="$(rpc_request trace_block '[\"0x1\"]' | jq -r 'has(\"result\")' 2>/dev/null || true)"
|
|
|
|
if [[ "$ACTIVE_STATE" != "active" || -z "$CHAIN_ID" || "$TRACE_OK" != "true" || -z "$PRIORITY_FEE" ]]; then
|
|
echo "ERROR: post-upgrade verification failed."
|
|
echo " eth_chainId result: ${CHAIN_ID:-missing}"
|
|
echo " trace_block result present: ${TRACE_OK:-false}"
|
|
echo " eth_maxPriorityFeePerGas result: ${PRIORITY_FEE:-missing}"
|
|
exit 1
|
|
fi
|
|
|
|
echo "OK: VMID ${VMID} upgraded successfully and public RPC now exposes eth_maxPriorityFeePerGas."
|