envio 3.3.0-alpha.6 → 3.3.0-alpha.8

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 (93) hide show
  1. package/index.d.ts +23 -5
  2. package/package.json +6 -6
  3. package/src/Address.res +5 -2
  4. package/src/Address.res.mjs +3 -1
  5. package/src/Api.res +1 -1
  6. package/src/Api.res.mjs +1 -1
  7. package/src/ChainFetching.res +34 -34
  8. package/src/ChainFetching.res.mjs +29 -29
  9. package/src/ChainState.res +328 -165
  10. package/src/ChainState.res.mjs +205 -100
  11. package/src/ChainState.resi +16 -7
  12. package/src/Config.res +55 -27
  13. package/src/Config.res.mjs +46 -7
  14. package/src/ContractRegisterContext.res +2 -12
  15. package/src/ContractRegisterContext.res.mjs +3 -5
  16. package/src/Core.res +7 -0
  17. package/src/CrossChainState.res +54 -79
  18. package/src/CrossChainState.res.mjs +45 -60
  19. package/src/CrossChainState.resi +1 -1
  20. package/src/Ecosystem.res +3 -3
  21. package/src/Ecosystem.res.mjs +3 -3
  22. package/src/Envio.res +14 -9
  23. package/src/EventConfigBuilder.res +105 -56
  24. package/src/EventConfigBuilder.res.mjs +69 -33
  25. package/src/EventProcessing.res +19 -15
  26. package/src/EventProcessing.res.mjs +13 -12
  27. package/src/FetchState.res +383 -182
  28. package/src/FetchState.res.mjs +260 -264
  29. package/src/HandlerLoader.res +7 -112
  30. package/src/HandlerLoader.res.mjs +1 -87
  31. package/src/HandlerRegister.res +209 -6
  32. package/src/HandlerRegister.res.mjs +90 -5
  33. package/src/HandlerRegister.resi +13 -2
  34. package/src/IndexerState.res +6 -3
  35. package/src/IndexerState.res.mjs +3 -3
  36. package/src/IndexerState.resi +1 -1
  37. package/src/IndexingAddresses.res +10 -7
  38. package/src/IndexingAddresses.res.mjs +8 -7
  39. package/src/IndexingAddresses.resi +3 -1
  40. package/src/Internal.res +82 -36
  41. package/src/Internal.res.mjs +11 -1
  42. package/src/Main.res +22 -23
  43. package/src/Main.res.mjs +15 -17
  44. package/src/Metrics.res +43 -2
  45. package/src/Metrics.res.mjs +39 -3
  46. package/src/Prometheus.res +0 -35
  47. package/src/Prometheus.res.mjs +33 -68
  48. package/src/RawEvent.res +7 -2
  49. package/src/RawEvent.res.mjs +4 -4
  50. package/src/SimulateItems.res +26 -8
  51. package/src/SimulateItems.res.mjs +11 -14
  52. package/src/TestIndexer.res +1 -1
  53. package/src/TestIndexer.res.mjs +1 -1
  54. package/src/sources/BlockStore.res +46 -0
  55. package/src/sources/BlockStore.res.mjs +24 -0
  56. package/src/sources/EventRouter.res +19 -12
  57. package/src/sources/EventRouter.res.mjs +7 -5
  58. package/src/sources/Evm.res +54 -4
  59. package/src/sources/Evm.res.mjs +43 -4
  60. package/src/sources/EvmChain.res +14 -18
  61. package/src/sources/EvmChain.res.mjs +12 -13
  62. package/src/sources/FieldMask.res +39 -0
  63. package/src/sources/FieldMask.res.mjs +42 -0
  64. package/src/sources/Fuel.res +5 -2
  65. package/src/sources/Fuel.res.mjs +4 -3
  66. package/src/sources/HyperFuelSource.res +32 -40
  67. package/src/sources/HyperFuelSource.res.mjs +53 -45
  68. package/src/sources/HyperSync.res +35 -9
  69. package/src/sources/HyperSync.res.mjs +52 -35
  70. package/src/sources/HyperSync.resi +11 -3
  71. package/src/sources/HyperSyncClient.res +15 -4
  72. package/src/sources/HyperSyncHeightStream.res +1 -8
  73. package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
  74. package/src/sources/HyperSyncSource.res +39 -58
  75. package/src/sources/HyperSyncSource.res.mjs +44 -44
  76. package/src/sources/RpcSource.res +114 -92
  77. package/src/sources/RpcSource.res.mjs +77 -46
  78. package/src/sources/RpcWebSocketHeightStream.res +0 -5
  79. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
  80. package/src/sources/SimulateSource.res +6 -3
  81. package/src/sources/SimulateSource.res.mjs +13 -5
  82. package/src/sources/Source.res +25 -5
  83. package/src/sources/SourceManager.res +66 -3
  84. package/src/sources/SourceManager.res.mjs +55 -7
  85. package/src/sources/SourceManager.resi +10 -0
  86. package/src/sources/Svm.res +15 -10
  87. package/src/sources/Svm.res.mjs +24 -7
  88. package/src/sources/SvmHyperSyncClient.res +5 -6
  89. package/src/sources/SvmHyperSyncSource.res +84 -41
  90. package/src/sources/SvmHyperSyncSource.res.mjs +90 -43
  91. package/src/sources/TransactionStore.res +6 -107
  92. package/src/sources/TransactionStore.res.mjs +5 -86
  93. package/svm.schema.json +19 -0
@@ -5,9 +5,11 @@ import * as Js_math from "@rescript/runtime/lib/es6/Js_math.js";
5
5
  import * as Logging from "./Logging.res.mjs";
6
6
  import * as Prometheus from "./Prometheus.res.mjs";
7
7
  import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
8
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
8
9
  import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
9
10
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
10
11
  import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
