envio 3.3.0-alpha.2 → 3.3.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/index.d.ts +23 -21
  2. package/package.json +6 -6
  3. package/src/Bin.res +3 -0
  4. package/src/Bin.res.mjs +4 -0
  5. package/src/ChainFetching.res +26 -3
  6. package/src/ChainFetching.res.mjs +22 -3
  7. package/src/ChainState.res +3 -12
  8. package/src/ChainState.res.mjs +6 -8
  9. package/src/ChainState.resi +0 -2
  10. package/src/CrossChainState.res +15 -0
  11. package/src/CrossChainState.res.mjs +12 -0
  12. package/src/Ecosystem.res +0 -6
  13. package/src/EventConfigBuilder.res +45 -18
  14. package/src/EventConfigBuilder.res.mjs +28 -10
  15. package/src/EventProcessing.res +53 -37
  16. package/src/EventProcessing.res.mjs +41 -36
  17. package/src/FetchState.res +35 -42
  18. package/src/FetchState.res.mjs +37 -63
  19. package/src/HandlerLoader.res +10 -1
  20. package/src/HandlerLoader.res.mjs +15 -8
  21. package/src/Internal.res +8 -3
  22. package/src/Internal.res.mjs +1 -1
  23. package/src/LoadLayer.res +5 -5
  24. package/src/LoadLayer.res.mjs +6 -6
  25. package/src/Main.res +17 -9
  26. package/src/Main.res.mjs +15 -6
  27. package/src/PgStorage.res +4 -4
  28. package/src/PgStorage.res.mjs +5 -5
  29. package/src/Prometheus.res +10 -10
  30. package/src/Prometheus.res.mjs +9 -9
  31. package/src/PruneStaleHistory.res +2 -2
  32. package/src/PruneStaleHistory.res.mjs +3 -3
  33. package/src/Rollback.res +2 -2
  34. package/src/Rollback.res.mjs +3 -3
  35. package/src/SimulateItems.res +81 -15
  36. package/src/SimulateItems.res.mjs +63 -20
  37. package/src/TestIndexer.res +77 -39
  38. package/src/TestIndexer.res.mjs +45 -31
  39. package/src/bindings/Performance.res +7 -0
  40. package/src/bindings/Performance.res.mjs +21 -0
  41. package/src/bindings/Performance.resi +7 -0
  42. package/src/sources/EventRouter.res +17 -21
  43. package/src/sources/EventRouter.res.mjs +6 -9
  44. package/src/sources/Evm.res +10 -37
  45. package/src/sources/Evm.res.mjs +5 -40
  46. package/src/sources/Fuel.res +0 -4
  47. package/src/sources/Fuel.res.mjs +0 -7
  48. package/src/sources/HyperFuelSource.res +10 -11
  49. package/src/sources/HyperFuelSource.res.mjs +11 -11
  50. package/src/sources/HyperSync.res +3 -0
  51. package/src/sources/HyperSync.res.mjs +1 -0
  52. package/src/sources/HyperSync.resi +1 -0
  53. package/src/sources/HyperSyncClient.res +5 -1
  54. package/src/sources/HyperSyncSource.res +42 -24
  55. package/src/sources/HyperSyncSource.res.mjs +30 -26
  56. package/src/sources/RpcSource.res +7 -8
  57. package/src/sources/RpcSource.res.mjs +8 -8
  58. package/src/sources/SimulateSource.res +1 -1
  59. package/src/sources/Source.res +1 -1
  60. package/src/sources/SourceManager.res +17 -16
  61. package/src/sources/SourceManager.res.mjs +10 -15
  62. package/src/sources/Svm.res +6 -11
  63. package/src/sources/Svm.res.mjs +6 -14
  64. package/src/sources/SvmHyperSyncSource.res +24 -18
  65. package/src/sources/SvmHyperSyncSource.res.mjs +22 -15
  66. package/src/sources/TransactionStore.res +62 -35
  67. package/src/sources/TransactionStore.res.mjs +44 -18
  68. package/svm.schema.json +30 -37
  69. package/src/bindings/Hrtime.res +0 -58
  70. package/src/bindings/Hrtime.res.mjs +0 -90
  71. package/src/bindings/Hrtime.resi +0 -30
