fix: use admin_addPeer for op-geth peer reconciliation

op-geth does not support admin_addStaticPeer; classify op-geth via
compose path (admin_nodeInfo often still says Geth) and fall back on
go-ethereum-style "does not exist/is not available" errors so reinject
and connect-peers restore peers (e.g. hashkey-mainnet).
This commit is contained in:
2026-07-30 11:58:12 +00:00
parent 4806a8ad1b
commit a7135129eb
3 changed files with 37 additions and 15 deletions

View File

@@ -318,12 +318,19 @@ check_rpc_success() {
return 1
}
# Function to detect client type from node name
# Function to detect client type from node name (+ optional compose path hint).
# op-geth often still reports admin_nodeInfo.name as "Geth/…", so the compose
# path (…/op-geth/… or *-op-geth-*) is the reliable signal.
detect_client_type() {
local node_name="$1"
local compose_hint="${2:-}"
local name_lower=$(echo "$node_name" | tr '[:upper:]' '[:lower:]')
if [[ "$name_lower" == *"geth"* ]]; then
local hint_lower=$(echo "$compose_hint" | tr '[:upper:]' '[:lower:]')
# op-geth lacks admin_addStaticPeer — must use admin_addPeer
if [[ "$name_lower" == *"op-geth"* ]] || [[ "$hint_lower" == *"op-geth"* ]]; then
echo "op-geth"
elif [[ "$name_lower" == *"geth"* ]]; then
echo "geth"
elif [[ "$name_lower" == *"reth"* ]]; then
echo "reth"
@@ -346,12 +353,12 @@ add_static_peer() {
local response
local method
# Determine which method to try first based on client type
# Determine which method to try first based on client type.
# Only vanilla geth supports admin_addStaticPeer; op-geth does not.
if [[ "$client_type" == "geth" ]]; then
# Geth supports admin_addStaticPeer
method="admin_addStaticPeer"
else
# Reth and most other clients use admin_addPeer
# op-geth, reth, and most other clients use admin_addPeer
method="admin_addPeer"
fi
@@ -364,10 +371,11 @@ add_static_peer() {
return 1
}
# Check if method not found, try fallback
if echo "$response" | grep -qi "method not found"; then
# Fallback when the primary method is unsupported. go-ethereum-style errors
# say "the method X does not exist/is not available", not "method not found".
if echo "$response" | grep -qiE 'method not found|does not exist|not available|-32601'; then
if [[ "$method" == "admin_addStaticPeer" ]]; then
# Try admin_addPeer as fallback
# Try admin_addPeer as fallback (required for op-geth)
method="admin_addPeer"
response=$(curl --ipv4 -s -X POST "$url" \
-H "Content-Type: application/json" \
@@ -425,7 +433,7 @@ echo -e "${GREEN}OK${NC}"
SOURCE_ENODE=$(extract_enode "$SOURCE_INFO")
SOURCE_NAME=$(extract_name "$SOURCE_INFO")
SOURCE_PUBKEY=$(echo "$SOURCE_ENODE" | sed -E 's|enode://([^@]+)@.*|\1|')
SOURCE_CLIENT=$(detect_client_type "$SOURCE_NAME")
SOURCE_CLIENT=$(detect_client_type "$SOURCE_NAME" "$COMPOSE_FILE")
if [[ -z "$SOURCE_ENODE" ]]; then
echo -e "${RED}Could not extract enode from source${NC}"
@@ -457,7 +465,7 @@ echo -e "${GREEN}OK${NC}"
TARGET_ENODE=$(extract_enode "$TARGET_INFO")
TARGET_NAME=$(extract_name "$TARGET_INFO")
TARGET_PUBKEY=$(echo "$TARGET_ENODE" | sed -E 's|enode://([^@]+)@.*|\1|')
TARGET_CLIENT=$(detect_client_type "$TARGET_NAME")
TARGET_CLIENT=$(detect_client_type "$TARGET_NAME" "$TARGET_COMPOSE_FILE")
if [[ -z "$TARGET_ENODE" ]]; then
echo -e "${RED}Could not extract enode from target${NC}"