From 7c56ce70f52273f53d5b9c9413389de8a32da154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Tkaczy=C5=84ski?= Date: Tue, 2 Apr 2024 17:14:36 +0200 Subject: [PATCH] fix: prevent fetching pool transactions every tick Currently we fetch receipt of each transaction that is in pending block on every tick, even if we already saw this transaction before. This is causing lots of requests as block can have ~400 transactions sitting in it for minutes and we hit it every 2 seconds. Now instead of fetching those and skipping this in handlePool we skip those before they are even fetched. --- src/providers/starknet/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/providers/starknet/index.ts b/src/providers/starknet/index.ts index 46c03c5..9f1f308 100644 --- a/src/providers/starknet/index.ts +++ b/src/providers/starknet/index.ts @@ -79,7 +79,9 @@ export class StarknetProvider extends BaseProvider { const block = await this.provider.getBlockWithTxs('pending'); const receipts = await Promise.all( block.transactions.map(async tx => { - if (!tx.transaction_hash) return null; + if (!tx.transaction_hash || this.seenPoolTransactions.has(tx.transaction_hash)) { + return null; + } try { return await this.provider.getTransactionReceipt(tx.transaction_hash); @@ -129,9 +131,7 @@ export class StarknetProvider extends BaseProvider { private async handlePool(txs: PendingTransaction[], eventsMap: EventsMap, blockNumber: number) { this.log.info('handling pool'); - const txsToCheck = txs.filter(tx => !this.seenPoolTransactions.has(tx.transaction_hash)); - - for (const [i, tx] of txsToCheck.entries()) { + for (const [i, tx] of txs.entries()) { await this.handleTx( null, blockNumber,