envio 3.3.0-alpha.2 → 3.3.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/index.d.ts +23 -21
- package/package.json +6 -6
- package/src/Bin.res +3 -0
- package/src/Bin.res.mjs +4 -0
- package/src/ChainFetching.res +26 -3
- package/src/ChainFetching.res.mjs +22 -3
- package/src/ChainState.res +3 -12
- package/src/ChainState.res.mjs +6 -8
- package/src/ChainState.resi +0 -2
- package/src/CrossChainState.res +15 -0
- package/src/CrossChainState.res.mjs +12 -0
- package/src/Ecosystem.res +0 -6
- package/src/EventConfigBuilder.res +45 -18
- package/src/EventConfigBuilder.res.mjs +28 -10
- package/src/EventProcessing.res +53 -37
- package/src/EventProcessing.res.mjs +41 -36
- package/src/FetchState.res +35 -42
- package/src/FetchState.res.mjs +37 -63
- package/src/HandlerLoader.res +10 -1
- package/src/HandlerLoader.res.mjs +15 -8
- package/src/Internal.res +8 -3
- package/src/Internal.res.mjs +1 -1
- package/src/LoadLayer.res +5 -5
- package/src/LoadLayer.res.mjs +6 -6
- package/src/Main.res +17 -9
- package/src/Main.res.mjs +15 -6
- 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 +2 -2
- package/src/Rollback.res.mjs +3 -3
- package/src/SimulateItems.res +81 -15
- package/src/SimulateItems.res.mjs +63 -20
- package/src/TestIndexer.res +77 -39
- package/src/TestIndexer.res.mjs +45 -31
- 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 +10 -37
- package/src/sources/Evm.res.mjs +5 -40
- package/src/sources/Fuel.res +0 -4
- package/src/sources/Fuel.res.mjs +0 -7
- package/src/sources/HyperFuelSource.res +10 -11
- package/src/sources/HyperFuelSource.res.mjs +11 -11
- package/src/sources/HyperSync.res +3 -0
- package/src/sources/HyperSync.res.mjs +1 -0
- package/src/sources/HyperSync.resi +1 -0
- package/src/sources/HyperSyncClient.res +5 -1
- package/src/sources/HyperSyncSource.res +42 -24
- package/src/sources/HyperSyncSource.res.mjs +30 -26
- package/src/sources/RpcSource.res +7 -8
- package/src/sources/RpcSource.res.mjs +8 -8
- package/src/sources/SimulateSource.res +1 -1
- package/src/sources/Source.res +1 -1
- package/src/sources/SourceManager.res +17 -16
- package/src/sources/SourceManager.res.mjs +10 -15
- package/src/sources/Svm.res +6 -11
- package/src/sources/Svm.res.mjs +6 -14
- package/src/sources/SvmHyperSyncSource.res +24 -18
- package/src/sources/SvmHyperSyncSource.res.mjs +22 -15
- package/src/sources/TransactionStore.res +62 -35
- package/src/sources/TransactionStore.res.mjs +44 -18
- 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
|
@@ -280,7 +280,9 @@ module EventItems = {
|
|
|
280
280
|
srcAddress: Address.t,
|
|
281
281
|
topic0: EvmTypes.Hex.t,
|
|
282
282
|
topicCount: int,
|
|
283
|
-
block
|
|
283
|
+
// Number of the block this log belongs to; the block itself is resolved from
|
|
284
|
+
// `response.blocks`, deduplicated across items sharing a block.
|
|
285
|
+
blockNumber: int,
|
|
284
286
|
// Key (with the block number) into the transaction store; the transaction
|
|
285
287
|
// is resolved from the store on demand.
|
|
286
288
|
transactionIndex: int,
|
|
@@ -290,6 +292,8 @@ module EventItems = {
|
|
|
290
292
|
type response = {
|
|
291
293
|
archiveHeight: option<int>,
|
|
292
294
|
nextBlock: int,
|
|
295
|
+
// One entry per block number referenced by `items`.
|
|
296
|
+
blocks: array<ResponseTypes.block>,
|
|
293
297
|
items: array<item>,
|
|
294
298
|
rollbackGuard: option<ResponseTypes.rollbackGuard>,
|
|
295
299
|
}
|
|
@@ -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,17 +197,18 @@ 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,
|
|
209
214
|
transactionIndex,
|
|
@@ -223,14 +228,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
223
228
|
~fromBlock,
|
|
224
229
|
~toBlock,
|
|
225
230
|
~addressesByContractName,
|
|
226
|
-
~
|
|
231
|
+
~contractNameByAddress,
|
|
227
232
|
~knownHeight,
|
|
228
233
|
~partitionId as _,
|
|
229
234
|
~selection,
|
|
230
235
|
~retry,
|
|
231
236
|
~logger,
|
|
232
237
|
) => {
|
|
233
|
-
let totalTimeRef =
|
|
238
|
+
let totalTimeRef = Performance.now()
|
|
234
239
|
|
|
235
240
|
let selectionConfig = selection->getSelectionConfig
|
|
236
241
|
|
|
@@ -239,7 +244,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
239
244
|
exn->ErrorHandling.mkLogAndRaise(~logger, ~msg="Failed getting log selection for the query")
|
|
240
245
|
}
|
|
241
246
|
|
|
242
|
-
let startFetchingBatchTimeRef =
|
|
247
|
+
let startFetchingBatchTimeRef = Performance.now()
|
|
243
248
|
|
|
244
249
|
//fetch batch
|
|
245
250
|
Prometheus.SourceRequestCount.increment(
|
|
@@ -299,7 +304,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
299
304
|
)
|
|
300
305
|
}
|
|
301
306
|
|
|
302
|
-
let pageFetchTime = startFetchingBatchTimeRef->
|
|
307
|
+
let pageFetchTime = startFetchingBatchTimeRef->Performance.secondsSince
|
|
303
308
|
|
|
304
309
|
//set height and next from block
|
|
305
310
|
let knownHeight = pageUnsafe.archiveHeight
|
|
@@ -309,11 +314,21 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
309
314
|
//In the query
|
|
310
315
|
let heighestBlockQueried = pageUnsafe.nextBlock - 1
|
|
311
316
|
|
|
312
|
-
let parsingTimeRef =
|
|
317
|
+
let parsingTimeRef = Performance.now()
|
|
313
318
|
|
|
314
319
|
//Parse page items into queue items
|
|
315
320
|
let parsedQueueItems = []
|
|
316
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
|
+
|
|
317
332
|
let handleDecodeFailure = (
|
|
318
333
|
~eventConfig: Internal.evmEventConfig,
|
|
319
334
|
~logIndex,
|
|
@@ -347,9 +362,8 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
347
362
|
~sighash=item.topic0->EvmTypes.Hex.toString,
|
|
348
363
|
~topicCount=item.topicCount,
|
|
349
364
|
),
|
|
350
|
-
~
|
|
365
|
+
~contractNameByAddress,
|
|
351
366
|
~contractAddress=item.srcAddress,
|
|
352
|
-
~blockNumber=item.block.number->Option.getUnsafe,
|
|
353
367
|
)
|
|
354
368
|
|
|
355
369
|
switch maybeEventConfig {
|
|
@@ -359,12 +373,16 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
359
373
|
->Nullable.toOption
|
|
360
374
|
->Option.flatMap(Dict.get(_, eventConfig.contractName)) {
|
|
361
375
|
| Some(params) =>
|
|
362
|
-
parsedQueueItems
|
|
376
|
+
parsedQueueItems
|
|
377
|
+
->Array.push(
|
|
378
|
+
makeEventBatchQueueItem(item, ~block=getBlock(item.blockNumber), ~params, ~eventConfig),
|
|
379
|
+
)
|
|
380
|
+
->ignore
|
|
363
381
|
| None =>
|
|
364
382
|
handleDecodeFailure(
|
|
365
383
|
~eventConfig,
|
|
366
384
|
~logIndex=item.logIndex,
|
|
367
|
-
~blockNumber=item.
|
|
385
|
+
~blockNumber=item.blockNumber,
|
|
368
386
|
~chainId,
|
|
369
387
|
~exn=UndefinedValue,
|
|
370
388
|
)
|
|
@@ -372,14 +390,14 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
372
390
|
}
|
|
373
391
|
})
|
|
374
392
|
|
|
375
|
-
let parsingTimeElapsed = parsingTimeRef->
|
|
393
|
+
let parsingTimeElapsed = parsingTimeRef->Performance.secondsSince
|
|
376
394
|
|
|
377
395
|
// Collect (blockNumber, blockHash) pairs we already have from the response —
|
|
378
|
-
// one per
|
|
396
|
+
// one per returned block plus, when present, the rollbackGuard's head block
|
|
379
397
|
// and the parent of the range's first block. Duplicates are allowed; reorg
|
|
380
398
|
// detection notices same-block-number-different-hash collisions itself.
|
|
381
399
|
let blockHashes = []
|
|
382
|
-
pageUnsafe.
|
|
400
|
+
pageUnsafe.blocks->Array.forEach(block => {
|
|
383
401
|
switch (block.number, block.hash) {
|
|
384
402
|
| (Some(blockNumber), Some(blockHash)) =>
|
|
385
403
|
blockHashes->Array.push({ReorgDetection.blockNumber, blockHash})->ignore
|
|
@@ -407,13 +425,13 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
407
425
|
| Some({timestamp}) => timestamp
|
|
408
426
|
| None =>
|
|
409
427
|
switch pageUnsafe.items->Array.get(pageUnsafe.items->Array.length - 1) {
|
|
410
|
-
| Some(
|
|
411
|
-
|
|
428
|
+
| Some(item) if item.blockNumber == heighestBlockQueried =>
|
|
429
|
+
getBlock(item.blockNumber).timestamp->Option.getUnsafe
|
|
412
430
|
| _ => 0
|
|
413
431
|
}
|
|
414
432
|
}
|
|
415
433
|
|
|
416
|
-
let totalTimeElapsed = totalTimeRef->
|
|
434
|
+
let totalTimeElapsed = totalTimeRef->Performance.secondsSince
|
|
417
435
|
|
|
418
436
|
let stats = {
|
|
419
437
|
totalTimeElapsed,
|
|
@@ -450,7 +468,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
450
468
|
poweredByHyperSync: true,
|
|
451
469
|
getBlockHashes,
|
|
452
470
|
getHeightOrThrow: async () => {
|
|
453
|
-
let timerRef =
|
|
471
|
+
let timerRef = Performance.now()
|
|
454
472
|
let result = try {
|
|
455
473
|
await client.getHeight()
|
|
456
474
|
} catch {
|
|
@@ -464,7 +482,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`)
|
|
|
464
482
|
| _ => throw(JsExn(e))
|
|
465
483
|
}
|
|
466
484
|
}
|
|
467
|
-
let seconds = timerRef->
|
|
485
|
+
let seconds = timerRef->Performance.secondsSince
|
|
468
486
|
Prometheus.SourceRequestCount.increment(
|
|
469
487
|
~sourceName=name,
|
|
470
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,15 +127,14 @@ 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,
|
|
138
140
|
transactionIndex: item.transactionIndex,
|
|
@@ -147,8 +149,8 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
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 = {
|
|
@@ -308,7 +312,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
308
312
|
pollingInterval: 100,
|
|
309
313
|
getBlockHashes: getBlockHashes,
|
|
310
314
|
getHeightOrThrow: async () => {
|
|
311
|
-
let timerRef =
|
|
315
|
+
let timerRef = Performance.now();
|
|
312
316
|
let result;
|
|
313
317
|
try {
|
|
314
318
|
result = await client.getHeight();
|
|
@@ -340,7 +344,7 @@ Learn more or get a free Envio API token at: https://envio.dev/app/api-tokens`);
|
|
|
340
344
|
throw e;
|
|
341
345
|
}
|
|
342
346
|
}
|
|
343
|
-
let seconds =
|
|
347
|
+
let seconds = Performance.secondsSince(timerRef);
|
|
344
348
|
Prometheus.SourceRequestCount.increment(name, chain, "getHeight");
|
|
345
349
|
Prometheus.SourceRequestCount.addSeconds(name, chain, "getHeight", seconds);
|
|
346
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) =>
|
|
@@ -1225,7 +1224,7 @@ let make = (
|
|
|
1225
1224
|
|
|
1226
1225
|
let optFirstBlockParent = await firstBlockParentPromise
|
|
1227
1226
|
|
|
1228
|
-
let totalTimeElapsed = startFetchingBatchTimeRef->
|
|
1227
|
+
let totalTimeElapsed = startFetchingBatchTimeRef->Performance.secondsSince
|
|
1229
1228
|
|
|
1230
1229
|
// Every fetched block carries `hash` and `parentHash`, so each one yields
|
|
1231
1230
|
// two confirmed (number, hash) pairs for reorg detection at no extra cost.
|
|
@@ -1308,12 +1307,12 @@ let make = (
|
|
|
1308
1307
|
getBlockHashes,
|
|
1309
1308
|
onReorg,
|
|
1310
1309
|
getHeightOrThrow: async () => {
|
|
1311
|
-
let timerRef =
|
|
1310
|
+
let timerRef = Performance.now()
|
|
1312
1311
|
let height = try {
|
|
1313
1312
|
await rpcClient.getHeight()
|
|
1314
1313
|
} catch {
|
|
1315
1314
|
| exn =>
|
|
1316
|
-
let seconds = timerRef->
|
|
1315
|
+
let seconds = timerRef->Performance.secondsSince
|
|
1317
1316
|
Prometheus.SourceRequestCount.increment(
|
|
1318
1317
|
~sourceName=name,
|
|
1319
1318
|
~chainId=chain->ChainMap.Chain.toChainId,
|
|
@@ -1327,7 +1326,7 @@ let make = (
|
|
|
1327
1326
|
)
|
|
1328
1327
|
exn->throw
|
|
1329
1328
|
}
|
|
1330
|
-
let seconds = timerRef->
|
|
1329
|
+
let seconds = timerRef->Performance.secondsSince
|
|
1331
1330
|
Prometheus.SourceRequestCount.increment(
|
|
1332
1331
|
~sourceName=name,
|
|
1333
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
|
}
|
|
@@ -1146,7 +1146,7 @@ function make(param) {
|
|
|
1146
1146
|
})();
|
|
1147
1147
|
}));
|
|
1148
1148
|
let optFirstBlockParent = await firstBlockParentPromise;
|
|
1149
|
-
let totalTimeElapsed =
|
|
1149
|
+
let totalTimeElapsed = Performance.secondsSince(startFetchingBatchTimeRef);
|
|
1150
1150
|
let blockHashes = [];
|
|
1151
1151
|
let pushBlockInfo = b => {
|
|
1152
1152
|
blockHashes.push({
|
|
@@ -1212,17 +1212,17 @@ function make(param) {
|
|
|
1212
1212
|
pollingInterval: syncConfig.pollingInterval,
|
|
1213
1213
|
getBlockHashes: getBlockHashes,
|
|
1214
1214
|
getHeightOrThrow: async () => {
|
|
1215
|
-
let timerRef =
|
|
1215
|
+
let timerRef = Performance.now();
|
|
1216
1216
|
let height;
|
|
1217
1217
|
try {
|
|
1218
1218
|
height = await rpcClient.getHeight();
|
|
1219
1219
|
} catch (exn) {
|
|
1220
|
-
let seconds =
|
|
1220
|
+
let seconds = Performance.secondsSince(timerRef);
|
|
1221
1221
|
Prometheus.SourceRequestCount.increment(name, chain, "eth_blockNumber");
|
|
1222
1222
|
Prometheus.SourceRequestCount.addSeconds(name, chain, "eth_blockNumber", seconds);
|
|
1223
1223
|
throw exn;
|
|
1224
1224
|
}
|
|
1225
|
-
let seconds$1 =
|
|
1225
|
+
let seconds$1 = Performance.secondsSince(timerRef);
|
|
1226
1226
|
Prometheus.SourceRequestCount.increment(name, chain, "eth_blockNumber");
|
|
1227
1227
|
Prometheus.SourceRequestCount.addSeconds(name, chain, "eth_blockNumber", seconds$1);
|
|
1228
1228
|
return height;
|
|
@@ -21,7 +21,7 @@ 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 _,
|
package/src/sources/Source.res
CHANGED
|
@@ -60,7 +60,7 @@ type t = {
|
|
|
60
60
|
~fromBlock: int,
|
|
61
61
|
~toBlock: option<int>,
|
|
62
62
|
~addressesByContractName: dict<array<Address.t>>,
|
|
63
|
-
~
|
|
63
|
+
~contractNameByAddress: dict<string>,
|
|
64
64
|
~knownHeight: int,
|
|
65
65
|
~partitionId: string,
|
|
66
66
|
~selection: FetchState.selection,
|
|
@@ -15,7 +15,7 @@ type sourceState = {
|
|
|
15
15
|
// with a mutable state for easier reasoning and testing.
|
|
16
16
|
type t = {
|
|
17
17
|
sourcesState: array<sourceState>,
|
|
18
|
-
mutable statusStart:
|
|
18
|
+
mutable statusStart: Performance.timeRef,
|
|
19
19
|
mutable status: sourceManagerStatus,
|
|
20
20
|
newBlockStallTimeout: int,
|
|
21
21
|
newBlockStallTimeoutRealtime: int,
|
|
@@ -24,6 +24,10 @@ type t = {
|
|
|
24
24
|
getHeightRetryInterval: (~retry: int) => int,
|
|
25
25
|
mutable activeSource: Source.t,
|
|
26
26
|
mutable waitingForNewBlockStateId: option<int>,
|
|
27
|
+
// Dedupes the "waiting for new blocks" trace so it fires once per contiguous
|
|
28
|
+
// wait period instead of on every epoch that re-enters the wait before any
|
|
29
|
+
// new block is found. Reset when blocks are found.
|
|
30
|
+
mutable waitingLogged: bool,
|
|
27
31
|
// Should take into consideration partitions fetching for previous states (before rollback)
|
|
28
32
|
mutable fetchingPartitionsCount: int,
|
|
29
33
|
recoveryTimeout: float,
|
|
@@ -186,6 +190,7 @@ let make = (
|
|
|
186
190
|
}),
|
|
187
191
|
activeSource: initialActiveSource,
|
|
188
192
|
waitingForNewBlockStateId: None,
|
|
193
|
+
waitingLogged: false,
|
|
189
194
|
fetchingPartitionsCount: 0,
|
|
190
195
|
newBlockStallTimeout,
|
|
191
196
|
newBlockStallTimeoutRealtime,
|
|
@@ -193,7 +198,7 @@ let make = (
|
|
|
193
198
|
reducedPollingInterval,
|
|
194
199
|
getHeightRetryInterval,
|
|
195
200
|
recoveryTimeout,
|
|
196
|
-
statusStart:
|
|
201
|
+
statusStart: Performance.now(),
|
|
197
202
|
status: Idle,
|
|
198
203
|
hasRealtime,
|
|
199
204
|
committedRateLimitTimeMs: 0.0,
|
|
@@ -211,9 +216,9 @@ let trackNewStatus = (sourceManager: t, ~newStatus) => {
|
|
|
211
216
|
}
|
|
212
217
|
promCounter->Prometheus.SafeCounter.handleFloat(
|
|
213
218
|
~labels=sourceManager.activeSource.chain->ChainMap.Chain.toChainId,
|
|
214
|
-
~value=sourceManager.statusStart->
|
|
219
|
+
~value=sourceManager.statusStart->Performance.secondsSince,
|
|
215
220
|
)
|
|
216
|
-
sourceManager.statusStart =
|
|
221
|
+
sourceManager.statusStart = Performance.now()
|
|
217
222
|
sourceManager.status = newStatus
|
|
218
223
|
}
|
|
219
224
|
|
|
@@ -496,13 +501,14 @@ let waitForNewBlock = async (sourceManager: t, ~knownHeight, ~isRealtime, ~reduc
|
|
|
496
501
|
"knownHeight": knownHeight,
|
|
497
502
|
},
|
|
498
503
|
)
|
|
499
|
-
if
|
|
504
|
+
if !sourceManager.waitingLogged {
|
|
500
505
|
logger->Logging.childTrace(
|
|
501
|
-
|
|
502
|
-
|
|
506
|
+
reducedPolling
|
|
507
|
+
? `Waiting for new blocks with reduced polling (${(sourceManager.reducedPollingInterval / 1000)
|
|
508
|
+
->Int.toString}s). Chain is caught up, waiting for other chains to backfill.`
|
|
509
|
+
: "Initiating check for new blocks.",
|
|
503
510
|
)
|
|
504
|
-
|
|
505
|
-
logger->Logging.childTrace("Initiating check for new blocks.")
|
|
511
|
+
sourceManager.waitingLogged = true
|
|
506
512
|
}
|
|
507
513
|
|
|
508
514
|
let mainSources = sourceManager->getNextSources(~isRealtime)
|
|
@@ -600,6 +606,7 @@ let waitForNewBlock = async (sourceManager: t, ~knownHeight, ~isRealtime, ~reduc
|
|
|
600
606
|
"source": source.name,
|
|
601
607
|
"newBlockHeight": newBlockHeight,
|
|
602
608
|
})
|
|
609
|
+
sourceManager.waitingLogged = false
|
|
603
610
|
|
|
604
611
|
status := Done
|
|
605
612
|
|
|
@@ -669,19 +676,13 @@ let executeQuery = async (
|
|
|
669
676
|
~fromBlock=query.fromBlock,
|
|
670
677
|
~toBlock,
|
|
671
678
|
~addressesByContractName=query.addressesByContractName,
|
|
672
|
-
~
|
|
679
|
+
~contractNameByAddress=query.addressesByContractName->FetchState.deriveContractNameByAddress,
|
|
673
680
|
~partitionId=query.partitionId,
|
|
674
681
|
~knownHeight,
|
|
675
682
|
~selection=query.selection,
|
|
676
683
|
~retry,
|
|
677
684
|
~logger,
|
|
678
685
|
)
|
|
679
|
-
logger->Logging.childTrace({
|
|
680
|
-
"msg": "Fetched block range from server",
|
|
681
|
-
"toBlock": response.latestFetchedBlockNumber,
|
|
682
|
-
"numEvents": response.parsedQueueItems->Array.length,
|
|
683
|
-
"stats": response.stats,
|
|
684
|
-
})
|
|
685
686
|
sourceState.lastFailedAt = None
|
|
686
687
|
responseRef := Some(response)
|
|
687
688
|
} catch {
|