Repository: ponder-sh/ponder
Pull request #1709 (2025-04-29 23:45:23)

fix thirdweb retry logic


Patch:
diff --git a/.changeset/angry-games-vanish.md b/.changeset/angry-games-vanish.md
new file mode 100644
index 00000000..02262b2d
--- /dev/null
+++ b/.changeset/angry-games-vanish.md
@@ -0,0 +1,5 @@
+---
+"@ponder/utils": patch
+---
+
+Fixed eth_getLogs error handling for thirdweb that was causing the error: `Log response size exceeded. Maximum allowed number of requested blocks is 1000`.
diff --git a/packages/utils/src/getLogsRetryHelper.ts b/packages/utils/src/getLogsRetryHelper.ts
index 19095173..bf2b4222 100644
--- a/packages/utils/src/getLogsRetryHelper.ts
+++ b/packages/utils/src/getLogsRetryHelper.ts
@@ -56,7 +56,26 @@ export const getLogsRetryHelper = ({
     } as const;
   }
 
-  // infura, thirdweb, zksync
+  // thirdweb
+  match = sError.match(/Maximum allowed number of requested blocks is ([\d]+)/);
+  if (match !== null) {
+    const ranges = chunk({
+      params,
+      range: BigInt(match[1]!),
+    });
+
+    if (isRangeUnchanged(params, ranges)) {
+      return { shouldRetry: false } as const;
+    }
+
+    return {
+      shouldRetry: true,
+      ranges,
+      isSuggestedRange: true,
+    } as const;
+  }
+
+  // infura, zksync
   match = sError.match(
     /Try with this block range \[0x([0-9a-fA-F]+),\s*0x([0-9a-fA-F]+)\]/,
   )!;


Test patch:
diff --git a/packages/utils/src/_test/thirdweb.test.ts b/packages/utils/src/_test/thirdweb.test.ts
index c99b8919..6bd45ebe 100644
--- a/packages/utils/src/_test/thirdweb.test.ts
+++ b/packages/utils/src/_test/thirdweb.test.ts
@@ -1,9 +1,10 @@
-import { InvalidParamsRpcError, numberToHex } from "viem";
+import { MethodNotFoundRpcError, numberToHex } from "viem";
 import { expect, test } from "vitest";
 import { getLogsRetryHelper } from "../getLogsRetryHelper.js";
 import { type Params, UNI, WETH, fromBlock, getRequest } from "./utils.js";
 
 const request = getRequest("https://1.rpc.thirdweb.com");
+const maxBlockRange = 1_000n;
 
 test("thirdweb success", async () => {
   const logs = await request({
@@ -12,12 +13,12 @@ test("thirdweb success", async () => {
       {
         address: UNI,
         fromBlock: numberToHex(fromBlock),
-        toBlock: numberToHex(fromBlock + 2_000n),
+        toBlock: numberToHex(fromBlock + maxBlockRange),
       },
     ],
   });
 
-  expect(logs).toHaveLength(11);
+  expect(logs).toHaveLength(9);
 });
 
 test("thirdweb response size", async () => {
@@ -25,7 +26,7 @@ test("thirdweb response size", async () => {
     {
       address: WETH,
       fromBlock: numberToHex(fromBlock),
-      toBlock: numberToHex(fromBlock + 2_000n),
+      toBlock: numberToHex(fromBlock + maxBlockRange + 1n),
     },
   ];
 
@@ -34,18 +35,28 @@ test("thirdweb response size", async () => {
     params,
   }).catch((error) => error);
 
-  expect(error).toBeInstanceOf(InvalidParamsRpcError);
-  expect(JSON.stringify(error)).includes("Try with this block range ");
+  expect(error).toBeInstanceOf(MethodNotFoundRpcError);
+  expect(JSON.stringify(error)).includes(
+    "Maximum allowed number of requested blocks is 1000",
+  );
 
   const retry = getLogsRetryHelper({
     params,
     error,
   });
 
-  expect(retry.shouldRetry).toBe(true);
-  expect(retry.ranges).toHaveLength(8);
-  expect(retry.ranges![0]).toStrictEqual({
-    fromBlock: "0x112a880",
-    toBlock: "0x112a993",
+  expect(retry).toStrictEqual({
+    shouldRetry: true,
+    isSuggestedRange: true,
+    ranges: [
+      {
+        fromBlock: numberToHex(fromBlock),
+        toBlock: numberToHex(fromBlock + maxBlockRange),
+      },
+      {
+        fromBlock: numberToHex(fromBlock + maxBlockRange + 1n),
+        toBlock: numberToHex(fromBlock + maxBlockRange + 1n),
+      },
+    ],
   });
 });