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 (#4119).
  • Loading branch information
ricmoo committed Jun 6, 2023
1 parent 56ed4e7 commit 9b0e992
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 9b0e992

Please sign in to comment.