envio 3.3.0-alpha.7 → 3.3.0-alpha.9

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 (95) hide show
  1. package/index.d.ts +23 -5
  2. package/package.json +6 -6
  3. package/src/Api.res +1 -1
  4. package/src/Api.res.mjs +1 -1
  5. package/src/ChainFetching.res +21 -10
  6. package/src/ChainFetching.res.mjs +11 -10
  7. package/src/ChainState.res +401 -171
  8. package/src/ChainState.res.mjs +270 -104
  9. package/src/ChainState.resi +19 -7
  10. package/src/Config.res +11 -27
  11. package/src/Config.res.mjs +8 -7
  12. package/src/Core.res +7 -0
  13. package/src/CrossChainState.res +82 -82
  14. package/src/CrossChainState.res.mjs +52 -59
  15. package/src/CrossChainState.resi +1 -1
  16. package/src/Ecosystem.res +3 -3
  17. package/src/Ecosystem.res.mjs +3 -3
  18. package/src/Envio.res +14 -9
  19. package/src/EnvioGlobal.res +53 -0
  20. package/src/EnvioGlobal.res.mjs +31 -0
  21. package/src/EventConfigBuilder.res +117 -69
  22. package/src/EventConfigBuilder.res.mjs +71 -34
  23. package/src/EventProcessing.res +19 -15
  24. package/src/EventProcessing.res.mjs +13 -12
  25. package/src/FetchState.res +410 -185
  26. package/src/FetchState.res.mjs +268 -253
  27. package/src/HandlerLoader.res +8 -113
  28. package/src/HandlerLoader.res.mjs +2 -88
  29. package/src/HandlerRegister.res +518 -144
  30. package/src/HandlerRegister.res.mjs +285 -133
  31. package/src/HandlerRegister.resi +24 -8
  32. package/src/IndexerState.res +6 -3
  33. package/src/IndexerState.res.mjs +3 -3
  34. package/src/IndexerState.resi +1 -1
  35. package/src/IndexingAddresses.res +10 -7
  36. package/src/IndexingAddresses.res.mjs +8 -7
  37. package/src/IndexingAddresses.resi +3 -1
  38. package/src/Internal.res +104 -39
  39. package/src/Internal.res.mjs +11 -1
  40. package/src/LogSelection.res +102 -165
  41. package/src/LogSelection.res.mjs +101 -116
  42. package/src/Main.res +49 -164
  43. package/src/Main.res.mjs +39 -104
  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/RollbackCommit.res +4 -1
  51. package/src/RollbackCommit.res.mjs +3 -2
  52. package/src/SimulateItems.res +20 -7
  53. package/src/SimulateItems.res.mjs +7 -11
  54. package/src/TestIndexer.res +1 -1
  55. package/src/TestIndexer.res.mjs +1 -1
  56. package/src/sources/BlockStore.res +46 -0
  57. package/src/sources/BlockStore.res.mjs +24 -0
  58. package/src/sources/EventRouter.res +19 -12
  59. package/src/sources/EventRouter.res.mjs +7 -5
  60. package/src/sources/Evm.res +58 -5
  61. package/src/sources/Evm.res.mjs +44 -5
  62. package/src/sources/EvmChain.res +14 -18
  63. package/src/sources/EvmChain.res.mjs +12 -13
  64. package/src/sources/FieldMask.res +39 -0
  65. package/src/sources/FieldMask.res.mjs +42 -0
  66. package/src/sources/Fuel.res +8 -3
  67. package/src/sources/Fuel.res.mjs +5 -4
  68. package/src/sources/HyperFuelSource.res +31 -40
  69. package/src/sources/HyperFuelSource.res.mjs +52 -44
  70. package/src/sources/HyperSync.res +31 -9
  71. package/src/sources/HyperSync.res.mjs +47 -31
  72. package/src/sources/HyperSync.resi +10 -3
  73. package/src/sources/HyperSyncClient.res +15 -4
  74. package/src/sources/HyperSyncHeightStream.res +1 -8
  75. package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
  76. package/src/sources/HyperSyncSource.res +58 -90
  77. package/src/sources/HyperSyncSource.res.mjs +57 -66
  78. package/src/sources/RpcSource.res +118 -120
  79. package/src/sources/RpcSource.res.mjs +92 -74
  80. package/src/sources/RpcWebSocketHeightStream.res +0 -5
  81. package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
  82. package/src/sources/SimulateSource.res +5 -3
  83. package/src/sources/SimulateSource.res.mjs +12 -4
  84. package/src/sources/Source.res +19 -5
  85. package/src/sources/SourceManager.res +60 -10
  86. package/src/sources/SourceManager.res.mjs +54 -8
  87. package/src/sources/SourceManager.resi +10 -0
  88. package/src/sources/Svm.res +14 -10
  89. package/src/sources/Svm.res.mjs +23 -6
  90. package/src/sources/SvmHyperSyncClient.res +5 -6
  91. package/src/sources/SvmHyperSyncSource.res +82 -41
  92. package/src/sources/SvmHyperSyncSource.res.mjs +86 -41
  93. package/src/sources/TransactionStore.res +6 -107
  94. package/src/sources/TransactionStore.res.mjs +5 -86
  95. package/svm.schema.json +19 -0
@@ -5,6 +5,7 @@ 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";
@@ -22,23 +23,23 @@ let deriveContractNameByAddress = Utils.$$WeakMap.memoize(addressesByContractNam
22
23
  return result;
23
24
  });
24
25
 
