envio 3.2.1 → 3.3.0-alpha.1
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.
- package/package.json +6 -7
- package/src/Batch.res +12 -15
- package/src/Batch.res.mjs +4 -5
- package/src/BatchProcessing.res +199 -0
- package/src/BatchProcessing.res.mjs +125 -0
- package/src/ChainFetching.res +373 -0
- package/src/ChainFetching.res.mjs +206 -0
- package/src/ChainMetadata.res +27 -0
- package/src/ChainMetadata.res.mjs +27 -0
- package/src/ChainState.res +643 -0
- package/src/ChainState.res.mjs +476 -0
- package/src/ChainState.resi +87 -0
- package/src/Config.res +13 -4
- package/src/Config.res.mjs +8 -3
- package/src/ContractRegisterContext.res +106 -0
- package/src/ContractRegisterContext.res.mjs +76 -0
- package/src/Core.res +3 -0
- package/src/CrossChainState.res +294 -0
- package/src/CrossChainState.res.mjs +221 -0
- package/src/CrossChainState.resi +39 -0
- package/src/Ecosystem.res +58 -0
- package/src/Ecosystem.res.mjs +43 -1
- package/src/Env.res +0 -2
- package/src/Env.res.mjs +0 -3
- package/src/EventConfigBuilder.res +2 -2
- package/src/EventProcessing.res +60 -46
- package/src/EventProcessing.res.mjs +33 -32
- package/src/EventUtils.res +0 -4
- package/src/EventUtils.res.mjs +0 -4
- package/src/ExitOnCaughtUp.res +10 -0
- package/src/ExitOnCaughtUp.res.mjs +22 -0
- package/src/FetchState.res +205 -73
- package/src/FetchState.res.mjs +242 -103
- package/src/InMemoryStore.res +36 -451
- package/src/InMemoryStore.res.mjs +20 -369
- package/src/IndexerLoop.res +43 -0
- package/src/IndexerLoop.res.mjs +46 -0
- package/src/IndexerState.res +536 -0
- package/src/IndexerState.res.mjs +543 -0
- package/src/IndexerState.resi +128 -0
- package/src/Internal.res +29 -8
- package/src/LoadLayer.res +20 -18
- package/src/LoadLayer.res.mjs +14 -12
- package/src/LoadLayer.resi +6 -3
- package/src/Logging.res +11 -44
- package/src/Logging.res.mjs +10 -42
- package/src/Main.res +54 -79
- package/src/Main.res.mjs +44 -56
- package/src/PgStorage.res +8 -71
- package/src/PgStorage.res.mjs +3 -47
- package/src/Prometheus.res +1 -13
- package/src/Prometheus.res.mjs +84 -96
- package/src/PruneStaleHistory.res +45 -0
- package/src/PruneStaleHistory.res.mjs +46 -0
- package/src/RawEvent.res +73 -0
- package/src/RawEvent.res.mjs +51 -0
- package/src/Rollback.res +204 -0
- package/src/Rollback.res.mjs +118 -0
- package/src/SimulateItems.res +12 -10
- package/src/SimulateItems.res.mjs +1 -1
- package/src/UserContext.res +26 -114
- package/src/UserContext.res.mjs +15 -78
- package/src/Writing.res +242 -0
- package/src/Writing.res.mjs +215 -0
- package/src/db/InternalTable.res +14 -27
- package/src/sources/Evm.res +40 -1
- package/src/sources/Evm.res.mjs +94 -84
- package/src/sources/Fuel.res +40 -1
- package/src/sources/Fuel.res.mjs +36 -26
- package/src/sources/HyperFuel.res +41 -120
- package/src/sources/HyperFuel.res.mjs +42 -80
- package/src/sources/HyperFuel.resi +1 -24
- package/src/sources/HyperFuelClient.res +16 -297
- package/src/sources/HyperFuelClient.res.mjs +5 -4
- package/src/sources/HyperFuelSource.res +33 -8
- package/src/sources/HyperFuelSource.res.mjs +56 -10
- package/src/sources/HyperSyncSource.res +5 -3
- package/src/sources/HyperSyncSource.res.mjs +1 -1
- package/src/sources/RpcSource.res +2 -2
- package/src/sources/RpcSource.res.mjs +1 -1
- package/src/sources/SourceManager.res +14 -23
- package/src/sources/SourceManager.res.mjs +27 -29
- package/src/sources/SourceManager.resi +4 -2
- package/src/sources/Svm.res +18 -1
- package/src/sources/Svm.res.mjs +30 -22
- package/src/sources/SvmHyperSyncSource.res +1 -1
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/tui/Tui.res +38 -36
- package/src/tui/Tui.res.mjs +51 -51
- package/src/ChainFetcher.res +0 -519
- package/src/ChainFetcher.res.mjs +0 -314
- package/src/ChainManager.res +0 -358
- package/src/ChainManager.res.mjs +0 -291
- package/src/Ctx.res +0 -6
- package/src/Ctx.res.mjs +0 -2
- package/src/GlobalState.res +0 -1056
- package/src/GlobalState.res.mjs +0 -1086
- package/src/GlobalStateManager.res +0 -57
- package/src/GlobalStateManager.res.mjs +0 -68
- package/src/GlobalStateManager.resi +0 -7
- package/src/Ports.res +0 -5
- package/src/Ports.res.mjs +0 -9
- package/src/adapters/MarkBatchProcessedAdapter.res +0 -5
- package/src/adapters/MarkBatchProcessedAdapter.res.mjs +0 -14
- package/src/sources/EnvioApiClient.res +0 -15
- package/src/sources/EnvioApiClient.res.mjs +0 -24
package/src/FetchState.res.mjs
CHANGED
|
@@ -14,6 +14,14 @@ function deriveEffectiveStartBlock(registrationBlock, contractStartBlock) {
|
|
|
14
14
|
return Primitive_int.max(Primitive_int.max(registrationBlock, 0), Stdlib_Option.getOr(contractStartBlock, 0));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function calculateEstResponseSize(p, fromBlock, toBlock, maxQueryBlockNumber) {
|
|
18
|
+
if (p.prevQueryRange <= 0) {
|
|
19
|
+
return 10000;
|
|
20
|
+
}
|
|
21
|
+
let density = p.prevRangeSize / p.prevQueryRange;
|
|
22
|
+
return ((Stdlib_Option.getOr(toBlock, maxQueryBlockNumber) - fromBlock | 0) + 1 | 0) * density;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
function getMinHistoryRange(p) {
|
|
18
26
|
let match = p.prevQueryRange;
|
|
19
27
|
let match$1 = p.prevPrevQueryRange;
|
|
@@ -69,6 +77,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
69
77
|
mutPendingQueries: p1.mutPendingQueries,
|
|
70
78
|
prevQueryRange: p1.prevQueryRange,
|
|
71
79
|
prevPrevQueryRange: p1.prevPrevQueryRange,
|
|
80
|
+
prevRangeSize: p1.prevRangeSize,
|
|
72
81
|
latestBlockRangeUpdateBlock: p1.latestBlockRangeUpdateBlock
|
|
73
82
|
});
|
|
74
83
|
completed.push({
|
|
@@ -81,6 +90,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
81
90
|
mutPendingQueries: p2.mutPendingQueries,
|
|
82
91
|
prevQueryRange: p2.prevQueryRange,
|
|
83
92
|
prevPrevQueryRange: p2.prevPrevQueryRange,
|
|
93
|
+
prevRangeSize: p2.prevRangeSize,
|
|
84
94
|
latestBlockRangeUpdateBlock: p2.latestBlockRangeUpdateBlock
|
|
85
95
|
});
|
|
86
96
|
let newId = nextPartitionIndexRef.contents.toString();
|
|
@@ -102,6 +112,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
102
112
|
mutPendingQueries: [],
|
|
103
113
|
prevQueryRange: minRange,
|
|
104
114
|
prevPrevQueryRange: minRange,
|
|
115
|
+
prevRangeSize: 0,
|
|
105
116
|
latestBlockRangeUpdateBlock: 0
|
|
106
117
|
};
|
|
107
118
|
} else {
|
|
@@ -115,6 +126,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
115
126
|
mutPendingQueries: p1.mutPendingQueries,
|
|
116
127
|
prevQueryRange: p1.prevQueryRange,
|
|
117
128
|
prevPrevQueryRange: p1.prevPrevQueryRange,
|
|
129
|
+
prevRangeSize: p1.prevRangeSize,
|
|
118
130
|
latestBlockRangeUpdateBlock: p1.latestBlockRangeUpdateBlock
|
|
119
131
|
});
|
|
120
132
|
continuingBase = p2;
|
|
@@ -130,6 +142,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
130
142
|
mutPendingQueries: p2.mutPendingQueries,
|
|
131
143
|
prevQueryRange: p2.prevQueryRange,
|
|
132
144
|
prevPrevQueryRange: p2.prevPrevQueryRange,
|
|
145
|
+
prevRangeSize: p2.prevRangeSize,
|
|
133
146
|
latestBlockRangeUpdateBlock: p2.latestBlockRangeUpdateBlock
|
|
134
147
|
});
|
|
135
148
|
continuingBase = p1;
|
|
@@ -153,6 +166,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
153
166
|
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
154
167
|
prevQueryRange: continuingBase.prevQueryRange,
|
|
155
168
|
prevPrevQueryRange: continuingBase.prevPrevQueryRange,
|
|
169
|
+
prevRangeSize: continuingBase.prevRangeSize,
|
|
156
170
|
latestBlockRangeUpdateBlock: continuingBase.latestBlockRangeUpdateBlock
|
|
157
171
|
});
|
|
158
172
|
let restId = nextPartitionIndexRef.contents.toString();
|
|
@@ -167,6 +181,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
167
181
|
mutPendingQueries: [],
|
|
168
182
|
prevQueryRange: continuingBase.prevQueryRange,
|
|
169
183
|
prevPrevQueryRange: continuingBase.prevPrevQueryRange,
|
|
184
|
+
prevRangeSize: continuingBase.prevRangeSize,
|
|
170
185
|
latestBlockRangeUpdateBlock: continuingBase.latestBlockRangeUpdateBlock
|
|
171
186
|
});
|
|
172
187
|
return completed;
|
|
@@ -183,6 +198,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
183
198
|
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
184
199
|
prevQueryRange: continuingBase.prevQueryRange,
|
|
185
200
|
prevPrevQueryRange: continuingBase.prevPrevQueryRange,
|
|
201
|
+
prevRangeSize: continuingBase.prevRangeSize,
|
|
186
202
|
latestBlockRangeUpdateBlock: continuingBase.latestBlockRangeUpdateBlock
|
|
187
203
|
});
|
|
188
204
|
return completed;
|
|
@@ -320,7 +336,7 @@ function getPendingQueryOrThrow(p, fromBlock) {
|
|
|
320
336
|
}
|
|
321
337
|
}
|
|
322
338
|
|
|
323
|
-
function handleQueryResponse(optimizedPartitions, query, knownHeight, latestFetchedBlock) {
|
|
339
|
+
function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount, latestFetchedBlock) {
|
|
324
340
|
let partitionId = query.partitionId;
|
|
325
341
|
let p = optimizedPartitions.entities[partitionId];
|
|
326
342
|
let p$1 = p !== undefined ? p : Stdlib_JsError.throwWithMessage(`Unexpected case: Couldn't find partition ` + partitionId);
|
|
@@ -346,6 +362,7 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, latestFetc
|
|
|
346
362
|
}
|
|
347
363
|
let updatedPrevQueryRange = shouldUpdateBlockRange ? blockRange : p$1.prevQueryRange;
|
|
348
364
|
let updatedPrevPrevQueryRange = shouldUpdateBlockRange ? p$1.prevQueryRange : p$1.prevPrevQueryRange;
|
|
365
|
+
let updatedPrevRangeSize = shouldUpdateBlockRange ? itemsCount : p$1.prevRangeSize;
|
|
349
366
|
let mutPendingQueries = p$1.mutPendingQueries;
|
|
350
367
|
let latestFetchedBlock$1 = p$1.latestFetchedBlock;
|
|
351
368
|
while ((() => {
|
|
@@ -382,6 +399,7 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, latestFetc
|
|
|
382
399
|
mutPendingQueries: updatedMainPartition_mutPendingQueries,
|
|
383
400
|
prevQueryRange: updatedPrevQueryRange,
|
|
384
401
|
prevPrevQueryRange: updatedPrevPrevQueryRange,
|
|
402
|
+
prevRangeSize: updatedPrevRangeSize,
|
|
385
403
|
latestBlockRangeUpdateBlock: updatedMainPartition_latestBlockRangeUpdateBlock
|
|
386
404
|
};
|
|
387
405
|
mutEntities[p$1.id] = updatedMainPartition;
|
|
@@ -449,10 +467,10 @@ function numAddresses(fetchState) {
|
|
|
449
467
|
return Utils.Dict.size(fetchState.indexingAddresses);
|
|
450
468
|
}
|
|
451
469
|
|
|
452
|
-
function appendOnBlockItems(mutItems, onBlockConfigs, indexerStartBlock, fromBlock, maxBlockNumber,
|
|
470
|
+
function appendOnBlockItems(mutItems, onBlockConfigs, indexerStartBlock, fromBlock, maxBlockNumber, maxOnBlockBufferSize) {
|
|
453
471
|
let newItemsCounter = 0;
|
|
454
472
|
let latestOnBlockBlockNumber = fromBlock;
|
|
455
|
-
while (latestOnBlockBlockNumber < maxBlockNumber && newItemsCounter <=
|
|
473
|
+
while (latestOnBlockBlockNumber < maxBlockNumber && newItemsCounter <= maxOnBlockBufferSize) {
|
|
456
474
|
let blockNumber = latestOnBlockBlockNumber + 1 | 0;
|
|
457
475
|
latestOnBlockBlockNumber = blockNumber;
|
|
458
476
|
for (let configIdx = 0, configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx) {
|
|
@@ -490,7 +508,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, indexingAddressesOpt
|
|
|
490
508
|
let mutItems$1 = mutItemsRef;
|
|
491
509
|
let item = (
|
|
492
510
|
mutItems$1 !== undefined ? mutItems$1 : fetchState.buffer
|
|
493
|
-
)[fetchState.
|
|
511
|
+
)[fetchState.maxOnBlockBufferSize - 1 | 0];
|
|
494
512
|
let maxBlockNumber;
|
|
495
513
|
if (item !== undefined) {
|
|
496
514
|
maxBlockNumber = item.blockNumber;
|
|
@@ -502,7 +520,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, indexingAddressesOpt
|
|
|
502
520
|
let mutItems$2 = mutItemsRef;
|
|
503
521
|
let mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.buffer.slice();
|
|
504
522
|
mutItemsRef = mutItems$3;
|
|
505
|
-
latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockConfigs, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.
|
|
523
|
+
latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockConfigs, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
|
|
506
524
|
} else {
|
|
507
525
|
latestOnBlockBlockNumber = knownHeight;
|
|
508
526
|
}
|
|
@@ -513,7 +531,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, indexingAddressesOpt
|
|
|
513
531
|
let updatedFetchState_contractConfigs = fetchState.contractConfigs;
|
|
514
532
|
let updatedFetchState_chainId = fetchState.chainId;
|
|
515
533
|
let updatedFetchState_buffer = mutItems$4 !== undefined ? (mutItems$4.sort(compareBufferItem), mutItems$4) : fetchState.buffer;
|
|
516
|
-
let
|
|
534
|
+
let updatedFetchState_maxOnBlockBufferSize = fetchState.maxOnBlockBufferSize;
|
|
517
535
|
let updatedFetchState_onBlockConfigs = fetchState.onBlockConfigs;
|
|
518
536
|
let updatedFetchState_firstEventBlock = fetchState.firstEventBlock;
|
|
519
537
|
let updatedFetchState = {
|
|
@@ -527,7 +545,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, indexingAddressesOpt
|
|
|
527
545
|
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
528
546
|
blockLag: blockLag,
|
|
529
547
|
buffer: updatedFetchState_buffer,
|
|
530
|
-
|
|
548
|
+
maxOnBlockBufferSize: updatedFetchState_maxOnBlockBufferSize,
|
|
531
549
|
onBlockConfigs: updatedFetchState_onBlockConfigs,
|
|
532
550
|
knownHeight: knownHeight,
|
|
533
551
|
firstEventBlock: updatedFetchState_firstEventBlock
|
|
@@ -628,6 +646,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
628
646
|
mutPendingQueries: [],
|
|
629
647
|
prevQueryRange: 0,
|
|
630
648
|
prevPrevQueryRange: 0,
|
|
649
|
+
prevRangeSize: 0,
|
|
631
650
|
latestBlockRangeUpdateBlock: 0
|
|
632
651
|
});
|
|
633
652
|
nextPartitionIndexRef = nextPartitionIndexRef + 1 | 0;
|
|
@@ -678,6 +697,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
678
697
|
mutPendingQueries: currentP.mutPendingQueries,
|
|
679
698
|
prevQueryRange: currentP.prevQueryRange,
|
|
680
699
|
prevPrevQueryRange: currentP.prevPrevQueryRange,
|
|
700
|
+
prevRangeSize: currentP.prevRangeSize,
|
|
681
701
|
latestBlockRangeUpdateBlock: currentP.latestBlockRangeUpdateBlock
|
|
682
702
|
});
|
|
683
703
|
currentPRef = {
|
|
@@ -690,6 +710,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
690
710
|
mutPendingQueries: nextP.mutPendingQueries,
|
|
691
711
|
prevQueryRange: nextP.prevQueryRange,
|
|
692
712
|
prevPrevQueryRange: nextP.prevPrevQueryRange,
|
|
713
|
+
prevRangeSize: nextP.prevRangeSize,
|
|
693
714
|
latestBlockRangeUpdateBlock: nextP.latestBlockRangeUpdateBlock
|
|
694
715
|
};
|
|
695
716
|
} else {
|
|
@@ -703,6 +724,7 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
703
724
|
mutPendingQueries: currentP.mutPendingQueries,
|
|
704
725
|
prevQueryRange: currentP.prevQueryRange,
|
|
705
726
|
prevPrevQueryRange: currentP.prevPrevQueryRange,
|
|
727
|
+
prevRangeSize: currentP.prevRangeSize,
|
|
706
728
|
latestBlockRangeUpdateBlock: currentP.latestBlockRangeUpdateBlock
|
|
707
729
|
};
|
|
708
730
|
}
|
|
@@ -847,6 +869,7 @@ function registerDynamicContracts(fetchState, items) {
|
|
|
847
869
|
mutPendingQueries: p.mutPendingQueries,
|
|
848
870
|
prevQueryRange: p.prevQueryRange,
|
|
849
871
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
872
|
+
prevRangeSize: p.prevRangeSize,
|
|
850
873
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
851
874
|
};
|
|
852
875
|
let addressesByContractName = {};
|
|
@@ -861,6 +884,7 @@ function registerDynamicContracts(fetchState, items) {
|
|
|
861
884
|
mutPendingQueries: p.mutPendingQueries,
|
|
862
885
|
prevQueryRange: p.prevQueryRange,
|
|
863
886
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
887
|
+
prevRangeSize: p.prevRangeSize,
|
|
864
888
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
865
889
|
});
|
|
866
890
|
}
|
|
@@ -875,6 +899,7 @@ function registerDynamicContracts(fetchState, items) {
|
|
|
875
899
|
mutPendingQueries: p.mutPendingQueries,
|
|
876
900
|
prevQueryRange: p.prevQueryRange,
|
|
877
901
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
902
|
+
prevRangeSize: p.prevRangeSize,
|
|
878
903
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
879
904
|
};
|
|
880
905
|
}
|
|
@@ -903,12 +928,12 @@ function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
|
903
928
|
}
|
|
904
929
|
let filter = item.eventConfig.clientAddressFilter;
|
|
905
930
|
if (filter !== undefined) {
|
|
906
|
-
return filter(item.
|
|
931
|
+
return filter(item.payload, item.blockNumber, fetchState.indexingAddresses);
|
|
907
932
|
} else {
|
|
908
933
|
return true;
|
|
909
934
|
}
|
|
910
935
|
});
|
|
911
|
-
return updateInternal(fetchState, handleQueryResponse(fetchState.optimizedPartitions, query, fetchState.knownHeight, latestFetchedBlock), undefined, newItems$1.length !== 0 ? fetchState.buffer.concat(newItems$1) : undefined, undefined, undefined);
|
|
936
|
+
return updateInternal(fetchState, handleQueryResponse(fetchState.optimizedPartitions, query, fetchState.knownHeight, newItems$1.length, latestFetchedBlock), undefined, newItems$1.length !== 0 ? fetchState.buffer.concat(newItems$1) : undefined, undefined, undefined);
|
|
912
937
|
}
|
|
913
938
|
|
|
914
939
|
function startFetchingQueries(param, queries) {
|
|
@@ -922,6 +947,7 @@ function startFetchingQueries(param, queries) {
|
|
|
922
947
|
fromBlock: q.fromBlock,
|
|
923
948
|
toBlock: q.toBlock,
|
|
924
949
|
isChunk: q.isChunk,
|
|
950
|
+
estResponseSize: q.estResponseSize,
|
|
925
951
|
fetchedBlock: undefined
|
|
926
952
|
};
|
|
927
953
|
let inserted = false;
|
|
@@ -939,7 +965,7 @@ function startFetchingQueries(param, queries) {
|
|
|
939
965
|
}
|
|
940
966
|
}
|
|
941
967
|
|
|
942
|
-
function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, selection, addressesByContractName, indexingAddresses) {
|
|
968
|
+
function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, partition, selection, addressesByContractName, indexingAddresses) {
|
|
943
969
|
if (rangeFromBlock > maxQueryBlockNumber) {
|
|
944
970
|
return;
|
|
945
971
|
}
|
|
@@ -949,36 +975,48 @@ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock
|
|
|
949
975
|
if (maybeChunkRange !== undefined) {
|
|
950
976
|
let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
|
|
951
977
|
let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
978
|
+
let probeSize = Js_math.ceil_int(maybeChunkRange * 0.9);
|
|
979
|
+
let getChunkSize = chunkIdx => {
|
|
980
|
+
if (chunkIdx < 2) {
|
|
981
|
+
return probeSize;
|
|
982
|
+
} else {
|
|
983
|
+
return chunkSize;
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
if ((((rangeFromBlock + probeSize | 0) + probeSize | 0) - 1 | 0) <= maxBlock) {
|
|
987
|
+
let chunkFromBlock = rangeFromBlock;
|
|
988
|
+
let chunkIdx = 0;
|
|
989
|
+
while (chunkIdx < 5 && ((chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0) <= maxBlock) {
|
|
990
|
+
let chunkToBlock = (chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0;
|
|
991
|
+
queries.push({
|
|
992
|
+
partitionId: partitionId,
|
|
993
|
+
fromBlock: chunkFromBlock,
|
|
994
|
+
toBlock: chunkToBlock,
|
|
995
|
+
isChunk: true,
|
|
996
|
+
estResponseSize: calculateEstResponseSize(partition, chunkFromBlock, chunkToBlock, maxQueryBlockNumber),
|
|
997
|
+
chainId: 0,
|
|
998
|
+
progress: 0,
|
|
999
|
+
selection: selection,
|
|
1000
|
+
addressesByContractName: addressesByContractName,
|
|
1001
|
+
indexingAddresses: indexingAddresses
|
|
1002
|
+
});
|
|
1003
|
+
chunkFromBlock = chunkToBlock + 1 | 0;
|
|
1004
|
+
chunkIdx = chunkIdx + 1 | 0;
|
|
1005
|
+
};
|
|
1006
|
+
return;
|
|
981
1007
|
}
|
|
1008
|
+
queries.push({
|
|
1009
|
+
partitionId: partitionId,
|
|
1010
|
+
fromBlock: rangeFromBlock,
|
|
1011
|
+
toBlock: rangeEndBlock,
|
|
1012
|
+
isChunk: rangeEndBlock !== undefined,
|
|
1013
|
+
estResponseSize: calculateEstResponseSize(partition, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
|
|
1014
|
+
chainId: 0,
|
|
1015
|
+
progress: 0,
|
|
1016
|
+
selection: selection,
|
|
1017
|
+
addressesByContractName: addressesByContractName,
|
|
1018
|
+
indexingAddresses: indexingAddresses
|
|
1019
|
+
});
|
|
982
1020
|
return;
|
|
983
1021
|
}
|
|
984
1022
|
queries.push({
|
|
@@ -986,13 +1024,16 @@ function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock
|
|
|
986
1024
|
fromBlock: rangeFromBlock,
|
|
987
1025
|
toBlock: rangeEndBlock,
|
|
988
1026
|
isChunk: false,
|
|
1027
|
+
estResponseSize: calculateEstResponseSize(partition, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
|
|
1028
|
+
chainId: 0,
|
|
1029
|
+
progress: 0,
|
|
989
1030
|
selection: selection,
|
|
990
1031
|
addressesByContractName: addressesByContractName,
|
|
991
1032
|
indexingAddresses: indexingAddresses
|
|
992
1033
|
});
|
|
993
1034
|
}
|
|
994
1035
|
|
|
995
|
-
function getNextQuery(fetchState,
|
|
1036
|
+
function getNextQuery(fetchState, budget, chainPendingBudget) {
|
|
996
1037
|
let knownHeight = fetchState.knownHeight;
|
|
997
1038
|
let blockLag = fetchState.blockLag;
|
|
998
1039
|
let indexingAddresses = fetchState.indexingAddresses;
|
|
@@ -1001,15 +1042,15 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1001
1042
|
if (headBlockNumber <= 0) {
|
|
1002
1043
|
return "WaitingForNewBlock";
|
|
1003
1044
|
}
|
|
1004
|
-
if (
|
|
1005
|
-
return "
|
|
1045
|
+
if (budget <= 0) {
|
|
1046
|
+
return "NothingToQuery";
|
|
1006
1047
|
}
|
|
1007
1048
|
let isOnBlockBehindTheHead = fetchState.latestOnBlockBlockNumber < headBlockNumber;
|
|
1008
1049
|
let endBlock = fetchState.endBlock;
|
|
1009
1050
|
let shouldWaitForNewBlock = (
|
|
1010
1051
|
endBlock !== undefined ? headBlockNumber < endBlock : true
|
|
1011
1052
|
) && !isOnBlockBehindTheHead;
|
|
1012
|
-
let item = fetchState.buffer[
|
|
1053
|
+
let item = fetchState.buffer[(budget + (chainPendingBudget | 0) | 0) - 1 | 0];
|
|
1013
1054
|
let maxQueryBlockNumber = item !== undefined ? Primitive_int.min(item.blockNumber, knownHeight) : knownHeight;
|
|
1014
1055
|
let queries = [];
|
|
1015
1056
|
let partitionsCount = optimizedPartitions.idsInAscOrder.length;
|
|
@@ -1018,11 +1059,13 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1018
1059
|
let idx = idxRef;
|
|
1019
1060
|
let partitionId = optimizedPartitions.idsInAscOrder[idx];
|
|
1020
1061
|
let p = optimizedPartitions.entities[partitionId];
|
|
1062
|
+
let pendingCount = p.mutPendingQueries.length;
|
|
1021
1063
|
let isBehindTheHead = p.latestFetchedBlock.blockNumber < headBlockNumber;
|
|
1022
|
-
let hasPendingQueries =
|
|
1064
|
+
let hasPendingQueries = pendingCount > 0;
|
|
1023
1065
|
if (hasPendingQueries || isBehindTheHead) {
|
|
1024
1066
|
shouldWaitForNewBlock = false;
|
|
1025
1067
|
}
|
|
1068
|
+
let partitionQueriesStart = queries.length;
|
|
1026
1069
|
let queryEndBlock = Utils.$$Math.minOptInt(fetchState.endBlock, p.mergeBlock);
|
|
1027
1070
|
let queryEndBlock$1 = blockLag !== 0 ? Utils.$$Math.minOptInt(headBlockNumber, queryEndBlock) : queryEndBlock;
|
|
1028
1071
|
let match = maxQueryBlockNumber < knownHeight;
|
|
@@ -1051,31 +1094,43 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1051
1094
|
if (maybeChunkRange !== undefined) {
|
|
1052
1095
|
let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
|
|
1053
1096
|
let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1097
|
+
let probeSize = Js_math.ceil_int(maybeChunkRange * 0.9);
|
|
1098
|
+
let getChunkSize = chunkIdx => {
|
|
1099
|
+
if (chunkIdx < 2) {
|
|
1100
|
+
return probeSize;
|
|
1101
|
+
} else {
|
|
1102
|
+
return chunkSize;
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
if ((((rangeFromBlock + getChunkSize(0) | 0) + getChunkSize(1) | 0) - 1 | 0) <= maxBlock) {
|
|
1106
|
+
let chunkFromBlock = rangeFromBlock;
|
|
1107
|
+
let chunkIdx = 0;
|
|
1108
|
+
while (chunkIdx < 5 && ((chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0) <= maxBlock) {
|
|
1109
|
+
let chunkToBlock = (chunkFromBlock + getChunkSize(chunkIdx) | 0) - 1 | 0;
|
|
1110
|
+
queries.push({
|
|
1111
|
+
partitionId: partitionId,
|
|
1112
|
+
fromBlock: chunkFromBlock,
|
|
1113
|
+
toBlock: chunkToBlock,
|
|
1114
|
+
isChunk: true,
|
|
1115
|
+
estResponseSize: calculateEstResponseSize(p, chunkFromBlock, chunkToBlock, maxQueryBlockNumber),
|
|
1116
|
+
chainId: 0,
|
|
1117
|
+
progress: 0,
|
|
1118
|
+
selection: selection,
|
|
1119
|
+
addressesByContractName: addressesByContractName,
|
|
1120
|
+
indexingAddresses: indexingAddresses
|
|
1121
|
+
});
|
|
1122
|
+
chunkFromBlock = chunkToBlock + 1 | 0;
|
|
1123
|
+
chunkIdx = chunkIdx + 1 | 0;
|
|
1124
|
+
};
|
|
1073
1125
|
} else {
|
|
1074
1126
|
queries.push({
|
|
1075
1127
|
partitionId: partitionId,
|
|
1076
1128
|
fromBlock: rangeFromBlock,
|
|
1077
1129
|
toBlock: rangeEndBlock,
|
|
1078
1130
|
isChunk: rangeEndBlock !== undefined,
|
|
1131
|
+
estResponseSize: calculateEstResponseSize(p, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
|
|
1132
|
+
chainId: 0,
|
|
1133
|
+
progress: 0,
|
|
1079
1134
|
selection: selection,
|
|
1080
1135
|
addressesByContractName: addressesByContractName,
|
|
1081
1136
|
indexingAddresses: indexingAddresses
|
|
@@ -1087,6 +1142,9 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1087
1142
|
fromBlock: rangeFromBlock,
|
|
1088
1143
|
toBlock: rangeEndBlock,
|
|
1089
1144
|
isChunk: false,
|
|
1145
|
+
estResponseSize: calculateEstResponseSize(p, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber),
|
|
1146
|
+
chainId: 0,
|
|
1147
|
+
progress: 0,
|
|
1090
1148
|
selection: selection,
|
|
1091
1149
|
addressesByContractName: addressesByContractName,
|
|
1092
1150
|
indexingAddresses: indexingAddresses
|
|
@@ -1122,31 +1180,43 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1122
1180
|
if (maybeChunkRange !== undefined) {
|
|
1123
1181
|
let maxBlock$1 = queryEndBlock$2 !== undefined ? queryEndBlock$2 : maxQueryBlockNumber;
|
|
1124
1182
|
let chunkSize$1 = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1183
|
+
let probeSize$1 = Js_math.ceil_int(maybeChunkRange * 0.9);
|
|
1184
|
+
let getChunkSize$1 = chunkIdx => {
|
|
1185
|
+
if (chunkIdx < 2) {
|
|
1186
|
+
return probeSize$1;
|
|
1187
|
+
} else {
|
|
1188
|
+
return chunkSize$1;
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
if ((((rangeFromBlock$1 + getChunkSize$1(0) | 0) + getChunkSize$1(1) | 0) - 1 | 0) <= maxBlock$1) {
|
|
1192
|
+
let chunkFromBlock$1 = rangeFromBlock$1;
|
|
1193
|
+
let chunkIdx$1 = 0;
|
|
1194
|
+
while (chunkIdx$1 < 5 && ((chunkFromBlock$1 + getChunkSize$1(chunkIdx$1) | 0) - 1 | 0) <= maxBlock$1) {
|
|
1195
|
+
let chunkToBlock$1 = (chunkFromBlock$1 + getChunkSize$1(chunkIdx$1) | 0) - 1 | 0;
|
|
1196
|
+
queries.push({
|
|
1197
|
+
partitionId: partitionId,
|
|
1198
|
+
fromBlock: chunkFromBlock$1,
|
|
1199
|
+
toBlock: chunkToBlock$1,
|
|
1200
|
+
isChunk: true,
|
|
1201
|
+
estResponseSize: calculateEstResponseSize(p, chunkFromBlock$1, chunkToBlock$1, maxQueryBlockNumber),
|
|
1202
|
+
chainId: 0,
|
|
1203
|
+
progress: 0,
|
|
1204
|
+
selection: selection$1,
|
|
1205
|
+
addressesByContractName: addressesByContractName$1,
|
|
1206
|
+
indexingAddresses: indexingAddresses
|
|
1207
|
+
});
|
|
1208
|
+
chunkFromBlock$1 = chunkToBlock$1 + 1 | 0;
|
|
1209
|
+
chunkIdx$1 = chunkIdx$1 + 1 | 0;
|
|
1210
|
+
};
|
|
1144
1211
|
} else {
|
|
1145
1212
|
queries.push({
|
|
1146
1213
|
partitionId: partitionId,
|
|
1147
1214
|
fromBlock: rangeFromBlock$1,
|
|
1148
1215
|
toBlock: queryEndBlock$2,
|
|
1149
1216
|
isChunk: queryEndBlock$2 !== undefined,
|
|
1217
|
+
estResponseSize: calculateEstResponseSize(p, rangeFromBlock$1, queryEndBlock$2, maxQueryBlockNumber),
|
|
1218
|
+
chainId: 0,
|
|
1219
|
+
progress: 0,
|
|
1150
1220
|
selection: selection$1,
|
|
1151
1221
|
addressesByContractName: addressesByContractName$1,
|
|
1152
1222
|
indexingAddresses: indexingAddresses
|
|
@@ -1158,6 +1228,9 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1158
1228
|
fromBlock: rangeFromBlock$1,
|
|
1159
1229
|
toBlock: queryEndBlock$2,
|
|
1160
1230
|
isChunk: false,
|
|
1231
|
+
estResponseSize: calculateEstResponseSize(p, rangeFromBlock$1, queryEndBlock$2, maxQueryBlockNumber),
|
|
1232
|
+
chainId: 0,
|
|
1233
|
+
progress: 0,
|
|
1161
1234
|
selection: selection$1,
|
|
1162
1235
|
addressesByContractName: addressesByContractName$1,
|
|
1163
1236
|
indexingAddresses: indexingAddresses
|
|
@@ -1166,6 +1239,11 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1166
1239
|
}
|
|
1167
1240
|
}
|
|
1168
1241
|
}
|
|
1242
|
+
let maxNewChunks = Primitive_int.max(0, 10 - pendingCount | 0);
|
|
1243
|
+
let generatedCount = queries.length - partitionQueriesStart | 0;
|
|
1244
|
+
if (generatedCount > maxNewChunks) {
|
|
1245
|
+
queries.splice(partitionQueriesStart + maxNewChunks | 0, generatedCount - maxNewChunks | 0);
|
|
1246
|
+
}
|
|
1169
1247
|
idxRef = idxRef + 1 | 0;
|
|
1170
1248
|
};
|
|
1171
1249
|
if (Utils.$$Array.isEmpty(queries)) {
|
|
@@ -1174,12 +1252,12 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1174
1252
|
} else {
|
|
1175
1253
|
return "NothingToQuery";
|
|
1176
1254
|
}
|
|
1255
|
+
} else {
|
|
1256
|
+
return {
|
|
1257
|
+
TAG: "Ready",
|
|
1258
|
+
_0: queries
|
|
1259
|
+
};
|
|
1177
1260
|
}
|
|
1178
|
-
let queries$1 = queries.length > concurrencyLimit ? (queries.sort((a, b) => Primitive_int.compare(a.fromBlock, b.fromBlock)), queries.slice(0, concurrencyLimit)) : queries;
|
|
1179
|
-
return {
|
|
1180
|
-
TAG: "Ready",
|
|
1181
|
-
_0: queries$1
|
|
1182
|
-
};
|
|
1183
1261
|
}
|
|
1184
1262
|
|
|
1185
1263
|
function hasReadyItem(fetchState) {
|
|
@@ -1214,7 +1292,7 @@ function getReadyItemsCount(fetchState, targetSize, fromItem) {
|
|
|
1214
1292
|
return acc;
|
|
1215
1293
|
}
|
|
1216
1294
|
|
|
1217
|
-
function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartition, chainId,
|
|
1295
|
+
function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartition, chainId, maxOnBlockBufferSize, knownHeight, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt, firstEventBlockOpt) {
|
|
1218
1296
|
let progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
1219
1297
|
let onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
|
|
1220
1298
|
let blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
@@ -1267,6 +1345,7 @@ function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartitio
|
|
|
1267
1345
|
mutPendingQueries: [],
|
|
1268
1346
|
prevQueryRange: 0,
|
|
1269
1347
|
prevPrevQueryRange: 0,
|
|
1348
|
+
prevRangeSize: 0,
|
|
1270
1349
|
latestBlockRangeUpdateBlock: 0
|
|
1271
1350
|
});
|
|
1272
1351
|
}
|
|
@@ -1311,7 +1390,7 @@ function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartitio
|
|
|
1311
1390
|
let id = optimizedPartitions.idsInAscOrder[0];
|
|
1312
1391
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
1313
1392
|
let maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock.blockNumber : knownHeight;
|
|
1314
|
-
latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockConfigs, startBlock, progressBlockNumber, maxBlockNumber,
|
|
1393
|
+
latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockConfigs, startBlock, progressBlockNumber, maxBlockNumber, maxOnBlockBufferSize);
|
|
1315
1394
|
} else {
|
|
1316
1395
|
latestOnBlockBlockNumber = progressBlockNumber;
|
|
1317
1396
|
}
|
|
@@ -1326,7 +1405,7 @@ function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartitio
|
|
|
1326
1405
|
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
1327
1406
|
blockLag: blockLag,
|
|
1328
1407
|
buffer: buffer,
|
|
1329
|
-
|
|
1408
|
+
maxOnBlockBufferSize: maxOnBlockBufferSize,
|
|
1330
1409
|
onBlockConfigs: onBlockConfigs,
|
|
1331
1410
|
knownHeight: knownHeight,
|
|
1332
1411
|
firstEventBlock: firstEventBlock
|
|
@@ -1346,6 +1425,22 @@ function bufferSize(param) {
|
|
|
1346
1425
|
return param.buffer.length;
|
|
1347
1426
|
}
|
|
1348
1427
|
|
|
1428
|
+
function bufferReadyCount(fetchState) {
|
|
1429
|
+
let frontier = bufferBlockNumber(fetchState);
|
|
1430
|
+
let buffer = fetchState.buffer;
|
|
1431
|
+
let lo = 0;
|
|
1432
|
+
let hi = buffer.length;
|
|
1433
|
+
while (lo < hi) {
|
|
1434
|
+
let mid = (lo + hi | 0) / 2 | 0;
|
|
1435
|
+
if (buffer[mid].blockNumber <= frontier) {
|
|
1436
|
+
lo = mid + 1 | 0;
|
|
1437
|
+
} else {
|
|
1438
|
+
hi = mid;
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
return lo;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1349
1444
|
function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
|
|
1350
1445
|
let adjusted = [];
|
|
1351
1446
|
for (let qIdx = 0, qIdx_finish = mutPendingQueries.length; qIdx < qIdx_finish; ++qIdx) {
|
|
@@ -1358,6 +1453,7 @@ function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
|
|
|
1358
1453
|
fromBlock: pq.fromBlock,
|
|
1359
1454
|
toBlock: pq.toBlock,
|
|
1360
1455
|
isChunk: pq.isChunk,
|
|
1456
|
+
estResponseSize: pq.estResponseSize,
|
|
1361
1457
|
fetchedBlock: {
|
|
1362
1458
|
blockNumber: targetBlockNumber,
|
|
1363
1459
|
blockTimestamp: 0
|
|
@@ -1425,6 +1521,7 @@ function rollback(fetchState, targetBlockNumber) {
|
|
|
1425
1521
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1426
1522
|
prevQueryRange: p.prevQueryRange,
|
|
1427
1523
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
1524
|
+
prevRangeSize: p.prevRangeSize,
|
|
1428
1525
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
1429
1526
|
});
|
|
1430
1527
|
}
|
|
@@ -1445,6 +1542,7 @@ function rollback(fetchState, targetBlockNumber) {
|
|
|
1445
1542
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1446
1543
|
prevQueryRange: p.prevQueryRange,
|
|
1447
1544
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
1545
|
+
prevRangeSize: p.prevRangeSize,
|
|
1448
1546
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
1449
1547
|
});
|
|
1450
1548
|
}
|
|
@@ -1461,7 +1559,7 @@ function rollback(fetchState, targetBlockNumber) {
|
|
|
1461
1559
|
latestOnBlockBlockNumber: Primitive_int.min(fetchState.latestOnBlockBlockNumber, targetBlockNumber),
|
|
1462
1560
|
blockLag: fetchState.blockLag,
|
|
1463
1561
|
buffer: fetchState.buffer,
|
|
1464
|
-
|
|
1562
|
+
maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
|
|
1465
1563
|
onBlockConfigs: fetchState.onBlockConfigs,
|
|
1466
1564
|
knownHeight: fetchState.knownHeight,
|
|
1467
1565
|
firstEventBlock: fetchState.firstEventBlock
|
|
@@ -1489,6 +1587,7 @@ function resetPendingQueries(fetchState) {
|
|
|
1489
1587
|
mutPendingQueries: kept,
|
|
1490
1588
|
prevQueryRange: partition.prevQueryRange,
|
|
1491
1589
|
prevPrevQueryRange: partition.prevPrevQueryRange,
|
|
1590
|
+
prevRangeSize: partition.prevRangeSize,
|
|
1492
1591
|
latestBlockRangeUpdateBlock: partition.latestBlockRangeUpdateBlock
|
|
1493
1592
|
};
|
|
1494
1593
|
}
|
|
@@ -1511,7 +1610,7 @@ function resetPendingQueries(fetchState) {
|
|
|
1511
1610
|
latestOnBlockBlockNumber: fetchState.latestOnBlockBlockNumber,
|
|
1512
1611
|
blockLag: fetchState.blockLag,
|
|
1513
1612
|
buffer: fetchState.buffer,
|
|
1514
|
-
|
|
1613
|
+
maxOnBlockBufferSize: fetchState.maxOnBlockBufferSize,
|
|
1515
1614
|
onBlockConfigs: fetchState.onBlockConfigs,
|
|
1516
1615
|
knownHeight: fetchState.knownHeight,
|
|
1517
1616
|
firstEventBlock: fetchState.firstEventBlock
|
|
@@ -1531,24 +1630,31 @@ function isActivelyIndexing(fetchState) {
|
|
|
1531
1630
|
}
|
|
1532
1631
|
}
|
|
1533
1632
|
|
|
1534
|
-
function
|
|
1633
|
+
function isFetchingAtHead(fetchState) {
|
|
1535
1634
|
let knownHeight = fetchState.knownHeight;
|
|
1536
1635
|
let blockLag = fetchState.blockLag;
|
|
1537
1636
|
let endBlock = fetchState.endBlock;
|
|
1538
1637
|
let bufferBlockNumber$1 = bufferBlockNumber(fetchState);
|
|
1539
|
-
if (knownHeight !== 0
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1638
|
+
if (knownHeight !== 0) {
|
|
1639
|
+
if (endBlock !== undefined && bufferBlockNumber$1 >= endBlock) {
|
|
1640
|
+
return true;
|
|
1641
|
+
} else {
|
|
1642
|
+
return bufferBlockNumber$1 >= (knownHeight - blockLag | 0);
|
|
1643
|
+
}
|
|
1543
1644
|
} else {
|
|
1544
1645
|
return false;
|
|
1545
1646
|
}
|
|
1546
1647
|
}
|
|
1547
1648
|
|
|
1548
|
-
function
|
|
1549
|
-
let
|
|
1550
|
-
|
|
1551
|
-
|
|
1649
|
+
function isReadyToEnterReorgThreshold(fetchState) {
|
|
1650
|
+
let knownHeight = fetchState.knownHeight;
|
|
1651
|
+
let blockLag = fetchState.blockLag;
|
|
1652
|
+
let endBlock = fetchState.endBlock;
|
|
1653
|
+
let bufferBlockNumber$1 = bufferBlockNumber(fetchState);
|
|
1654
|
+
if (knownHeight !== 0 && (
|
|
1655
|
+
endBlock !== undefined && bufferBlockNumber$1 >= endBlock ? true : bufferBlockNumber$1 >= (knownHeight - blockLag | 0)
|
|
1656
|
+
)) {
|
|
1657
|
+
return Utils.$$Array.isEmpty(fetchState.buffer);
|
|
1552
1658
|
} else {
|
|
1553
1659
|
return false;
|
|
1554
1660
|
}
|
|
@@ -1568,7 +1674,29 @@ function getProgressPercentage(fetchState) {
|
|
|
1568
1674
|
return progress / totalRange;
|
|
1569
1675
|
}
|
|
1570
1676
|
|
|
1571
|
-
function
|
|
1677
|
+
function getProgressPercentageAt(fetchState, blockNumber) {
|
|
1678
|
+
let firstEventBlock = fetchState.firstEventBlock;
|
|
1679
|
+
if (firstEventBlock === undefined) {
|
|
1680
|
+
return 0;
|
|
1681
|
+
}
|
|
1682
|
+
let totalRange = fetchState.knownHeight - firstEventBlock | 0;
|
|
1683
|
+
if (totalRange <= 0) {
|
|
1684
|
+
return 0;
|
|
1685
|
+
} else {
|
|
1686
|
+
return (blockNumber - firstEventBlock | 0) / totalRange;
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
function hasFullBatch(fetchState, batchSizeTarget) {
|
|
1691
|
+
let item = fetchState.buffer[batchSizeTarget - 1 | 0];
|
|
1692
|
+
if (item !== undefined) {
|
|
1693
|
+
return item.blockNumber <= bufferBlockNumber(fetchState);
|
|
1694
|
+
} else {
|
|
1695
|
+
return false;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
function sortForBatch(fetchStates, batchSizeTarget) {
|
|
1572
1700
|
let copied = fetchStates.slice();
|
|
1573
1701
|
copied.sort((a, b) => {
|
|
1574
1702
|
let match = hasFullBatch(a, batchSizeTarget);
|
|
@@ -1612,10 +1740,16 @@ function updateKnownHeight(fetchState, knownHeight) {
|
|
|
1612
1740
|
}
|
|
1613
1741
|
}
|
|
1614
1742
|
|
|
1743
|
+
let defaultEstResponseSize = 10000;
|
|
1744
|
+
|
|
1615
1745
|
let blockItemLogIndex = 16777216;
|
|
1616
1746
|
|
|
1747
|
+
let maxPendingChunksPerPartition = 10;
|
|
1748
|
+
|
|
1617
1749
|
export {
|
|
1618
1750
|
deriveEffectiveStartBlock,
|
|
1751
|
+
defaultEstResponseSize,
|
|
1752
|
+
calculateEstResponseSize,
|
|
1619
1753
|
getMinHistoryRange,
|
|
1620
1754
|
getMinQueryRange,
|
|
1621
1755
|
OptimizedPartitions,
|
|
@@ -1634,17 +1768,22 @@ export {
|
|
|
1634
1768
|
handleQueryResult,
|
|
1635
1769
|
startFetchingQueries,
|
|
1636
1770
|
pushQueriesForRange,
|
|
1771
|
+
maxPendingChunksPerPartition,
|
|
1637
1772
|
getNextQuery,
|
|
1638
1773
|
hasReadyItem,
|
|
1639
1774
|
getReadyItemsCount,
|
|
1640
1775
|
make$1 as make,
|
|
1641
1776
|
bufferSize,
|
|
1777
|
+
bufferReadyCount,
|
|
1642
1778
|
rollbackPendingQueries,
|
|
1643
1779
|
rollback,
|
|
1644
1780
|
resetPendingQueries,
|
|
1645
1781
|
isActivelyIndexing,
|
|
1782
|
+
isFetchingAtHead,
|
|
1646
1783
|
isReadyToEnterReorgThreshold,
|
|
1647
|
-
|
|
1784
|
+
getProgressPercentage,
|
|
1785
|
+
getProgressPercentageAt,
|
|
1786
|
+
sortForBatch,
|
|
1648
1787
|
getProgressBlockNumberAt,
|
|
1649
1788
|
updateKnownHeight,
|
|
1650
1789
|
}
|