183 lines
6.6 KiB
Bash
Executable File
183 lines
6.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Clear transaction pools on all Besu nodes (RPC and Validators)
|
|
# This script clears transaction pool databases to remove stuck transactions
|
|
|
|
set -euo pipefail
|
|
|
|
# Load IP configuration
|
|
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
|
|
source "${PROJECT_ROOT}/scripts/lib/load-project-env.sh" 2>/dev/null || true
|
|
|
|
|
|
PROXMOX_SSH_USER="${PROXMOX_SSH_USER:-root}"
|
|
PROXMOX_R630="${PROXMOX_R630:-192.168.11.11}"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
CYAN='\033[0;36m'
|
|
NC='\033[0m'
|
|
|
|
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
|
|
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
|
|
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
|
|
log_error() { echo -e "${RED}[✗]${NC} $1"; }
|
|
log_section() { echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"; echo -e "${CYAN}$1${NC}"; echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"; }
|
|
|
|
echo "=== Clear Transaction Pools on All Nodes ==="
|
|
echo ""
|
|
|
|
host_for_vmid() {
|
|
local vmid="$1"
|
|
if type get_host_for_vmid >/dev/null 2>&1; then
|
|
get_host_for_vmid "$vmid"
|
|
elif [ "$vmid" -le 1002 ]; then
|
|
echo "$PROXMOX_R630"
|
|
elif [ "$vmid" -eq 2201 ]; then
|
|
echo "${PROXMOX_R630_02:-${PROXMOX_HOST_R630_02:-192.168.11.12}}"
|
|
else
|
|
echo "${PROXMOX_HOST_ML110:-192.168.11.10}"
|
|
fi
|
|
}
|
|
|
|
# Function to clear transaction pool for a node
|
|
clear_node_pool() {
|
|
local VMID=$1
|
|
local HOST=$2
|
|
local NODE_TYPE=$3
|
|
local SSH_TARGET="${PROXMOX_SSH_USER}@${HOST}"
|
|
|
|
log_info "Clearing transaction pool for $NODE_TYPE (VMID $VMID on $HOST)..."
|
|
|
|
# Stop the service
|
|
log_info " Stopping service..."
|
|
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no "$SSH_TARGET" \
|
|
"pct exec $VMID -- systemctl stop besu-validator 2>/dev/null || pct exec $VMID -- systemctl stop besu-rpc-core 2>/dev/null || pct exec $VMID -- systemctl stop besu-rpc.service 2>/dev/null || pct exec $VMID -- systemctl stop besu-rpc 2>/dev/null || true" 2>&1 | grep -v "Configuration file" || true
|
|
|
|
sleep 2
|
|
|
|
# Find and clear transaction pool database
|
|
log_info " Clearing transaction pool database..."
|
|
CLEAR_RESULT=$(ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no "$SSH_TARGET" \
|
|
"pct exec $VMID -- bash -c '
|
|
DATA_DIRS=\"/data/besu /var/lib/besu\"
|
|
for DATA_DIR in \$DATA_DIRS; do
|
|
if [ -d \"\$DATA_DIR\" ]; then
|
|
# Find transaction pool database files
|
|
find \"\$DATA_DIR\" -type d -name \"*pool*\" -exec rm -rf {} \; 2>/dev/null || true
|
|
find \"\$DATA_DIR\" -type f -name \"*transaction*\" -delete 2>/dev/null || true
|
|
find \"\$DATA_DIR\" -type f -name \"*txpool*\" -delete 2>/dev/null || true
|
|
echo \"Cleared: \$DATA_DIR\"
|
|
fi
|
|
done
|
|
'" 2>&1 | grep -v "Configuration file" || echo "Cleared")
|
|
|
|
if [ -n "$CLEAR_RESULT" ]; then
|
|
log_success " Transaction pool cleared"
|
|
else
|
|
log_warn " Could not clear transaction pool (may not exist)"
|
|
fi
|
|
|
|
# Restart the service
|
|
log_info " Restarting service..."
|
|
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no "$SSH_TARGET" \
|
|
"pct exec $VMID -- systemctl start besu-validator 2>/dev/null || pct exec $VMID -- systemctl start besu-rpc-core 2>/dev/null || pct exec $VMID -- systemctl start besu-rpc.service 2>/dev/null || pct exec $VMID -- systemctl start besu-rpc 2>/dev/null || true" 2>&1 | grep -v "Configuration file" || true
|
|
|
|
sleep 3
|
|
|
|
# Verify service is running
|
|
STATUS=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "$SSH_TARGET" \
|
|
"pct exec $VMID -- systemctl is-active besu-validator 2>/dev/null || pct exec $VMID -- systemctl is-active besu-rpc-core 2>/dev/null || pct exec $VMID -- systemctl is-active besu-rpc.service 2>/dev/null || pct exec $VMID -- systemctl is-active besu-rpc 2>/dev/null || echo 'unknown'" 2>&1 | grep -v "Configuration file" || echo "unknown")
|
|
|
|
if [ "$STATUS" = "active" ]; then
|
|
log_success " Service restarted and active"
|
|
else
|
|
log_warn " Service status: $STATUS"
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# Clear validators
|
|
log_section "Clearing Validator Transaction Pools"
|
|
|
|
VALIDATORS=(
|
|
"1000:$(host_for_vmid 1000):Validator"
|
|
"1001:$(host_for_vmid 1001):Validator"
|
|
"1002:$(host_for_vmid 1002):Validator"
|
|
"1003:$(host_for_vmid 1003):Validator"
|
|
"1004:$(host_for_vmid 1004):Validator"
|
|
)
|
|
|
|
for validator in "${VALIDATORS[@]}"; do
|
|
IFS=':' read -r VMID HOST TYPE <<< "$validator"
|
|
clear_node_pool "$VMID" "$HOST" "$TYPE"
|
|
done
|
|
|
|
RPC_NODES=(
|
|
"2101:Core RPC"
|
|
"2102:Core RPC Replica"
|
|
"2103:Thirdweb admin core RPC"
|
|
"2201:RPC Public"
|
|
"2301:RPC Private"
|
|
"2303:RPC Ali 0x8a"
|
|
"2304:RPC Ali 0x1"
|
|
"2305:RPC Luis 0x8a"
|
|
"2306:RPC Luis 0x1"
|
|
"2307:RPC Putu 0x8a"
|
|
"2308:RPC Putu 0x1"
|
|
"2400:Thirdweb RPC 1"
|
|
"2401:Thirdweb RPC 2"
|
|
"2402:Thirdweb RPC 3"
|
|
"2403:Thirdweb RPC 4"
|
|
)
|
|
|
|
log_section "Clearing RPC Transaction Pools"
|
|
for rpc in "${RPC_NODES[@]}"; do
|
|
IFS=':' read -r VMID TYPE <<< "$rpc"
|
|
HOST="$(host_for_vmid "$VMID")"
|
|
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${PROXMOX_SSH_USER}@${HOST}" \
|
|
"pct list | awk '{print \$1}' | grep -qx '$VMID'" 2>/dev/null; then
|
|
clear_node_pool "$VMID" "$HOST" "$TYPE"
|
|
else
|
|
log_warn "$TYPE (VMID $VMID) not found on ${HOST}"
|
|
fi
|
|
done
|
|
|
|
SENTRY_NODES=(
|
|
"1500:Sentry"
|
|
"1501:Sentry"
|
|
"1502:Sentry"
|
|
"1503:Sentry"
|
|
"1504:Sentry"
|
|
"1505:Sentry"
|
|
"1506:Sentry"
|
|
"1507:Sentry"
|
|
"1508:Sentry"
|
|
"1509:Sentry"
|
|
"1510:Sentry"
|
|
)
|
|
|
|
log_section "Clearing Sentry Transaction Pools"
|
|
for sentry in "${SENTRY_NODES[@]}"; do
|
|
IFS=':' read -r VMID TYPE <<< "$sentry"
|
|
HOST="$(host_for_vmid "$VMID")"
|
|
if ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "${PROXMOX_SSH_USER}@${HOST}" \
|
|
"pct list | awk '{print \$1}' | grep -qx '$VMID'" 2>/dev/null; then
|
|
clear_node_pool "$VMID" "$HOST" "$TYPE"
|
|
else
|
|
log_warn "$TYPE (VMID $VMID) not found on ${HOST}"
|
|
fi
|
|
done
|
|
|
|
log_section "Transaction Pool Clear Complete"
|
|
|
|
echo "Next steps:"
|
|
echo " 1. Wait 30-60 seconds for nodes to fully restart"
|
|
echo " 2. Check pending transactions: bash scripts/check-pending-transactions.sh"
|
|
echo " 3. Monitor health: bash scripts/monitoring/monitor-blockchain-health.sh"
|