From b519d96a0f7f313b23fe17e16f199b53077c373b Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Mon, 11 Sep 2023 03:33:15 -0700 Subject: [PATCH] feat(block-logs-stream): add more logging (#1426) --- packages/block-logs-stream/src/blockRangeToLogs.ts | 4 +++- packages/block-logs-stream/src/fetchLogs.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) 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