envio 3.0.0-alpha.2 → 3.0.0-alpha.4
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/README.md +2 -2
- package/evm.schema.json +44 -34
- package/fuel.schema.json +32 -21
- package/index.d.ts +4 -1
- package/index.js +1 -0
- package/package.json +7 -6
- package/src/Batch.res.mjs +1 -1
- package/src/Benchmark.res +394 -0
- package/src/Benchmark.res.mjs +398 -0
- package/src/ChainFetcher.res +459 -0
- package/src/ChainFetcher.res.mjs +281 -0
- package/src/ChainManager.res +179 -0
- package/src/ChainManager.res.mjs +139 -0
- package/src/Config.res +15 -1
- package/src/Config.res.mjs +28 -5
- package/src/Ecosystem.res +9 -124
- package/src/Ecosystem.res.mjs +19 -160
- package/src/Env.res +0 -1
- package/src/Env.res.mjs +0 -3
- package/src/Envio.gen.ts +9 -1
- package/src/Envio.res +12 -9
- package/src/EventProcessing.res +476 -0
- package/src/EventProcessing.res.mjs +341 -0
- package/src/FetchState.res +54 -29
- package/src/FetchState.res.mjs +62 -35
- package/src/GlobalState.res +1169 -0
- package/src/GlobalState.res.mjs +1196 -0
- package/src/Internal.res +43 -1
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/Prometheus.res +8 -8
- package/src/Prometheus.res.mjs +10 -10
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/Types.ts +1 -1
- package/src/UserContext.res +356 -0
- package/src/UserContext.res.mjs +238 -0
- package/src/Utils.res +15 -0
- package/src/Utils.res.mjs +18 -0
- package/src/bindings/ClickHouse.res +31 -1
- package/src/bindings/ClickHouse.res.mjs +27 -1
- package/src/bindings/DateFns.res +71 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/Ethers.res +27 -63
- package/src/bindings/Ethers.res.mjs +18 -65
- package/src/sources/Evm.res +87 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +95 -0
- package/src/sources/EvmChain.res.mjs +61 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +37 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +8 -8
- package/src/sources/HyperFuelSource.res.mjs +5 -5
- package/src/sources/HyperSyncHeightStream.res +28 -110
- package/src/sources/HyperSyncHeightStream.res.mjs +30 -63
- package/src/sources/HyperSyncSource.res +16 -18
- package/src/sources/HyperSyncSource.res.mjs +25 -25
- package/src/sources/Rpc.res +43 -0
- package/src/sources/Rpc.res.mjs +31 -0
- package/src/sources/RpcSource.res +13 -8
- package/src/sources/RpcSource.res.mjs +12 -7
- package/src/sources/Source.res +3 -2
- package/src/sources/SourceManager.res +183 -108
- package/src/sources/SourceManager.res.mjs +162 -99
- package/src/sources/SourceManager.resi +4 -5
- package/src/sources/Svm.res +59 -0
- package/src/sources/Svm.res.mjs +79 -0
- package/src/bindings/Ethers.gen.ts +0 -14
package/src/FetchState.res.mjs
CHANGED
|
@@ -121,28 +121,37 @@ function compareBufferItem(a, b) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexingContractsOpt, mutItems, blockLagOpt) {
|
|
124
|
+
function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexingContractsOpt, mutItems, blockLagOpt, knownHeightOpt) {
|
|
125
125
|
var partitions = partitionsOpt !== undefined ? partitionsOpt : fetchState.partitions;
|
|
126
126
|
var nextPartitionIndex = nextPartitionIndexOpt !== undefined ? nextPartitionIndexOpt : fetchState.nextPartitionIndex;
|
|
127
127
|
var indexingContracts = indexingContractsOpt !== undefined ? indexingContractsOpt : fetchState.indexingContracts;
|
|
128
128
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
|
|
129
|
-
var
|
|
130
|
-
var latestFullyFetchedBlock
|
|
131
|
-
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
var knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : fetchState.knownHeight;
|
|
130
|
+
var latestFullyFetchedBlock;
|
|
131
|
+
if (Utils.$$Array.notEmpty(partitions)) {
|
|
132
|
+
var firstPartition = partitions[0];
|
|
133
|
+
var latestFullyFetchedBlock$1 = firstPartition.latestFetchedBlock;
|
|
134
|
+
for(var idx = 0 ,idx_finish = partitions.length; idx < idx_finish; ++idx){
|
|
135
|
+
var p = partitions[idx];
|
|
136
|
+
if (latestFullyFetchedBlock$1.blockNumber > p.latestFetchedBlock.blockNumber) {
|
|
137
|
+
latestFullyFetchedBlock$1 = p.latestFetchedBlock;
|
|
138
|
+
}
|
|
139
|
+
|
|
135
140
|
}
|
|
136
|
-
|
|
141
|
+
latestFullyFetchedBlock = latestFullyFetchedBlock$1;
|
|
142
|
+
} else {
|
|
143
|
+
latestFullyFetchedBlock = {
|
|
144
|
+
blockNumber: knownHeight,
|
|
145
|
+
blockTimestamp: 0
|
|
146
|
+
};
|
|
137
147
|
}
|
|
138
|
-
var latestFullyFetchedBlock$1 = latestFullyFetchedBlock;
|
|
139
148
|
var mutItemsRef = mutItems;
|
|
140
149
|
var onBlockConfigs = fetchState.onBlockConfigs;
|
|
141
150
|
var latestOnBlockBlockNumber;
|
|
142
151
|
if (onBlockConfigs.length !== 0) {
|
|
143
152
|
var mutItems$1 = mutItemsRef;
|
|
144
153
|
var item = Belt_Array.get(mutItems$1 !== undefined ? mutItems$1 : fetchState.buffer, fetchState.targetBufferSize - 1 | 0);
|
|
145
|
-
var maxBlockNumber = item !== undefined ? item.blockNumber : latestFullyFetchedBlock
|
|
154
|
+
var maxBlockNumber = item !== undefined ? item.blockNumber : latestFullyFetchedBlock.blockNumber;
|
|
146
155
|
var mutItems$2 = mutItemsRef;
|
|
147
156
|
var mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.buffer.slice(0);
|
|
148
157
|
mutItemsRef = mutItems$3;
|
|
@@ -174,7 +183,7 @@ function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexi
|
|
|
174
183
|
};
|
|
175
184
|
latestOnBlockBlockNumber = latestOnBlockBlockNumber$1;
|
|
176
185
|
} else {
|
|
177
|
-
latestOnBlockBlockNumber = latestFullyFetchedBlock
|
|
186
|
+
latestOnBlockBlockNumber = latestFullyFetchedBlock.blockNumber;
|
|
178
187
|
}
|
|
179
188
|
var mutItems$4 = mutItemsRef;
|
|
180
189
|
var updatedFetchState_startBlock = fetchState.startBlock;
|
|
@@ -196,16 +205,17 @@ function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexi
|
|
|
196
205
|
indexingContracts: indexingContracts,
|
|
197
206
|
contractConfigs: updatedFetchState_contractConfigs,
|
|
198
207
|
chainId: updatedFetchState_chainId,
|
|
199
|
-
latestFullyFetchedBlock: latestFullyFetchedBlock
|
|
208
|
+
latestFullyFetchedBlock: latestFullyFetchedBlock,
|
|
200
209
|
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
201
210
|
blockLag: blockLag,
|
|
202
211
|
buffer: updatedFetchState_buffer,
|
|
203
212
|
targetBufferSize: updatedFetchState_targetBufferSize,
|
|
204
|
-
onBlockConfigs: updatedFetchState_onBlockConfigs
|
|
213
|
+
onBlockConfigs: updatedFetchState_onBlockConfigs,
|
|
214
|
+
knownHeight: knownHeight
|
|
205
215
|
};
|
|
206
216
|
Prometheus.IndexingPartitions.set(partitions.length, fetchState.chainId);
|
|
207
217
|
Prometheus.IndexingBufferSize.set(updatedFetchState_buffer.length, fetchState.chainId);
|
|
208
|
-
Prometheus.IndexingBufferBlockNumber.set(latestOnBlockBlockNumber < latestFullyFetchedBlock
|
|
218
|
+
Prometheus.IndexingBufferBlockNumber.set(latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber, fetchState.chainId);
|
|
209
219
|
return updatedFetchState;
|
|
210
220
|
}
|
|
211
221
|
|
|
@@ -389,7 +399,7 @@ function registerDynamicContracts(fetchState, items) {
|
|
|
389
399
|
newPartitions = partitions;
|
|
390
400
|
}
|
|
391
401
|
Prometheus.IndexingAddresses.set(Object.keys(fetchState.indexingContracts).length + dcsToStore.length | 0, fetchState.chainId);
|
|
392
|
-
return updateInternal(fetchState, fetchState.partitions.concat(newPartitions), fetchState.nextPartitionIndex + newPartitions.length | 0, Object.assign(registeringContracts, indexingContracts), undefined, undefined);
|
|
402
|
+
return updateInternal(fetchState, fetchState.partitions.concat(newPartitions), fetchState.nextPartitionIndex + newPartitions.length | 0, Object.assign(registeringContracts, indexingContracts), undefined, undefined, undefined);
|
|
393
403
|
}
|
|
394
404
|
|
|
395
405
|
var UnexpectedPartitionNotFound = /* @__PURE__ */Caml_exceptions.create("FetchState.UnexpectedPartitionNotFound");
|
|
@@ -466,7 +476,7 @@ function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
|
466
476
|
};
|
|
467
477
|
}
|
|
468
478
|
return Belt_Result.map(tmp, (function (partitions) {
|
|
469
|
-
return updateInternal(fetchState, partitions, undefined, undefined, newItems.length !== 0 ? Belt_Array.concat(fetchState.buffer, newItems) : undefined, undefined);
|
|
479
|
+
return updateInternal(fetchState, partitions, undefined, undefined, newItems.length !== 0 ? Belt_Array.concat(fetchState.buffer, newItems) : undefined, undefined, undefined);
|
|
470
480
|
}));
|
|
471
481
|
}
|
|
472
482
|
|
|
@@ -553,14 +563,15 @@ function isFullPartition(p, maxAddrInPartition) {
|
|
|
553
563
|
}
|
|
554
564
|
}
|
|
555
565
|
|
|
556
|
-
function getNextQuery(param, concurrencyLimit,
|
|
566
|
+
function getNextQuery(param, concurrencyLimit, stateId) {
|
|
567
|
+
var knownHeight = param.knownHeight;
|
|
557
568
|
var blockLag = param.blockLag;
|
|
558
569
|
var indexingContracts = param.indexingContracts;
|
|
559
570
|
var maxAddrInPartition = param.maxAddrInPartition;
|
|
560
571
|
var endBlock = param.endBlock;
|
|
561
572
|
var partitions = param.partitions;
|
|
562
|
-
var
|
|
563
|
-
if (
|
|
573
|
+
var headBlockNumber = knownHeight - blockLag | 0;
|
|
574
|
+
if (headBlockNumber <= 0) {
|
|
564
575
|
return "WaitingForNewBlock";
|
|
565
576
|
}
|
|
566
577
|
if (concurrencyLimit === 0) {
|
|
@@ -571,7 +582,10 @@ function getNextQuery(param, concurrencyLimit, currentBlockHeight, stateId) {
|
|
|
571
582
|
var areMergingPartitionsFetching = false;
|
|
572
583
|
var mostBehindMergingPartition;
|
|
573
584
|
var mergingPartitionTarget;
|
|
574
|
-
var
|
|
585
|
+
var isOnBlockBehindTheHead = param.latestOnBlockBlockNumber < headBlockNumber;
|
|
586
|
+
var shouldWaitForNewBlock = (
|
|
587
|
+
endBlock !== undefined ? headBlockNumber < endBlock : true
|
|
588
|
+
) && !isOnBlockBehindTheHead;
|
|
575
589
|
var checkIsFetchingPartition = function (p) {
|
|
576
590
|
var fetchingStateId = p.status.fetchingStateId;
|
|
577
591
|
if (fetchingStateId !== undefined) {
|
|
@@ -583,8 +597,8 @@ function getNextQuery(param, concurrencyLimit, currentBlockHeight, stateId) {
|
|
|
583
597
|
for(var idx = 0 ,idx_finish = partitions.length; idx < idx_finish; ++idx){
|
|
584
598
|
var p = partitions[idx];
|
|
585
599
|
var isFetching = checkIsFetchingPartition(p);
|
|
586
|
-
var
|
|
587
|
-
if (isFetching ||
|
|
600
|
+
var isBehindTheHead = p.latestFetchedBlock.blockNumber < headBlockNumber;
|
|
601
|
+
if (isFetching || isBehindTheHead) {
|
|
588
602
|
shouldWaitForNewBlock = false;
|
|
589
603
|
}
|
|
590
604
|
if (p.selection.dependsOnAddresses ? addressesByContractNameCount(p.addressesByContractName) >= maxAddrInPartition : true) {
|
|
@@ -615,7 +629,7 @@ function getNextQuery(param, concurrencyLimit, currentBlockHeight, stateId) {
|
|
|
615
629
|
}
|
|
616
630
|
}
|
|
617
631
|
var item = Belt_Array.get(param.buffer, param.targetBufferSize - 1 | 0);
|
|
618
|
-
var maxQueryBlockNumber = item !== undefined && item.blockNumber <
|
|
632
|
+
var maxQueryBlockNumber = item !== undefined && item.blockNumber < knownHeight ? item.blockNumber : knownHeight;
|
|
619
633
|
var queries = [];
|
|
620
634
|
var registerPartitionQuery = function (p, mergeTarget) {
|
|
621
635
|
if (!(!checkIsFetchingPartition(p) && p.latestFetchedBlock.blockNumber < maxQueryBlockNumber)) {
|
|
@@ -623,10 +637,10 @@ function getNextQuery(param, concurrencyLimit, currentBlockHeight, stateId) {
|
|
|
623
637
|
}
|
|
624
638
|
var endBlock$1 = blockLag !== 0 ? (
|
|
625
639
|
endBlock !== undefined ? (
|
|
626
|
-
|
|
627
|
-
) :
|
|
640
|
+
headBlockNumber < endBlock ? headBlockNumber : endBlock
|
|
641
|
+
) : headBlockNumber
|
|
628
642
|
) : endBlock;
|
|
629
|
-
var match = maxQueryBlockNumber <
|
|
643
|
+
var match = maxQueryBlockNumber < knownHeight;
|
|
630
644
|
var endBlock$2 = endBlock$1 !== undefined ? (
|
|
631
645
|
match ? (
|
|
632
646
|
maxQueryBlockNumber < endBlock$1 ? maxQueryBlockNumber : endBlock$1
|
|
@@ -739,7 +753,7 @@ function getReadyItemsCount(fetchState, targetSize, fromItem) {
|
|
|
739
753
|
return acc;
|
|
740
754
|
}
|
|
741
755
|
|
|
742
|
-
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, targetBufferSize, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt) {
|
|
756
|
+
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, targetBufferSize, knownHeight, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt) {
|
|
743
757
|
var progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
744
758
|
var onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
|
|
745
759
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
@@ -824,8 +838,8 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
824
838
|
}
|
|
825
839
|
|
|
826
840
|
}
|
|
827
|
-
if (partitions
|
|
828
|
-
Js_exn.raiseError("Invalid configuration: Nothing to fetch. Make sure that you provided at least one contract address to index, or have events with Wildcard mode enabled.");
|
|
841
|
+
if (Utils.$$Array.isEmpty(partitions) && Utils.$$Array.isEmpty(onBlockConfigs)) {
|
|
842
|
+
Js_exn.raiseError("Invalid configuration: Nothing to fetch. Make sure that you provided at least one contract address to index, or have events with Wildcard mode enabled, or have onBlock handlers.");
|
|
829
843
|
}
|
|
830
844
|
var numAddresses = Object.keys(indexingContracts).length;
|
|
831
845
|
Prometheus.IndexingAddresses.set(numAddresses, chainId);
|
|
@@ -850,7 +864,8 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
850
864
|
blockLag: blockLag,
|
|
851
865
|
buffer: [],
|
|
852
866
|
targetBufferSize: targetBufferSize,
|
|
853
|
-
onBlockConfigs: onBlockConfigs
|
|
867
|
+
onBlockConfigs: onBlockConfigs,
|
|
868
|
+
knownHeight: knownHeight
|
|
854
869
|
};
|
|
855
870
|
}
|
|
856
871
|
|
|
@@ -931,12 +946,13 @@ function rollback(fetchState, targetBlockNumber) {
|
|
|
931
946
|
blockLag: fetchState.blockLag,
|
|
932
947
|
buffer: fetchState.buffer,
|
|
933
948
|
targetBufferSize: fetchState.targetBufferSize,
|
|
934
|
-
onBlockConfigs: fetchState.onBlockConfigs
|
|
949
|
+
onBlockConfigs: fetchState.onBlockConfigs,
|
|
950
|
+
knownHeight: fetchState.knownHeight
|
|
935
951
|
}, partitions, undefined, indexingContracts, Belt_Array.keep(fetchState.buffer, (function (item) {
|
|
936
952
|
var tmp;
|
|
937
953
|
tmp = item.kind === 0 ? item.blockNumber : item.blockNumber;
|
|
938
954
|
return tmp <= targetBlockNumber;
|
|
939
|
-
})), undefined);
|
|
955
|
+
})), undefined, undefined);
|
|
940
956
|
}
|
|
941
957
|
|
|
942
958
|
function isActivelyIndexing(fetchState) {
|
|
@@ -956,14 +972,15 @@ function isActivelyIndexing(fetchState) {
|
|
|
956
972
|
}
|
|
957
973
|
}
|
|
958
974
|
|
|
959
|
-
function isReadyToEnterReorgThreshold(fetchState
|
|
975
|
+
function isReadyToEnterReorgThreshold(fetchState) {
|
|
976
|
+
var knownHeight = fetchState.knownHeight;
|
|
960
977
|
var blockLag = fetchState.blockLag;
|
|
961
978
|
var endBlock = fetchState.endBlock;
|
|
962
979
|
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
963
980
|
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
964
981
|
var bufferBlockNumber = latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber;
|
|
965
|
-
if (
|
|
966
|
-
endBlock !== undefined && bufferBlockNumber >= endBlock ? true : bufferBlockNumber >= (
|
|
982
|
+
if (knownHeight !== 0 && (
|
|
983
|
+
endBlock !== undefined && bufferBlockNumber >= endBlock ? true : bufferBlockNumber >= (knownHeight - blockLag | 0)
|
|
967
984
|
)) {
|
|
968
985
|
return Utils.$$Array.isEmpty(fetchState.buffer);
|
|
969
986
|
} else {
|
|
@@ -1045,6 +1062,15 @@ function getUnorderedMultichainProgressBlockNumberAt(fetchState, index) {
|
|
|
1045
1062
|
}
|
|
1046
1063
|
}
|
|
1047
1064
|
|
|
1065
|
+
function updateKnownHeight(fetchState, knownHeight) {
|
|
1066
|
+
if (knownHeight > fetchState.knownHeight) {
|
|
1067
|
+
Prometheus.setKnownHeight(knownHeight, fetchState.chainId);
|
|
1068
|
+
return updateInternal(fetchState, undefined, undefined, undefined, undefined, undefined, knownHeight);
|
|
1069
|
+
} else {
|
|
1070
|
+
return fetchState;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1048
1074
|
var blockItemLogIndex = 16777216;
|
|
1049
1075
|
|
|
1050
1076
|
export {
|
|
@@ -1077,5 +1103,6 @@ export {
|
|
|
1077
1103
|
isReadyToEnterReorgThreshold ,
|
|
1078
1104
|
sortForUnorderedBatch ,
|
|
1079
1105
|
getUnorderedMultichainProgressBlockNumberAt ,
|
|
1106
|
+
updateKnownHeight ,
|
|
1080
1107
|
}
|
|
1081
1108
|
/* Utils Not a pure module */
|