From 796309cee3475be311d786829e1a7420b2dca27c Mon Sep 17 00:00:00 2001 From: shardAstronaut <127413534+shardAstronaut@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:12:47 +0100 Subject: [PATCH] fix: Maximum call stack size exceeded with array.push (Bug: last_indexed_block reset to Zero after reaching the seed blocks #300) When indexing contracts with a big number of events the array.push method will throw an error. When you use spread operator all items of the source array are stored in the stack as arguments list, so having a large number of items (~ > 100K) will cause the this stack size exceed. The most simple work-around is to manually push all items one by one. --- src/providers/starknet/provider.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/providers/starknet/provider.ts b/src/providers/starknet/provider.ts index 0615208..8ea6c1f 100644 --- a/src/providers/starknet/provider.ts +++ b/src/providers/starknet/provider.ts @@ -299,7 +299,9 @@ export class StarknetProvider extends BaseProvider { nextSource => !lastSources.find(lastSource => lastSource.contract === nextSource.contract) ); - sourcesQueue.push(...newSources); + for (let i = 0; i < newSources.length; i++) { + sourcesQueue.push(newSources[i]); + } lastSources = nextSources; } @@ -318,7 +320,9 @@ export class StarknetProvider extends BaseProvider { continuation_token: continuationToken }); - events.push(...result.events); + for (let i = 0; i < result.events.length; i++) { + events.push(result.events[i]); + } continuationToken = result.continuation_token; } while (continuationToken); @@ -357,7 +361,9 @@ export class StarknetProvider extends BaseProvider { continuation_token: continuationToken }); - events.push(...result.events); + for (let i = 0; i < result.events.length; i++) { + events.push(result.events[i]); + } continuationToken = result.continuation_token; } while (continuationToken); @@ -377,7 +383,9 @@ export class StarknetProvider extends BaseProvider { toBlock, source.contract ); - events.push(...addressEvents); + for (let i = 0; i < addressEvents.length; i++) { + events.push(addressEvents[i]); + } } return events;