12
+ import * as Primitive_float from "@rescript/runtime/lib/es6/Primitive_float.js";
11
13
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
12
14
  import * as IndexingAddresses from "./IndexingAddresses.res.mjs";
13
15
 
@@ -21,12 +23,9 @@ let deriveContractNameByAddress = Utils.$$WeakMap.memoize(addressesByContractNam
21
23
  return result;
22
24
  });
23
25
 
24
- function calculateEstResponseSize(p, fromBlock, toBlock, maxQueryBlockNumber) {
25
- if (p.prevQueryRange <= 0) {
26
- return 10000;
27
- }
26
+ function densityItemsTarget(p, fromBlock, toBlock, chainTargetBlock) {
28
27
  let density = p.prevRangeSize / p.prevQueryRange;
29
- return ((Stdlib_Option.getOr(toBlock, maxQueryBlockNumber) - fromBlock | 0) + 1 | 0) * density;
28
+ return ((Stdlib_Option.getOr(toBlock, chainTargetBlock) - fromBlock | 0) + 1 | 0) * density;
30
29
  }
31
30
 
32
31
  function getMinHistoryRange(p) {
@@ -486,27 +485,27 @@ function compareBufferItem(a, b) {
486
485
  }
487
486
  }
488
487
 
489
- function appendOnBlockItems(mutItems, onBlockConfigs, indexerStartBlock, fromBlock, maxBlockNumber, maxOnBlockBufferSize) {
488
+ function appendOnBlockItems(mutItems, onBlockRegistrations, indexerStartBlock, fromBlock, maxBlockNumber, maxOnBlockBufferSize) {
490
489
  let newItemsCounter = 0;
491
490
  let latestOnBlockBlockNumber = fromBlock;
492
491
  while (latestOnBlockBlockNumber < maxBlockNumber && newItemsCounter <= maxOnBlockBufferSize) {
493
492
  let blockNumber = latestOnBlockBlockNumber + 1 | 0;
494
493
  latestOnBlockBlockNumber = blockNumber;
495
- for (let configIdx = 0, configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx) {
496
- let onBlockConfig = onBlockConfigs[configIdx];
497
- let startBlock = onBlockConfig.startBlock;
494
+ for (let configIdx = 0, configIdx_finish = onBlockRegistrations.length; configIdx < configIdx_finish; ++configIdx) {
495
+ let onBlockRegistration = onBlockRegistrations[configIdx];
496
+ let startBlock = onBlockRegistration.startBlock;
498
497
  let handlerStartBlock = startBlock !== undefined ? startBlock : indexerStartBlock;
499
498
  let tmp = false;
500
499
  if (blockNumber >= handlerStartBlock) {
501
- let endBlock = onBlockConfig.endBlock;
500
+ let endBlock = onBlockRegistration.endBlock;
502
501
  tmp = endBlock !== undefined ? blockNumber <= endBlock : true;
503
502
  }
504
- if (tmp && Primitive_int.mod_(blockNumber - handlerStartBlock | 0, onBlockConfig.interval) === 0) {
503
+ if (tmp && Primitive_int.mod_(blockNumber - handlerStartBlock | 0, onBlockRegistration.interval) === 0) {
505
504
  mutItems.push({
506
505
  kind: 1,
507
- onBlockConfig: onBlockConfig,
506
+ onBlockRegistration: onBlockRegistration,
508
507
  blockNumber: blockNumber,
509
- logIndex: 16777216 + onBlockConfig.index | 0
508
+ logIndex: 16777216 + onBlockRegistration.index | 0
510
509
  });
511
510
  newItemsCounter = newItemsCounter + 1 | 0;
512
511
  }
@@ -520,9 +519,9 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
520
519
  let blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
521
520
  let knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : fetchState.knownHeight;
522
521
  let mutItemsRef = mutItems;
523
- let onBlockConfigs = fetchState.onBlockConfigs;
522
+ let onBlockRegistrations = fetchState.onBlockRegistrations;
524
523
  let latestOnBlockBlockNumber;
525
- if (onBlockConfigs.length !== 0) {
524
+ if (onBlockRegistrations.length !== 0) {
526
525
  let mutItems$1 = mutItemsRef;
527
526
  let item = (
528
527
  mutItems$1 !== undefined ? mutItems$1 : fetchState.buffer
@@ -538,7 +537,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
538
537
  let mutItems$2 = mutItemsRef;
539
538
  let mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.buffer.slice();
540
539
  mutItemsRef = mutItems$3;
541
- latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockConfigs, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
540
+ latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockRegistrations, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
542
541
  } else {
543
542
  latestOnBlockBlockNumber = knownHeight;
544
543
  }
@@ -550,7 +549,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
550
549
  let updatedFetchState_chainId = fetchState.chainId;
551
550
  let updatedFetchState_buffer = mutItems$4 !== undefined ? (mutItems$4.sort(compareBufferItem), mutItems$4) : fetchState.buffer;
552
551
  let updatedFetchState_maxOnBlockBufferSize = fetchState.maxOnBlockBufferSize;
553
- let updatedFetchState_onBlockConfigs = fetchState.onBlockConfigs;
552
+ let updatedFetchState_onBlockRegistrations = fetchState.onBlockRegistrations;
554
553
  let updatedFetchState_firstEventBlock = fetchState.firstEventBlock;
555
554
  let updatedFetchState = {
556
555
  optimizedPartitions: optimizedPartitions,
@@ -563,7 +562,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
563
562
  blockLag: blockLag,
564
563
  buffer: updatedFetchState_buffer,
565
564
  maxOnBlockBufferSize: updatedFetchState_maxOnBlockBufferSize,
566
- onBlockConfigs: updatedFetchState_onBlockConfigs,
565
+ onBlockRegistrations: updatedFetchState_onBlockRegistrations,
567
566
  knownHeight: knownHeight,
568
567
  firstEventBlock: updatedFetchState_firstEventBlock
569
568
  };
@@ -752,7 +751,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
752
751
  }
753
752
 
754
753
  function registerDynamicContracts(fetchState, indexingAddresses, items) {
755
- if (Utils.$$Array.isEmpty(fetchState.normalSelection.eventConfigs)) {
754
+ if (Utils.$$Array.isEmpty(fetchState.normalSelection.onEventRegistrations)) {
756
755
  Stdlib_JsError.throwWithMessage("Invalid configuration. No events to fetch for the dynamic contract registration.");
757
756
  }
758
757
  let registeringContractsByContract = {};
@@ -938,7 +937,7 @@ function handleQueryResult(fetchState, indexingAddresses, query, latestFetchedBl
938
937
  if (item.kind !== 0) {
939
938
  return true;
940
939
  }
941
- let filter = item.eventConfig.clientAddressFilter;
940
+ let filter = item.onEventRegistration.clientAddressFilter;
942
941
  if (filter !== undefined) {
943
942
  return filter(item.payload, item.blockNumber, IndexingAddresses.rawForFilter(indexingAddresses));
944
943
  } else {
@@ -959,7 +958,7 @@ function startFetchingQueries(param, queries) {
959
958
  fromBlock: q.fromBlock,
960
959
  toBlock: q.toBlock,
961
960
  isChunk: q.isChunk,
962
- estResponseSize: q.estResponseSize,
961
+ itemsTarget: q.itemsTarget,
963
962
  fetchedBlock: undefined
964
963
  };
965
964
  let inserted = false;
@@ -977,177 +976,135 @@ function startFetchingQueries(param, queries) {
977
976
  }
978
977
  }
979
978
 
980
- function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, maxChunks, partition, selection, addressesByContractName) {
981
- if (!(rangeFromBlock <= maxQueryBlockNumber && maxChunks > 0)) {
982
- return;
983
- }
984
- if (rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock) {
985
- return;
986
- }
987
- if (maybeChunkRange !== undefined) {
988
- let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
989
- let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
990
- if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
991
- let chunkFromBlock = rangeFromBlock;
992
- let chunkIdx = 0;
993
- while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
994
- let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
979
+ function pushGapFillQueries(queries, partitionId, rangeFromBlock, rangeEndBlock, knownHeight, chainTargetBlock, maybeChunkRange, maxChunks, partition, selection, addressesByContractName) {
980
+ let cost = 0;
981
+ if (rangeFromBlock <= knownHeight && maxChunks > 0) {
982
+ let exit = 0;
983
+ if (!(rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock)) {
984
+ exit = 1;
985
+ }
986
+ if (exit === 1) {
987
+ if (maybeChunkRange !== undefined) {
988
+ let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : chainTargetBlock;
989
+ let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
990
+ if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
991
+ let chunkFromBlock = rangeFromBlock;
992
+ let chunkIdx = 0;
993
+ while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
994
+ let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
995
+ let itemsTarget = densityItemsTarget(partition, chunkFromBlock, chunkToBlock, chainTargetBlock);
996
+ queries.push({
997
+ partitionId: partitionId,
998
+ fromBlock: chunkFromBlock,
999
+ toBlock: chunkToBlock,
1000
+ isChunk: true,
1001
+ itemsTarget: itemsTarget,
1002
+ selection: selection,
1003
+ addressesByContractName: addressesByContractName
1004
+ });
1005
+ cost = cost + itemsTarget;
1006
+ chunkFromBlock = chunkToBlock + 1 | 0;
1007
+ chunkIdx = chunkIdx + 1 | 0;
1008
+ };
1009
+ } else {
1010
+ let itemsTarget$1 = densityItemsTarget(partition, rangeFromBlock, rangeEndBlock, chainTargetBlock);
1011
+ queries.push({
1012
+ partitionId: partitionId,
1013
+ fromBlock: rangeFromBlock,
1014
+ toBlock: rangeEndBlock,
1015
+ isChunk: rangeEndBlock !== undefined,
1016
+ itemsTarget: itemsTarget$1,
1017
+ selection: selection,
1018
+ addressesByContractName: addressesByContractName
1019
+ });
1020
+ cost = cost + itemsTarget$1;
1021
+ }
1022
+ } else {
1023
+ let itemsTarget$2 = densityItemsTarget(partition, rangeFromBlock, rangeEndBlock, chainTargetBlock);
995
1024
  queries.push({
996
1025
  partitionId: partitionId,
997
- fromBlock: chunkFromBlock,
998
- toBlock: chunkToBlock,
999
- isChunk: true,
1000
- estResponseSize: calculateEstResponseSize(partition, chunkFromBlock, chunkToBlock, maxQueryBlockNumber),
1001
- chainId: 0,
1002
- progress: 0,
1026
+ fromBlock: rangeFromBlock,
1027
+ toBlock: rangeEndBlock,
1028
+ isChunk: false,
1029
+ itemsTarget: itemsTarget$2,
1003
1030
  selection: selection,
1004
1031
  addressesByContractName: addressesByContractName
1005
1032
  });
1006
- chunkFromBlock = chunkToBlock + 1 | 0;
1007
- chunkIdx = chunkIdx + 1 | 0;
1008
- };
1009
- return;
1033
+ cost = cost + itemsTarget$2;
1034
+ }
1010
1035
  }
1011
- queries.push({
1012
- partitionId: partitionId,
1013
- fromBlock: rangeFromBlock,
1014
- toBlock: rangeEndBlock,
1015
- isChunk: rangeEndBlock !== undefined,
1016
- estResponseSize: calculateEstResponseSize(partition, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
1017
- chainId: 0,
1018
- progress: 0,
1019
- selection: selection,
1020
- addressesByContractName: addressesByContractName
1021
- });
1022
- return;
1023
1036
  }
1024
- queries.push({
1025
- partitionId: partitionId,
1026
- fromBlock: rangeFromBlock,
1027
- toBlock: rangeEndBlock,
1028
- isChunk: false,
1029
- estResponseSize: calculateEstResponseSize(partition, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
1030
- chainId: 0,
1031
- progress: 0,
1032
- selection: selection,
1033
- addressesByContractName: addressesByContractName
1034
- });
1037
+ return cost;
1035
1038
  }
1036
1039
 
1037
- function getNextQuery(fetchState, budget, chainPendingBudget) {
1038
- let knownHeight = fetchState.knownHeight;
1039
- let blockLag = fetchState.blockLag;
1040
- let optimizedPartitions = fetchState.optimizedPartitions;
1040
+ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
1041
+ let knownHeight = param.knownHeight;
1042
+ let blockLag = param.blockLag;
1043
+ let endBlock = param.endBlock;
1044
+ let optimizedPartitions = param.optimizedPartitions;
1041
1045
  let headBlockNumber = knownHeight - blockLag | 0;
1042
1046
  if (headBlockNumber <= 0) {
1043
1047
  return "WaitingForNewBlock";
1044
1048
  }
1045
- if (budget <= 0) {
1046
- return "NothingToQuery";
1047
- }
1048
- let isOnBlockBehindTheHead = fetchState.latestOnBlockBlockNumber < headBlockNumber;
1049
- let endBlock = fetchState.endBlock;
1049
+ let isOnBlockBehindTheHead = param.latestOnBlockBlockNumber < headBlockNumber;
1050
1050
  let shouldWaitForNewBlock = (
1051
1051
  endBlock !== undefined ? headBlockNumber < endBlock : true
1052
1052
  ) && !isOnBlockBehindTheHead;
1053
- let item = fetchState.buffer[((bufferReadyCount(fetchState) + budget | 0) + (chainPendingBudget | 0) | 0) - 1 | 0];
1054
- let maxQueryBlockNumber = item !== undefined ? Primitive_int.min(item.blockNumber, knownHeight) : knownHeight;
1055
- let queries = [];
1056
1053
  let partitionsCount = optimizedPartitions.idsInAscOrder.length;
1057
- let idxRef = 0;
1058
- while (idxRef < partitionsCount) {
1059
- let idx = idxRef;
1054
+ for (let idx = 0; idx < partitionsCount; ++idx) {
1060
1055
  let partitionId = optimizedPartitions.idsInAscOrder[idx];
1061
1056
  let p = optimizedPartitions.entities[partitionId];
1062
- let pendingCount = p.mutPendingQueries.length;
1063
- let isBehindTheHead = p.latestFetchedBlock.blockNumber < headBlockNumber;
1064
- let hasPendingQueries = pendingCount > 0;
1065
- if (hasPendingQueries || isBehindTheHead) {
1057
+ if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock.blockNumber < headBlockNumber) {
1066
1058
  shouldWaitForNewBlock = false;
1067
1059
  }
1068
- let partitionQueriesStart = queries.length;
1069
- let queryEndBlock = Utils.$$Math.minOptInt(fetchState.endBlock, p.mergeBlock);
1070
- let queryEndBlock$1 = blockLag !== 0 ? Utils.$$Math.minOptInt(headBlockNumber, queryEndBlock) : queryEndBlock;
1071
- let match = maxQueryBlockNumber < knownHeight;
1072
- let queryEndBlock$2 = queryEndBlock$1 !== undefined ? (
1073
- match ? Primitive_int.min(maxQueryBlockNumber, queryEndBlock$1) : queryEndBlock$1
1074
- ) : (
1075
- match ? maxQueryBlockNumber : queryEndBlock$1
1076
- );
1077
- let maybeChunkRange = getMinHistoryRange(p);
1078
- let cursor = p.latestFetchedBlock.blockNumber + 1 | 0;
1060
+ }
1061
+ let queriesByPartitionIndex = Stdlib_Array.fromInitializer(partitionsCount, param => []);
1062
+ let computeQueryEndBlock = p => {
1063
+ let queryEndBlock = Utils.$$Math.minOptInt(endBlock, p.mergeBlock);
1064
+ if (blockLag !== 0) {
1065
+ return Utils.$$Math.minOptInt(headBlockNumber, queryEndBlock);
1066
+ } else {
1067
+ return queryEndBlock;
1068
+ }
1069
+ };
1070
+ let existingReservedByPartition = {};
1071
+ let chainReserved = 0;
1072
+ for (let idx$1 = 0; idx$1 < partitionsCount; ++idx$1) {
1073
+ let partitionId$1 = optimizedPartitions.idsInAscOrder[idx$1];
1074
+ let p$1 = optimizedPartitions.entities[partitionId$1];
1075
+ let cost = 0;
1076
+ for (let pqIdx = 0, pqIdx_finish = p$1.mutPendingQueries.length; pqIdx < pqIdx_finish; ++pqIdx) {
1077
+ cost = cost + p$1.mutPendingQueries[pqIdx].itemsTarget;
1078
+ }
1079
+ existingReservedByPartition[partitionId$1] = cost;
1080
+ chainReserved = chainReserved + cost;
1081
+ }
1082
+ let fillStates = [];
1083
+ let gapFillCost = 0;
1084
+ for (let idx$2 = 0; idx$2 < partitionsCount; ++idx$2) {
1085
+ let partitionId$2 = optimizedPartitions.idsInAscOrder[idx$2];
1086
+ let p$2 = optimizedPartitions.entities[partitionId$2];
1087
+ let bucket = queriesByPartitionIndex[idx$2];
1088
+ let pendingCount = p$2.mutPendingQueries.length;
1089
+ let queryEndBlock = computeQueryEndBlock(p$2);
1090
+ let maybeChunkRange = getMinHistoryRange(p$2);
1091
+ let cursor = p$2.latestFetchedBlock.blockNumber + 1 | 0;
1079
1092
  let canContinue = true;
1080
- let pqIdx = 0;
1081
- while (pqIdx < p.mutPendingQueries.length && canContinue) {
1082
- let pq = p.mutPendingQueries[pqIdx];
1093
+ let chunksUsedThisCall = 0;
1094
+ let pqIdx$1 = 0;
1095
+ while (pqIdx$1 < pendingCount && canContinue) {
1096
+ let pq = p$2.mutPendingQueries[pqIdx$1];
1083
1097
  if (pq.fromBlock > cursor) {
1084
- let addressesByContractName = p.addressesByContractName;
1085
- let selection = p.selection;
1086
- let maxChunks = (10 - pendingCount | 0) - (queries.length - partitionQueriesStart | 0) | 0;
1087
- let rangeEndBlock = Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock$2);
1088
- let rangeFromBlock = cursor;
1089
- if (rangeFromBlock <= maxQueryBlockNumber && maxChunks > 0) {
1090
- let exit = 0;
1091
- if (!(rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock)) {
1092
- exit = 1;
1093
- }
1094
- if (exit === 1) {
1095
- if (maybeChunkRange !== undefined) {
1096
- let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
1097
- let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
1098
- if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
1099
- let chunkFromBlock = rangeFromBlock;
1100
- let chunkIdx = 0;
1101
- while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
1102
- let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
1103
- queries.push({
1104
- partitionId: partitionId,
1105
- fromBlock: chunkFromBlock,
1106
- toBlock: chunkToBlock,
1107
- isChunk: true,
1108
- estResponseSize: calculateEstResponseSize(p, chunkFromBlock, chunkToBlock, maxQueryBlockNumber),
1109
- chainId: 0,
1110
- progress: 0,
1111
- selection: selection,
1112
- addressesByContractName: addressesByContractName
1113
- });
1114
- chunkFromBlock = chunkToBlock + 1 | 0;
1115
- chunkIdx = chunkIdx + 1 | 0;
1116
- };
1117
- } else {
1118
- queries.push({
1119
- partitionId: partitionId,
1120
- fromBlock: rangeFromBlock,
1121
- toBlock: rangeEndBlock,
1122
- isChunk: rangeEndBlock !== undefined,
1123
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
1124
- chainId: 0,
1125
- progress: 0,
1126
- selection: selection,
1127
- addressesByContractName: addressesByContractName
1128
- });
1129
- }
1130
- } else {
1131
- queries.push({
1132
- partitionId: partitionId,
1133
- fromBlock: rangeFromBlock,
1134
- toBlock: rangeEndBlock,
1135
- isChunk: false,
1136
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
1137
- chainId: 0,
1138
- progress: 0,
1139
- selection: selection,
1140
- addressesByContractName: addressesByContractName
1141
- });
1142
- }
1143
- }
1144
- }
1098
+ let beforeLen = bucket.length;
1099
+ let cost$1 = pushGapFillQueries(bucket, partitionId$2, cursor, Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock), knownHeight, chainTargetBlock, maybeChunkRange, (10 - pendingCount | 0) - chunksUsedThisCall | 0, p$2, p$2.selection, p$2.addressesByContractName);
1100
+ chunksUsedThisCall = chunksUsedThisCall + (bucket.length - beforeLen | 0) | 0;
1101
+ gapFillCost = gapFillCost + cost$1;
1145
1102
  }
1146
1103
  let toBlock = pq.toBlock;
1147
1104
  if (toBlock !== undefined && pq.isChunk) {
1148
- let match$1 = pq.fetchedBlock;
1149
- if (match$1 !== undefined) {
1150
- let blockNumber = match$1.blockNumber;
1105
+ let match = pq.fetchedBlock;
1106
+ if (match !== undefined) {
1107
+ let blockNumber = match.blockNumber;
1151
1108
  cursor = blockNumber < toBlock ? blockNumber + 1 | 0 : toBlock + 1 | 0;
1152
1109
  } else {
1153
1110
  cursor = toBlock + 1 | 0;
@@ -1155,72 +1112,122 @@ function getNextQuery(fetchState, budget, chainPendingBudget) {
1155
1112
  } else {
1156
1113
  canContinue = false;
1157
1114
  }
1158
- pqIdx = pqIdx + 1 | 0;
1115
+ pqIdx$1 = pqIdx$1 + 1 | 0;
1159
1116
  };
1160
1117
  if (canContinue) {
1161
- let addressesByContractName$1 = p.addressesByContractName;
1162
- let selection$1 = p.selection;
1163
- let maxChunks$1 = (10 - pendingCount | 0) - (queries.length - partitionQueriesStart | 0) | 0;
1164
- let rangeFromBlock$1 = cursor;
1165
- if (rangeFromBlock$1 <= maxQueryBlockNumber && maxChunks$1 > 0) {
1166
- let exit$1 = 0;
1167
- if (!(queryEndBlock$2 !== undefined && rangeFromBlock$1 > queryEndBlock$2)) {
1168
- exit$1 = 1;
1169
- }
1170
- if (exit$1 === 1) {
1171
- if (maybeChunkRange !== undefined) {
1172
- let maxBlock$1 = queryEndBlock$2 !== undefined ? queryEndBlock$2 : maxQueryBlockNumber;
1173
- let chunkSize$1 = Js_math.ceil_int(maybeChunkRange * 1.8);
1174
- if (((rangeFromBlock$1 + (chunkSize$1 << 1) | 0) - 1 | 0) <= maxBlock$1) {
1175
- let chunkFromBlock$1 = rangeFromBlock$1;
1176
- let chunkIdx$1 = 0;
1177
- while (chunkIdx$1 < maxChunks$1 && ((chunkFromBlock$1 + chunkSize$1 | 0) - 1 | 0) <= maxBlock$1) {
1178
- let chunkToBlock$1 = (chunkFromBlock$1 + chunkSize$1 | 0) - 1 | 0;
1179
- queries.push({
1180
- partitionId: partitionId,
1181
- fromBlock: chunkFromBlock$1,
1182
- toBlock: chunkToBlock$1,
1183
- isChunk: true,
1184
- estResponseSize: calculateEstResponseSize(p, chunkFromBlock$1, chunkToBlock$1, maxQueryBlockNumber),
1185
- chainId: 0,
1186
- progress: 0,
1187
- selection: selection$1,
1188
- addressesByContractName: addressesByContractName$1
1189
- });
1190
- chunkFromBlock$1 = chunkToBlock$1 + 1 | 0;
1191
- chunkIdx$1 = chunkIdx$1 + 1 | 0;
1192
- };
1193
- } else {
1194
- queries.push({
1195
- partitionId: partitionId,
1196
- fromBlock: rangeFromBlock$1,
1197
- toBlock: queryEndBlock$2,
1198
- isChunk: queryEndBlock$2 !== undefined,
1199
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock$1, queryEndBlock$2, maxQueryBlockNumber),
1200
- chainId: 0,
1201
- progress: 0,
1202
- selection: selection$1,
1203
- addressesByContractName: addressesByContractName$1
1204
- });
1205
- }
1206
- } else {
1207
- queries.push({
1208
- partitionId: partitionId,
1209
- fromBlock: rangeFromBlock$1,
1210
- toBlock: queryEndBlock$2,
1211
- isChunk: false,
1212
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock$1, queryEndBlock$2, maxQueryBlockNumber),
1213
- chainId: 0,
1214
- progress: 0,
1215
- selection: selection$1,
1216
- addressesByContractName: addressesByContractName$1
1217
- });
1218
- }
1219
- }
1220
- }
1118
+ fillStates.push({
1119
+ partitionId: partitionId$2,
1120
+ p: p$2,
1121
+ cursor: cursor,
1122
+ chunksUsedThisCall: chunksUsedThisCall,
1123
+ pendingCount: pendingCount,
1124
+ queryEndBlock: queryEndBlock,
1125
+ maybeChunkRange: maybeChunkRange,
1126
+ bucket: bucket
1127
+ });
1221
1128
  }
1222
- idxRef = idxRef + 1 | 0;
1129
+ }
1130
+ let rangeItemsTarget = Primitive_float.max(0, chainTargetItems - chainReserved - gapFillCost);
1131
+ let reservedByPartition = {};
1132
+ fillStates.forEach(fs => {
1133
+ let cost = existingReservedByPartition[fs.partitionId];
1134
+ for (let i = 0, i_finish = fs.bucket.length; i < i_finish; ++i) {
1135
+ cost = cost + fs.bucket[i].itemsTarget;
1136
+ }
1137
+ reservedByPartition[fs.partitionId] = cost;
1138
+ });
1139
+ let emitQueries = (fs, budget) => {
1140
+ let p = fs.p;
1141
+ let eb = fs.queryEndBlock;
1142
+ let maxBlock = eb !== undefined ? eb : chainTargetBlock;
1143
+ let minHistoryRange = fs.maybeChunkRange;
1144
+ if (minHistoryRange !== undefined) {
1145
+ let density = p.prevRangeSize / p.prevQueryRange;
1146
+ let chunkSize = Js_math.ceil_int(minHistoryRange * 1.8);
1147
+ let chunkCost = density * chunkSize;
1148
+ let maxChunksRemaining = (10 - fs.pendingCount | 0) - fs.chunksUsedThisCall | 0;
1149
+ let affordable = chunkCost > 0 ? Math.floor(budget / chunkCost) | 0 : maxChunksRemaining;
1150
+ let numChunks = Primitive_int.max(1, Primitive_int.min(affordable, maxChunksRemaining));
1151
+ let consumed = 0;
1152
+ let created = 0;
1153
+ let chunkFromBlock = fs.cursor;
1154
+ while (created < numChunks && chunkFromBlock <= maxBlock) {
1155
+ let chunkToBlock = Primitive_int.min((chunkFromBlock + chunkSize | 0) - 1 | 0, maxBlock);
1156
+ let itemsTarget = density * ((chunkToBlock - chunkFromBlock | 0) + 1 | 0);
1157
+ fs.bucket.push({
1158
+ partitionId: fs.partitionId,
1159
+ fromBlock: chunkFromBlock,
1160
+ toBlock: chunkToBlock,
1161
+ isChunk: true,
1162
+ itemsTarget: itemsTarget,
1163
+ selection: p.selection,
1164
+ addressesByContractName: p.addressesByContractName
1165
+ });
1166
+ consumed = consumed + itemsTarget;
1167
+ chunkFromBlock = chunkToBlock + 1 | 0;
1168
+ created = created + 1 | 0;
1169
+ };
1170
+ fs.cursor = chunkFromBlock;
1171
+ fs.chunksUsedThisCall = fs.chunksUsedThisCall + created | 0;
1172
+ return consumed;
1173
+ }
1174
+ let itemsTarget$1 = Primitive_float.min(Math.round(budget), 10000);
1175
+ fs.bucket.push({
1176
+ partitionId: fs.partitionId,
1177
+ fromBlock: fs.cursor,
1178
+ toBlock: fs.queryEndBlock,
1179
+ isChunk: false,
1180
+ itemsTarget: itemsTarget$1,
1181
+ selection: p.selection,
1182
+ addressesByContractName: p.addressesByContractName
1183
+ });
1184
+ fs.cursor = maxBlock + 1 | 0;
1185
+ fs.chunksUsedThisCall = fs.chunksUsedThisCall + 1 | 0;
1186
+ return itemsTarget$1;
1223
1187
  };
1188
+ let isInRange = fs => {
1189
+ let tmp = false;
1190
+ if (fs.cursor <= chainTargetBlock) {
1191
+ let eb = fs.queryEndBlock;
1192
+ tmp = eb !== undefined ? fs.cursor <= eb : true;
1193
+ }
1194
+ if (tmp) {
1195
+ return (fs.pendingCount + fs.chunksUsedThisCall | 0) < 10;
1196
+ } else {
1197
+ return false;
1198
+ }
1199
+ };
1200
+ let notFilledPartitions = fillStates.filter(isInRange);
1201
+ let reservedFromRange = {
1202
+ contents: 0
1203
+ };
1204
+ while (notFilledPartitions.length !== 0 && reservedFromRange.contents < rangeItemsTarget) {
1205
+ let n = notFilledPartitions.length;
1206
+ let footprintSum = {
1207
+ contents: 0
1208
+ };
1209
+ notFilledPartitions.forEach(fs => {
1210
+ footprintSum.contents = footprintSum.contents + reservedByPartition[fs.partitionId];
1211
+ });
1212
+ let line = (rangeItemsTarget - reservedFromRange.contents + footprintSum.contents) / n;
1213
+ let next = [];
1214
+ notFilledPartitions.forEach(fs => {
1215
+ let reserved = reservedByPartition[fs.partitionId];
1216
+ let budget = line - reserved;
1217
+ if (budget <= 0) {
1218
+ return;
1219
+ }
1220
+ let consumed = emitQueries(fs, budget);
1221
+ reservedByPartition[fs.partitionId] = reserved + consumed;
1222
+ reservedFromRange.contents = reservedFromRange.contents + consumed;
1223
+ if (isInRange(fs)) {
1224
+ next.push(fs);
1225
+ return;
1226
+ }
1227
+ });
1228
+ notFilledPartitions = next;
1229
+ };
1230
+ let queries = queriesByPartitionIndex.flat();
1224
1231
  if (Utils.$$Array.isEmpty(queries)) {
1225
1232
  if (shouldWaitForNewBlock) {
1226
1233
  return "WaitingForNewBlock";
@@ -1267,9 +1274,9 @@ function getReadyItemsCount(fetchState, targetSize, fromItem) {
1267
1274
  return acc;
1268
1275
  }
1269
1276
 
1270
- function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses, maxAddrInPartition, chainId, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt, firstEventBlockOpt) {
1277
+ function make$1(startBlock, endBlock, onEventRegistrations, contractConfigs, addresses, maxAddrInPartition, chainId, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockRegistrationsOpt, blockLagOpt, firstEventBlockOpt) {
1271
1278
  let progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
1272
- let onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
1279
+ let onBlockRegistrations = onBlockRegistrationsOpt !== undefined ? onBlockRegistrationsOpt : [];
1273
1280
  let blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
1274
1281
  let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
1275
1282
  let latestFetchedBlock = {
@@ -1277,14 +1284,14 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1277
1284
  blockTimestamp: 0
1278
1285
  };
1279
1286
  let notDependingOnAddresses = [];
1280
- let normalEventConfigs = [];
1287
+ let normalRegistrations = [];
1281
1288
  let contractNamesWithNormalEvents = new Set();
1282
- eventConfigs.forEach(ec => {
1283
- if (ec.dependsOnAddresses) {
1284
- normalEventConfigs.push(ec);
1285
- contractNamesWithNormalEvents.add(ec.contractName);
1289
+ onEventRegistrations.forEach(reg => {
1290
+ if (reg.dependsOnAddresses) {
1291
+ normalRegistrations.push(reg);
1292
+ contractNamesWithNormalEvents.add(reg.eventConfig.contractName);
1286
1293
  } else {
1287
- notDependingOnAddresses.push(ec);
1294
+ notDependingOnAddresses.push(reg);
1288
1295
  }
1289
1296
  });
1290
1297
  let partitions = [];
@@ -1293,7 +1300,7 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1293
1300
  id: partitions.length.toString(),
1294
1301
  latestFetchedBlock: latestFetchedBlock,
1295
1302
  selection: {
1296
- eventConfigs: notDependingOnAddresses,
1303
+ onEventRegistrations: notDependingOnAddresses,
1297
1304
  dependsOnAddresses: false
1298
1305
  },
1299
1306
  addressesByContractName: {},
@@ -1307,7 +1314,7 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1307
1314
  });
1308
1315
  }
1309
1316
  let normalSelection = {
1310
- eventConfigs: normalEventConfigs,
1317
+ onEventRegistrations: normalRegistrations,
1311
1318
  dependsOnAddresses: true
1312
1319
  };
1313
1320
  let registeringContractsByContract = {};
@@ -1325,16 +1332,16 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1325
1332
  }
1326
1333
  });
1327
1334
  let optimizedPartitions = createPartitionsFromIndexingAddresses(registeringContractsByContract, dynamicContracts, normalSelection, maxAddrInPartition, partitions.length, partitions, progressBlockNumber);
1328
- if (optimizedPartitions.idsInAscOrder.length === 0 && Utils.$$Array.isEmpty(onBlockConfigs)) {
1329
- Stdlib_JsError.throwWithMessage(`Invalid configuration: Nothing to fetch on chain ` + chainId.toString() + `. ` + (`addresses=` + addresses.length.toString() + `, `) + (`eventConfigs=` + eventConfigs.length.toString() + `, `) + (`normalEventConfigs=` + normalEventConfigs.length.toString() + `. `) + `Make sure that you provided at least one contract address to index, or have events with Wildcard mode enabled, or have onBlock handlers.`);
1335
+ if (optimizedPartitions.idsInAscOrder.length === 0 && Utils.$$Array.isEmpty(onBlockRegistrations)) {
1336
+ Stdlib_JsError.throwWithMessage(`Invalid configuration: Nothing to fetch on chain ` + chainId.toString() + `. ` + (`addresses=` + addresses.length.toString() + `, `) + (`onEventRegistrations=` + onEventRegistrations.length.toString() + `, `) + (`normalRegistrations=` + normalRegistrations.length.toString() + `. `) + `Make sure that you provided at least one contract address to index, or have events with Wildcard mode enabled, or have onBlock handlers.`);
1330
1337
  }
1331
1338
  let buffer = [];
1332
1339
  let latestOnBlockBlockNumber;
1333
- if (knownHeight > 0 && Utils.$$Array.notEmpty(onBlockConfigs)) {
1340
+ if (knownHeight > 0 && Utils.$$Array.notEmpty(onBlockRegistrations)) {
1334
1341
  let id = optimizedPartitions.idsInAscOrder[0];
1335
1342
  let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
1336
1343
  let maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock.blockNumber : knownHeight;
1337
- latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockConfigs, startBlock, progressBlockNumber, maxBlockNumber, maxOnBlockBufferSize);
1344
+ latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockRegistrations, startBlock, progressBlockNumber, maxBlockNumber, maxOnBlockBufferSize);
1338
1345
  } else {
1339
1346
  latestOnBlockBlockNumber = progressBlockNumber;
1340
1347
  }
@@ -1349,7 +1356,7 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1349
1356
  blockLag: blockLag,
1350
1357
  buffer: buffer,
1351
1358
  maxOnBlockBufferSize: maxOnBlockBufferSize,
1352
- onBlockConfigs: onBlockConfigs,
1359
+ onBlockRegistrations: onBlockRegistrations,
1353
1360
  knownHeight: knownHeight,
1354
1361
  firstEventBlock: firstEventBlock
1355
1362
  };
@@ -1378,7 +1385,7 @@ function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
1378
1385
  fromBlock: pq.fromBlock,
1379
1386
  toBlock: pq.toBlock,
1380
1387
  isChunk: pq.isChunk,
1381
- estResponseSize: pq.estResponseSize,
1388
+ itemsTarget: pq.itemsTarget,
1382
1389
  fetchedBlock: {
1383
1390
  blockNumber: targetBlockNumber,
1384
1391
  blockTimestamp: 0
@@ -1477,7 +1484,7 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
1477
1484
  blockLag: fetchState.blockLag,
1478
1485
  buffer: fetchState.buffer,
1479
1486
  maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
1480
- onBlockConfigs: fetchState.onBlockConfigs,
1487
+ onBlockRegistrations: fetchState.onBlockRegistrations,
1481
1488
  knownHeight: fetchState.knownHeight,
1482
1489
  firstEventBlock: fetchState.firstEventBlock
1483
1490
  }, optimizedPartitions, fetchState.buffer.filter(item => {
@@ -1527,7 +1534,7 @@ function resetPendingQueries(fetchState) {
1527
1534
  blockLag: fetchState.blockLag,
1528
1535
  buffer: fetchState.buffer,
1529
1536
  maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
1530
- onBlockConfigs: fetchState.onBlockConfigs,
1537
+ onBlockRegistrations: fetchState.onBlockRegistrations,
1531
1538
  knownHeight: fetchState.knownHeight,
1532
1539
  firstEventBlock: fetchState.firstEventBlock
1533
1540
  };
@@ -1590,19 +1597,6 @@ function getProgressPercentage(fetchState) {
1590
1597
  return progress / totalRange;
1591
1598
  }
1592
1599
 
1593
- function getProgressPercentageAt(fetchState, blockNumber) {
1594
- let firstEventBlock = fetchState.firstEventBlock;
1595
- if (firstEventBlock === undefined) {
1596
- return 0;
1597
- }
1598
- let totalRange = fetchState.knownHeight - firstEventBlock | 0;
1599
- if (totalRange <= 0) {
1600
- return 0;
1601
- } else {
1602
- return (blockNumber - firstEventBlock | 0) / totalRange;
1603
- }
1604
- }
1605
-
1606
1600
  function hasFullBatch(fetchState, batchSizeTarget) {
1607
1601
  let item = fetchState.buffer[batchSizeTarget - 1 | 0];
1608
1602
  if (item !== undefined) {
@@ -1656,7 +1650,9 @@ function updateKnownHeight(fetchState, knownHeight) {
1656
1650
  }
1657
1651
  }
1658
1652
 
1659
- let defaultEstResponseSize = 10000;
1653
+ let minItemsTarget = 2000;
1654
+
1655
+ let maxItemsTarget = 10000;
1660
1656
 
1661
1657
  let blockItemLogIndex = 16777216;
1662
1658
 
@@ -1664,8 +1660,9 @@ let maxPendingChunksPerPartition = 10;
1664
1660
 
1665
1661
  export {
1666
1662
  deriveContractNameByAddress,
1667
- defaultEstResponseSize,
1668
- calculateEstResponseSize,
1663
+ minItemsTarget,
1664
+ maxItemsTarget,
1665
+ densityItemsTarget,
1669
1666
  getMinHistoryRange,
1670
1667
  getMinQueryRange,
1671
1668
  OptimizedPartitions,
@@ -1684,7 +1681,7 @@ export {
1684
1681
  handleQueryResult,
1685
1682
  startFetchingQueries,
1686
1683
  maxPendingChunksPerPartition,
1687
- pushQueriesForRange,
1684
+ pushGapFillQueries,
1688
1685
  getNextQuery,
1689
1686
  hasReadyItem,
1690
1687
  getReadyItemsCount,
@@ -1697,7 +1694,6 @@ export {
1697
1694
  isFetchingAtHead,
1698
1695
  isReadyToEnterReorgThreshold,
1699
1696
  getProgressPercentage,
1700
- getProgressPercentageAt,
1701
1697
  sortForBatch,
1702
1698
  getProgressBlockNumberAt,
1703
1699
  updateKnownHeight,