25
- function calculateDefaultEstResponseSize(partitionsCount) {
26
- return Primitive_float.max(2000, Primitive_float.min(10000, 20000 / partitionsCount));
26
+ function densityItemsTarget(density, fromBlock, toBlock, chainTargetBlock) {
27
+ return Primitive_int.max(1, Math.ceil(((Stdlib_Option.getOr(toBlock, chainTargetBlock) - fromBlock | 0) + 1 | 0) * density) | 0);
27
28
  }
28
29
 
29
- function calculateEstResponseSize(p, fromBlock, toBlock, knownHeight, partitionsCount) {
30
- if (p.prevQueryRange <= 0) {
31
- return calculateDefaultEstResponseSize(partitionsCount);
30
+ function getMinHistoryRange(p) {
31
+ let match = p.prevQueryRange;
32
+ let match$1 = p.prevPrevQueryRange;
33
+ if (match !== 0 && match$1 !== 0) {
34
+ return match < match$1 ? match : match$1;
32
35
  }
33
- let density = p.prevRangeSize / p.prevQueryRange;
34
- return ((Stdlib_Option.getOr(toBlock, knownHeight) - fromBlock | 0) + 1 | 0) * density;
35
36
  }
36
37
 
37
- function getMinHistoryRange(p) {
38
+ function getTrustedDensity(p) {
38
39
  let match = p.prevQueryRange;
39
40
  let match$1 = p.prevPrevQueryRange;
40
41
  if (match !== 0 && match$1 !== 0) {
41
- return match < match$1 ? match : match$1;
42
+ return p.prevRangeSize / match;
42
43
  }
43
44
  }
44
45
 
@@ -111,6 +112,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
111
112
  p1,
112
113
  p2
113
114
  ]);
115
+ let inheritedDensity = Stdlib_Option.getOr(getTrustedDensity(p1), 0) + Stdlib_Option.getOr(getTrustedDensity(p2), 0);
114
116
  continuingBase = {
115
117
  id: newId,
116
118
  latestFetchedBlock: {
@@ -124,7 +126,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
124
126
  mutPendingQueries: [],
125
127
  prevQueryRange: minRange,
126
128
  prevPrevQueryRange: minRange,
127
- prevRangeSize: 0,
129
+ prevRangeSize: Math.ceil(inheritedDensity * minRange) | 0,
128
130
  latestBlockRangeUpdateBlock: 0
129
131
  };
130
132
  } else {
@@ -491,27 +493,27 @@ function compareBufferItem(a, b) {
491
493
  }
492
494
  }
493
495
 
494
- function appendOnBlockItems(mutItems, onBlockConfigs, indexerStartBlock, fromBlock, maxBlockNumber, maxOnBlockBufferSize) {
496
+ function appendOnBlockItems(mutItems, onBlockRegistrations, indexerStartBlock, fromBlock, maxBlockNumber, maxOnBlockBufferSize) {
495
497
  let newItemsCounter = 0;
496
498
  let latestOnBlockBlockNumber = fromBlock;
497
499
  while (latestOnBlockBlockNumber < maxBlockNumber && newItemsCounter <= maxOnBlockBufferSize) {
498
500
  let blockNumber = latestOnBlockBlockNumber + 1 | 0;
499
501
  latestOnBlockBlockNumber = blockNumber;
500
- for (let configIdx = 0, configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx) {
501
- let onBlockConfig = onBlockConfigs[configIdx];
502
- let startBlock = onBlockConfig.startBlock;
502
+ for (let configIdx = 0, configIdx_finish = onBlockRegistrations.length; configIdx < configIdx_finish; ++configIdx) {
503
+ let onBlockRegistration = onBlockRegistrations[configIdx];
504
+ let startBlock = onBlockRegistration.startBlock;
503
505
  let handlerStartBlock = startBlock !== undefined ? startBlock : indexerStartBlock;
504
506
  let tmp = false;
505
507
  if (blockNumber >= handlerStartBlock) {
506
- let endBlock = onBlockConfig.endBlock;
508
+ let endBlock = onBlockRegistration.endBlock;
507
509
  tmp = endBlock !== undefined ? blockNumber <= endBlock : true;
508
510
  }
509
- if (tmp && Primitive_int.mod_(blockNumber - handlerStartBlock | 0, onBlockConfig.interval) === 0) {
511
+ if (tmp && Primitive_int.mod_(blockNumber - handlerStartBlock | 0, onBlockRegistration.interval) === 0) {
510
512
  mutItems.push({
511
513
  kind: 1,
512
- onBlockConfig: onBlockConfig,
514
+ onBlockRegistration: onBlockRegistration,
513
515
  blockNumber: blockNumber,
514
- logIndex: 16777216 + onBlockConfig.index | 0
516
+ logIndex: 16777216 + onBlockRegistration.index | 0
515
517
  });
516
518
  newItemsCounter = newItemsCounter + 1 | 0;
517
519
  }
@@ -525,9 +527,9 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
525
527
  let blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
526
528
  let knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : fetchState.knownHeight;
527
529
  let mutItemsRef = mutItems;
528
- let onBlockConfigs = fetchState.onBlockConfigs;
530
+ let onBlockRegistrations = fetchState.onBlockRegistrations;
529
531
  let latestOnBlockBlockNumber;
530
- if (onBlockConfigs.length !== 0) {
532
+ if (onBlockRegistrations.length !== 0) {
531
533
  let mutItems$1 = mutItemsRef;
532
534
  let item = (
533
535
  mutItems$1 !== undefined ? mutItems$1 : fetchState.buffer
@@ -543,7 +545,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
543
545
  let mutItems$2 = mutItemsRef;
544
546
  let mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.buffer.slice();
545
547
  mutItemsRef = mutItems$3;
546
- latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockConfigs, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
548
+ latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockRegistrations, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
547
549
  } else {
548
550
  latestOnBlockBlockNumber = knownHeight;
549
551
  }
@@ -555,7 +557,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
555
557
  let updatedFetchState_chainId = fetchState.chainId;
556
558
  let updatedFetchState_buffer = mutItems$4 !== undefined ? (mutItems$4.sort(compareBufferItem), mutItems$4) : fetchState.buffer;
557
559
  let updatedFetchState_maxOnBlockBufferSize = fetchState.maxOnBlockBufferSize;
558
- let updatedFetchState_onBlockConfigs = fetchState.onBlockConfigs;
560
+ let updatedFetchState_onBlockRegistrations = fetchState.onBlockRegistrations;
559
561
  let updatedFetchState_firstEventBlock = fetchState.firstEventBlock;
560
562
  let updatedFetchState = {
561
563
  optimizedPartitions: optimizedPartitions,
@@ -568,7 +570,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
568
570
  blockLag: blockLag,
569
571
  buffer: updatedFetchState_buffer,
570
572
  maxOnBlockBufferSize: updatedFetchState_maxOnBlockBufferSize,
571
- onBlockConfigs: updatedFetchState_onBlockConfigs,
573
+ onBlockRegistrations: updatedFetchState_onBlockRegistrations,
572
574
  knownHeight: knownHeight,
573
575
  firstEventBlock: updatedFetchState_firstEventBlock
574
576
  };
@@ -757,7 +759,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
757
759
  }
758
760
 
759
761
  function registerDynamicContracts(fetchState, indexingAddresses, items) {
760
- if (Utils.$$Array.isEmpty(fetchState.normalSelection.eventConfigs)) {
762
+ if (Utils.$$Array.isEmpty(fetchState.normalSelection.onEventRegistrations)) {
761
763
  Stdlib_JsError.throwWithMessage("Invalid configuration. No events to fetch for the dynamic contract registration.");
762
764
  }
763
765
  let registeringContractsByContract = {};
@@ -943,7 +945,7 @@ function handleQueryResult(fetchState, indexingAddresses, query, latestFetchedBl
943
945
  if (item.kind !== 0) {
944
946
  return true;
945
947
  }
946
- let filter = item.eventConfig.clientAddressFilter;
948
+ let filter = item.onEventRegistration.clientAddressFilter;
947
949
  if (filter !== undefined) {
948
950
  return filter(item.payload, item.blockNumber, IndexingAddresses.rawForFilter(indexingAddresses));
949
951
  } else {
@@ -964,7 +966,7 @@ function startFetchingQueries(param, queries) {
964
966
  fromBlock: q.fromBlock,
965
967
  toBlock: q.toBlock,
966
968
  isChunk: q.isChunk,
967
- estResponseSize: q.estResponseSize,
969
+ itemsTarget: q.itemsTarget,
968
970
  fetchedBlock: undefined
969
971
  };
970
972
  let inserted = false;
@@ -982,64 +984,87 @@ function startFetchingQueries(param, queries) {
982
984
  }
983
985
  }
984
986
 
985
- function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, knownHeight, maybeChunkRange, maxChunks, partition, selection, addressesByContractName, partitionsCount) {
986
- if (!(rangeFromBlock <= knownHeight && maxChunks > 0)) {
987
- return;
988
- }
989
- if (rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock) {
990
- return;
991
- }
992
- if (maybeChunkRange !== undefined) {
993
- let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : knownHeight;
994
- let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
995
- if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
996
- let chunkFromBlock = rangeFromBlock;
997
- let chunkIdx = 0;
998
- while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
999
- let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
987
+ function pushGapFillQueries(queries, partitionId, rangeFromBlock, rangeEndBlock, knownHeight, chainTargetBlock, maybeChunkRange, maxChunks, partition, partitionBudget, selection, addressesByContractName) {
988
+ let cost = {
989
+ contents: 0
990
+ };
991
+ if (rangeFromBlock <= knownHeight && maxChunks > 0) {
992
+ let exit = 0;
993
+ if (!(rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock)) {
994
+ exit = 1;
995
+ }
996
+ if (exit === 1) {
997
+ let trustedDensity = getTrustedDensity(partition);
998
+ let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : chainTargetBlock;
999
+ let pushSingleQuery = (density, isChunk) => {
1000
+ let itemsTarget = densityItemsTarget(density, rangeFromBlock, rangeEndBlock, chainTargetBlock);
1000
1001
  queries.push({
1001
1002
  partitionId: partitionId,
1002
- fromBlock: chunkFromBlock,
1003
- toBlock: chunkToBlock,
1004
- isChunk: true,
1005
- estResponseSize: calculateEstResponseSize(partition, chunkFromBlock, chunkToBlock, knownHeight, partitionsCount),
1006
- chainId: 0,
1007
- progress: 0,
1003
+ fromBlock: rangeFromBlock,
1004
+ toBlock: rangeEndBlock,
1005
+ isChunk: isChunk,
1006
+ itemsTarget: itemsTarget,
1008
1007
  selection: selection,
1009
1008
  addressesByContractName: addressesByContractName
1010
1009
  });
1011
- chunkFromBlock = chunkToBlock + 1 | 0;
1012
- chunkIdx = chunkIdx + 1 | 0;
1010
+ cost.contents = cost.contents + itemsTarget;
1013
1011
  };
1014
- return;
1012
+ if (trustedDensity !== undefined) {
1013
+ if (maybeChunkRange !== undefined && trustedDensity > 0) {
1014
+ let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
1015
+ if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
1016
+ let chunkFromBlock = rangeFromBlock;
1017
+ let chunkIdx = 0;
1018
+ while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
1019
+ let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
1020
+ let itemsTarget = densityItemsTarget(trustedDensity, chunkFromBlock, chunkToBlock, chainTargetBlock);
1021
+ queries.push({
1022
+ partitionId: partitionId,
1023
+ fromBlock: chunkFromBlock,
1024
+ toBlock: chunkToBlock,
1025
+ isChunk: true,
1026
+ itemsTarget: itemsTarget,
1027
+ selection: selection,
1028
+ addressesByContractName: addressesByContractName
1029
+ });
1030
+ cost.contents = cost.contents + itemsTarget;
1031
+ chunkFromBlock = chunkToBlock + 1 | 0;
1032
+ chunkIdx = chunkIdx + 1 | 0;
1033
+ };
1034
+ } else {
1035
+ pushSingleQuery(trustedDensity, rangeEndBlock !== undefined);
1036
+ }
1037
+ } else {
1038
+ pushSingleQuery(trustedDensity, false);
1039
+ }
1040
+ } else {
1041
+ let remainingRange = Primitive_int.max(1, (chainTargetBlock - rangeFromBlock | 0) + 1 | 0);
1042
+ pushSingleQuery(partitionBudget / remainingRange, false);
1043
+ }
1015
1044
  }
1016
- queries.push({
1017
- partitionId: partitionId,
1018
- fromBlock: rangeFromBlock,
1019
- toBlock: rangeEndBlock,
1020
- isChunk: rangeEndBlock !== undefined,
1021
- estResponseSize: calculateEstResponseSize(partition, rangeFromBlock, rangeEndBlock, knownHeight, partitionsCount),
1022
- chainId: 0,
1023
- progress: 0,
1024
- selection: selection,
1025
- addressesByContractName: addressesByContractName
1026
- });
1027
- return;
1028
1045
  }
1029
- queries.push({
1030
- partitionId: partitionId,
1031
- fromBlock: rangeFromBlock,
1032
- toBlock: rangeEndBlock,
1033
- isChunk: false,
1034
- estResponseSize: calculateEstResponseSize(partition, rangeFromBlock, rangeEndBlock, knownHeight, partitionsCount),
1035
- chainId: 0,
1036
- progress: 0,
1037
- selection: selection,
1038
- addressesByContractName: addressesByContractName
1039
- });
1046
+ return cost.contents;
1040
1047
  }
1041
1048
 
1042
- function getNextQuery(param) {
1049
+ function waterLevel(budget, footprints) {
1050
+ let sorted = footprints.toSorted(Primitive_float.compare);
1051
+ let n = sorted.length;
1052
+ let prefix = 0;
1053
+ let level;
1054
+ let idx = 0;
1055
+ while (level === undefined && idx < n) {
1056
+ let i = idx;
1057
+ prefix = prefix + sorted[i];
1058
+ let candidate = (budget + prefix) / (i + 1 | 0);
1059
+ if (i === (n - 1 | 0) || candidate <= sorted[i + 1 | 0]) {
1060
+ level = candidate;
1061
+ }
1062
+ idx = idx + 1 | 0;
1063
+ };
1064
+ return Stdlib_Option.getOr(level, 0);
1065
+ }
1066
+
1067
+ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
1043
1068
  let knownHeight = param.knownHeight;
1044
1069
  let blockLag = param.blockLag;
1045
1070
  let endBlock = param.endBlock;
@@ -1052,90 +1077,55 @@ function getNextQuery(param) {
1052
1077
  let shouldWaitForNewBlock = (
1053
1078
  endBlock !== undefined ? headBlockNumber < endBlock : true
1054
1079
  ) && !isOnBlockBehindTheHead;
1055
- let queries = [];
1056
1080
  let partitionsCount = optimizedPartitions.idsInAscOrder.length;
1057
- let idxRef = 0;
1058
- while (idxRef < partitionsCount) {
1059
- let idx = idxRef;
1081
+ for (let idx = 0; idx < partitionsCount; ++idx) {
1060
1082
  let partitionId = optimizedPartitions.idsInAscOrder[idx];
1061
1083
  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) {
1084
+ if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock.blockNumber < headBlockNumber) {
1066
1085
  shouldWaitForNewBlock = false;
1067
1086
  }
1068
- let partitionQueriesStart = queries.length;
1087
+ }
1088
+ let queriesByPartitionIndex = Stdlib_Array.fromInitializer(partitionsCount, param => []);
1089
+ let computeQueryEndBlock = p => {
1069
1090
  let queryEndBlock = Utils.$$Math.minOptInt(endBlock, p.mergeBlock);
1070
- let queryEndBlock$1 = blockLag !== 0 ? Utils.$$Math.minOptInt(headBlockNumber, queryEndBlock) : queryEndBlock;
1071
- let maybeChunkRange = getMinHistoryRange(p);
1072
- let cursor = p.latestFetchedBlock.blockNumber + 1 | 0;
1091
+ if (blockLag !== 0) {
1092
+ return Utils.$$Math.minOptInt(headBlockNumber, queryEndBlock);
1093
+ } else {
1094
+ return queryEndBlock;
1095
+ }
1096
+ };
1097
+ let existingReservedByPartition = {};
1098
+ let chainReserved = 0;
1099
+ for (let idx$1 = 0; idx$1 < partitionsCount; ++idx$1) {
1100
+ let partitionId$1 = optimizedPartitions.idsInAscOrder[idx$1];
1101
+ let p$1 = optimizedPartitions.entities[partitionId$1];
1102
+ let cost = 0;
1103
+ for (let pqIdx = 0, pqIdx_finish = p$1.mutPendingQueries.length; pqIdx < pqIdx_finish; ++pqIdx) {
1104
+ cost = cost + p$1.mutPendingQueries[pqIdx].itemsTarget;
1105
+ }
1106
+ existingReservedByPartition[partitionId$1] = cost;
1107
+ chainReserved = chainReserved + cost;
1108
+ }
1109
+ let fillStates = [];
1110
+ let gapFillCost = 0;
1111
+ for (let idx$2 = 0; idx$2 < partitionsCount; ++idx$2) {
1112
+ let partitionId$2 = optimizedPartitions.idsInAscOrder[idx$2];
1113
+ let p$2 = optimizedPartitions.entities[partitionId$2];
1114
+ let bucket = queriesByPartitionIndex[idx$2];
1115
+ let pendingCount = p$2.mutPendingQueries.length;
1116
+ let queryEndBlock = computeQueryEndBlock(p$2);
1117
+ let maybeChunkRange = getMinHistoryRange(p$2);
1118
+ let cursor = p$2.latestFetchedBlock.blockNumber + 1 | 0;
1073
1119
  let canContinue = true;
1074
- let pqIdx = 0;
1075
- while (pqIdx < p.mutPendingQueries.length && canContinue) {
1076
- let pq = p.mutPendingQueries[pqIdx];
1120
+ let chunksUsedThisCall = 0;
1121
+ let pqIdx$1 = 0;
1122
+ while (pqIdx$1 < pendingCount && canContinue) {
1123
+ let pq = p$2.mutPendingQueries[pqIdx$1];
1077
1124
  if (pq.fromBlock > cursor) {
1078
- let addressesByContractName = p.addressesByContractName;
1079
- let selection = p.selection;
1080
- let maxChunks = (10 - pendingCount | 0) - (queries.length - partitionQueriesStart | 0) | 0;
1081
- let rangeEndBlock = Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock$1);
1082
- let rangeFromBlock = cursor;
1083
- if (rangeFromBlock <= knownHeight && maxChunks > 0) {
1084
- let exit = 0;
1085
- if (!(rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock)) {
1086
- exit = 1;
1087
- }
1088
- if (exit === 1) {
1089
- if (maybeChunkRange !== undefined) {
1090
- let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : knownHeight;
1091
- let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
1092
- if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
1093
- let chunkFromBlock = rangeFromBlock;
1094
- let chunkIdx = 0;
1095
- while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
1096
- let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
1097
- queries.push({
1098
- partitionId: partitionId,
1099
- fromBlock: chunkFromBlock,
1100
- toBlock: chunkToBlock,
1101
- isChunk: true,
1102
- estResponseSize: calculateEstResponseSize(p, chunkFromBlock, chunkToBlock, knownHeight, partitionsCount),
1103
- chainId: 0,
1104
- progress: 0,
1105
- selection: selection,
1106
- addressesByContractName: addressesByContractName
1107
- });
1108
- chunkFromBlock = chunkToBlock + 1 | 0;
1109
- chunkIdx = chunkIdx + 1 | 0;
1110
- };
1111
- } else {
1112
- queries.push({
1113
- partitionId: partitionId,
1114
- fromBlock: rangeFromBlock,
1115
- toBlock: rangeEndBlock,
1116
- isChunk: rangeEndBlock !== undefined,
1117
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock, rangeEndBlock, knownHeight, partitionsCount),
1118
- chainId: 0,
1119
- progress: 0,
1120
- selection: selection,
1121
- addressesByContractName: addressesByContractName
1122
- });
1123
- }
1124
- } else {
1125
- queries.push({
1126
- partitionId: partitionId,
1127
- fromBlock: rangeFromBlock,
1128
- toBlock: rangeEndBlock,
1129
- isChunk: false,
1130
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock, rangeEndBlock, knownHeight, partitionsCount),
1131
- chainId: 0,
1132
- progress: 0,
1133
- selection: selection,
1134
- addressesByContractName: addressesByContractName
1135
- });
1136
- }
1137
- }
1138
- }
1125
+ let beforeLen = bucket.length;
1126
+ 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, chainTargetItems / partitionsCount, p$2.selection, p$2.addressesByContractName);
1127
+ chunksUsedThisCall = chunksUsedThisCall + (bucket.length - beforeLen | 0) | 0;
1128
+ gapFillCost = gapFillCost + cost$1;
1139
1129
  }
1140
1130
  let toBlock = pq.toBlock;
1141
1131
  if (toBlock !== undefined && pq.isChunk) {
@@ -1149,72 +1139,116 @@ function getNextQuery(param) {
1149
1139
  } else {
1150
1140
  canContinue = false;
1151
1141
  }
1152
- pqIdx = pqIdx + 1 | 0;
1142
+ pqIdx$1 = pqIdx$1 + 1 | 0;
1153
1143
  };
1154
1144
  if (canContinue) {
1155
- let addressesByContractName$1 = p.addressesByContractName;
1156
- let selection$1 = p.selection;
1157
- let maxChunks$1 = (10 - pendingCount | 0) - (queries.length - partitionQueriesStart | 0) | 0;
1158
- let rangeFromBlock$1 = cursor;
1159
- if (rangeFromBlock$1 <= knownHeight && maxChunks$1 > 0) {
1160
- let exit$1 = 0;
1161
- if (!(queryEndBlock$1 !== undefined && rangeFromBlock$1 > queryEndBlock$1)) {
1162
- exit$1 = 1;
1163
- }
1164
- if (exit$1 === 1) {
1165
- if (maybeChunkRange !== undefined) {
1166
- let maxBlock$1 = queryEndBlock$1 !== undefined ? queryEndBlock$1 : knownHeight;
1167
- let chunkSize$1 = Js_math.ceil_int(maybeChunkRange * 1.8);
1168
- if (((rangeFromBlock$1 + (chunkSize$1 << 1) | 0) - 1 | 0) <= maxBlock$1) {
1169
- let chunkFromBlock$1 = rangeFromBlock$1;
1170
- let chunkIdx$1 = 0;
1171
- while (chunkIdx$1 < maxChunks$1 && ((chunkFromBlock$1 + chunkSize$1 | 0) - 1 | 0) <= maxBlock$1) {
1172
- let chunkToBlock$1 = (chunkFromBlock$1 + chunkSize$1 | 0) - 1 | 0;
1173
- queries.push({
1174
- partitionId: partitionId,
1175
- fromBlock: chunkFromBlock$1,
1176
- toBlock: chunkToBlock$1,
1177
- isChunk: true,
1178
- estResponseSize: calculateEstResponseSize(p, chunkFromBlock$1, chunkToBlock$1, knownHeight, partitionsCount),
1179
- chainId: 0,
1180
- progress: 0,
1181
- selection: selection$1,
1182
- addressesByContractName: addressesByContractName$1
1183
- });
1184
- chunkFromBlock$1 = chunkToBlock$1 + 1 | 0;
1185
- chunkIdx$1 = chunkIdx$1 + 1 | 0;
1186
- };
1187
- } else {
1188
- queries.push({
1189
- partitionId: partitionId,
1190
- fromBlock: rangeFromBlock$1,
1191
- toBlock: queryEndBlock$1,
1192
- isChunk: queryEndBlock$1 !== undefined,
1193
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock$1, queryEndBlock$1, knownHeight, partitionsCount),
1194
- chainId: 0,
1195
- progress: 0,
1196
- selection: selection$1,
1197
- addressesByContractName: addressesByContractName$1
1198
- });
1199
- }
1200
- } else {
1201
- queries.push({
1202
- partitionId: partitionId,
1203
- fromBlock: rangeFromBlock$1,
1204
- toBlock: queryEndBlock$1,
1205
- isChunk: false,
1206
- estResponseSize: calculateEstResponseSize(p, rangeFromBlock$1, queryEndBlock$1, knownHeight, partitionsCount),
1207
- chainId: 0,
1208
- progress: 0,
1209
- selection: selection$1,
1210
- addressesByContractName: addressesByContractName$1
1211
- });
1212
- }
1213
- }
1214
- }
1145
+ fillStates.push({
1146
+ partitionId: partitionId$2,
1147
+ p: p$2,
1148
+ cursor: cursor,
1149
+ chunksUsedThisCall: chunksUsedThisCall,
1150
+ pendingCount: pendingCount,
1151
+ queryEndBlock: queryEndBlock,
1152
+ maybeChunkRange: maybeChunkRange,
1153
+ bucket: bucket
1154
+ });
1215
1155
  }
1216
- idxRef = idxRef + 1 | 0;
1156
+ }
1157
+ let rangeItemsTarget = Primitive_float.max(0, chainTargetItems - chainReserved - gapFillCost);
1158
+ let reservedByPartition = {};
1159
+ fillStates.forEach(fs => {
1160
+ let cost = existingReservedByPartition[fs.partitionId];
1161
+ for (let i = 0, i_finish = fs.bucket.length; i < i_finish; ++i) {
1162
+ cost = cost + fs.bucket[i].itemsTarget;
1163
+ }
1164
+ reservedByPartition[fs.partitionId] = cost;
1165
+ });
1166
+ let isInRange = fs => {
1167
+ let tmp = false;
1168
+ if (fs.cursor <= chainTargetBlock) {
1169
+ let eb = fs.queryEndBlock;
1170
+ tmp = eb !== undefined ? fs.cursor <= eb : true;
1171
+ }
1172
+ if (tmp) {
1173
+ return (fs.pendingCount + fs.chunksUsedThisCall | 0) < 10;
1174
+ } else {
1175
+ return false;
1176
+ }
1177
+ };
1178
+ let inRangeStates = fillStates.filter(isInRange);
1179
+ let emitQueries = (fs, budget) => {
1180
+ let p = fs.p;
1181
+ let eb = fs.queryEndBlock;
1182
+ let maxBlock = eb !== undefined ? eb : chainTargetBlock;
1183
+ let match = fs.maybeChunkRange;
1184
+ let match$1 = getTrustedDensity(p);
1185
+ if (match !== undefined && match$1 !== undefined && match$1 > 0) {
1186
+ let chunkSize = Js_math.ceil_int(match * 1.8);
1187
+ let chunkCost = match$1 * chunkSize;
1188
+ let maxChunksRemaining = (10 - fs.pendingCount | 0) - fs.chunksUsedThisCall | 0;
1189
+ let affordable = Math.floor(budget / chunkCost) | 0;
1190
+ let numChunks = Primitive_int.max(1, Primitive_int.min(affordable, maxChunksRemaining));
1191
+ let consumed = 0;
1192
+ let created = 0;
1193
+ let chunkFromBlock = fs.cursor;
1194
+ while (created < numChunks && chunkFromBlock <= maxBlock) {
1195
+ let chunkToBlock = Primitive_int.min((chunkFromBlock + chunkSize | 0) - 1 | 0, maxBlock);
1196
+ let itemsTarget = Primitive_int.max(1, Math.ceil(match$1 * ((chunkToBlock - chunkFromBlock | 0) + 1 | 0)) | 0);
1197
+ fs.bucket.push({
1198
+ partitionId: fs.partitionId,
1199
+ fromBlock: chunkFromBlock,
1200
+ toBlock: chunkToBlock,
1201
+ isChunk: true,
1202
+ itemsTarget: itemsTarget,
1203
+ selection: p.selection,
1204
+ addressesByContractName: p.addressesByContractName
1205
+ });
1206
+ consumed = consumed + itemsTarget;
1207
+ chunkFromBlock = chunkToBlock + 1 | 0;
1208
+ created = created + 1 | 0;
1209
+ };
1210
+ fs.cursor = chunkFromBlock;
1211
+ fs.chunksUsedThisCall = fs.chunksUsedThisCall + created | 0;
1212
+ return consumed;
1213
+ }
1214
+ let itemsTarget$1 = Primitive_int.max(1, Math.round(budget) | 0);
1215
+ fs.bucket.push({
1216
+ partitionId: fs.partitionId,
1217
+ fromBlock: fs.cursor,
1218
+ toBlock: fs.queryEndBlock,
1219
+ isChunk: false,
1220
+ itemsTarget: itemsTarget$1,
1221
+ selection: p.selection,
1222
+ addressesByContractName: p.addressesByContractName
1223
+ });
1224
+ fs.cursor = maxBlock + 1 | 0;
1225
+ fs.chunksUsedThisCall = fs.chunksUsedThisCall + 1 | 0;
1226
+ return itemsTarget$1;
1227
+ };
1228
+ let notFilledPartitions = inRangeStates;
1229
+ let remainingBudget = {
1230
+ contents: rangeItemsTarget
1231
+ };
1232
+ while (notFilledPartitions.length !== 0 && remainingBudget.contents > 0) {
1233
+ let level = waterLevel(remainingBudget.contents, notFilledPartitions.map(fs => reservedByPartition[fs.partitionId]));
1234
+ let next = [];
1235
+ notFilledPartitions.forEach(fs => {
1236
+ let reserved = reservedByPartition[fs.partitionId];
1237
+ let budget = level - reserved;
1238
+ if (budget <= 0) {
1239
+ return;
1240
+ }
1241
+ let consumed = emitQueries(fs, budget);
1242
+ reservedByPartition[fs.partitionId] = reserved + consumed;
1243
+ remainingBudget.contents = remainingBudget.contents - consumed;
1244
+ if (isInRange(fs)) {
1245
+ next.push(fs);
1246
+ return;
1247
+ }
1248
+ });
1249
+ notFilledPartitions = next;
1217
1250
  };
1251
+ let queries = queriesByPartitionIndex.flat();
1218
1252
  if (Utils.$$Array.isEmpty(queries)) {
1219
1253
  if (shouldWaitForNewBlock) {
1220
1254
  return "WaitingForNewBlock";
@@ -1261,9 +1295,9 @@ function getReadyItemsCount(fetchState, targetSize, fromItem) {
1261
1295
  return acc;
1262
1296
  }
1263
1297
 
1264
- function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses, maxAddrInPartition, chainId, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt, firstEventBlockOpt) {
1298
+ function make$1(startBlock, endBlock, onEventRegistrations, contractConfigs, addresses, maxAddrInPartition, chainId, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockRegistrationsOpt, blockLagOpt, firstEventBlockOpt) {
1265
1299
  let progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
1266
- let onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
1300
+ let onBlockRegistrations = onBlockRegistrationsOpt !== undefined ? onBlockRegistrationsOpt : [];
1267
1301
  let blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
1268
1302
  let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
1269
1303
  let latestFetchedBlock = {
@@ -1271,14 +1305,14 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1271
1305
  blockTimestamp: 0
1272
1306
  };
1273
1307
  let notDependingOnAddresses = [];
1274
- let normalEventConfigs = [];
1308
+ let normalRegistrations = [];
1275
1309
  let contractNamesWithNormalEvents = new Set();
1276
- eventConfigs.forEach(ec => {
1277
- if (ec.dependsOnAddresses) {
1278
- normalEventConfigs.push(ec);
1279
- contractNamesWithNormalEvents.add(ec.contractName);
1310
+ onEventRegistrations.forEach(reg => {
1311
+ if (reg.dependsOnAddresses) {
1312
+ normalRegistrations.push(reg);
1313
+ contractNamesWithNormalEvents.add(reg.eventConfig.contractName);
1280
1314
  } else {
1281
- notDependingOnAddresses.push(ec);
1315
+ notDependingOnAddresses.push(reg);
1282
1316
  }
1283
1317
  });
1284
1318
  let partitions = [];
@@ -1287,7 +1321,7 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1287
1321
  id: partitions.length.toString(),
1288
1322
  latestFetchedBlock: latestFetchedBlock,
1289
1323
  selection: {
1290
- eventConfigs: notDependingOnAddresses,
1324
+ onEventRegistrations: notDependingOnAddresses,
1291
1325
  dependsOnAddresses: false
1292
1326
  },
1293
1327
  addressesByContractName: {},
@@ -1301,7 +1335,7 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1301
1335
  });
1302
1336
  }
1303
1337
  let normalSelection = {
1304
- eventConfigs: normalEventConfigs,
1338
+ onEventRegistrations: normalRegistrations,
1305
1339
  dependsOnAddresses: true
1306
1340
  };
1307
1341
  let registeringContractsByContract = {};
@@ -1319,16 +1353,16 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1319
1353
  }
1320
1354
  });
1321
1355
  let optimizedPartitions = createPartitionsFromIndexingAddresses(registeringContractsByContract, dynamicContracts, normalSelection, maxAddrInPartition, partitions.length, partitions, progressBlockNumber);
1322
- if (optimizedPartitions.idsInAscOrder.length === 0 && Utils.$$Array.isEmpty(onBlockConfigs)) {
1323
- 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.`);
1356
+ if (optimizedPartitions.idsInAscOrder.length === 0 && Utils.$$Array.isEmpty(onBlockRegistrations)) {
1357
+ 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.`);
1324
1358
  }
1325
1359
  let buffer = [];
1326
1360
  let latestOnBlockBlockNumber;
1327
- if (knownHeight > 0 && Utils.$$Array.notEmpty(onBlockConfigs)) {
1361
+ if (knownHeight > 0 && Utils.$$Array.notEmpty(onBlockRegistrations)) {
1328
1362
  let id = optimizedPartitions.idsInAscOrder[0];
1329
1363
  let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
1330
1364
  let maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock.blockNumber : knownHeight;
1331
- latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockConfigs, startBlock, progressBlockNumber, maxBlockNumber, maxOnBlockBufferSize);
1365
+ latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockRegistrations, startBlock, progressBlockNumber, maxBlockNumber, maxOnBlockBufferSize);
1332
1366
  } else {
1333
1367
  latestOnBlockBlockNumber = progressBlockNumber;
1334
1368
  }
@@ -1343,7 +1377,7 @@ function make$1(startBlock, endBlock, eventConfigs, contractConfigs, addresses,
1343
1377
  blockLag: blockLag,
1344
1378
  buffer: buffer,
1345
1379
  maxOnBlockBufferSize: maxOnBlockBufferSize,
1346
- onBlockConfigs: onBlockConfigs,
1380
+ onBlockRegistrations: onBlockRegistrations,
1347
1381
  knownHeight: knownHeight,
1348
1382
  firstEventBlock: firstEventBlock
1349
1383
  };
@@ -1372,7 +1406,7 @@ function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
1372
1406
  fromBlock: pq.fromBlock,
1373
1407
  toBlock: pq.toBlock,
1374
1408
  isChunk: pq.isChunk,
1375
- estResponseSize: pq.estResponseSize,
1409
+ itemsTarget: pq.itemsTarget,
1376
1410
  fetchedBlock: {
1377
1411
  blockNumber: targetBlockNumber,
1378
1412
  blockTimestamp: 0
@@ -1471,7 +1505,7 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
1471
1505
  blockLag: fetchState.blockLag,
1472
1506
  buffer: fetchState.buffer,
1473
1507
  maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
1474
- onBlockConfigs: fetchState.onBlockConfigs,
1508
+ onBlockRegistrations: fetchState.onBlockRegistrations,
1475
1509
  knownHeight: fetchState.knownHeight,
1476
1510
  firstEventBlock: fetchState.firstEventBlock
1477
1511
  }, optimizedPartitions, fetchState.buffer.filter(item => {
@@ -1521,7 +1555,7 @@ function resetPendingQueries(fetchState) {
1521
1555
  blockLag: fetchState.blockLag,
1522
1556
  buffer: fetchState.buffer,
1523
1557
  maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
1524
- onBlockConfigs: fetchState.onBlockConfigs,
1558
+ onBlockRegistrations: fetchState.onBlockRegistrations,
1525
1559
  knownHeight: fetchState.knownHeight,
1526
1560
  firstEventBlock: fetchState.firstEventBlock
1527
1561
  };
@@ -1584,19 +1618,6 @@ function getProgressPercentage(fetchState) {
1584
1618
  return progress / totalRange;
1585
1619
  }
1586
1620
 
1587
- function getProgressPercentageAt(fetchState, blockNumber) {
1588
- let firstEventBlock = fetchState.firstEventBlock;
1589
- if (firstEventBlock === undefined) {
1590
- return 0;
1591
- }
1592
- let totalRange = fetchState.knownHeight - firstEventBlock | 0;
1593
- if (totalRange <= 0) {
1594
- return 0;
1595
- } else {
1596
- return (blockNumber - firstEventBlock | 0) / totalRange;
1597
- }
1598
- }
1599
-
1600
1621
  function hasFullBatch(fetchState, batchSizeTarget) {
1601
1622
  let item = fetchState.buffer[batchSizeTarget - 1 | 0];
1602
1623
  if (item !== undefined) {
@@ -1650,21 +1671,15 @@ function updateKnownHeight(fetchState, knownHeight) {
1650
1671
  }
1651
1672
  }
1652
1673
 
1653
- let minEstResponseSize = 2000;
1654
-
1655
- let maxEstResponseSize = 10000;
1656
-
1657
1674
  let blockItemLogIndex = 16777216;
1658
1675
 
1659
1676
  let maxPendingChunksPerPartition = 10;
1660
1677
 
1661
1678
  export {
1662
1679
  deriveContractNameByAddress,
1663
- minEstResponseSize,
1664
- maxEstResponseSize,
1665
- calculateDefaultEstResponseSize,
1666
- calculateEstResponseSize,
1680
+ densityItemsTarget,
1667
1681
  getMinHistoryRange,
1682
+ getTrustedDensity,
1668
1683
  getMinQueryRange,
1669
1684
  OptimizedPartitions,
1670
1685
  bufferBlockNumber,
@@ -1682,7 +1697,8 @@ export {
1682
1697
  handleQueryResult,
1683
1698
  startFetchingQueries,
1684
1699
  maxPendingChunksPerPartition,
1685
- pushQueriesForRange,
1700
+ pushGapFillQueries,
1701
+ waterLevel,
1686
1702
  getNextQuery,
1687
1703
  hasReadyItem,
1688
1704
  getReadyItemsCount,
@@ -1695,7 +1711,6 @@ export {
1695
1711
  isFetchingAtHead,
1696
1712
  isReadyToEnterReorgThreshold,
1697
1713
  getProgressPercentage,
1698
- getProgressPercentageAt,
1699
1714
  sortForBatch,
1700
1715
  getProgressBlockNumberAt,
1701
1716
  updateKnownHeight,