envio 2.29.0-alpha.0 → 2.29.0-alpha.2
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 +3 -0
- package/package.json +5 -5
- package/src/Batch.res +4 -14
- package/src/Batch.res.js +3 -14
- package/src/Envio.gen.ts +14 -0
- package/src/Envio.res +18 -0
- package/src/EventRegister.res +173 -31
- package/src/EventRegister.res.js +138 -33
- package/src/EventRegister.resi +11 -0
- package/src/EventUtils.res +52 -58
- package/src/EventUtils.res.js +15 -51
- package/src/FetchState.res +90 -57
- package/src/FetchState.res.js +84 -56
- package/src/Internal.gen.ts +2 -0
- package/src/Internal.res +47 -3
- package/src/InternalConfig.res +18 -0
- package/src/Logging.res +36 -24
- package/src/Logging.res.js +35 -21
- package/src/sources/HyperFuelSource.res +506 -0
- package/src/sources/HyperFuelSource.res.js +451 -0
- package/src/sources/HyperSync.res +1 -1
- package/src/sources/HyperSync.resi +1 -1
- package/src/sources/HyperSyncSource.res +569 -0
- package/src/sources/HyperSyncSource.res.js +413 -0
- package/src/sources/RpcSource.res +18 -20
- package/src/sources/RpcSource.res.js +1 -0
- package/src/sources/Source.res +1 -1
package/src/EventUtils.res
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
type multiChainEventIndex = {
|
|
2
|
-
timestamp: int,
|
|
3
|
-
chainId: int,
|
|
4
|
-
blockNumber: int,
|
|
5
|
-
logIndex: int,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
1
|
//Comparator used when ordering multichain events
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
(timestamp,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
let getOrderedBatchItemComparator = (item: Internal.item) => {
|
|
3
|
+
switch item {
|
|
4
|
+
| Internal.Event({timestamp, chain, blockNumber, logIndex}) => (
|
|
5
|
+
timestamp,
|
|
6
|
+
chain->ChainMap.Chain.toChainId,
|
|
7
|
+
blockNumber,
|
|
8
|
+
logIndex,
|
|
9
|
+
)
|
|
10
|
+
| Internal.Block(_) =>
|
|
11
|
+
Js.Exn.raiseError("Block handlers are not supported for ordered multichain mode.")
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
event1->getEventComparator < event2->getEventComparator
|
|
15
|
+
let isEarlier = (item1: (int, int, int, int), item2: (int, int, int, int)) => {
|
|
16
|
+
item1 < item2
|
|
24
17
|
}
|
|
25
18
|
|
|
26
|
-
type eventIndex = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
19
|
+
// type eventIndex = {
|
|
20
|
+
// blockNumber: int,
|
|
21
|
+
// logIndex: int,
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
30
24
|
|
|
31
25
|
// takes blockNumber, logIndex and packs them into a number with
|
|
32
26
|
//32 bits, 16 bits and 16 bits respectively
|
|
@@ -38,44 +32,44 @@ let packEventIndex = (~blockNumber, ~logIndex) => {
|
|
|
38
32
|
blockNumber->BigInt.Bitwise.logor(logIndex)
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
//Currently not used but keeping in utils
|
|
42
|
-
//using @live flag for dead code analyser
|
|
43
|
-
@live
|
|
44
|
-
let packMultiChainEventIndex = (~timestamp, ~chainId, ~blockNumber, ~logIndex) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
// //Currently not used but keeping in utils
|
|
36
|
+
// //using @live flag for dead code analyser
|
|
37
|
+
// @live
|
|
38
|
+
// let packMultiChainEventIndex = (~timestamp, ~chainId, ~blockNumber, ~logIndex) => {
|
|
39
|
+
// let timestamp = timestamp->BigInt.fromInt
|
|
40
|
+
// let chainId = chainId->BigInt.fromInt
|
|
41
|
+
// let blockNumber = blockNumber->BigInt.fromInt
|
|
42
|
+
// let logIndex = logIndex->BigInt.fromInt
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
// let timestamp = BigInt.Bitwise.shift_left(timestamp, 48->BigInt.fromInt)
|
|
45
|
+
// let chainId = BigInt.Bitwise.shift_left(chainId, 16->BigInt.fromInt)
|
|
46
|
+
// let blockNumber = BigInt.Bitwise.shift_left(blockNumber, 16->BigInt.fromInt)
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
48
|
+
// timestamp
|
|
49
|
+
// ->BigInt.Bitwise.logor(chainId)
|
|
50
|
+
// ->BigInt.Bitwise.logor(blockNumber)
|
|
51
|
+
// ->BigInt.Bitwise.logor(logIndex)
|
|
52
|
+
// }
|
|
59
53
|
|
|
60
|
-
//Currently not used but keeping in utils
|
|
61
|
-
//using @live flag for dead code analyser
|
|
62
|
-
@live
|
|
63
|
-
let unpackEventIndex = (packedEventIndex: bigint) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
54
|
+
// //Currently not used but keeping in utils
|
|
55
|
+
// //using @live flag for dead code analyser
|
|
56
|
+
// @live
|
|
57
|
+
// let unpackEventIndex = (packedEventIndex: bigint) => {
|
|
58
|
+
// let blockNumber = packedEventIndex->BigInt.Bitwise.shift_right(16->BigInt.fromInt)
|
|
59
|
+
// let logIndexMask = 65535->BigInt.fromInt
|
|
60
|
+
// let logIndex = packedEventIndex->BigInt.Bitwise.logand(logIndexMask)
|
|
61
|
+
// {
|
|
62
|
+
// blockNumber: blockNumber->BigInt.toString->Belt.Int.fromString->Belt.Option.getUnsafe,
|
|
63
|
+
// logIndex: logIndex->BigInt.toString->Belt.Int.fromString->Belt.Option.getUnsafe,
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
72
66
|
|
|
73
|
-
//takes an eventIndex record and returnts a packed event index
|
|
74
|
-
//used in TS tests
|
|
75
|
-
@live
|
|
76
|
-
let packEventIndexFromRecord = (eventIndex: eventIndex) => {
|
|
77
|
-
|
|
78
|
-
}
|
|
67
|
+
// //takes an eventIndex record and returnts a packed event index
|
|
68
|
+
// //used in TS tests
|
|
69
|
+
// @live
|
|
70
|
+
// let packEventIndexFromRecord = (eventIndex: eventIndex) => {
|
|
71
|
+
// packEventIndex(~blockNumber=eventIndex.blockNumber, ~logIndex=eventIndex.logIndex)
|
|
72
|
+
// }
|
|
79
73
|
|
|
80
74
|
//Returns unique string id for an event using its chain id combined with event id
|
|
81
75
|
//Used in IO for the key in the in mem rawEvents table
|
package/src/EventUtils.res.js
CHANGED
|
@@ -2,30 +2,23 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var $$BigInt = require("./bindings/BigInt.res.js");
|
|
5
|
-
var
|
|
5
|
+
var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
6
6
|
var Caml_obj = require("rescript/lib/js/caml_obj.js");
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
function getOrderedBatchItemComparator(item) {
|
|
9
|
+
if (item.kind === 0) {
|
|
10
|
+
return [
|
|
11
|
+
item.timestamp,
|
|
12
|
+
item.chain,
|
|
13
|
+
item.blockNumber,
|
|
14
|
+
item.logIndex
|
|
15
|
+
];
|
|
16
|
+
} else {
|
|
17
|
+
return Js_exn.raiseError("Block handlers are not supported for ordered multichain mode.");
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
return [
|
|
19
|
-
param.timestamp,
|
|
20
|
-
param.chain,
|
|
21
|
-
param.blockNumber,
|
|
22
|
-
param.logIndex
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isEarlierEvent(event1, event2) {
|
|
27
|
-
return Caml_obj.lessthan(getEventComparator(event1), getEventComparator(event2));
|
|
28
|
-
}
|
|
21
|
+
var isEarlier = Caml_obj.lessthan;
|
|
29
22
|
|
|
30
23
|
function packEventIndex(blockNumber, logIndex) {
|
|
31
24
|
var blockNumber$1 = BigInt(blockNumber);
|
|
@@ -34,42 +27,13 @@ function packEventIndex(blockNumber, logIndex) {
|
|
|
34
27
|
return $$BigInt.Bitwise.logor(blockNumber$2, logIndex$1);
|
|
35
28
|
}
|
|
36
29
|
|
|
37
|
-
function packMultiChainEventIndex(timestamp, chainId, blockNumber, logIndex) {
|
|
38
|
-
var timestamp$1 = BigInt(timestamp);
|
|
39
|
-
var chainId$1 = BigInt(chainId);
|
|
40
|
-
var blockNumber$1 = BigInt(blockNumber);
|
|
41
|
-
var logIndex$1 = BigInt(logIndex);
|
|
42
|
-
var timestamp$2 = $$BigInt.Bitwise.shift_left(timestamp$1, BigInt(48));
|
|
43
|
-
var chainId$2 = $$BigInt.Bitwise.shift_left(chainId$1, BigInt(16));
|
|
44
|
-
var blockNumber$2 = $$BigInt.Bitwise.shift_left(blockNumber$1, BigInt(16));
|
|
45
|
-
return $$BigInt.Bitwise.logor($$BigInt.Bitwise.logor($$BigInt.Bitwise.logor(timestamp$2, chainId$2), blockNumber$2), logIndex$1);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function unpackEventIndex(packedEventIndex) {
|
|
49
|
-
var blockNumber = $$BigInt.Bitwise.shift_right(packedEventIndex, BigInt(16));
|
|
50
|
-
var logIndexMask = BigInt(65535);
|
|
51
|
-
var logIndex = $$BigInt.Bitwise.logand(packedEventIndex, logIndexMask);
|
|
52
|
-
return {
|
|
53
|
-
blockNumber: Belt_Int.fromString(blockNumber.toString()),
|
|
54
|
-
logIndex: Belt_Int.fromString(logIndex.toString())
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function packEventIndexFromRecord(eventIndex) {
|
|
59
|
-
return packEventIndex(eventIndex.blockNumber, eventIndex.logIndex);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
30
|
function getEventIdKeyString(chainId, eventId) {
|
|
63
31
|
var chainIdStr = String(chainId);
|
|
64
32
|
return chainIdStr + "_" + eventId;
|
|
65
33
|
}
|
|
66
34
|
|
|
67
|
-
exports.
|
|
68
|
-
exports.
|
|
69
|
-
exports.isEarlierEvent = isEarlierEvent;
|
|
35
|
+
exports.getOrderedBatchItemComparator = getOrderedBatchItemComparator;
|
|
36
|
+
exports.isEarlier = isEarlier;
|
|
70
37
|
exports.packEventIndex = packEventIndex;
|
|
71
|
-
exports.packMultiChainEventIndex = packMultiChainEventIndex;
|
|
72
|
-
exports.unpackEventIndex = unpackEventIndex;
|
|
73
|
-
exports.packEventIndexFromRecord = packEventIndexFromRecord;
|
|
74
38
|
exports.getEventIdKeyString = getEventIdKeyString;
|
|
75
39
|
/* BigInt Not a pure module */
|
package/src/FetchState.res
CHANGED
|
@@ -52,9 +52,9 @@ type t = {
|
|
|
52
52
|
// since partitions might be deleted on merge or cleaned up
|
|
53
53
|
nextPartitionIndex: int,
|
|
54
54
|
isFetchingAtHead: bool,
|
|
55
|
+
startBlock: int,
|
|
55
56
|
endBlock: option<int>,
|
|
56
57
|
maxAddrInPartition: int,
|
|
57
|
-
firstEventBlockNumber: option<int>,
|
|
58
58
|
normalSelection: selection,
|
|
59
59
|
// By address
|
|
60
60
|
indexingContracts: dict<indexingContract>,
|
|
@@ -71,25 +71,27 @@ type t = {
|
|
|
71
71
|
// Needed to query before entering reorg threshold
|
|
72
72
|
blockLag: int,
|
|
73
73
|
//Items ordered from latest to earliest
|
|
74
|
-
queue: array<Internal.
|
|
74
|
+
queue: array<Internal.item>,
|
|
75
|
+
onBlockConfigs: option<array<Internal.onBlockConfig>>,
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
let copy = (fetchState: t) => {
|
|
78
79
|
{
|
|
79
80
|
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
80
81
|
partitions: fetchState.partitions,
|
|
82
|
+
startBlock: fetchState.startBlock,
|
|
81
83
|
endBlock: fetchState.endBlock,
|
|
82
84
|
nextPartitionIndex: fetchState.nextPartitionIndex,
|
|
83
85
|
isFetchingAtHead: fetchState.isFetchingAtHead,
|
|
84
86
|
latestFullyFetchedBlock: fetchState.latestFullyFetchedBlock,
|
|
85
87
|
normalSelection: fetchState.normalSelection,
|
|
86
|
-
firstEventBlockNumber: fetchState.firstEventBlockNumber,
|
|
87
88
|
chainId: fetchState.chainId,
|
|
88
89
|
contractConfigs: fetchState.contractConfigs,
|
|
89
90
|
indexingContracts: fetchState.indexingContracts,
|
|
90
91
|
dcsToStore: fetchState.dcsToStore,
|
|
91
92
|
blockLag: fetchState.blockLag,
|
|
92
93
|
queue: fetchState.queue->Array.copy,
|
|
94
|
+
onBlockConfigs: fetchState.onBlockConfigs,
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -252,15 +254,13 @@ let updateInternal = (
|
|
|
252
254
|
|
|
253
255
|
{
|
|
254
256
|
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
257
|
+
startBlock: fetchState.startBlock,
|
|
255
258
|
endBlock: fetchState.endBlock,
|
|
256
259
|
contractConfigs: fetchState.contractConfigs,
|
|
257
260
|
normalSelection: fetchState.normalSelection,
|
|
258
261
|
chainId: fetchState.chainId,
|
|
262
|
+
onBlockConfigs: fetchState.onBlockConfigs,
|
|
259
263
|
nextPartitionIndex,
|
|
260
|
-
firstEventBlockNumber: switch queue->Utils.Array.last {
|
|
261
|
-
| Some(item) => Utils.Math.minOptInt(fetchState.firstEventBlockNumber, Some(item.blockNumber))
|
|
262
|
-
| None => fetchState.firstEventBlockNumber
|
|
263
|
-
},
|
|
264
264
|
partitions,
|
|
265
265
|
isFetchingAtHead,
|
|
266
266
|
latestFullyFetchedBlock,
|
|
@@ -549,15 +549,18 @@ exception UnexpectedMergeQueryResponse({message: string})
|
|
|
549
549
|
/*
|
|
550
550
|
Comparitor for two events from the same chain. No need for chain id or timestamp
|
|
551
551
|
*/
|
|
552
|
-
let compareBufferItem = (a: Internal.
|
|
553
|
-
let blockDiff = b.
|
|
552
|
+
let compareBufferItem = (a: Internal.item, b: Internal.item) => {
|
|
553
|
+
let blockDiff = b->Internal.getItemBlockNumber - a->Internal.getItemBlockNumber
|
|
554
554
|
if blockDiff === 0 {
|
|
555
|
-
b.
|
|
555
|
+
b->Internal.getItemLogIndex - a->Internal.getItemLogIndex
|
|
556
556
|
} else {
|
|
557
557
|
blockDiff
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
// Some big number which should be bigger than any log index
|
|
562
|
+
let blockItemLogIndex = 16777216
|
|
563
|
+
|
|
561
564
|
/*
|
|
562
565
|
Updates fetchState with a response for a given query.
|
|
563
566
|
Returns Error if the partition with given query cannot be found (unexpected)
|
|
@@ -623,11 +626,55 @@ let handleQueryResult = (
|
|
|
623
626
|
)
|
|
624
627
|
}
|
|
625
628
|
}->Result.map(partitions => {
|
|
629
|
+
let newQueue = fetchState.queue->Array.concat(newItems)
|
|
630
|
+
|
|
631
|
+
switch fetchState.onBlockConfigs {
|
|
632
|
+
| Some(onBlockConfigs) => {
|
|
633
|
+
let prevLatestFetchedBlockNumber = fetchState.latestFullyFetchedBlock.blockNumber
|
|
634
|
+
let nextLatestFullyFetchedBlockNumber = {
|
|
635
|
+
let nextLatestFullyFetchedBlockNumber = ref(latestFetchedBlock.blockNumber)
|
|
636
|
+
for idx in 0 to partitions->Array.length - 1 {
|
|
637
|
+
let p = partitions->Js.Array2.unsafe_get(idx)
|
|
638
|
+
if nextLatestFullyFetchedBlockNumber.contents > p.latestFetchedBlock.blockNumber {
|
|
639
|
+
nextLatestFullyFetchedBlockNumber := p.latestFetchedBlock.blockNumber
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
nextLatestFullyFetchedBlockNumber.contents
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if nextLatestFullyFetchedBlockNumber > prevLatestFetchedBlockNumber {
|
|
646
|
+
for configIdx in 0 to onBlockConfigs->Array.length - 1 {
|
|
647
|
+
let onBlockConfig = onBlockConfigs->Js.Array2.unsafe_get(configIdx)
|
|
648
|
+
|
|
649
|
+
let handlerStartBlock = switch onBlockConfig.startBlock {
|
|
650
|
+
| Some(startBlock) => startBlock
|
|
651
|
+
| None => fetchState.startBlock
|
|
652
|
+
}
|
|
653
|
+
let rangeStart = Pervasives.max(handlerStartBlock, prevLatestFetchedBlockNumber + 1)
|
|
654
|
+
let rangeEnd = switch onBlockConfig.endBlock {
|
|
655
|
+
| Some(endBlock) => Pervasives.min(endBlock, nextLatestFullyFetchedBlockNumber)
|
|
656
|
+
| None => nextLatestFullyFetchedBlockNumber
|
|
657
|
+
}
|
|
658
|
+
if rangeStart <= rangeEnd {
|
|
659
|
+
for blockNumber in rangeStart to rangeEnd {
|
|
660
|
+
if (blockNumber - handlerStartBlock)->Pervasives.mod(onBlockConfig.interval) === 0 {
|
|
661
|
+
newQueue->Array.push(
|
|
662
|
+
Block({onBlockConfig, blockNumber, logIndex: blockItemLogIndex}),
|
|
663
|
+
)
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
| None => ()
|
|
672
|
+
}
|
|
673
|
+
|
|
626
674
|
fetchState->updateInternal(
|
|
627
675
|
~partitions,
|
|
628
676
|
~currentBlockHeight,
|
|
629
|
-
~queue=
|
|
630
|
-
->Array.concat(newItems)
|
|
677
|
+
~queue=newQueue
|
|
631
678
|
// Theoretically it could be faster to asume that
|
|
632
679
|
// the items are sorted, but there are cases
|
|
633
680
|
// when the data source returns them unsorted
|
|
@@ -807,7 +854,7 @@ let getNextQuery = (
|
|
|
807
854
|
currentBlockHeight
|
|
808
855
|
} else {
|
|
809
856
|
switch queue->Array.get(targetBlockIdx) {
|
|
810
|
-
| Some(item) => Pervasives.min(item.
|
|
857
|
+
| Some(item) => Pervasives.min(item->Internal.getItemBlockNumber, currentBlockHeight) // Just in case check that we don't query beyond the current block
|
|
811
858
|
| None => currentBlockHeight
|
|
812
859
|
}
|
|
813
860
|
}
|
|
@@ -881,7 +928,7 @@ let getNextQuery = (
|
|
|
881
928
|
}
|
|
882
929
|
}
|
|
883
930
|
|
|
884
|
-
type itemWithPopFn = {item: Internal.
|
|
931
|
+
type itemWithPopFn = {item: Internal.item, popItemOffQueue: unit => unit}
|
|
885
932
|
|
|
886
933
|
/**
|
|
887
934
|
Represents a fetchState partitions head of the fetchedEventQueue as either
|
|
@@ -891,13 +938,6 @@ type queueItem =
|
|
|
891
938
|
| Item(itemWithPopFn)
|
|
892
939
|
| NoItem({latestFetchedBlock: blockNumberAndTimestamp})
|
|
893
940
|
|
|
894
|
-
let queueItemBlockNumber = (queueItem: queueItem) => {
|
|
895
|
-
switch queueItem {
|
|
896
|
-
| Item({item}) => item.blockNumber
|
|
897
|
-
| NoItem({latestFetchedBlock: {blockNumber}}) => blockNumber === 0 ? 0 : blockNumber + 1
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
|
|
901
941
|
/**
|
|
902
942
|
Simple constructor for no item from partition
|
|
903
943
|
*/
|
|
@@ -905,30 +945,6 @@ let makeNoItem = ({latestFetchedBlock}: partition) => NoItem({
|
|
|
905
945
|
latestFetchedBlock: latestFetchedBlock,
|
|
906
946
|
})
|
|
907
947
|
|
|
908
|
-
/**
|
|
909
|
-
Creates a compareable value for items and no items on partition queues.
|
|
910
|
-
Block number takes priority here. Since a latest fetched timestamp could
|
|
911
|
-
be zero from initialization of partition but a higher latest fetched block number exists
|
|
912
|
-
|
|
913
|
-
Note: on the chain manager, when comparing multi chain, the timestamp is the highest priority compare value
|
|
914
|
-
*/
|
|
915
|
-
let qItemLt = (a, b) => {
|
|
916
|
-
let aBlockNumber = a->queueItemBlockNumber
|
|
917
|
-
let bBlockNumber = b->queueItemBlockNumber
|
|
918
|
-
if aBlockNumber < bBlockNumber {
|
|
919
|
-
true
|
|
920
|
-
} else if aBlockNumber === bBlockNumber {
|
|
921
|
-
switch (a, b) {
|
|
922
|
-
| (Item(a), Item(b)) => a.item.logIndex < b.item.logIndex
|
|
923
|
-
| (NoItem(_), Item(_)) => true
|
|
924
|
-
| (Item(_), NoItem(_))
|
|
925
|
-
| (NoItem(_), NoItem(_)) => false
|
|
926
|
-
}
|
|
927
|
-
} else {
|
|
928
|
-
false
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
|
|
932
948
|
/**
|
|
933
949
|
Gets the earliest queueItem from thgetNodeEarliestEventWithUpdatedQueue.
|
|
934
950
|
|
|
@@ -938,7 +954,7 @@ queue item with an update fetch state.
|
|
|
938
954
|
let getEarliestEvent = ({queue, latestFullyFetchedBlock}: t) => {
|
|
939
955
|
switch queue->Utils.Array.last {
|
|
940
956
|
| Some(item) =>
|
|
941
|
-
if item.
|
|
957
|
+
if item->Internal.getItemBlockNumber <= latestFullyFetchedBlock.blockNumber {
|
|
942
958
|
Item({item, popItemOffQueue: () => queue->Js.Array2.pop->ignore})
|
|
943
959
|
} else {
|
|
944
960
|
NoItem({
|
|
@@ -962,11 +978,13 @@ let make = (
|
|
|
962
978
|
~contracts: array<indexingContract>,
|
|
963
979
|
~maxAddrInPartition,
|
|
964
980
|
~chainId,
|
|
981
|
+
~progressBlockNumber=startBlock - 1,
|
|
982
|
+
~onBlockConfigs=?,
|
|
965
983
|
~blockLag=0,
|
|
966
984
|
): t => {
|
|
967
985
|
let latestFetchedBlock = {
|
|
968
986
|
blockTimestamp: 0,
|
|
969
|
-
blockNumber:
|
|
987
|
+
blockNumber: progressBlockNumber,
|
|
970
988
|
}
|
|
971
989
|
|
|
972
990
|
let notDependingOnAddresses = []
|
|
@@ -1080,13 +1098,14 @@ let make = (
|
|
|
1080
1098
|
isFetchingAtHead: false,
|
|
1081
1099
|
maxAddrInPartition,
|
|
1082
1100
|
chainId,
|
|
1101
|
+
startBlock,
|
|
1083
1102
|
endBlock,
|
|
1084
1103
|
latestFullyFetchedBlock: latestFetchedBlock,
|
|
1085
|
-
firstEventBlockNumber: None,
|
|
1086
1104
|
normalSelection,
|
|
1087
1105
|
indexingContracts,
|
|
1088
1106
|
dcsToStore: None,
|
|
1089
1107
|
blockLag,
|
|
1108
|
+
onBlockConfigs,
|
|
1090
1109
|
queue: [],
|
|
1091
1110
|
}
|
|
1092
1111
|
}
|
|
@@ -1099,11 +1118,15 @@ let bufferSize = ({queue}: t) => queue->Array.length
|
|
|
1099
1118
|
let getLatestFullyFetchedBlock = ({latestFullyFetchedBlock}: t) => latestFullyFetchedBlock
|
|
1100
1119
|
|
|
1101
1120
|
let pruneQueueFromFirstChangeEvent = (
|
|
1102
|
-
queue: array<Internal.
|
|
1121
|
+
queue: array<Internal.item>,
|
|
1103
1122
|
~firstChangeEvent: blockNumberAndLogIndex,
|
|
1104
1123
|
) => {
|
|
1105
1124
|
queue->Array.keep(item =>
|
|
1106
|
-
|
|
1125
|
+
switch item {
|
|
1126
|
+
| Event({blockNumber, logIndex})
|
|
1127
|
+
| Block({blockNumber, logIndex}) => (blockNumber, logIndex)
|
|
1128
|
+
} <
|
|
1129
|
+
(firstChangeEvent.blockNumber, firstChangeEvent.logIndex)
|
|
1107
1130
|
)
|
|
1108
1131
|
}
|
|
1109
1132
|
|
|
@@ -1235,7 +1258,7 @@ let isReadyToEnterReorgThreshold = (
|
|
|
1235
1258
|
let filterAndSortForUnorderedBatch = {
|
|
1236
1259
|
let hasBatchItem = ({queue, latestFullyFetchedBlock}: t) => {
|
|
1237
1260
|
switch queue->Utils.Array.last {
|
|
1238
|
-
| Some(item) => item.
|
|
1261
|
+
| Some(item) => item->Internal.getItemBlockNumber <= latestFullyFetchedBlock.blockNumber
|
|
1239
1262
|
| None => false
|
|
1240
1263
|
}
|
|
1241
1264
|
}
|
|
@@ -1251,8 +1274,8 @@ let filterAndSortForUnorderedBatch = {
|
|
|
1251
1274
|
} else {
|
|
1252
1275
|
// Unsafe can fail when maxBatchSize is 0,
|
|
1253
1276
|
// but we ignore the case
|
|
1254
|
-
|
|
1255
|
-
|
|
1277
|
+
queue->Js.Array2.unsafe_get(targetBlockIdx)->Internal.getItemBlockNumber <=
|
|
1278
|
+
latestFullyFetchedBlock.blockNumber
|
|
1256
1279
|
}
|
|
1257
1280
|
}
|
|
1258
1281
|
|
|
@@ -1264,7 +1287,15 @@ let filterAndSortForUnorderedBatch = {
|
|
|
1264
1287
|
| (true, true)
|
|
1265
1288
|
| (false, false) =>
|
|
1266
1289
|
// Use unsafe since we filtered out all queues without batch items
|
|
1267
|
-
(a.queue->Utils.Array.lastUnsafe
|
|
1290
|
+
switch (a.queue->Utils.Array.lastUnsafe, b.queue->Utils.Array.lastUnsafe) {
|
|
1291
|
+
| (Event({timestamp: aTimestamp}), Event({timestamp: bTimestamp})) =>
|
|
1292
|
+
aTimestamp - bTimestamp
|
|
1293
|
+
| (Block(_), _)
|
|
1294
|
+
| (_, Block(_)) =>
|
|
1295
|
+
// Currently block items don't have a timestamp,
|
|
1296
|
+
// so we sort chains with them in a random order
|
|
1297
|
+
Js.Math.random_int(-1, 1)
|
|
1298
|
+
}
|
|
1268
1299
|
| (true, false) => -1
|
|
1269
1300
|
| (false, true) => 1
|
|
1270
1301
|
}
|
|
@@ -1274,15 +1305,17 @@ let filterAndSortForUnorderedBatch = {
|
|
|
1274
1305
|
|
|
1275
1306
|
let getProgressBlockNumber = ({latestFullyFetchedBlock, queue}: t) => {
|
|
1276
1307
|
switch queue->Utils.Array.last {
|
|
1277
|
-
| Some(item) if latestFullyFetchedBlock.blockNumber >= item.
|
|
1308
|
+
| Some(item) if latestFullyFetchedBlock.blockNumber >= item->Internal.getItemBlockNumber =>
|
|
1309
|
+
item->Internal.getItemBlockNumber - 1
|
|
1278
1310
|
| _ => latestFullyFetchedBlock.blockNumber
|
|
1279
1311
|
}
|
|
1280
1312
|
}
|
|
1281
1313
|
|
|
1282
1314
|
let getProgressNextBlockLogIndex = ({queue, latestFullyFetchedBlock}: t) => {
|
|
1283
1315
|
switch queue->Utils.Array.last {
|
|
1284
|
-
| Some(
|
|
1285
|
-
|
|
1316
|
+
| Some(Event({logIndex, blockNumber}))
|
|
1317
|
+
if latestFullyFetchedBlock.blockNumber >= blockNumber && logIndex > 0 =>
|
|
1318
|
+
Some(logIndex - 1)
|
|
1286
1319
|
| _ => None
|
|
1287
1320
|
}
|
|
1288
1321
|
}
|