diff --git a/packages/block-logs-stream/src/blockRangeToLogs.ts b/packages/block-logs-stream/src/blockRangeToLogs.ts index a626858a42..56912638c7 100644 --- a/packages/block-logs-stream/src/blockRangeToLogs.ts +++ b/packages/block-logs-stream/src/blockRangeToLogs.ts @@ -2,6 +2,7 @@ import { EMPTY, OperatorFunction, concatMap, from, pipe, tap } from "rxjs"; import { FetchLogsResult, fetchLogs } from "./fetchLogs"; import { AbiEvent } from "abitype"; import { Address, BlockNumber, PublicClient } from "viem"; +import { debug } from "./debug"; export type BlockRangeToLogsOptions = { /** @@ -50,9 +51,10 @@ export function blockRangeToLogs({ toBlock = endBlock; }), // concatMap only processes the next emission once the inner observable completes, - // so it always uses the latest`toBlock` value. + // so it always uses the latest `toBlock` value. concatMap(() => { if (fromBlock > toBlock) return EMPTY; + debug("fetching logs for block range", { fromBlock, toBlock }); return from( fetchLogs({ publicClient, diff --git a/packages/block-logs-stream/src/fetchLogs.ts b/packages/block-logs-stream/src/fetchLogs.ts index 00d8e47af9..57ec401e74 100644 --- a/packages/block-logs-stream/src/fetchLogs.ts +++ b/packages/block-logs-stream/src/fetchLogs.ts @@ -70,11 +70,13 @@ export async function* fetchLogs({ while (fromBlock <= getLogsOpts.toBlock) { try { const toBlock = fromBlock + blockRange; + debug("getting logs", { fromBlock, toBlock }); const logs = await publicClient.getLogs({ ...getLogsOpts, fromBlock, toBlock, strict: true }); yield { fromBlock, toBlock, logs }; fromBlock = toBlock + 1n; blockRange = bigIntMin(maxBlockRange, getLogsOpts.toBlock - fromBlock); } catch (error: unknown) { + debug("error getting logs:", String(error)); if (!(error instanceof Error)) throw error; // TODO: figure out actual rate limit message for RPCs