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

@@ -1,7 +1,8 @@
#!/bin/bash
# peer-reinject.sh — generic .after-start hook: re-seed peers from peer-capture state.
# Uses admin_addStaticPeer for geth, admin_addPeer otherwise (connect-peers.sh).
# In-network vantage (rpc_chains). Idempotent; best-effort (never fails the restart).
# Uses admin_addStaticPeer for vanilla geth, admin_addPeer for op-geth and others
# (connect-peers.sh). In-network vantage (rpc_chains). Idempotent; best-effort
# (never fails the restart).
#
# Seed order (one path for us and customers):
# 1. Own persisted peerset (peer-state/<compose>.json from peer-capture)
@@ -68,6 +69,12 @@ if [ "${#ENODES[@]}" -eq 0 ]; then
exit 0
fi
# op-geth lacks admin_addStaticPeer; compose path wins over stale capture state
# that classified the node as plain "geth" (admin_nodeInfo often still says Geth).
case "$COMPOSE_PATH" in
*op-geth*) CLIENT_TYPE="op-geth" ;;
esac
BASE="$(basename "$COMPOSE_PATH" | sed 's/--.*//')"
EL=""
# wait briefly for container after recreate
@@ -120,6 +127,7 @@ done
add_peer() {
local enode="$1"
local method
# Only vanilla geth supports admin_addStaticPeer; op-geth must use admin_addPeer
if [ "$CLIENT_TYPE" = "geth" ]; then
method="admin_addStaticPeer"
else
@@ -132,7 +140,8 @@ add_peer() {
resp="$(docker exec peer-hook-probe curl -s --max-time 8 -X POST \
-H 'Content-Type: application/json' --data "$payload" \
"http://${IP}:8545" 2>/dev/null || true)"
if echo "$resp" | grep -qi 'method not found'; then
# go-ethereum-style: "the method X does not exist/is not available" (not "method not found")
if echo "$resp" | grep -qiE 'method not found|does not exist|not available|-32601'; then
if [ "$method" = "admin_addStaticPeer" ]; then
method="admin_addPeer"
else