Skip to content

Commit

Permalink
Fix for networks with polling with non-consistent block and filter ev…
Browse files Browse the repository at this point in the history
…ents (ethers-io#4119).
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent e78a1fd commit 9c826f2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src.ts/providers/subscriber-polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 9c826f2

Please sign in to comment.