envio 3.3.0-alpha.1 → 3.3.0-alpha.3
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 +23 -21
- package/package.json +6 -6
- package/src/Batch.res +0 -6
- package/src/Batch.res.mjs +0 -11
- package/src/BatchProcessing.res +2 -12
- package/src/BatchProcessing.res.mjs +2 -7
- package/src/ChainFetching.res +42 -6
- package/src/ChainFetching.res.mjs +30 -11
- package/src/ChainMetadata.res +1 -11
- package/src/ChainMetadata.res.mjs +1 -10
- package/src/ChainState.res +150 -1
- package/src/ChainState.res.mjs +138 -9
- package/src/ChainState.resi +51 -1
- package/src/Config.res +3 -6
- package/src/Config.res.mjs +2 -3
- package/src/Core.res +7 -0
- package/src/CrossChainState.res +24 -26
- package/src/CrossChainState.res.mjs +19 -16
- package/src/Ecosystem.res +6 -3
- package/src/Envio.res +3 -2
- package/src/EventConfigBuilder.res +61 -23
- package/src/EventConfigBuilder.res.mjs +27 -13
- package/src/EventProcessing.res +63 -21
- package/src/EventProcessing.res.mjs +47 -22
- package/src/FetchState.res +53 -43
- package/src/FetchState.res.mjs +71 -54
- package/src/HandlerLoader.res +10 -1
- package/src/HandlerLoader.res.mjs +15 -8
- package/src/Internal.res +46 -7
- package/src/Internal.res.mjs +19 -1
- package/src/LoadLayer.res +5 -5
- package/src/LoadLayer.res.mjs +6 -6
- package/src/Main.res +3 -50
- package/src/Main.res.mjs +2 -23
- package/src/PgStorage.res +4 -4
- package/src/PgStorage.res.mjs +5 -5
- package/src/Prometheus.res +10 -10
- package/src/Prometheus.res.mjs +9 -9
- package/src/PruneStaleHistory.res +2 -2
- package/src/PruneStaleHistory.res.mjs +3 -3
- package/src/Rollback.res +3 -3
- package/src/Rollback.res.mjs +4 -4
- package/src/SimulateItems.res +80 -15
- package/src/SimulateItems.res.mjs +65 -21
- package/src/TestIndexer.res +48 -36
- package/src/TestIndexer.res.mjs +35 -28
- package/src/bindings/Performance.res +7 -0
- package/src/bindings/Performance.res.mjs +21 -0
- package/src/bindings/Performance.resi +7 -0
- package/src/sources/EventRouter.res +17 -21
- package/src/sources/EventRouter.res.mjs +6 -9
- package/src/sources/Evm.res +47 -67
- package/src/sources/Evm.res.mjs +42 -65
- package/src/sources/Fuel.res +3 -3
- package/src/sources/Fuel.res.mjs +1 -6
- package/src/sources/HyperFuelSource.res +15 -11
- package/src/sources/HyperFuelSource.res.mjs +13 -11
- package/src/sources/HyperSync.res +7 -1
- package/src/sources/HyperSync.res.mjs +6 -3
- package/src/sources/HyperSync.resi +2 -0
- package/src/sources/HyperSyncClient.res +14 -79
- package/src/sources/HyperSyncClient.res.mjs +1 -22
- package/src/sources/HyperSyncSource.res +44 -27
- package/src/sources/HyperSyncSource.res.mjs +32 -27
- package/src/sources/RpcSource.res +14 -10
- package/src/sources/RpcSource.res.mjs +11 -9
- package/src/sources/SimulateSource.res +4 -2
- package/src/sources/SimulateSource.res.mjs +1 -0
- package/src/sources/Source.res +5 -1
- package/src/sources/SourceManager.res +17 -16
- package/src/sources/SourceManager.res.mjs +10 -15
- package/src/sources/Svm.res +23 -6
- package/src/sources/Svm.res.mjs +24 -6
- package/src/sources/SvmHyperSyncClient.res +3 -29
- package/src/sources/SvmHyperSyncSource.res +78 -96
- package/src/sources/SvmHyperSyncSource.res.mjs +79 -91
- package/src/sources/TransactionStore.res +128 -0
- package/src/sources/TransactionStore.res.mjs +97 -0
- package/src/tui/Tui.res +13 -16
- package/src/tui/Tui.res.mjs +12 -14
- package/svm.schema.json +30 -37
- package/src/bindings/Hrtime.res +0 -58
- package/src/bindings/Hrtime.res.mjs +0 -90
- package/src/bindings/Hrtime.resi +0 -30
|
@@ -36,11 +36,15 @@ let getSelectionConfig = (selection: FetchState.selection, ~chain) => {
|
|
|
36
36
|
)
|
|
37
37
|
selectedTransactionFields
|
|
38
38
|
->Utils.Set.toArray
|
|
39
|
-
->Array.forEach(name =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
->Array.forEach(name => {
|
|
40
|
+
// transactionIndex is read off the log (the store key), so it never needs
|
|
41
|
+
// to be requested as a transaction column — and requesting it alone would
|
|
42
|
+
// pull the whole transaction table for nothing.
|
|
43
|
+
let fieldName = (name :> string)
|
|
44
|
+
if fieldName != "transactionIndex" {
|
|
45
|
+
capitalizedTransactionFields->Utils.Set.add(fieldName->Utils.String.capitalize)->ignore
|
|
46
|
+
}
|
|
47
|
+
})
|
|
44
48
|
|
|
45
49
|
let eventFilters = getEventFiltersOrThrow(chain)
|
|
46
50
|
if dependsOnAddresses {
|
|
@@ -193,27 +197,26 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
193
197
|
|
|
194
198
|
let makeEventBatchQueueItem = (
|
|
195
199
|
item: HyperSyncClient.EventItems.item,
|
|
200
|
+
~block: HyperSyncClient.ResponseTypes.block,
|
|
196
201
|
~params: Internal.eventParams,
|
|
197
202
|
~eventConfig: Internal.evmEventConfig,
|
|
198
203
|
): Internal.item => {
|
|
199
|
-
let {
|
|
204
|
+
let {transactionIndex, logIndex, srcAddress} = item
|
|
200
205
|
let chainId = chain->ChainMap.Chain.toChainId
|
|
201
206
|
|
|
202
207
|
Internal.Event({
|
|
203
208
|
eventConfig: (eventConfig :> Internal.eventConfig),
|
|
204
209
|
timestamp: block.timestamp->Option.getUnsafe,
|
|
205
210
|
chain,
|
|
206
|
-
blockNumber:
|
|
211
|
+
blockNumber: item.blockNumber,
|
|
207
212
|
blockHash: block.hash->Option.getUnsafe,
|
|
208
213
|
logIndex,
|
|
214
|
+
transactionIndex,
|
|
209
215
|
payload: {
|
|
210
216
|
contractName: eventConfig.contractName,
|
|
211
217
|
eventName: eventConfig.name,
|
|
212
218
|
chainId,
|
|
213
219
|
params,
|
|
214
|
-
transaction: transaction->(
|
|
215
|
-
Utils.magic: HyperSyncClient.ResponseTypes.transaction => Internal.eventTransaction
|
|
216
|
-
),
|
|
217
220
|
block: block->(Utils.magic: HyperSyncClient.ResponseTypes.block => Internal.eventBlock),
|
|
218
221
|
srcAddress,
|
|
219
222
|
logIndex,
|
|
@@ -225,14 +228,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
225
228
|
~fromBlock,
|
|
226
229
|
~toBlock,
|
|
227
230
|
~addressesByContractName,
|
|
228
|
-
~
|
|
231
|
+
~contractNameByAddress,
|
|
229
232
|
~knownHeight,
|
|
230
233
|
~partitionId as _,
|
|
231
234
|
~selection,
|
|
232
235
|
~retry,
|
|
233
236
|
~logger,
|
|
234
237
|
) => {
|
|
235
|
-
let totalTimeRef =
|
|
238
|
+
let totalTimeRef = Performance.now()
|
|
236
239
|
|
|
237
240
|
let selectionConfig = selection->getSelectionConfig
|
|
238
241
|
|
|
@@ -241,7 +244,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
241
244
|
exn->ErrorHandling.mkLogAndRaise(~logger, ~msg="Failed getting log selection for the query")
|
|
242
245
|
}
|
|
243
246
|
|
|
244
|
-
let startFetchingBatchTimeRef =
|
|
247
|
+
let startFetchingBatchTimeRef = Performance.now()
|
|
245
248
|
|
|
246
249
|
//fetch batch
|
|
247
250
|
Prometheus.SourceRequestCount.increment(
|
|
@@ -301,7 +304,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
301
304
|
)
|
|
302
305
|
}
|
|
303
306
|
|
|
304
|
-
let pageFetchTime = startFetchingBatchTimeRef->
|
|
307
|
+
let pageFetchTime = startFetchingBatchTimeRef->Performance.secondsSince
|
|
305
308
|
|
|
306
309
|
//set height and next from block
|
|
307
310
|
let knownHeight = pageUnsafe.archiveHeight
|
|
@@ -311,11 +314,21 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
311
314
|
//In the query
|
|
312
315
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1
|
|
313
316
|
|
|
314
|
-
let parsingTimeRef =
|
|
317
|
+
let parsingTimeRef = Performance.now()
|
|
315
318
|
|
|
316
319
|
//Parse page items into queue items
|
|
317
320
|
let parsedQueueItems = []
|
|
318
321
|
|
|
322
|
+
// Blocks are returned once per number; items reference them by blockNumber.
|
|
323
|
+
let blocksByNumber = Utils.Map.make()
|
|
324
|
+
pageUnsafe.blocks->Array.forEach(block => {
|
|
325
|
+
switch block.number {
|
|
326
|
+
| Some(number) => blocksByNumber->Utils.Map.set(number, block)->ignore
|
|
327
|
+
| None => ()
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
let getBlock = blockNumber => blocksByNumber->Utils.Map.unsafeGet(blockNumber)
|
|
331
|
+
|
|
319
332
|
let handleDecodeFailure = (
|
|
320
333
|
~eventConfig: Internal.evmEventConfig,
|
|
321
334
|
~logIndex,
|
|
@@ -349,9 +362,8 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
349
362
|
~sighash=item.topic0->EvmTypes.Hex.toString,
|
|
350
363
|
~topicCount=item.topicCount,
|
|
351
364
|
),
|
|
352
|
-
~
|
|
365
|
+
~contractNameByAddress,
|
|
353
366
|
~contractAddress=item.srcAddress,
|
|
354
|
-
~blockNumber=item.block.number->Option.getUnsafe,
|
|
355
367
|
)
|
|
356
368
|
|
|
357
369
|
switch maybeEventConfig {
|
|
@@ -361,12 +373,16 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
361
373
|
->Nullable.toOption
|
|
362
374
|
->Option.flatMap(Dict.get(_, eventConfig.contractName)) {
|
|
363
375
|
| Some(params) =>
|
|
364
|
-
parsedQueueItems
|
|
376
|
+
parsedQueueItems
|
|
377
|
+
->Array.push(
|
|
378
|
+
makeEventBatchQueueItem(item, ~block=getBlock(item.blockNumber), ~params, ~eventConfig),
|
|
379
|
+
)
|
|
380
|
+
->ignore
|
|
365
381
|
| None =>
|
|
366
382
|
handleDecodeFailure(
|
|
367
383
|
~eventConfig,
|
|
368
384
|
~logIndex=item.logIndex,
|
|
369
|
-
~blockNumber=item.
|
|
385
|
+
~blockNumber=item.blockNumber,
|
|
370
386
|
~chainId,
|
|
371
387
|
~exn=UndefinedValue,
|
|
372
388
|
)
|
|
@@ -374,14 +390,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
374
390
|
}
|
|
375
391
|
})
|
|
376
392
|
|
|
377
|
-
let parsingTimeElapsed = parsingTimeRef->
|
|
393
|
+
let parsingTimeElapsed = parsingTimeRef->Performance.secondsSince
|
|
378
394
|
|
|
379
395
|
// Collect (blockNumber, blockHash) pairs we already have from the response —
|
|
380
|
-
// one per
|
|
396
|
+
// one per returned block plus, when present, the rollbackGuard's head block
|
|
381
397
|
// and the parent of the range's first block. Duplicates are allowed; reorg
|
|
382
398
|
// detection notices same-block-number-different-hash collisions itself.
|
|
383
399
|
let blockHashes = []
|
|
384
|
-
pageUnsafe.
|
|
400
|
+
pageUnsafe.blocks->Array.forEach(block => {
|
|
385
401
|
switch (block.number, block.hash) {
|
|
386
402
|
| (Some(blockNumber), Some(blockHash)) =>
|
|
387
403
|
blockHashes->Array.push({ReorgDetection.blockNumber, blockHash})->ignore
|
|
@@ -409,13 +425,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
409
425
|
| Some({timestamp}) => timestamp
|
|
410
426
|
| None =>
|
|
411
427
|
switch pageUnsafe.items->Array.get(pageUnsafe.items->Array.length - 1) {
|
|
412
|
-
| Some(
|
|
413
|
-
|
|
428
|
+
| Some(item) if item.blockNumber == heighestBlockQueried =>
|
|
429
|
+
getBlock(item.blockNumber).timestamp->Option.getUnsafe
|
|
414
430
|
| _ => 0
|
|
415
431
|
}
|
|
416
432
|
}
|
|
417
433
|
|
|
418
|
-
let totalTimeElapsed = totalTimeRef->
|
|
434
|
+
let totalTimeElapsed = totalTimeRef->Performance.secondsSince
|
|
419
435
|
|
|
420
436
|
let stats = {
|
|
421
437
|
totalTimeElapsed,
|
|
@@ -426,6 +442,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
426
442
|
{
|
|
427
443
|
latestFetchedBlockTimestamp,
|
|
428
444
|
parsedQueueItems,
|
|
445
|
+
transactionStore: Some(pageUnsafe.transactionStore),
|
|
429
446
|
latestFetchedBlockNumber: heighestBlockQueried,
|
|
430
447
|
stats,
|
|
431
448
|
knownHeight,
|
|
@@ -451,7 +468,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
451
468
|
poweredByHyperSync: true,
|
|
452
469
|
getBlockHashes,
|
|
453
470
|
getHeightOrThrow: async () => {
|
|
454
|
-
let timerRef =
|
|
471
|
+
let timerRef = Performance.now()
|
|
455
472
|
let result = try {
|
|
456
473
|
await client.getHeight()
|
|
457
474
|
} catch {
|
|
@@ -465,7 +482,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
465
482
|
| _ => throw(JsExn(e))
|
|
466
483
|
}
|
|
467
484
|
}
|
|
468
|
-
let seconds = timerRef->
|
|
485
|
+
let seconds = timerRef->Performance.secondsSince
|
|
469
486
|
Prometheus.SourceRequestCount.increment(
|
|
470
487
|
~sourceName=name,
|
|
471
488
|
~chainId=chain->ChainMap.Chain.toChainId,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Utils from "../Utils.res.mjs";
|
|
4
|
-
import * as Hrtime from "../bindings/Hrtime.res.mjs";
|
|
5
4
|
import * as Source from "./Source.res.mjs";
|
|
6
5
|
import * as Logging from "../Logging.res.mjs";
|
|
7
6
|
import * as HyperSync from "./HyperSync.res.mjs";
|
|
8
7
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
9
8
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
9
|
+
import * as Performance from "../bindings/Performance.res.mjs";
|
|
10
10
|
import * as LogSelection from "../LogSelection.res.mjs";
|
|
11
11
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
12
12
|
import * as ErrorHandling from "../ErrorHandling.res.mjs";
|
|
@@ -31,7 +31,10 @@ function getSelectionConfig(selection, chain) {
|
|
|
31
31
|
capitalizedBlockFields.add(Utils.$$String.capitalize(name));
|
|
32
32
|
});
|
|
33
33
|
Array.from(param.selectedTransactionFields).forEach(name => {
|
|
34
|
-
|
|
34
|
+
if (name !== "transactionIndex") {
|
|
35
|
+
capitalizedTransactionFields.add(Utils.$$String.capitalize(name));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
});
|
|
36
39
|
let eventFilters = param.getEventFiltersOrThrow(chain);
|
|
37
40
|
if (param.dependsOnAddresses) {
|
|
@@ -124,17 +127,17 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
124
127
|
client = ErrorHandling.mkLogAndRaise(undefined, "Failed to instantiate the hypersync client, please double check your ABI", exn);
|
|
125
128
|
}
|
|
126
129
|
let UndefinedValue = /* @__PURE__ */Primitive_exceptions.create("UndefinedValue");
|
|
127
|
-
let makeEventBatchQueueItem = (item, params, eventConfig) => {
|
|
128
|
-
let block = item.block;
|
|
130
|
+
let makeEventBatchQueueItem = (item, block, params, eventConfig) => {
|
|
129
131
|
let logIndex = item.logIndex;
|
|
130
132
|
return {
|
|
131
133
|
kind: 0,
|
|
132
134
|
eventConfig: eventConfig,
|
|
133
135
|
timestamp: block.timestamp,
|
|
134
136
|
chain: chain,
|
|
135
|
-
blockNumber:
|
|
137
|
+
blockNumber: item.blockNumber,
|
|
136
138
|
blockHash: block.hash,
|
|
137
139
|
logIndex: logIndex,
|
|
140
|
+
transactionIndex: item.transactionIndex,
|
|
138
141
|
payload: {
|
|
139
142
|
contractName: eventConfig.contractName,
|
|
140
143
|
eventName: eventConfig.name,
|
|
@@ -142,13 +145,12 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
142
145
|
chainId: chain,
|
|
143
146
|
srcAddress: item.srcAddress,
|
|
144
147
|
logIndex: logIndex,
|
|
145
|
-
transaction: item.transaction,
|
|
146
148
|
block: block
|
|
147
149
|
}
|
|
148
150
|
};
|
|
149
151
|
};
|
|
150
|
-
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName,
|
|
151
|
-
let totalTimeRef =
|
|
152
|
+
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, param, selection, retry, logger) => {
|
|
153
|
+
let totalTimeRef = Performance.now();
|
|
152
154
|
let selectionConfig = getSelectionConfig(selection);
|
|
153
155
|
let logSelections;
|
|
154
156
|
try {
|
|
@@ -157,7 +159,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
157
159
|
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
158
160
|
logSelections = ErrorHandling.mkLogAndRaise(logger, "Failed getting log selection for the query", exn);
|
|
159
161
|
}
|
|
160
|
-
let startFetchingBatchTimeRef =
|
|
162
|
+
let startFetchingBatchTimeRef = Performance.now();
|
|
161
163
|
Prometheus.SourceRequestCount.increment(name, chain, "getLogs");
|
|
162
164
|
let pageUnsafe;
|
|
163
165
|
try {
|
|
@@ -209,23 +211,31 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
209
211
|
Error: new Error()
|
|
210
212
|
};
|
|
211
213
|
}
|
|
212
|
-
let pageFetchTime =
|
|
214
|
+
let pageFetchTime = Performance.secondsSince(startFetchingBatchTimeRef);
|
|
213
215
|
let knownHeight$1 = pageUnsafe.archiveHeight;
|
|
214
216
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1 | 0;
|
|
215
|
-
let parsingTimeRef =
|
|
217
|
+
let parsingTimeRef = Performance.now();
|
|
216
218
|
let parsedQueueItems = [];
|
|
219
|
+
let blocksByNumber = new Map();
|
|
220
|
+
pageUnsafe.blocks.forEach(block => {
|
|
221
|
+
let number = block.number;
|
|
222
|
+
if (number !== undefined) {
|
|
223
|
+
blocksByNumber.set(number, block);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
217
227
|
pageUnsafe.items.forEach(item => {
|
|
218
|
-
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress,
|
|
228
|
+
let maybeEventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(item.topic0, item.topicCount), item.srcAddress, contractNameByAddress);
|
|
219
229
|
if (maybeEventConfig === undefined) {
|
|
220
230
|
return;
|
|
221
231
|
}
|
|
222
232
|
let params = Stdlib_Option.flatMap(Primitive_option.fromNullable(item.params), __x => __x[maybeEventConfig.contractName]);
|
|
223
233
|
if (params !== undefined) {
|
|
224
|
-
parsedQueueItems.push(makeEventBatchQueueItem(item, Primitive_option.valFromOption(params), maybeEventConfig));
|
|
234
|
+
parsedQueueItems.push(makeEventBatchQueueItem(item, blocksByNumber.get(item.blockNumber), Primitive_option.valFromOption(params), maybeEventConfig));
|
|
225
235
|
return;
|
|
226
236
|
} else {
|
|
227
237
|
let logIndex = item.logIndex;
|
|
228
|
-
let blockNumber = item.
|
|
238
|
+
let blockNumber = item.blockNumber;
|
|
229
239
|
let exn = {
|
|
230
240
|
RE_EXN_ID: UndefinedValue
|
|
231
241
|
};
|
|
@@ -242,10 +252,9 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
242
252
|
return ErrorHandling.mkLogAndRaise(logger$1, msg, exn);
|
|
243
253
|
}
|
|
244
254
|
});
|
|
245
|
-
let parsingTimeElapsed =
|
|
255
|
+
let parsingTimeElapsed = Performance.secondsSince(parsingTimeRef);
|
|
246
256
|
let blockHashes = [];
|
|
247
|
-
pageUnsafe.
|
|
248
|
-
let block = param.block;
|
|
257
|
+
pageUnsafe.blocks.forEach(block => {
|
|
249
258
|
let match = block.number;
|
|
250
259
|
let match$1 = block.hash;
|
|
251
260
|
if (match !== undefined && match$1 !== undefined) {
|
|
@@ -272,15 +281,10 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
272
281
|
if (match$1 !== undefined) {
|
|
273
282
|
latestFetchedBlockTimestamp = match$1.timestamp;
|
|
274
283
|
} else {
|
|
275
|
-
let
|
|
276
|
-
|
|
277
|
-
let block = match$2.block;
|
|
278
|
-
latestFetchedBlockTimestamp = block.number === heighestBlockQueried ? block.timestamp : 0;
|
|
279
|
-
} else {
|
|
280
|
-
latestFetchedBlockTimestamp = 0;
|
|
281
|
-
}
|
|
284
|
+
let item = pageUnsafe.items[pageUnsafe.items.length - 1 | 0];
|
|
285
|
+
latestFetchedBlockTimestamp = item !== undefined && item.blockNumber === heighestBlockQueried ? blocksByNumber.get(item.blockNumber).timestamp : 0;
|
|
282
286
|
}
|
|
283
|
-
let totalTimeElapsed =
|
|
287
|
+
let totalTimeElapsed = Performance.secondsSince(totalTimeRef);
|
|
284
288
|
let stats_parsing$unknowntime$unknown$lpars$rpar = parsingTimeElapsed;
|
|
285
289
|
let stats_page$unknownfetch$unknowntime$unknown$lpars$rpar = pageFetchTime;
|
|
286
290
|
let stats = {
|
|
@@ -292,6 +296,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
292
296
|
knownHeight: knownHeight$1,
|
|
293
297
|
blockHashes: blockHashes,
|
|
294
298
|
parsedQueueItems: parsedQueueItems,
|
|
299
|
+
transactionStore: Primitive_option.some(pageUnsafe.transactionStore),
|
|
295
300
|
fromBlockQueried: fromBlock,
|
|
296
301
|
latestFetchedBlockNumber: heighestBlockQueried,
|
|
297
302
|
latestFetchedBlockTimestamp: latestFetchedBlockTimestamp,
|
|
@@ -307,7 +312,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
307
312
|
pollingInterval: 100,
|
|
308
313
|
getBlockHashes: getBlockHashes,
|
|
309
314
|
getHeightOrThrow: async () => {
|
|
310
|
-
let timerRef =
|
|
315
|
+
let timerRef = Performance.now();
|
|
311
316
|
let result;
|
|
312
317
|
try {
|
|
313
318
|
result = await client.getHeight();
|
|
@@ -339,7 +344,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
339
344
|
throw e;
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
|
-
let seconds =
|
|
347
|
+
let seconds = Performance.secondsSince(timerRef);
|
|
343
348
|
Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
|
|
344
349
|
Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
|
|
345
350
|
return result;
|
|
@@ -1034,14 +1034,14 @@ let make = (
|
|
|
1034
1034
|
~fromBlock,
|
|
1035
1035
|
~toBlock,
|
|
1036
1036
|
~addressesByContractName,
|
|
1037
|
-
~
|
|
1037
|
+
~contractNameByAddress,
|
|
1038
1038
|
~knownHeight,
|
|
1039
1039
|
~partitionId,
|
|
1040
1040
|
~selection: FetchState.selection,
|
|
1041
1041
|
~retry,
|
|
1042
1042
|
~logger as _,
|
|
1043
1043
|
) => {
|
|
1044
|
-
let startFetchingBatchTimeRef =
|
|
1044
|
+
let startFetchingBatchTimeRef = Performance.now()
|
|
1045
1045
|
|
|
1046
1046
|
let suggestedBlockInterval = switch mutSuggestedBlockIntervals->Utils.Dict.dangerouslyGetNonOption(
|
|
1047
1047
|
maxSuggestedBlockIntervalKey,
|
|
@@ -1144,9 +1144,8 @@ let make = (
|
|
|
1144
1144
|
|
|
1145
1145
|
switch eventRouter->EventRouter.get(
|
|
1146
1146
|
~tag=EventRouter.getEvmEventId(~sighash=topic0, ~topicCount=log.topics->Array.length),
|
|
1147
|
-
~
|
|
1147
|
+
~contractNameByAddress,
|
|
1148
1148
|
~contractAddress=routedAddress,
|
|
1149
|
-
~blockNumber=log.blockNumber,
|
|
1150
1149
|
) {
|
|
1151
1150
|
| None => None
|
|
1152
1151
|
| Some(eventConfig) =>
|
|
@@ -1160,7 +1159,9 @@ let make = (
|
|
|
1160
1159
|
let (block, transaction) = try await Promise.all2((
|
|
1161
1160
|
log->getEventBlockOrThrow(~selectedBlockFields=eventConfig.selectedBlockFields),
|
|
1162
1161
|
log->getEventTransactionOrThrow(
|
|
1163
|
-
~selectedTransactionFields=eventConfig.selectedTransactionFields
|
|
1162
|
+
~selectedTransactionFields=eventConfig.selectedTransactionFields->(
|
|
1163
|
+
Utils.magic: Utils.Set.t<string> => Utils.Set.t<Internal.evmTransactionField>
|
|
1164
|
+
),
|
|
1164
1165
|
),
|
|
1165
1166
|
)) catch {
|
|
1166
1167
|
| TransactionDataNotFound({message}) =>
|
|
@@ -1200,13 +1201,14 @@ let make = (
|
|
|
1200
1201
|
blockHash: block->getBlockHash,
|
|
1201
1202
|
chain,
|
|
1202
1203
|
logIndex: log.logIndex,
|
|
1204
|
+
transactionIndex: log.transactionIndex,
|
|
1203
1205
|
payload: {
|
|
1204
1206
|
contractName: eventConfig.contractName,
|
|
1205
1207
|
eventName: eventConfig.name,
|
|
1206
1208
|
chainId: chain->ChainMap.Chain.toChainId,
|
|
1207
1209
|
params: decoded,
|
|
1208
|
-
transaction,
|
|
1209
1210
|
block,
|
|
1211
|
+
transaction,
|
|
1210
1212
|
srcAddress: routedAddress,
|
|
1211
1213
|
logIndex: log.logIndex,
|
|
1212
1214
|
}->Evm.fromPayload,
|
|
@@ -1222,7 +1224,7 @@ let make = (
|
|
|
1222
1224
|
|
|
1223
1225
|
let optFirstBlockParent = await firstBlockParentPromise
|
|
1224
1226
|
|
|
1225
|
-
let totalTimeElapsed = startFetchingBatchTimeRef->
|
|
1227
|
+
let totalTimeElapsed = startFetchingBatchTimeRef->Performance.secondsSince
|
|
1226
1228
|
|
|
1227
1229
|
// Every fetched block carries `hash` and `parentHash`, so each one yields
|
|
1228
1230
|
// two confirmed (number, hash) pairs for reorg detection at no extra cost.
|
|
@@ -1250,6 +1252,8 @@ let make = (
|
|
|
1250
1252
|
latestFetchedBlockTimestamp: latestFetchedBlockInfo.timestamp,
|
|
1251
1253
|
latestFetchedBlockNumber: latestFetchedBlockInfo.number,
|
|
1252
1254
|
parsedQueueItems,
|
|
1255
|
+
// RPC keeps the transaction inline on the payload; no store page.
|
|
1256
|
+
transactionStore: None,
|
|
1253
1257
|
stats: {
|
|
1254
1258
|
totalTimeElapsed: totalTimeElapsed,
|
|
1255
1259
|
},
|
|
@@ -1303,12 +1307,12 @@ let make = (
|
|
|
1303
1307
|
getBlockHashes,
|
|
1304
1308
|
onReorg,
|
|
1305
1309
|
getHeightOrThrow: async () => {
|
|
1306
|
-
let timerRef =
|
|
1310
|
+
let timerRef = Performance.now()
|
|
1307
1311
|
let height = try {
|
|
1308
1312
|
await rpcClient.getHeight()
|
|
1309
1313
|
} catch {
|
|
1310
1314
|
| exn =>
|
|
1311
|
-
let seconds = timerRef->
|
|
1315
|
+
let seconds = timerRef->Performance.secondsSince
|
|
1312
1316
|
Prometheus.SourceRequestCount.increment(
|
|
1313
1317
|
~sourceName=name,
|
|
1314
1318
|
~chainId=chain->ChainMap.Chain.toChainId,
|
|
@@ -1322,7 +1326,7 @@ let make = (
|
|
|
1322
1326
|
)
|
|
1323
1327
|
exn->throw
|
|
1324
1328
|
}
|
|
1325
|
-
let seconds = timerRef->
|
|
1329
|
+
let seconds = timerRef->Performance.secondsSince
|
|
1326
1330
|
Prometheus.SourceRequestCount.increment(
|
|
1327
1331
|
~sourceName=name,
|
|
1328
1332
|
~chainId=chain->ChainMap.Chain.toChainId,
|
|
@@ -4,7 +4,6 @@ import * as Rpc from "./Rpc.res.mjs";
|
|
|
4
4
|
import * as Rest from "../vendored/Rest.res.mjs";
|
|
5
5
|
import * as Time from "../Time.res.mjs";
|
|
6
6
|
import * as Utils from "../Utils.res.mjs";
|
|
7
|
-
import * as Hrtime from "../bindings/Hrtime.res.mjs";
|
|
8
7
|
import * as Source from "./Source.res.mjs";
|
|
9
8
|
import * as Address from "../Address.res.mjs";
|
|
10
9
|
import * as Logging from "../Logging.res.mjs";
|
|
@@ -14,6 +13,7 @@ import * as LazyLoader from "../LazyLoader.res.mjs";
|
|
|
14
13
|
import * as Prometheus from "../Prometheus.res.mjs";
|
|
15
14
|
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
16
15
|
import * as EventRouter from "./EventRouter.res.mjs";
|
|
16
|
+
import * as Performance from "../bindings/Performance.res.mjs";
|
|
17
17
|
import * as EvmRpcClient from "./EvmRpcClient.res.mjs";
|
|
18
18
|
import * as LogSelection from "../LogSelection.res.mjs";
|
|
19
19
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
@@ -1035,8 +1035,8 @@ function make(param) {
|
|
|
1035
1035
|
hscDecoder.contents = decoder$1;
|
|
1036
1036
|
return decoder$1;
|
|
1037
1037
|
};
|
|
1038
|
-
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName,
|
|
1039
|
-
let startFetchingBatchTimeRef =
|
|
1038
|
+
let getItemsOrThrow = async (fromBlock, toBlock, addressesByContractName, contractNameByAddress, knownHeight, partitionId, selection, retry, param) => {
|
|
1039
|
+
let startFetchingBatchTimeRef = Performance.now();
|
|
1040
1040
|
let maxSuggestedBlockInterval = mutSuggestedBlockIntervals[maxSuggestedBlockIntervalKey];
|
|
1041
1041
|
let suggestedBlockInterval = maxSuggestedBlockInterval !== undefined ? maxSuggestedBlockInterval : Stdlib_Option.getOr(mutSuggestedBlockIntervals[partitionId], syncConfig.initialBlockInterval);
|
|
1042
1042
|
let toBlock$1 = toBlock !== undefined ? Primitive_int.min(toBlock, knownHeight) : knownHeight;
|
|
@@ -1075,7 +1075,7 @@ function make(param) {
|
|
|
1075
1075
|
let log = param[0];
|
|
1076
1076
|
let topic0 = Stdlib_Option.getOr(log.topics[0], "0x0");
|
|
1077
1077
|
let routedAddress = lowercaseAddresses ? Address.Evm.fromAddressLowercaseOrThrow(log.address) : Address.Evm.fromAddressOrThrow(log.address);
|
|
1078
|
-
let eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), routedAddress,
|
|
1078
|
+
let eventConfig = EventRouter.get(eventRouter, EventRouter.getEvmEventId(topic0, log.topics.length), routedAddress, contractNameByAddress);
|
|
1079
1079
|
if (eventConfig === undefined) {
|
|
1080
1080
|
return;
|
|
1081
1081
|
}
|
|
@@ -1131,6 +1131,7 @@ function make(param) {
|
|
|
1131
1131
|
blockNumber: block.number,
|
|
1132
1132
|
blockHash: block.hash,
|
|
1133
1133
|
logIndex: log.logIndex,
|
|
1134
|
+
transactionIndex: log.transactionIndex,
|
|
1134
1135
|
payload: {
|
|
1135
1136
|
contractName: eventConfig.contractName,
|
|
1136
1137
|
eventName: eventConfig.name,
|
|
@@ -1138,14 +1139,14 @@ function make(param) {
|
|
|
1138
1139
|
chainId: chain,
|
|
1139
1140
|
srcAddress: routedAddress,
|
|
1140
1141
|
logIndex: log.logIndex,
|
|
1141
|
-
transaction: match[1],
|
|
1142
|
+
transaction: Primitive_option.some(match[1]),
|
|
1142
1143
|
block: block
|
|
1143
1144
|
}
|
|
1144
1145
|
};
|
|
1145
1146
|
})();
|
|
1146
1147
|
}));
|
|
1147
1148
|
let optFirstBlockParent = await firstBlockParentPromise;
|
|
1148
|
-
let totalTimeElapsed =
|
|
1149
|
+
let totalTimeElapsed = Performance.secondsSince(startFetchingBatchTimeRef);
|
|
1149
1150
|
let blockHashes = [];
|
|
1150
1151
|
let pushBlockInfo = b => {
|
|
1151
1152
|
blockHashes.push({
|
|
@@ -1174,6 +1175,7 @@ function make(param) {
|
|
|
1174
1175
|
knownHeight: knownHeight,
|
|
1175
1176
|
blockHashes: blockHashes,
|
|
1176
1177
|
parsedQueueItems: parsedQueueItems,
|
|
1178
|
+
transactionStore: undefined,
|
|
1177
1179
|
fromBlockQueried: fromBlock,
|
|
1178
1180
|
latestFetchedBlockNumber: latestFetchedBlockInfo.number,
|
|
1179
1181
|
latestFetchedBlockTimestamp: latestFetchedBlockInfo.timestamp,
|
|
@@ -1210,17 +1212,17 @@ function make(param) {
|
|
|
1210
1212
|
pollingInterval: syncConfig.pollingInterval,
|
|
1211
1213
|
getBlockHashes: getBlockHashes,
|
|
1212
1214
|
getHeightOrThrow: async () => {
|
|
1213
|
-
let timerRef =
|
|
1215
|
+
let timerRef = Performance.now();
|
|
1214
1216
|
let height;
|
|
1215
1217
|
try {
|
|
1216
1218
|
height = await rpcClient.getHeight();
|
|
1217
1219
|
} catch (exn) {
|
|
1218
|
-
let seconds =
|
|
1220
|
+
let seconds = Performance.secondsSince(timerRef);
|
|
1219
1221
|
Prometheus.SourceRequestCount.increment(name, chain, "eth_blockNumber");
|
|
1220
1222
|
Prometheus.SourceRequestCount.addSeconds(name, chain, "eth_blockNumber", seconds);
|
|
1221
1223
|
throw exn;
|
|
1222
1224
|
}
|
|
1223
|
-
let seconds$1 =
|
|
1225
|
+
let seconds$1 = Performance.secondsSince(timerRef);
|
|
1224
1226
|
Prometheus.SourceRequestCount.increment(name, chain, "eth_blockNumber");
|
|
1225
1227
|
Prometheus.SourceRequestCount.addSeconds(name, chain, "eth_blockNumber", seconds$1);
|
|
1226
1228
|
return height;
|
|
@@ -21,14 +21,14 @@ let make = (~items: array<Internal.item>, ~endBlock: int, ~chain: ChainMap.Chain
|
|
|
21
21
|
~fromBlock as _,
|
|
22
22
|
~toBlock as _,
|
|
23
23
|
~addressesByContractName as _,
|
|
24
|
-
~
|
|
24
|
+
~contractNameByAddress as _,
|
|
25
25
|
~knownHeight as _,
|
|
26
26
|
~partitionId as _,
|
|
27
27
|
~selection as _,
|
|
28
28
|
~retry as _,
|
|
29
29
|
~logger as _,
|
|
30
30
|
) => {
|
|
31
|
-
// Return all items on first call, empty on subsequent
|
|
31
|
+
// Return all items on the first call, empty on subsequent.
|
|
32
32
|
let result = if delivered.contents {
|
|
33
33
|
[]
|
|
34
34
|
} else {
|
|
@@ -41,6 +41,8 @@ let make = (~items: array<Internal.item>, ~endBlock: int, ~chain: ChainMap.Chain
|
|
|
41
41
|
Source.knownHeight: reportedHeight,
|
|
42
42
|
blockHashes: [],
|
|
43
43
|
parsedQueueItems: result,
|
|
44
|
+
// Simulate keeps the transaction inline on the payload; no store page.
|
|
45
|
+
transactionStore: None,
|
|
44
46
|
fromBlockQueried: 0,
|
|
45
47
|
latestFetchedBlockNumber: reportedHeight,
|
|
46
48
|
latestFetchedBlockTimestamp: 0,
|
package/src/sources/Source.res
CHANGED
|
@@ -18,6 +18,10 @@ type blockRangeFetchResponse = {
|
|
|
18
18
|
// a within-array hash mismatch on the same block number as a reorg.
|
|
19
19
|
blockHashes: array<ReorgDetection.blockData>,
|
|
20
20
|
parsedQueueItems: array<Internal.item>,
|
|
21
|
+
// Page of transactions for this response's items, keyed by (blockNumber,
|
|
22
|
+
// transactionIndex); merged into the chain's store on apply. `None` for
|
|
23
|
+
// sources that keep the transaction inline on the payload (RPC/Fuel/Simulate).
|
|
24
|
+
transactionStore: option<TransactionStore.t>,
|
|
21
25
|
fromBlockQueried: int,
|
|
22
26
|
latestFetchedBlockNumber: int,
|
|
23
27
|
latestFetchedBlockTimestamp: int,
|
|
@@ -56,7 +60,7 @@ type t = {
|
|
|
56
60
|
~fromBlock: int,
|
|
57
61
|
~toBlock: option<int>,
|
|
58
62
|
~addressesByContractName: dict<array<Address.t>>,
|
|
59
|
-
~
|
|
63
|
+
~contractNameByAddress: dict<string>,
|
|
60
64
|
~knownHeight: int,
|
|
61
65
|
~partitionId: string,
|
|
62
66
|
~selection: FetchState.selection,
|