From 8ebbcb11cf261650a261e74479f8d557bc35d2e1 Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Wed, 18 Mar 2026 17:50:48 +0000 Subject: [PATCH] Fix trade indexer BlockNotFoundError with retry getBlock fails on recently confirmed blocks when the RPC node hasn't propagated yet. Add retry loop (5 attempts, linear backoff) matching the existing getReceiptWithRetry pattern. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/api/index/trade/route.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app/api/index/trade/route.ts b/src/app/api/index/trade/route.ts index a71e9cda..9f5a250c 100644 --- a/src/app/api/index/trade/route.ts +++ b/src/app/api/index/trade/route.ts @@ -36,8 +36,18 @@ export async function POST(req: Request) { const receipt = await getReceiptWithRetry(txHash); if (!receipt) return error("Receipt not found", 404); - const block = await publicClient.getBlock({ blockNumber: receipt.blockNumber }); - const timestampISO = new Date(Number(block.timestamp) * 1000).toISOString(); + // Retry getBlock — RPC may not have the block yet on load-balanced nodes + let timestampISO: string; + for (let attempt = 1; ; attempt++) { + try { + const block = await publicClient.getBlock({ blockNumber: receipt.blockNumber }); + timestampISO = new Date(Number(block.timestamp) * 1000).toISOString(); + break; + } catch (err) { + if (attempt >= 5) throw err; + await new Promise((r) => setTimeout(r, attempt * 1000)); + } + } let indexed = 0;