From 9b0e9920c09577296ec0e2abb3acc3f3299d96c7 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 5 Jun 2023 22:08:43 -0400 Subject: [PATCH] Fix for networks with polling with non-consistent block and filter events (#4119). --- src.ts/providers/subscriber-polling.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src.ts/providers/subscriber-polling.ts b/src.ts/providers/subscriber-polling.ts index 7dfff2b7a..3e40c1f93 100644 --- a/src.ts/providers/subscriber-polling.ts +++ b/src.ts/providers/subscriber-polling.ts @@ -239,6 +239,7 @@ export class PollingEventSubscriber implements Subscriber { const filter = copy(this.#filter); filter.fromBlock = this.#blockNumber + 1; filter.toBlock = blockNumber; + const logs = await this.#provider.getLogs(filter); // No logs could just mean the node has not indexed them yet, @@ -250,10 +251,13 @@ export class PollingEventSubscriber implements Subscriber { return; } - this.#blockNumber = blockNumber; - for (const log of logs) { this.#provider.emit(this.#filter, log); + + // Only advance the block number when logs were found to + // account for networks (like BNB and Polygon) which may + // sacrifice event consistency for block event speed + this.#blockNumber = log.blockNumber; } }