@@ -39,7 +39,7 @@ let runEventHandlerOrThrow = async (
39
39
  let eventItem = item->Internal.castUnsafeEventItem
40
40
 
41
41
  //Include the load in time before handler
42
- let timeBeforeHandler = Hrtime.makeTimer()
42
+ let timeBeforeHandler = Performance.now()
43
43
 
44
44
  try {
45
45
  let contextParams: UserContext.contextParams = {
@@ -72,7 +72,7 @@ let runEventHandlerOrThrow = async (
72
72
  }),
73
73
  )
74
74
  }
75
- let handlerDuration = timeBeforeHandler->Hrtime.timeSince->Hrtime.toSecondsFloat
75
+ let handlerDuration = timeBeforeHandler->Performance.secondsSince
76
76
  Prometheus.ProcessingHandler.increment(
77
77
  ~contract=eventItem.eventConfig.contractName,
78
78
  ~event=eventItem.eventConfig.name,
@@ -264,11 +264,19 @@ let runBatchHandlersOrThrow = async (
264
264
  }
265
265
  }
266
266
 
267
- let registerProcessEventBatchMetrics = (~logger, ~loadDuration, ~handlerDuration) => {
268
- logger->Logging.childTrace({
269
- "msg": "Finished processing batch",
270
- "loader_time_elapsed": loadDuration,
271
- "handlers_time_elapsed": handlerDuration,
267
+ let registerProcessEventBatchMetrics = (
268
+ ~logger,
269
+ ~batch: Batch.t,
270
+ ~loadDuration,
271
+ ~handlerDuration,
272
+ ) => {
273
+ batch.progressedChainsById->Dict.forEachWithKey((chainAfterBatch, chainId) => {
274
+ logger->Logging.childTrace({
275
+ "msg": "Finished processing",
276
+ "chainId": chainId->Int.fromString->Option.getUnsafe,
277
+ "batchSize": chainAfterBatch.batchSize,
278
+ "progress": chainAfterBatch.progressBlockNumber,
279
+ })
272
280
  })
273
281
 
274
282
  Prometheus.ProcessingBatch.registerMetrics(~loadDuration, ~handlerDuration)
@@ -286,22 +294,28 @@ type logPartitionInfo = {
286
294
  // handlers read plain objects. A batch can span chains, each with its own store
287
295
  // and field mask, so group items by chain before materialising.
288
296
  let materializeBatchTransactions = async (batch: Batch.t, ~chainStates: dict<ChainState.t>) => {
289
- let itemsByChain: dict<array<Internal.item>> = Dict.make()
290
- batch.items->Array.forEach(item => {
291
- let chainId = item->Internal.getItemChainId->Int.toString
292
- switch itemsByChain->Utils.Dict.dangerouslyGetNonOption(chainId) {
293
- | Some(items) => items->Array.push(item)
294
- | None => itemsByChain->Dict.set(chainId, [item])
295
- }
296
- })
297
-
298
- let _ = await itemsByChain
299
- ->Dict.toArray
300
- ->Array.map(async ((chainId, items)) => {
301
- let cs = chainStates->Dict.getUnsafe(chainId)
302
- await cs->ChainState.materializeBatchItems(~items)
303
- })
304
- ->Promise.all
297
+ switch chainStates->Dict.valuesToArray {
298
+ // Single-chain indexers (the common case): every item belongs to the one
299
+ // chain, so skip the per-chain grouping and its allocations.
300
+ | [cs] => await cs->ChainState.materializeBatchItems(~items=batch.items)
301
+ | _ =>
302
+ let itemsByChain: dict<array<Internal.item>> = Dict.make()
303
+ batch.items->Array.forEach(item => {
304
+ let chainId = item->Internal.getItemChainId->Int.toString
305
+ switch itemsByChain->Utils.Dict.dangerouslyGetNonOption(chainId) {
306
+ | Some(items) => items->Array.push(item)
307
+ | None => itemsByChain->Dict.set(chainId, [item])
308
+ }
309
+ })
310
+
311
+ let _ = await itemsByChain
312
+ ->Dict.toArray
313
+ ->Array.map(async ((chainId, items)) => {
314
+ let cs = chainStates->Dict.getUnsafe(chainId)
315
+ await cs->ChainState.materializeBatchItems(~items)
316
+ })
317
+ ->Promise.all
318
+ }
305
319
  }
306
320
 
307
321
  let processEventBatch = async (
@@ -312,27 +326,24 @@ let processEventBatch = async (
312
326
  ~config: Config.t,
313
327
  ~chainStates: dict<ChainState.t>,
314
328
  ) => {
315
- let totalBatchSize = batch.totalBatchSize
316
329
  // Compute chains state for this batch
317
330
  let chains: Internal.chains = chainStates->computeChainsState
318
331
 
319
332
  let logger = Logging.getLogger()
320
- logger->Logging.childTrace({
321
- "msg": "Started processing batch",
322
- "totalBatchSize": totalBatchSize,
323
- "chains": batch.progressedChainsById->Utils.Dict.mapValues(chainAfterBatch => {
324
- {
325
- "batchSize": chainAfterBatch.batchSize,
326
- "progress": chainAfterBatch.progressBlockNumber,
327
- }
328
- }),
333
+
334
+ batch.progressedChainsById->Dict.forEachWithKey((chainAfterBatch, chainId) => {
335
+ logger->Logging.childTrace({
336
+ "msg": "Started processing",
337
+ "chainId": chainId->Int.fromString->Option.getUnsafe,
338
+ "batchSize": chainAfterBatch.batchSize,
339
+ })
329
340
  })
330
341
 
331
342
  try {
332
343
  // Backpressure: keep processing within keepLatestChangesLimit of the cycle.
333
344
  await indexerState->Writing.awaitCapacity
334
345
 
335
- let timeRef = Hrtime.makeTimer()
346
+ let timeRef = Performance.now()
336
347
 
337
348
  if batch.items->Utils.Array.notEmpty {
338
349
  // Materialise store-backed transactions onto payloads before any handler
@@ -341,7 +352,7 @@ let processEventBatch = async (
341
352
  await batch->preloadBatchOrThrow(~loadManager, ~persistence, ~indexerState, ~chains, ~config)
342
353
  }
343
354
 
344
- let elapsedTimeAfterLoaders = timeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
355
+ let elapsedTimeAfterLoaders = timeRef->Performance.secondsSince
345
356
 
346
357
  if batch.items->Utils.Array.notEmpty {
347
358
  await batch->runBatchHandlersOrThrow(
@@ -353,13 +364,18 @@ let processEventBatch = async (
353
364
  )
354
365
  }
355
366
 
356
- let elapsedTimeAfterProcessing = timeRef->Hrtime.timeSince->Hrtime.toSecondsFloat
367
+ let elapsedTimeAfterProcessing = timeRef->Performance.secondsSince
357
368
 
358
369
  indexerState->Writing.commitBatch(~batch)
359
370
 
360
371
  let loaderDuration = elapsedTimeAfterLoaders
361
372
  let handlerDuration = elapsedTimeAfterProcessing -. loaderDuration
362
- registerProcessEventBatchMetrics(~logger, ~loadDuration=loaderDuration, ~handlerDuration)
373
+ registerProcessEventBatchMetrics(
374
+ ~logger,
375
+ ~batch,
376
+ ~loadDuration=loaderDuration,
377
+ ~handlerDuration,
378
+ )
363
379
  Ok()
364
380
  } catch {
365
381
  | Persistence.StorageError({message, reason}) =>
@@ -1,14 +1,16 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Utils from "./Utils.res.mjs";
4
- import * as Hrtime from "./bindings/Hrtime.res.mjs";
5
4
  import * as Logging from "./Logging.res.mjs";
6
5
  import * as Writing from "./Writing.res.mjs";
7
6
  import * as Internal from "./Internal.res.mjs";
8
7
  import * as Ecosystem from "./Ecosystem.res.mjs";
9
8
  import * as ChainState from "./ChainState.res.mjs";
10
9
  import * as Prometheus from "./Prometheus.res.mjs";
10
+ import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
11
+ import * as Performance from "./bindings/Performance.res.mjs";
11
12
  import * as Persistence from "./Persistence.res.mjs";
13
+ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
12
14
  import * as UserContext from "./UserContext.res.mjs";
13
15
  import * as ErrorHandling from "./ErrorHandling.res.mjs";
14
16
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
@@ -34,7 +36,7 @@ function computeChainsState(chainStates) {
34
36
  let ProcessingError = /* @__PURE__ */Primitive_exceptions.create("EventProcessing.ProcessingError");
35
37
 
36
38
  async function runEventHandlerOrThrow(item, checkpointId, handler, indexerState, loadManager, persistence, chains, config) {
37
- let timeBeforeHandler = Hrtime.makeTimer();
39
+ let timeBeforeHandler = Performance.now();
38
40
  try {
39
41
  let contextParams = {
40
42
  item: item,
@@ -62,7 +64,7 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, indexerState,
62
64
  Error: new Error()
63
65
  };
64
66
  }
65
- let handlerDuration = Hrtime.toSecondsFloat(Hrtime.timeSince(timeBeforeHandler));
67
+ let handlerDuration = Performance.secondsSince(timeBeforeHandler);
66
68
  return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
67
69
  }
68
70
 
@@ -172,59 +174,62 @@ async function runBatchHandlersOrThrow(batch, indexerState, loadManager, persist
172
174
  }
173
175
  }
174
176
 
175
- function registerProcessEventBatchMetrics(logger, loadDuration, handlerDuration) {
176
- Logging.childTrace(logger, {
177
- msg: "Finished processing batch",
178
- loader_time_elapsed: loadDuration,
179
- handlers_time_elapsed: handlerDuration
180
- });
177
+ function registerProcessEventBatchMetrics(logger, batch, loadDuration, handlerDuration) {
178
+ Stdlib_Dict.forEachWithKey(batch.progressedChainsById, (chainAfterBatch, chainId) => Logging.childTrace(logger, {
179
+ msg: "Finished processing",
180
+ chainId: Stdlib_Int.fromString(chainId, undefined),
181
+ batchSize: chainAfterBatch.batchSize,
182
+ progress: chainAfterBatch.progressBlockNumber
183
+ }));
181
184
  Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration);
182
185
  }
183
186
 
184
187
  async function materializeBatchTransactions(batch, chainStates) {
185
- let itemsByChain = {};
186
- batch.items.forEach(item => {
187
- let chainId = Internal.getItemChainId(item).toString();
188
- let items = itemsByChain[chainId];
189
- if (items !== undefined) {
190
- items.push(item);
191
- } else {
192
- itemsByChain[chainId] = [item];
193
- }
194
- });
195
- await Promise.all(Object.entries(itemsByChain).map(async param => {
196
- let cs = chainStates[param[0]];
197
- return await ChainState.materializeBatchItems(cs, param[1]);
198
- }));
188
+ let match = Object.values(chainStates);
189
+ if (match.length !== 1) {
190
+ let itemsByChain = {};
191
+ batch.items.forEach(item => {
192
+ let chainId = Internal.getItemChainId(item).toString();
193
+ let items = itemsByChain[chainId];
194
+ if (items !== undefined) {
195
+ items.push(item);
196
+ } else {
197
+ itemsByChain[chainId] = [item];
198
+ }
199
+ });
200
+ await Promise.all(Object.entries(itemsByChain).map(async param => {
201
+ let cs = chainStates[param[0]];
202
+ return await ChainState.materializeBatchItems(cs, param[1]);
203
+ }));
204
+ return;
205
+ }
206
+ let cs = match[0];
207
+ return await ChainState.materializeBatchItems(cs, batch.items);
199
208
  }
200
209
 
201
210
  async function processEventBatch(batch, indexerState, loadManager, persistence, config, chainStates) {
202
- let totalBatchSize = batch.totalBatchSize;
203
211
  let chains = computeChainsState(chainStates);
204
212
  let logger = Logging.getLogger();
205
- Logging.childTrace(logger, {
206
- msg: "Started processing batch",
207
- totalBatchSize: totalBatchSize,
208
- chains: Utils.Dict.mapValues(batch.progressedChainsById, chainAfterBatch => ({
209
- batchSize: chainAfterBatch.batchSize,
210
- progress: chainAfterBatch.progressBlockNumber
211
- }))
212
- });
213
+ Stdlib_Dict.forEachWithKey(batch.progressedChainsById, (chainAfterBatch, chainId) => Logging.childTrace(logger, {
214
+ msg: "Started processing",
215
+ chainId: Stdlib_Int.fromString(chainId, undefined),
216
+ batchSize: chainAfterBatch.batchSize
217
+ }));
213
218
  try {
214
219
  await Writing.awaitCapacity(indexerState);
215
- let timeRef = Hrtime.makeTimer();
220
+ let timeRef = Performance.now();
216
221
  if (Utils.$$Array.notEmpty(batch.items)) {
217
222
  await materializeBatchTransactions(batch, chainStates);
218
223
  await preloadBatchOrThrow(batch, loadManager, persistence, config, indexerState, chains);
219
224
  }
220
- let elapsedTimeAfterLoaders = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
225
+ let elapsedTimeAfterLoaders = Performance.secondsSince(timeRef);
221
226
  if (Utils.$$Array.notEmpty(batch.items)) {
222
227
  await runBatchHandlersOrThrow(batch, indexerState, loadManager, persistence, config, chains);
223
228
  }
224
- let elapsedTimeAfterProcessing = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
229
+ let elapsedTimeAfterProcessing = Performance.secondsSince(timeRef);
225
230
  Writing.commitBatch(indexerState, batch);
226
231
  let handlerDuration = elapsedTimeAfterProcessing - elapsedTimeAfterLoaders;
227
- registerProcessEventBatchMetrics(logger, elapsedTimeAfterLoaders, handlerDuration);
232
+ registerProcessEventBatchMetrics(logger, batch, elapsedTimeAfterLoaders, handlerDuration);
228
233
  return {
229
234
  TAG: "Ok",
230
235
  _0: undefined
@@ -76,9 +76,26 @@ type query = {
76
76
  mutable progress: float,
77
77
  selection: selection,
78
78
  addressesByContractName: dict<array<Address.t>>,
79
- indexingAddresses: dict<indexingAddress>,
80
79
  }
81
80
 
81
+ // Invert addressesByContractName into address→contractName for log-ownership
82
+ // routing. 1:1 today (each address belongs to one contract), so no key
83
+ // collisions. Memoized on the addressesByContractName object so a partition's
84
+ // many responses share one derivation and a large factory never rebuilds the
85
+ // whole index; sound because the dict is immutable after construction (every
86
+ // mutation produces a new dict).
87
+ let deriveContractNameByAddress: dict<array<Address.t>> => dict<
88
+ string,
89
+ > = Utils.WeakMap.memoize(addressesByContractName => {
90
+ let result = Dict.make()
91
+ addressesByContractName->Utils.Dict.forEachWithKey((addresses, contractName) => {
92
+ for i in 0 to addresses->Array.length - 1 {
93
+ result->Dict.set(addresses->Array.getUnsafe(i)->Address.toString, contractName)
94
+ }
95
+ })
96
+ result
97
+ })
98
+
82
99
  // Default estimate for a query whose partition hasn't responded yet, so the
83
100
  // shared budget still accounts for unknown queries instead of treating them as
84
101
  // free.
@@ -1329,6 +1346,9 @@ let startFetchingQueries = ({optimizedPartitions}: t, ~queries: array<query>) =>
1329
1346
  }
1330
1347
  }
1331
1348
 
1349
+ // Most parallel in-flight chunk queries a single partition may have at once.
1350
+ let maxPendingChunksPerPartition = 10
1351
+
1332
1352
  @inline
1333
1353
  let pushQueriesForRange = (
1334
1354
  queries: array<query>,
@@ -1337,12 +1357,12 @@ let pushQueriesForRange = (
1337
1357
  ~rangeEndBlock: option<int>,
1338
1358
  ~maxQueryBlockNumber: int,
1339
1359
  ~maybeChunkRange: option<int>,
1360
+ ~maxChunks: int,
1340
1361
  ~partition: partition,
1341
1362
  ~selection: selection,
1342
1363
  ~addressesByContractName: dict<array<Address.t>>,
1343
- ~indexingAddresses: dict<indexingAddress>,
1344
1364
  ) => {
1345
- if rangeFromBlock <= maxQueryBlockNumber {
1365
+ if rangeFromBlock <= maxQueryBlockNumber && maxChunks > 0 {
1346
1366
  switch rangeEndBlock {
1347
1367
  | Some(endBlock) if rangeFromBlock > endBlock => ()
1348
1368
  | _ =>
@@ -1363,7 +1383,6 @@ let pushQueriesForRange = (
1363
1383
  chainId: 0,
1364
1384
  progress: 0.,
1365
1385
  addressesByContractName,
1366
- indexingAddresses,
1367
1386
  })
1368
1387
  | Some(chunkRange) =>
1369
1388
  let maxBlock = switch rangeEndBlock {
@@ -1371,18 +1390,13 @@ let pushQueriesForRange = (
1371
1390
  | None => maxQueryBlockNumber
1372
1391
  }
1373
1392
  let chunkSize = Js.Math.ceil_int(chunkRange->Int.toFloat *. 1.8)
1374
- // Probe with two smaller chunks first so their responses come back
1375
- // quickly and refresh the chunking heuristic, then three full-size chunks.
1376
- let probeSize = Js.Math.ceil_int(chunkRange->Int.toFloat *. 0.9)
1377
- let getChunkSize = chunkIdx => chunkIdx < 2 ? probeSize : chunkSize
1378
- if rangeFromBlock + getChunkSize(0) + getChunkSize(1) - 1 <= maxBlock {
1393
+ if rangeFromBlock + chunkSize * 2 - 1 <= maxBlock {
1379
1394
  let chunkFromBlock = ref(rangeFromBlock)
1380
1395
  let chunkIdx = ref(0)
1381
1396
  while (
1382
- chunkIdx.contents < 5 &&
1383
- chunkFromBlock.contents + getChunkSize(chunkIdx.contents) - 1 <= maxBlock
1397
+ chunkIdx.contents < maxChunks && chunkFromBlock.contents + chunkSize - 1 <= maxBlock
1384
1398
  ) {
1385
- let chunkToBlock = chunkFromBlock.contents + getChunkSize(chunkIdx.contents) - 1
1399
+ let chunkToBlock = chunkFromBlock.contents + chunkSize - 1
1386
1400
  queries->Array.push({
1387
1401
  partitionId,
1388
1402
  fromBlock: chunkFromBlock.contents,
@@ -1398,7 +1412,6 @@ let pushQueriesForRange = (
1398
1412
  chainId: 0,
1399
1413
  progress: 0.,
1400
1414
  addressesByContractName,
1401
- indexingAddresses,
1402
1415
  })
1403
1416
  chunkFromBlock := chunkToBlock + 1
1404
1417
  chunkIdx := chunkIdx.contents + 1
@@ -1420,7 +1433,6 @@ let pushQueriesForRange = (
1420
1433
  chainId: 0,
1421
1434
  progress: 0.,
1422
1435
  addressesByContractName,
1423
- indexingAddresses,
1424
1436
  })
1425
1437
  }
1426
1438
  }
@@ -1428,18 +1440,8 @@ let pushQueriesForRange = (
1428
1440
  }
1429
1441
  }
1430
1442
 
1431
- // Most parallel in-flight chunk queries a single partition may have at once.
1432
- let maxPendingChunksPerPartition = 10
1433
-
1434
1443
  let getNextQuery = (
1435
- {
1436
- buffer,
1437
- optimizedPartitions,
1438
- indexingAddresses,
1439
- blockLag,
1440
- latestOnBlockBlockNumber,
1441
- knownHeight,
1442
- } as fetchState: t,
1444
+ {buffer, optimizedPartitions, blockLag, latestOnBlockBlockNumber, knownHeight} as fetchState: t,
1443
1445
  ~budget,
1444
1446
  ~chainPendingBudget,
1445
1447
  ) => {
@@ -1533,10 +1535,13 @@ let getNextQuery = (
1533
1535
  ~rangeEndBlock=Utils.Math.minOptInt(Some(pq.fromBlock - 1), queryEndBlock),
1534
1536
  ~maxQueryBlockNumber,
1535
1537
  ~maybeChunkRange,
1538
+ ~maxChunks=maxPendingChunksPerPartition -
1539
+ pendingCount -
1540
+ (queries->Array.length -
1541
+ partitionQueriesStart),
1536
1542
  ~partition=p,
1537
1543
  ~selection=p.selection,
1538
1544
  ~addressesByContractName=p.addressesByContractName,
1539
- ~indexingAddresses,
1540
1545
  )
1541
1546
  }
1542
1547
  switch pq {
@@ -1558,28 +1563,16 @@ let getNextQuery = (
1558
1563
  ~rangeEndBlock=queryEndBlock,
1559
1564
  ~maxQueryBlockNumber,
1560
1565
  ~maybeChunkRange,
1566
+ ~maxChunks=maxPendingChunksPerPartition -
1567
+ pendingCount -
1568
+ (queries->Array.length -
1569
+ partitionQueriesStart),
1561
1570
  ~partition=p,
1562
1571
  ~selection=p.selection,
1563
1572
  ~addressesByContractName=p.addressesByContractName,
1564
- ~indexingAddresses,
1565
1573
  )
1566
1574
  }
1567
1575
 
1568
- // Cap parallel in-flight chunks per partition so a single partition can't
1569
- // monopolize fetching. Keep the earliest new chunks; the furthest-ahead
1570
- // ones wait for the next round once these resolve.
1571
- let maxNewChunks = Pervasives.max(0, maxPendingChunksPerPartition - pendingCount)
1572
- let generatedCount = queries->Array.length - partitionQueriesStart
1573
- if generatedCount > maxNewChunks {
1574
- queries
1575
- ->Array.splice(
1576
- ~start=partitionQueriesStart + maxNewChunks,
1577
- ~remove=generatedCount - maxNewChunks,
1578
- ~insert=[],
1579
- )
1580
- ->ignore
1581
- }
1582
-
1583
1576
  idxRef := idxRef.contents + 1
1584
1577
  }
1585
1578