envio 3.6.1 → 3.7.0
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/index.d.ts +197 -9
- package/package.json +6 -6
- package/src/Batch.res +64 -25
- package/src/Batch.res.mjs +69 -46
- package/src/ChainFetching.res +13 -17
- package/src/ChainFetching.res.mjs +9 -14
- package/src/ChainState.res +160 -119
- package/src/ChainState.res.mjs +75 -46
- package/src/ChainState.resi +15 -12
- package/src/Config.res +9 -2
- package/src/Config.res.mjs +4 -4
- package/src/Core.res +5 -0
- package/src/Ecosystem.res +0 -1
- package/src/Envio.res +16 -3
- package/src/EventConfigBuilder.res +155 -40
- package/src/EventConfigBuilder.res.mjs +76 -24
- package/src/EventProcessing.res +4 -8
- package/src/EventProcessing.res.mjs +4 -4
- package/src/EventUtils.res +3 -47
- package/src/FetchState.res +124 -104
- package/src/FetchState.res.mjs +116 -100
- package/src/HandlerRegister.res +108 -2
- package/src/HandlerRegister.res.mjs +59 -10
- package/src/HandlerRegister.resi +4 -0
- package/src/Internal.res +84 -24
- package/src/Internal.res.mjs +33 -2
- package/src/LazyLoader.res +12 -11
- package/src/LazyLoader.res.mjs +13 -7
- package/src/Main.res +22 -9
- package/src/Main.res.mjs +18 -5
- package/src/MemoryStorage.res +724 -0
- package/src/MemoryStorage.res.mjs +601 -0
- package/src/PgStorage.res +18 -7
- package/src/PgStorage.res.mjs +14 -11
- package/src/ReorgDetection.res +0 -222
- package/src/ReorgDetection.res.mjs +0 -163
- package/src/Rollback.res +14 -15
- package/src/Rollback.res.mjs +4 -5
- package/src/SimulateItems.res +2 -2
- package/src/Utils.res +3 -0
- package/src/bindings/ClickHouse.res +16 -11
- package/src/bindings/ClickHouse.res.mjs +10 -10
- package/src/bindings/Vitest.res +1 -1
- package/src/sources/BlockStore.res +115 -5
- package/src/sources/BlockStore.res.mjs +25 -0
- package/src/sources/Evm.res +0 -1
- package/src/sources/Evm.res.mjs +0 -1
- package/src/sources/EvmHyperSyncSource.res +19 -84
- package/src/sources/EvmHyperSyncSource.res.mjs +24 -60
- package/src/sources/Fuel.res +24 -4
- package/src/sources/Fuel.res.mjs +23 -3
- package/src/sources/FuelHyperSync.res +8 -3
- package/src/sources/FuelHyperSync.res.mjs +5 -4
- package/src/sources/FuelHyperSync.resi +3 -1
- package/src/sources/FuelHyperSyncClient.res +7 -10
- package/src/sources/FuelHyperSyncSource.res +18 -45
- package/src/sources/FuelHyperSyncSource.res.mjs +18 -35
- package/src/sources/HyperSync.res +49 -229
- package/src/sources/HyperSync.res.mjs +74 -191
- package/src/sources/HyperSync.resi +11 -35
- package/src/sources/HyperSyncClient.res +9 -79
- package/src/sources/HyperSyncClient.res.mjs +2 -6
- package/src/sources/RequestStat.res +5 -0
- package/src/sources/RequestStat.res.mjs +2 -0
- package/src/sources/RpcSource.res +149 -43
- package/src/sources/RpcSource.res.mjs +104 -41
- package/src/sources/SimulateSource.res +8 -5
- package/src/sources/SimulateSource.res.mjs +6 -6
- package/src/sources/Source.res +89 -16
- package/src/sources/Source.res.mjs +50 -1
- package/src/sources/SourceManager.res +255 -50
- package/src/sources/SourceManager.res.mjs +149 -55
- package/src/sources/SourceManager.resi +2 -6
- package/src/sources/Svm.res +0 -7
- package/src/sources/Svm.res.mjs +0 -8
- package/src/sources/SvmHyperSyncClient.res +21 -16
- package/src/sources/SvmHyperSyncClient.res.mjs +3 -4
- package/src/sources/SvmHyperSyncSource.res +25 -117
- package/src/sources/SvmHyperSyncSource.res.mjs +8 -121
- package/svm.schema.json +3 -2
package/src/FetchState.res.mjs
CHANGED
|
@@ -134,8 +134,8 @@ function getOrThrow(optimizedPartitions, partitionId) {
|
|
|
134
134
|
|
|
135
135
|
function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAddrInPartition, nextPartitionIndexRef) {
|
|
136
136
|
let combinedAddresses = p1.addresses.merge(p2.addresses);
|
|
137
|
-
let p1Below = p1.latestFetchedBlock
|
|
138
|
-
let p2Below = p2.latestFetchedBlock
|
|
137
|
+
let p1Below = p1.latestFetchedBlock < potentialMergeBlock;
|
|
138
|
+
let p2Below = p2.latestFetchedBlock < potentialMergeBlock;
|
|
139
139
|
let completed = [];
|
|
140
140
|
let continuingBase;
|
|
141
141
|
if (p1Below) {
|
|
@@ -181,10 +181,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
181
181
|
);
|
|
182
182
|
continuingBase = {
|
|
183
183
|
id: newId,
|
|
184
|
-
latestFetchedBlock:
|
|
185
|
-
blockNumber: potentialMergeBlock,
|
|
186
|
-
blockTimestamp: 0
|
|
187
|
-
},
|
|
184
|
+
latestFetchedBlock: potentialMergeBlock,
|
|
188
185
|
selection: p1.selection,
|
|
189
186
|
addresses: p1.addresses,
|
|
190
187
|
mergeBlock: undefined,
|
|
@@ -254,7 +251,7 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
254
251
|
}
|
|
255
252
|
|
|
256
253
|
function ascSortFn(a, b) {
|
|
257
|
-
return Primitive_int.compare(a.latestFetchedBlock
|
|
254
|
+
return Primitive_int.compare(a.latestFetchedBlock, b.latestFetchedBlock);
|
|
258
255
|
}
|
|
259
256
|
|
|
260
257
|
function anchoredContracts(partitions) {
|
|
@@ -276,7 +273,7 @@ function anchoredContracts(partitions) {
|
|
|
276
273
|
|
|
277
274
|
function getAnchorSafeBlock(p) {
|
|
278
275
|
let safeRef = {
|
|
279
|
-
contents: p.latestFetchedBlock
|
|
276
|
+
contents: p.latestFetchedBlock
|
|
280
277
|
};
|
|
281
278
|
p.mutPendingQueries.forEach(pq => {
|
|
282
279
|
let match = safeRef.contents;
|
|
@@ -284,23 +281,23 @@ function getAnchorSafeBlock(p) {
|
|
|
284
281
|
return;
|
|
285
282
|
}
|
|
286
283
|
let toBlock = pq.toBlock;
|
|
287
|
-
let
|
|
288
|
-
if (
|
|
289
|
-
if (
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return;
|
|
293
|
-
} else {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
284
|
+
let blockNumber = pq.fetchedBlock;
|
|
285
|
+
if (blockNumber !== undefined) {
|
|
286
|
+
if (blockNumber > match) {
|
|
287
|
+
safeRef.contents = blockNumber;
|
|
288
|
+
return;
|
|
296
289
|
} else {
|
|
297
|
-
safeRef.contents = undefined;
|
|
298
290
|
return;
|
|
299
291
|
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
292
|
+
} else if (toBlock !== undefined) {
|
|
293
|
+
if (toBlock > match) {
|
|
294
|
+
safeRef.contents = toBlock;
|
|
295
|
+
return;
|
|
296
|
+
} else {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
safeRef.contents = undefined;
|
|
304
301
|
return;
|
|
305
302
|
}
|
|
306
303
|
});
|
|
@@ -339,7 +336,7 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
339
336
|
let p = partitions[idx];
|
|
340
337
|
let mergeBlock = p.mergeBlock;
|
|
341
338
|
if (mergeBlock !== undefined) {
|
|
342
|
-
if (p.latestFetchedBlock
|
|
339
|
+
if (p.latestFetchedBlock < mergeBlock || isFetching(p)) {
|
|
343
340
|
newPartitions.push(p);
|
|
344
341
|
}
|
|
345
342
|
} else if (p.dynamicContract !== undefined && p.selection.dependsOnAddresses) {
|
|
@@ -351,7 +348,7 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
351
348
|
let toBlock = match.toBlock;
|
|
352
349
|
potentialMergeBlock = toBlock !== undefined && match.isChunk ? toBlock : undefined;
|
|
353
350
|
} else {
|
|
354
|
-
potentialMergeBlock = p.latestFetchedBlock
|
|
351
|
+
potentialMergeBlock = p.latestFetchedBlock;
|
|
355
352
|
}
|
|
356
353
|
if (potentialMergeBlock !== undefined && pAddressesCount < maxAddrInPartition) {
|
|
357
354
|
let partitionsByMergeBlock = Utils.Dict.getOrInsertEmptyDict(mergingPartitions, contractName);
|
|
@@ -421,7 +418,7 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
421
418
|
if (anchoredContractsSet.has(contractName)) {
|
|
422
419
|
let anchorSafeBlock = anchorSafeBlocks[contractName];
|
|
423
420
|
if (anchorSafeBlock !== undefined) {
|
|
424
|
-
if (p.latestFetchedBlock
|
|
421
|
+
if (p.latestFetchedBlock < anchorSafeBlock) {
|
|
425
422
|
anchored.push({
|
|
426
423
|
id: p.id,
|
|
427
424
|
latestFetchedBlock: p.latestFetchedBlock,
|
|
@@ -442,7 +439,7 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
442
439
|
latestFetchedBlock: p.latestFetchedBlock,
|
|
443
440
|
selection: p.selection,
|
|
444
441
|
addresses: p.addresses,
|
|
445
|
-
mergeBlock: p.latestFetchedBlock
|
|
442
|
+
mergeBlock: p.latestFetchedBlock,
|
|
446
443
|
dynamicContract: p.dynamicContract,
|
|
447
444
|
mutPendingQueries: p.mutPendingQueries,
|
|
448
445
|
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
@@ -493,7 +490,7 @@ function consumeFetchedQueries(mutPendingQueries, initialLatestFetchedBlock) {
|
|
|
493
490
|
let match = mutPendingQueries[consumedCount];
|
|
494
491
|
if (match !== undefined) {
|
|
495
492
|
let fetchedBlock = match.fetchedBlock;
|
|
496
|
-
if (fetchedBlock !== undefined && match.fromBlock <= (latestFetchedBlock
|
|
493
|
+
if (fetchedBlock !== undefined && match.fromBlock <= (latestFetchedBlock + 1 | 0)) {
|
|
497
494
|
latestFetchedBlock = fetchedBlock;
|
|
498
495
|
consumedCount = consumedCount + 1 | 0;
|
|
499
496
|
} else {
|
|
@@ -531,16 +528,16 @@ function handleQueryResponseForPartition(optimizedPartitions, p, query, knownHei
|
|
|
531
528
|
let mutEntities = Utils.Dict.shallowCopy(optimizedPartitions.entities);
|
|
532
529
|
let pendingQuery = getPendingQueryOrThrow(p, query.fromBlock);
|
|
533
530
|
pendingQuery.fetchedBlock = latestFetchedBlock;
|
|
534
|
-
let blockRange = (latestFetchedBlock
|
|
531
|
+
let blockRange = (latestFetchedBlock - query.fromBlock | 0) + 1 | 0;
|
|
535
532
|
let observedEventDensity = itemsCount / blockRange;
|
|
536
533
|
let eventDensity = p.eventDensity;
|
|
537
534
|
let updatedEventDensity = eventDensity !== undefined ? (eventDensity + observedEventDensity) / 2 : observedEventDensity;
|
|
538
535
|
let shouldUpdateSourceRangeCapacity = false;
|
|
539
|
-
if (latestFetchedBlock
|
|
536
|
+
if (latestFetchedBlock > p.latestSourceRangeCapacityUpdateBlock) {
|
|
540
537
|
let queryToBlock = query.toBlock;
|
|
541
538
|
let tmp;
|
|
542
539
|
if (queryToBlock !== undefined) {
|
|
543
|
-
if (latestFetchedBlock
|
|
540
|
+
if (latestFetchedBlock < queryToBlock) {
|
|
544
541
|
let itemsTarget = query.itemsTarget;
|
|
545
542
|
tmp = itemsTarget !== undefined ? itemsCount < itemsTarget : true;
|
|
546
543
|
} else {
|
|
@@ -548,7 +545,7 @@ function handleQueryResponseForPartition(optimizedPartitions, p, query, knownHei
|
|
|
548
545
|
tmp = minHistoryRange !== undefined ? ((queryToBlock - query.fromBlock | 0) + 1 | 0) >= minHistoryRange : false;
|
|
549
546
|
}
|
|
550
547
|
} else {
|
|
551
|
-
tmp = latestFetchedBlock
|
|
548
|
+
tmp = latestFetchedBlock < (knownHeight - 10 | 0);
|
|
552
549
|
}
|
|
553
550
|
shouldUpdateSourceRangeCapacity = tmp;
|
|
554
551
|
}
|
|
@@ -562,7 +559,7 @@ function handleQueryResponseForPartition(optimizedPartitions, p, query, knownHei
|
|
|
562
559
|
let match = mutPendingQueries[consumedCount];
|
|
563
560
|
if (match !== undefined) {
|
|
564
561
|
let fetchedBlock = match.fetchedBlock;
|
|
565
|
-
if (fetchedBlock !== undefined && match.fromBlock <= (latestFetchedBlock$1
|
|
562
|
+
if (fetchedBlock !== undefined && match.fromBlock <= (latestFetchedBlock$1 + 1 | 0)) {
|
|
566
563
|
latestFetchedBlock$1 = fetchedBlock;
|
|
567
564
|
consumedCount = consumedCount + 1 | 0;
|
|
568
565
|
} else {
|
|
@@ -578,7 +575,7 @@ function handleQueryResponseForPartition(optimizedPartitions, p, query, knownHei
|
|
|
578
575
|
let updatedLatestFetchedBlock = latestFetchedBlock$1;
|
|
579
576
|
let mergeBlock = p.mergeBlock;
|
|
580
577
|
let partitionReachedMergeBlock = (
|
|
581
|
-
mergeBlock !== undefined ? updatedLatestFetchedBlock
|
|
578
|
+
mergeBlock !== undefined ? updatedLatestFetchedBlock >= mergeBlock : false
|
|
582
579
|
) && !isFetching(p);
|
|
583
580
|
if (partitionReachedMergeBlock) {
|
|
584
581
|
Utils.Dict.deleteInPlace(mutEntities, p.id);
|
|
@@ -590,7 +587,7 @@ function handleQueryResponseForPartition(optimizedPartitions, p, query, knownHei
|
|
|
590
587
|
let updatedMainPartition_mergeBlock = p.mergeBlock;
|
|
591
588
|
let updatedMainPartition_dynamicContract = p.dynamicContract;
|
|
592
589
|
let updatedMainPartition_mutPendingQueries = p.mutPendingQueries;
|
|
593
|
-
let updatedMainPartition_latestSourceRangeCapacityUpdateBlock = shouldUpdateSourceRangeCapacity ? latestFetchedBlock
|
|
590
|
+
let updatedMainPartition_latestSourceRangeCapacityUpdateBlock = shouldUpdateSourceRangeCapacity ? latestFetchedBlock : p.latestSourceRangeCapacityUpdateBlock;
|
|
594
591
|
let updatedMainPartition = {
|
|
595
592
|
id: updatedMainPartition_id,
|
|
596
593
|
latestFetchedBlock: updatedLatestFetchedBlock,
|
|
@@ -613,7 +610,7 @@ function handleQueryResponseForPartition(optimizedPartitions, p, query, knownHei
|
|
|
613
610
|
let idx = ids.indexOf(p.id);
|
|
614
611
|
let isAfter = jdx => {
|
|
615
612
|
if (jdx < count) {
|
|
616
|
-
return mutEntities[ids[jdx]].latestFetchedBlock
|
|
613
|
+
return mutEntities[ids[jdx]].latestFetchedBlock < updatedLatestFetchedBlock;
|
|
617
614
|
} else {
|
|
618
615
|
return false;
|
|
619
616
|
}
|
|
@@ -679,8 +676,8 @@ function bufferBlockNumber(param) {
|
|
|
679
676
|
let optimizedPartitions = param.optimizedPartitions;
|
|
680
677
|
let id = optimizedPartitions.idsInAscOrder[0];
|
|
681
678
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
682
|
-
if (latestFullyFetchedBlock !== undefined && latestOnBlockBlockNumber >= latestFullyFetchedBlock
|
|
683
|
-
return latestFullyFetchedBlock
|
|
679
|
+
if (latestFullyFetchedBlock !== undefined && latestOnBlockBlockNumber >= latestFullyFetchedBlock) {
|
|
680
|
+
return latestFullyFetchedBlock;
|
|
684
681
|
} else {
|
|
685
682
|
return latestOnBlockBlockNumber;
|
|
686
683
|
}
|
|
@@ -691,13 +688,10 @@ function bufferBlock(param) {
|
|
|
691
688
|
let optimizedPartitions = param.optimizedPartitions;
|
|
692
689
|
let id = optimizedPartitions.idsInAscOrder[0];
|
|
693
690
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
694
|
-
if (latestFullyFetchedBlock !== undefined && latestOnBlockBlockNumber >= latestFullyFetchedBlock
|
|
691
|
+
if (latestFullyFetchedBlock !== undefined && latestOnBlockBlockNumber >= latestFullyFetchedBlock) {
|
|
695
692
|
return latestFullyFetchedBlock;
|
|
696
693
|
} else {
|
|
697
|
-
return
|
|
698
|
-
blockNumber: latestOnBlockBlockNumber,
|
|
699
|
-
blockTimestamp: 0
|
|
700
|
-
};
|
|
694
|
+
return latestOnBlockBlockNumber;
|
|
701
695
|
}
|
|
702
696
|
}
|
|
703
697
|
|
|
@@ -725,6 +719,50 @@ function getRegistrationIndex(item) {
|
|
|
725
719
|
}
|
|
726
720
|
}
|
|
727
721
|
|
|
722
|
+
function comparePath(a, b) {
|
|
723
|
+
let la = a.length;
|
|
724
|
+
let lb = b.length;
|
|
725
|
+
let shared = la < lb ? la : lb;
|
|
726
|
+
let i = 0;
|
|
727
|
+
let result = 0;
|
|
728
|
+
while (result === 0 && i < shared) {
|
|
729
|
+
let x = a[i];
|
|
730
|
+
let y = b[i];
|
|
731
|
+
if (x !== y) {
|
|
732
|
+
result = x < y ? -1 : 1;
|
|
733
|
+
}
|
|
734
|
+
i = i + 1 | 0;
|
|
735
|
+
};
|
|
736
|
+
if (result !== 0) {
|
|
737
|
+
return result;
|
|
738
|
+
} else if (la === lb) {
|
|
739
|
+
return 0;
|
|
740
|
+
} else if (la < lb) {
|
|
741
|
+
return -1;
|
|
742
|
+
} else {
|
|
743
|
+
return 1;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function compareTiebreak(a, b) {
|
|
748
|
+
let match = a.orderPath;
|
|
749
|
+
let match$1 = b.orderPath;
|
|
750
|
+
let byPath;
|
|
751
|
+
byPath = (match == null) || (match$1 == null) ? 0 : comparePath(match, match$1);
|
|
752
|
+
if (byPath !== 0) {
|
|
753
|
+
return byPath;
|
|
754
|
+
}
|
|
755
|
+
let ia = getRegistrationIndex(a);
|
|
756
|
+
let ib = getRegistrationIndex(b);
|
|
757
|
+
if (ia < ib) {
|
|
758
|
+
return -1;
|
|
759
|
+
} else if (ia > ib) {
|
|
760
|
+
return 1;
|
|
761
|
+
} else {
|
|
762
|
+
return 0;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
728
766
|
function compareBufferItem(a, b) {
|
|
729
767
|
let ba = a.blockNumber;
|
|
730
768
|
let bb = b.blockNumber;
|
|
@@ -735,6 +773,15 @@ function compareBufferItem(a, b) {
|
|
|
735
773
|
return 1;
|
|
736
774
|
}
|
|
737
775
|
}
|
|
776
|
+
let ka = a.kind;
|
|
777
|
+
let kb = b.kind;
|
|
778
|
+
if (ka !== kb) {
|
|
779
|
+
if (ka < kb) {
|
|
780
|
+
return -1;
|
|
781
|
+
} else {
|
|
782
|
+
return 1;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
738
785
|
let la = a.logIndex;
|
|
739
786
|
let lb = b.logIndex;
|
|
740
787
|
if (la !== lb) {
|
|
@@ -743,15 +790,8 @@ function compareBufferItem(a, b) {
|
|
|
743
790
|
} else {
|
|
744
791
|
return 1;
|
|
745
792
|
}
|
|
746
|
-
}
|
|
747
|
-
let ia = getRegistrationIndex(a);
|
|
748
|
-
let ib = getRegistrationIndex(b);
|
|
749
|
-
if (ia < ib) {
|
|
750
|
-
return -1;
|
|
751
|
-
} else if (ia > ib) {
|
|
752
|
-
return 1;
|
|
753
793
|
} else {
|
|
754
|
-
return
|
|
794
|
+
return compareTiebreak(a, b);
|
|
755
795
|
}
|
|
756
796
|
}
|
|
757
797
|
|
|
@@ -822,8 +862,7 @@ function appendOnBlockItems(mutItems, onBlockRegistrations, indexerStartBlock, f
|
|
|
822
862
|
mutItems.push({
|
|
823
863
|
kind: 1,
|
|
824
864
|
onBlockRegistration: onBlockRegistration,
|
|
825
|
-
blockNumber: blockNumber
|
|
826
|
-
logIndex: 16777216 + onBlockRegistration.index | 0
|
|
865
|
+
blockNumber: blockNumber
|
|
827
866
|
});
|
|
828
867
|
newItemsCounter = newItemsCounter + 1 | 0;
|
|
829
868
|
}
|
|
@@ -851,7 +890,7 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, mutItemsSo
|
|
|
851
890
|
} else {
|
|
852
891
|
let id = optimizedPartitions.idsInAscOrder[0];
|
|
853
892
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
854
|
-
maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock
|
|
893
|
+
maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock : knownHeight;
|
|
855
894
|
}
|
|
856
895
|
latestOnBlockBlockNumber = appendOnBlockItems(blockItems, onBlockRegistrations, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
|
|
857
896
|
} else {
|
|
@@ -888,9 +927,9 @@ function addClientFilteredContract(clientFilteredContracts, contractName, chainI
|
|
|
888
927
|
}
|
|
889
928
|
|
|
890
929
|
function claimedFetchedBlock(p, knownHeight) {
|
|
891
|
-
return Stdlib_Array.reduce(p.mutPendingQueries, p.latestFetchedBlock
|
|
892
|
-
let
|
|
893
|
-
return Primitive_int.max(max,
|
|
930
|
+
return Stdlib_Array.reduce(p.mutPendingQueries, p.latestFetchedBlock, (max, q) => {
|
|
931
|
+
let blockNumber = q.fetchedBlock;
|
|
932
|
+
return Primitive_int.max(max, blockNumber !== undefined ? blockNumber : Stdlib_Option.getOr(q.toBlock, knownHeight));
|
|
894
933
|
});
|
|
895
934
|
}
|
|
896
935
|
|
|
@@ -912,7 +951,7 @@ function collapseClientFilteredContracts(partitions, clientFilteredContracts, no
|
|
|
912
951
|
latestFetchedBlock: p.latestFetchedBlock,
|
|
913
952
|
selection: p.selection,
|
|
914
953
|
addresses: p.addresses,
|
|
915
|
-
mergeBlock: p.latestFetchedBlock
|
|
954
|
+
mergeBlock: p.latestFetchedBlock,
|
|
916
955
|
dynamicContract: p.dynamicContract,
|
|
917
956
|
mutPendingQueries: p.mutPendingQueries,
|
|
918
957
|
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
@@ -972,7 +1011,7 @@ function collapseClientFilteredContracts(partitions, clientFilteredContracts, no
|
|
|
972
1011
|
};
|
|
973
1012
|
let considerFrontier = b => {
|
|
974
1013
|
let m = minFrontierRef.contents;
|
|
975
|
-
if (m !== undefined && m
|
|
1014
|
+
if (m !== undefined && m <= b) {
|
|
976
1015
|
return;
|
|
977
1016
|
} else {
|
|
978
1017
|
minFrontierRef.contents = b;
|
|
@@ -1028,7 +1067,7 @@ function collapseClientFilteredContracts(partitions, clientFilteredContracts, no
|
|
|
1028
1067
|
kept.push(standingOut);
|
|
1029
1068
|
let catchUpToBlock = claimedFetchedBlock(standingOut, knownHeight);
|
|
1030
1069
|
let minFrontier = minFrontierRef.contents;
|
|
1031
|
-
if (minFrontier !== undefined && minFrontier
|
|
1070
|
+
if (minFrontier !== undefined && minFrontier < catchUpToBlock) {
|
|
1032
1071
|
let id$1 = nextPartitionIndexRef.contents.toString();
|
|
1033
1072
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
1034
1073
|
kept.push({
|
|
@@ -1125,10 +1164,7 @@ function createPartitions(registeringSetsByContract, addressStore, dynamicContra
|
|
|
1125
1164
|
if (clientFilteredContracts.has(contractName) && !isAnchored) {
|
|
1126
1165
|
let match = groups[0];
|
|
1127
1166
|
if (match !== undefined) {
|
|
1128
|
-
clientFilteredFrontiers.push(
|
|
1129
|
-
blockNumber: Primitive_int.max(match.startBlock - 1 | 0, progressBlockNumber),
|
|
1130
|
-
blockTimestamp: 0
|
|
1131
|
-
});
|
|
1167
|
+
clientFilteredFrontiers.push(Primitive_int.max(match.startBlock - 1 | 0, progressBlockNumber));
|
|
1132
1168
|
}
|
|
1133
1169
|
} else {
|
|
1134
1170
|
let offsetRef = 0;
|
|
@@ -1147,11 +1183,7 @@ function createPartitions(registeringSetsByContract, addressStore, dynamicContra
|
|
|
1147
1183
|
joining = false;
|
|
1148
1184
|
}
|
|
1149
1185
|
};
|
|
1150
|
-
let
|
|
1151
|
-
let latestFetchedBlock = {
|
|
1152
|
-
blockNumber: latestFetchedBlock_blockNumber,
|
|
1153
|
-
blockTimestamp: 0
|
|
1154
|
-
};
|
|
1186
|
+
let latestFetchedBlock = Primitive_int.max(startBlock - 1 | 0, progressBlockNumber);
|
|
1155
1187
|
let remainingRef = countRef;
|
|
1156
1188
|
let chunkOffsetRef = offsetRef;
|
|
1157
1189
|
while (remainingRef > 0) {
|
|
@@ -1187,8 +1219,8 @@ function createPartitions(registeringSetsByContract, addressStore, dynamicContra
|
|
|
1187
1219
|
while (nextIdx$1 < nonDynamicPartitions.length) {
|
|
1188
1220
|
let nextP = nonDynamicPartitions[nextIdx$1];
|
|
1189
1221
|
let currentP = currentPRef;
|
|
1190
|
-
let currentPBlock = currentP.latestFetchedBlock
|
|
1191
|
-
let nextPBlock = nextP.latestFetchedBlock
|
|
1222
|
+
let currentPBlock = currentP.latestFetchedBlock;
|
|
1223
|
+
let nextPBlock = nextP.latestFetchedBlock;
|
|
1192
1224
|
let totalCount = currentP.addresses.size() + nextP.addresses.size() | 0;
|
|
1193
1225
|
if (totalCount > maxAddrInPartition) {
|
|
1194
1226
|
mergedNonDynamic.push(currentP);
|
|
@@ -1430,7 +1462,7 @@ function pushGapFillQueries(queries, partitionId, rangeFromBlock, rangeEndBlock,
|
|
|
1430
1462
|
function walkPartitionPending(p, partitionId, inFlightCount, candidates, headBlockNumber, chainTargetBlock, partitionBudget, queryEndBlock) {
|
|
1431
1463
|
let maybeChunkRange = getMinHistoryRange(p);
|
|
1432
1464
|
let pendingCount = p.mutPendingQueries.length;
|
|
1433
|
-
let cursor = p.latestFetchedBlock
|
|
1465
|
+
let cursor = p.latestFetchedBlock + 1 | 0;
|
|
1434
1466
|
let canContinue = true;
|
|
1435
1467
|
let chunksUsedThisCall = 0;
|
|
1436
1468
|
let pqIdx = 0;
|
|
@@ -1443,13 +1475,8 @@ function walkPartitionPending(p, partitionId, inFlightCount, candidates, headBlo
|
|
|
1443
1475
|
}
|
|
1444
1476
|
let toBlock = pq.toBlock;
|
|
1445
1477
|
if (toBlock !== undefined && pq.isChunk) {
|
|
1446
|
-
let
|
|
1447
|
-
|
|
1448
|
-
let blockNumber = match.blockNumber;
|
|
1449
|
-
cursor = blockNumber < toBlock ? blockNumber + 1 | 0 : toBlock + 1 | 0;
|
|
1450
|
-
} else {
|
|
1451
|
-
cursor = toBlock + 1 | 0;
|
|
1452
|
-
}
|
|
1478
|
+
let blockNumber = pq.fetchedBlock;
|
|
1479
|
+
cursor = blockNumber !== undefined && blockNumber < toBlock ? blockNumber + 1 | 0 : toBlock + 1 | 0;
|
|
1453
1480
|
} else {
|
|
1454
1481
|
canContinue = false;
|
|
1455
1482
|
}
|
|
@@ -1609,7 +1636,7 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
|
|
|
1609
1636
|
}
|
|
1610
1637
|
}
|
|
1611
1638
|
inFlightCounts[idx] = inFlightCount;
|
|
1612
|
-
if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock
|
|
1639
|
+
if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock < headBlockNumber) {
|
|
1613
1640
|
shouldWaitForNewBlock = false;
|
|
1614
1641
|
}
|
|
1615
1642
|
}
|
|
@@ -1707,10 +1734,6 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1707
1734
|
let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
|
|
1708
1735
|
let clientFilterAddressThreshold = clientFilterAddressThresholdOpt !== undefined ? Primitive_option.valFromOption(clientFilterAddressThresholdOpt) : undefined;
|
|
1709
1736
|
let isResumed = isResumedOpt !== undefined ? isResumedOpt : false;
|
|
1710
|
-
let latestFetchedBlock = {
|
|
1711
|
-
blockNumber: progressBlockNumber,
|
|
1712
|
-
blockTimestamp: 0
|
|
1713
|
-
};
|
|
1714
1737
|
let notDependingOnAddresses = [];
|
|
1715
1738
|
let normalRegistrations = [];
|
|
1716
1739
|
let contractNamesWithNormalEvents = new Set();
|
|
@@ -1726,7 +1749,7 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1726
1749
|
if (notDependingOnAddresses.length !== 0) {
|
|
1727
1750
|
partitions.push({
|
|
1728
1751
|
id: partitions.length.toString(),
|
|
1729
|
-
latestFetchedBlock:
|
|
1752
|
+
latestFetchedBlock: progressBlockNumber,
|
|
1730
1753
|
selection: makeSelection(notDependingOnAddresses, false, undefined),
|
|
1731
1754
|
addresses: addressStore.emptySet(),
|
|
1732
1755
|
mergeBlock: undefined,
|
|
@@ -1781,7 +1804,7 @@ function make$1(startBlock, endBlock, onEventRegistrations, addressStore, addres
|
|
|
1781
1804
|
if (knownHeight > 0 && Utils.$$Array.notEmpty(onBlockRegistrations)) {
|
|
1782
1805
|
let id = optimizedPartitions.idsInAscOrder[0];
|
|
1783
1806
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
1784
|
-
let maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock
|
|
1807
|
+
let maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock : knownHeight;
|
|
1785
1808
|
latestOnBlockBlockNumber = appendOnBlockItems(buffer, onBlockRegistrations, startBlock, progressBlockNumber, maxBlockNumber, maxOnBlockBufferSize);
|
|
1786
1809
|
} else {
|
|
1787
1810
|
latestOnBlockBlockNumber = progressBlockNumber;
|
|
@@ -1816,19 +1839,16 @@ function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
|
|
|
1816
1839
|
for (let qIdx = 0, qIdx_finish = mutPendingQueries.length; qIdx < qIdx_finish; ++qIdx) {
|
|
1817
1840
|
let pq = mutPendingQueries[qIdx];
|
|
1818
1841
|
if (pq.fromBlock <= targetBlockNumber) {
|
|
1819
|
-
let
|
|
1820
|
-
if (
|
|
1821
|
-
if (
|
|
1842
|
+
let blockNumber = pq.fetchedBlock;
|
|
1843
|
+
if (blockNumber !== undefined) {
|
|
1844
|
+
if (blockNumber > targetBlockNumber) {
|
|
1822
1845
|
adjusted.push({
|
|
1823
1846
|
fromBlock: pq.fromBlock,
|
|
1824
1847
|
toBlock: pq.toBlock,
|
|
1825
1848
|
isChunk: pq.isChunk,
|
|
1826
1849
|
itemsTarget: pq.itemsTarget,
|
|
1827
1850
|
itemsEst: pq.itemsEst,
|
|
1828
|
-
fetchedBlock:
|
|
1829
|
-
blockNumber: targetBlockNumber,
|
|
1830
|
-
blockTimestamp: 0
|
|
1831
|
-
}
|
|
1851
|
+
fetchedBlock: targetBlockNumber
|
|
1832
1852
|
});
|
|
1833
1853
|
} else {
|
|
1834
1854
|
adjusted.push(pq);
|
|
@@ -1857,7 +1877,7 @@ function rollback(fetchState, addressStore, targetBlockNumber) {
|
|
|
1857
1877
|
for (let idx = 0, idx_finish = partitions.length; idx < idx_finish; ++idx) {
|
|
1858
1878
|
let p = partitions[idx];
|
|
1859
1879
|
if (p.selection.dependsOnAddresses) {
|
|
1860
|
-
if (p.latestFetchedBlock
|
|
1880
|
+
if (p.latestFetchedBlock > targetBlockNumber) {
|
|
1861
1881
|
collectForRecreation(p.addresses.filterByRegistrationBlock(targetBlockNumber));
|
|
1862
1882
|
} else {
|
|
1863
1883
|
let mergeBlock = p.mergeBlock;
|
|
@@ -1888,10 +1908,7 @@ function rollback(fetchState, addressStore, targetBlockNumber) {
|
|
|
1888
1908
|
let mergeBlock$2 = p.mergeBlock;
|
|
1889
1909
|
keptPartitions.push({
|
|
1890
1910
|
id: id$1,
|
|
1891
|
-
latestFetchedBlock: p.latestFetchedBlock
|
|
1892
|
-
blockNumber: targetBlockNumber,
|
|
1893
|
-
blockTimestamp: 0
|
|
1894
|
-
}) : p.latestFetchedBlock,
|
|
1911
|
+
latestFetchedBlock: p.latestFetchedBlock > targetBlockNumber ? targetBlockNumber : p.latestFetchedBlock,
|
|
1895
1912
|
selection: p.selection,
|
|
1896
1913
|
addresses: p.addresses,
|
|
1897
1914
|
mergeBlock: mergeBlock$2 !== undefined && mergeBlock$2 > targetBlockNumber ? targetBlockNumber : mergeBlock$2,
|
|
@@ -2082,8 +2099,6 @@ function updateKnownHeight(fetchState, knownHeight) {
|
|
|
2082
2099
|
}
|
|
2083
2100
|
}
|
|
2084
2101
|
|
|
2085
|
-
let blockItemLogIndex = 16777216;
|
|
2086
|
-
|
|
2087
2102
|
let maxInFlightChunksPerPartition = 12;
|
|
2088
2103
|
|
|
2089
2104
|
let maxChainConcurrency = Env.maxChainConcurrency;
|
|
@@ -2105,9 +2120,10 @@ export {
|
|
|
2105
2120
|
bufferBlock,
|
|
2106
2121
|
bufferReadyCount,
|
|
2107
2122
|
getRegistrationIndex,
|
|
2123
|
+
comparePath,
|
|
2124
|
+
compareTiebreak,
|
|
2108
2125
|
compareBufferItem,
|
|
2109
2126
|
mergeIntoBuffer,
|
|
2110
|
-
blockItemLogIndex,
|
|
2111
2127
|
appendOnBlockItems,
|
|
2112
2128
|
updateInternal,
|
|
2113
2129
|
addClientFilteredContract,
|