From 20f5ac68cdcbe9204a5fcce34b8e8cb45d47b12a Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 19 Mar 2026 23:45:31 +0000 Subject: [PATCH] fix: add polling timeouts and safe fallback in recovery script (#644) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add max-iterations guard (60 polls × 5s = 5 min) to both cooldown polling loops with explicit error on timeout - Use LAST_RECENTER (already validated) as fallback instead of "0" for post-seed-buy lastRecenterTime read, preventing silent cooldown skip on transient RPC failure Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/recover-bootstrap.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/recover-bootstrap.sh b/scripts/recover-bootstrap.sh index 93f5743..12ea545 100755 --- a/scripts/recover-bootstrap.sh +++ b/scripts/recover-bootstrap.sh @@ -139,8 +139,15 @@ if [[ "$NOW" -lt "$COOLDOWN_END" ]]; then if [[ "$DRY_RUN" == "true" ]]; then exit 0 fi - info "Polling for recenter cooldown to elapse ..." + info "Polling for recenter cooldown to elapse (timeout: 5 min) ..." + POLL_ATTEMPTS=0 + MAX_POLL_ATTEMPTS=60 # 60 × 5s = 5 min while true; do + POLL_ATTEMPTS=$(( POLL_ATTEMPTS + 1 )) + if [[ "$POLL_ATTEMPTS" -gt "$MAX_POLL_ATTEMPTS" ]]; then + error "Timed out waiting for recenter cooldown (${MAX_POLL_ATTEMPTS} polls). RPC may be degraded." + exit 1 + fi NOW="$(cast block latest --rpc-url "$RPC_URL" --field timestamp 2>/dev/null || echo "0")" if [[ "$NOW" -ge "$COOLDOWN_END" ]]; then info "Recenter cooldown elapsed." @@ -183,10 +190,17 @@ if [[ -n "$SEED_ETH" && -n "$KRAIKEN" ]]; then info "Seed buy complete." # Poll until recenter cooldown elapses - info "Polling for recenter cooldown to elapse ..." - LAST_RECENTER_AFTER="$(cast call --rpc-url "$RPC_URL" "$LM_ADDRESS" "lastRecenterTime()(uint256)" 2>/dev/null || echo "0")" + info "Polling for recenter cooldown to elapse (timeout: 5 min) ..." + LAST_RECENTER_AFTER="$(cast call --rpc-url "$RPC_URL" "$LM_ADDRESS" "lastRecenterTime()(uint256)" 2>/dev/null || echo "$LAST_RECENTER")" COOLDOWN_TARGET=$(( LAST_RECENTER_AFTER + 60 )) + POLL_ATTEMPTS=0 + MAX_POLL_ATTEMPTS=60 # 60 × 5s = 5 min while true; do + POLL_ATTEMPTS=$(( POLL_ATTEMPTS + 1 )) + if [[ "$POLL_ATTEMPTS" -gt "$MAX_POLL_ATTEMPTS" ]]; then + error "Timed out waiting for recenter cooldown (${MAX_POLL_ATTEMPTS} polls). RPC may be degraded." + exit 1 + fi NOW="$(cast block latest --rpc-url "$RPC_URL" --field timestamp 2>/dev/null || echo "0")" if [[ "$NOW" -ge "$COOLDOWN_TARGET" ]]; then info "Recenter cooldown elapsed."