envio 3.0.0-alpha.21 → 3.0.0-alpha.23
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 +3 -3
- package/bin.mjs +2 -48
- package/evm.schema.json +67 -0
- package/fuel.schema.json +67 -0
- package/index.d.ts +822 -38
- package/index.js +5 -3
- package/package.json +10 -8
- package/rescript.json +5 -9
- package/src/Address.res +4 -5
- package/src/Address.res.mjs +9 -12
- package/src/Api.res +15 -0
- package/src/Api.res.mjs +20 -0
- package/src/Batch.res +32 -34
- package/src/Batch.res.mjs +172 -187
- package/src/Bin.res +89 -0
- package/src/Bin.res.mjs +97 -0
- package/src/ChainFetcher.res +33 -57
- package/src/ChainFetcher.res.mjs +197 -227
- package/src/ChainManager.res +6 -14
- package/src/ChainManager.res.mjs +74 -85
- package/src/ChainMap.res +14 -16
- package/src/ChainMap.res.mjs +38 -38
- package/src/Config.res +193 -135
- package/src/Config.res.mjs +566 -592
- package/src/Core.res +182 -0
- package/src/Core.res.mjs +207 -0
- package/src/Ecosystem.res +25 -4
- package/src/Ecosystem.res.mjs +12 -13
- package/src/Env.res +20 -13
- package/src/Env.res.mjs +124 -113
- package/src/EnvSafe.res +269 -0
- package/src/EnvSafe.res.mjs +296 -0
- package/src/EnvSafe.resi +18 -0
- package/src/Envio.res +37 -26
- package/src/Envio.res.mjs +59 -60
- package/src/ErrorHandling.res +2 -2
- package/src/ErrorHandling.res.mjs +15 -15
- package/src/EventConfigBuilder.res +219 -81
- package/src/EventConfigBuilder.res.mjs +259 -202
- package/src/EventProcessing.res +27 -38
- package/src/EventProcessing.res.mjs +165 -183
- package/src/EventUtils.res +11 -11
- package/src/EventUtils.res.mjs +21 -22
- package/src/EvmTypes.res +0 -1
- package/src/EvmTypes.res.mjs +5 -5
- package/src/FetchState.res +360 -256
- package/src/FetchState.res.mjs +958 -914
- package/src/GlobalState.res +365 -351
- package/src/GlobalState.res.mjs +958 -992
- package/src/GlobalStateManager.res +1 -2
- package/src/GlobalStateManager.res.mjs +36 -44
- package/src/HandlerLoader.res +107 -23
- package/src/HandlerLoader.res.mjs +128 -38
- package/src/HandlerRegister.res +127 -103
- package/src/HandlerRegister.res.mjs +164 -164
- package/src/HandlerRegister.resi +12 -4
- package/src/Hasura.res +35 -22
- package/src/Hasura.res.mjs +158 -167
- package/src/InMemoryStore.res +20 -27
- package/src/InMemoryStore.res.mjs +64 -80
- package/src/InMemoryTable.res +34 -39
- package/src/InMemoryTable.res.mjs +165 -170
- package/src/Internal.res +52 -33
- package/src/Internal.res.mjs +84 -81
- package/src/LazyLoader.res.mjs +55 -61
- package/src/LoadLayer.res +77 -78
- package/src/LoadLayer.res.mjs +160 -189
- package/src/LoadManager.res +16 -21
- package/src/LoadManager.res.mjs +79 -84
- package/src/LogSelection.res +236 -68
- package/src/LogSelection.res.mjs +211 -141
- package/src/Logging.res +13 -9
- package/src/Logging.res.mjs +130 -143
- package/src/Main.res +430 -51
- package/src/Main.res.mjs +530 -271
- package/src/Persistence.res +80 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +294 -167
- package/src/PgStorage.res.mjs +799 -817
- package/src/Prometheus.res +50 -58
- package/src/Prometheus.res.mjs +345 -373
- package/src/ReorgDetection.res +22 -24
- package/src/ReorgDetection.res.mjs +100 -106
- package/src/SafeCheckpointTracking.res +7 -7
- package/src/SafeCheckpointTracking.res.mjs +40 -43
- package/src/SimulateItems.res +41 -49
- package/src/SimulateItems.res.mjs +257 -272
- package/src/Sink.res +2 -2
- package/src/Sink.res.mjs +22 -26
- package/src/TableIndices.res +1 -2
- package/src/TableIndices.res.mjs +42 -48
- package/src/TestIndexer.res +196 -189
- package/src/TestIndexer.res.mjs +536 -536
- package/src/TestIndexerProxyStorage.res +16 -16
- package/src/TestIndexerProxyStorage.res.mjs +99 -122
- package/src/TestIndexerWorker.res +4 -0
- package/src/TestIndexerWorker.res.mjs +7 -0
- package/src/Throttler.res +3 -3
- package/src/Throttler.res.mjs +23 -24
- package/src/Time.res +1 -1
- package/src/Time.res.mjs +18 -21
- package/src/TopicFilter.res +3 -3
- package/src/TopicFilter.res.mjs +29 -30
- package/src/UserContext.res +93 -54
- package/src/UserContext.res.mjs +197 -182
- package/src/Utils.res +141 -86
- package/src/Utils.res.mjs +334 -295
- package/src/bindings/BigDecimal.res +0 -2
- package/src/bindings/BigDecimal.res.mjs +19 -23
- package/src/bindings/ClickHouse.res +28 -27
- package/src/bindings/ClickHouse.res.mjs +243 -240
- package/src/bindings/DateFns.res +11 -11
- package/src/bindings/DateFns.res.mjs +7 -7
- package/src/bindings/EventSource.res.mjs +2 -2
- package/src/bindings/Express.res +2 -5
- package/src/bindings/Hrtime.res +2 -2
- package/src/bindings/Hrtime.res.mjs +30 -32
- package/src/bindings/Lodash.res.mjs +1 -1
- package/src/bindings/NodeJs.res +14 -9
- package/src/bindings/NodeJs.res.mjs +20 -20
- package/src/bindings/Pino.res +8 -10
- package/src/bindings/Pino.res.mjs +40 -43
- package/src/bindings/Postgres.res +7 -5
- package/src/bindings/Postgres.res.mjs +9 -9
- package/src/bindings/PromClient.res +17 -2
- package/src/bindings/PromClient.res.mjs +30 -7
- package/src/bindings/SDSL.res.mjs +2 -2
- package/src/bindings/Viem.res +4 -4
- package/src/bindings/Viem.res.mjs +20 -22
- package/src/bindings/Vitest.res +1 -1
- package/src/bindings/Vitest.res.mjs +2 -2
- package/src/bindings/WebSocket.res +1 -1
- package/src/db/EntityHistory.res +9 -3
- package/src/db/EntityHistory.res.mjs +84 -59
- package/src/db/InternalTable.res +62 -60
- package/src/db/InternalTable.res.mjs +271 -203
- package/src/db/Schema.res +1 -2
- package/src/db/Schema.res.mjs +28 -32
- package/src/db/Table.res +28 -27
- package/src/db/Table.res.mjs +276 -292
- package/src/sources/EventRouter.res +21 -16
- package/src/sources/EventRouter.res.mjs +55 -57
- package/src/sources/Evm.res +17 -1
- package/src/sources/Evm.res.mjs +16 -8
- package/src/sources/EvmChain.res +15 -17
- package/src/sources/EvmChain.res.mjs +40 -42
- package/src/sources/Fuel.res +14 -1
- package/src/sources/Fuel.res.mjs +16 -8
- package/src/sources/FuelSDK.res +1 -1
- package/src/sources/FuelSDK.res.mjs +6 -8
- package/src/sources/HyperFuel.res +8 -10
- package/src/sources/HyperFuel.res.mjs +113 -123
- package/src/sources/HyperFuelClient.res.mjs +6 -7
- package/src/sources/HyperFuelSource.res +19 -20
- package/src/sources/HyperFuelSource.res.mjs +339 -356
- package/src/sources/HyperSync.res +11 -13
- package/src/sources/HyperSync.res.mjs +206 -220
- package/src/sources/HyperSyncClient.res +5 -7
- package/src/sources/HyperSyncClient.res.mjs +70 -75
- package/src/sources/HyperSyncHeightStream.res +8 -9
- package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
- package/src/sources/HyperSyncJsonApi.res +18 -15
- package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
- package/src/sources/HyperSyncSource.res +17 -21
- package/src/sources/HyperSyncSource.res.mjs +268 -290
- package/src/sources/Rpc.res +5 -5
- package/src/sources/Rpc.res.mjs +168 -192
- package/src/sources/RpcSource.res +166 -167
- package/src/sources/RpcSource.res.mjs +972 -1046
- package/src/sources/RpcWebSocketHeightStream.res +10 -11
- package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
- package/src/sources/SimulateSource.res +1 -1
- package/src/sources/SimulateSource.res.mjs +35 -38
- package/src/sources/Source.res +1 -1
- package/src/sources/Source.res.mjs +3 -3
- package/src/sources/SourceManager.res +39 -20
- package/src/sources/SourceManager.res.mjs +340 -371
- package/src/sources/SourceManager.resi +2 -1
- package/src/sources/Svm.res +12 -5
- package/src/sources/Svm.res.mjs +44 -41
- package/src/tui/Tui.res +23 -12
- package/src/tui/Tui.res.mjs +292 -290
- package/src/tui/bindings/Ink.res +2 -4
- package/src/tui/bindings/Ink.res.mjs +35 -41
- package/src/tui/components/BufferedProgressBar.res +7 -7
- package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
- package/src/tui/components/CustomHooks.res +1 -2
- package/src/tui/components/CustomHooks.res.mjs +102 -122
- package/src/tui/components/Messages.res +1 -2
- package/src/tui/components/Messages.res.mjs +38 -42
- package/src/tui/components/SyncETA.res +10 -11
- package/src/tui/components/SyncETA.res.mjs +178 -196
- package/src/tui/components/TuiData.res +1 -1
- package/src/tui/components/TuiData.res.mjs +7 -6
- package/src/vendored/Rest.res +52 -66
- package/src/vendored/Rest.res.mjs +324 -364
- package/svm.schema.json +67 -0
- package/src/Address.gen.ts +0 -8
- package/src/Config.gen.ts +0 -19
- package/src/Envio.gen.ts +0 -55
- package/src/EvmTypes.gen.ts +0 -6
- package/src/InMemoryStore.gen.ts +0 -6
- package/src/Internal.gen.ts +0 -64
- package/src/PgStorage.gen.ts +0 -10
- package/src/PgStorage.res.d.mts +0 -5
- package/src/Types.ts +0 -56
- package/src/bindings/BigDecimal.gen.ts +0 -14
- package/src/bindings/BigDecimal.res.d.mts +0 -5
- package/src/bindings/BigInt.gen.ts +0 -10
- package/src/bindings/BigInt.res +0 -70
- package/src/bindings/BigInt.res.d.mts +0 -5
- package/src/bindings/BigInt.res.mjs +0 -154
- package/src/bindings/Ethers.res.d.mts +0 -5
- package/src/bindings/Pino.gen.ts +0 -17
- package/src/bindings/Postgres.gen.ts +0 -8
- package/src/bindings/Postgres.res.d.mts +0 -5
- package/src/bindings/Promise.res +0 -67
- package/src/bindings/Promise.res.mjs +0 -26
- package/src/db/InternalTable.gen.ts +0 -36
- package/src/sources/HyperSyncClient.gen.ts +0 -19
package/src/EventProcessing.res
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
open Belt
|
|
2
|
-
|
|
3
1
|
let allChainsEventsProcessedToEndblock = (chainFetchers: ChainMap.t<ChainFetcher.t>) => {
|
|
4
2
|
chainFetchers
|
|
5
3
|
->ChainMap.values
|
|
@@ -7,7 +5,7 @@ let allChainsEventsProcessedToEndblock = (chainFetchers: ChainMap.t<ChainFetcher
|
|
|
7
5
|
}
|
|
8
6
|
|
|
9
7
|
let computeChainsState = (chainFetchers: ChainMap.t<ChainFetcher.t>): Internal.chains => {
|
|
10
|
-
let chains =
|
|
8
|
+
let chains = Dict.make()
|
|
11
9
|
|
|
12
10
|
chainFetchers
|
|
13
11
|
->ChainMap.entries
|
|
@@ -15,7 +13,7 @@ let computeChainsState = (chainFetchers: ChainMap.t<ChainFetcher.t>): Internal.c
|
|
|
15
13
|
let chainId = chain->ChainMap.Chain.toChainId->Int.toString
|
|
16
14
|
let isLive = chainFetcher->ChainFetcher.isReady
|
|
17
15
|
|
|
18
|
-
chains->
|
|
16
|
+
chains->Dict.set(
|
|
19
17
|
chainId,
|
|
20
18
|
{
|
|
21
19
|
Internal.id: chain->ChainMap.Chain.toChainId,
|
|
@@ -30,26 +28,19 @@ let computeChainsState = (chainFetchers: ChainMap.t<ChainFetcher.t>): Internal.c
|
|
|
30
28
|
let convertFieldsToJson = (fields: option<dict<unknown>>) => {
|
|
31
29
|
switch fields {
|
|
32
30
|
| None => %raw(`{}`)
|
|
33
|
-
| Some(fields) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
->BigInt.toString
|
|
47
|
-
->(Utils.magic: string => unknown)
|
|
48
|
-
: value,
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
new->(Utils.magic: dict<unknown> => Js.Json.t)
|
|
52
|
-
}
|
|
31
|
+
| Some(fields) =>
|
|
32
|
+
// Convert bigint fields to string. There are no fields with nested
|
|
33
|
+
// bigints, so iterating only the top level is safe.
|
|
34
|
+
fields
|
|
35
|
+
->Utils.Dict.mapValues(value =>
|
|
36
|
+
typeof(value) === #bigint
|
|
37
|
+
? value
|
|
38
|
+
->(Utils.magic: unknown => bigint)
|
|
39
|
+
->BigInt.toString
|
|
40
|
+
->(Utils.magic: string => unknown)
|
|
41
|
+
: value
|
|
42
|
+
)
|
|
43
|
+
->(Utils.magic: dict<unknown> => JSON.t)
|
|
53
44
|
}
|
|
54
45
|
}
|
|
55
46
|
|
|
@@ -77,7 +68,7 @@ let addItemToRawEvents = (
|
|
|
77
68
|
let params =
|
|
78
69
|
params
|
|
79
70
|
->S.reverseConvertOrThrow(eventConfig.paramsRawEventSchema)
|
|
80
|
-
->(Utils.magic: unknown =>
|
|
71
|
+
->(Utils.magic: unknown => JSON.t)
|
|
81
72
|
let params = if params === %raw(`null`) {
|
|
82
73
|
// Should probably make the params field nullable
|
|
83
74
|
// But this is currently needed to make events
|
|
@@ -149,7 +140,7 @@ let runEventHandlerOrThrow = async (
|
|
|
149
140
|
contextParams.isResolved = true
|
|
150
141
|
} catch {
|
|
151
142
|
| exn =>
|
|
152
|
-
|
|
143
|
+
throw(
|
|
153
144
|
ProcessingError({
|
|
154
145
|
message: "Unexpected error in the event handler. Please handle the error to keep the indexer running smoothly.",
|
|
155
146
|
item,
|
|
@@ -199,7 +190,7 @@ let runHandlerOrThrow = async (
|
|
|
199
190
|
contextParams.isResolved = true
|
|
200
191
|
} catch {
|
|
201
192
|
| exn =>
|
|
202
|
-
|
|
193
|
+
throw(
|
|
203
194
|
ProcessingError({
|
|
204
195
|
message: "Unexpected error in the block handler. Please handle the error to keep the indexer running smoothly.",
|
|
205
196
|
item,
|
|
@@ -249,12 +240,11 @@ let preloadBatchOrThrow = async (
|
|
|
249
240
|
let itemIdx = ref(0)
|
|
250
241
|
|
|
251
242
|
for checkpointIdx in 0 to batch.checkpointIds->Array.length - 1 {
|
|
252
|
-
let checkpointId = batch.checkpointIds->
|
|
253
|
-
let checkpointEventsProcessed =
|
|
254
|
-
batch.checkpointEventsProcessed->Js.Array2.unsafe_get(checkpointIdx)
|
|
243
|
+
let checkpointId = batch.checkpointIds->Array.getUnsafe(checkpointIdx)
|
|
244
|
+
let checkpointEventsProcessed = batch.checkpointEventsProcessed->Array.getUnsafe(checkpointIdx)
|
|
255
245
|
|
|
256
246
|
for idx in 0 to checkpointEventsProcessed - 1 {
|
|
257
|
-
let item = batch.items->
|
|
247
|
+
let item = batch.items->Array.getUnsafe(itemIdx.contents + idx)
|
|
258
248
|
switch item {
|
|
259
249
|
| Event({eventConfig: {handler, contractName, name: eventName}, event}) =>
|
|
260
250
|
switch handler {
|
|
@@ -287,7 +277,7 @@ let preloadBatchOrThrow = async (
|
|
|
287
277
|
~event=eventName,
|
|
288
278
|
)
|
|
289
279
|
})
|
|
290
|
-
->Promise.silentCatch,
|
|
280
|
+
->Utils.Promise.silentCatch,
|
|
291
281
|
// Must have Promise.catch as well as normal catch,
|
|
292
282
|
// because if user throws an error before await in the handler,
|
|
293
283
|
// it won't create a rejected promise
|
|
@@ -316,7 +306,7 @@ let preloadBatchOrThrow = async (
|
|
|
316
306
|
config,
|
|
317
307
|
}),
|
|
318
308
|
)
|
|
319
|
-
})->Promise.silentCatch,
|
|
309
|
+
})->Utils.Promise.silentCatch,
|
|
320
310
|
)
|
|
321
311
|
} catch {
|
|
322
312
|
| _ => ()
|
|
@@ -341,12 +331,11 @@ let runBatchHandlersOrThrow = async (
|
|
|
341
331
|
let itemIdx = ref(0)
|
|
342
332
|
|
|
343
333
|
for checkpointIdx in 0 to batch.checkpointIds->Array.length - 1 {
|
|
344
|
-
let checkpointId = batch.checkpointIds->
|
|
345
|
-
let checkpointEventsProcessed =
|
|
346
|
-
batch.checkpointEventsProcessed->Js.Array2.unsafe_get(checkpointIdx)
|
|
334
|
+
let checkpointId = batch.checkpointIds->Array.getUnsafe(checkpointIdx)
|
|
335
|
+
let checkpointEventsProcessed = batch.checkpointEventsProcessed->Array.getUnsafe(checkpointIdx)
|
|
347
336
|
|
|
348
337
|
for idx in 0 to checkpointEventsProcessed - 1 {
|
|
349
|
-
let item = batch.items->
|
|
338
|
+
let item = batch.items->Array.getUnsafe(itemIdx.contents + idx)
|
|
350
339
|
|
|
351
340
|
await runHandlerOrThrow(
|
|
352
341
|
item,
|
|
@@ -375,7 +364,7 @@ let registerProcessEventBatchMetrics = (
|
|
|
375
364
|
"write_time_elapsed": dbWriteDuration,
|
|
376
365
|
})
|
|
377
366
|
|
|
378
|
-
Prometheus.ProcessingBatch.registerMetrics(~loadDuration, ~handlerDuration
|
|
367
|
+
Prometheus.ProcessingBatch.registerMetrics(~loadDuration, ~handlerDuration)
|
|
379
368
|
}
|
|
380
369
|
|
|
381
370
|
type logPartitionInfo = {
|
|
@@ -4,10 +4,8 @@ import * as Utils from "./Utils.res.mjs";
|
|
|
4
4
|
import * as Config from "./Config.res.mjs";
|
|
5
5
|
import * as Hrtime from "./bindings/Hrtime.res.mjs";
|
|
6
6
|
import * as Logging from "./Logging.res.mjs";
|
|
7
|
-
import * as $$Promise from "./bindings/Promise.res.mjs";
|
|
8
7
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
9
8
|
import * as Ecosystem from "./Ecosystem.res.mjs";
|
|
10
|
-
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
11
9
|
import * as EventUtils from "./EventUtils.res.mjs";
|
|
12
10
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
13
11
|
import * as Persistence from "./Persistence.res.mjs";
|
|
@@ -15,63 +13,60 @@ import * as UserContext from "./UserContext.res.mjs";
|
|
|
15
13
|
import * as ChainFetcher from "./ChainFetcher.res.mjs";
|
|
16
14
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
17
15
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
18
|
-
import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
|
|
19
16
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
20
|
-
import * as
|
|
17
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
21
18
|
|
|
22
19
|
function allChainsEventsProcessedToEndblock(chainFetchers) {
|
|
23
|
-
return
|
|
24
|
-
return ChainFetcher.hasProcessedToEndblock(cf);
|
|
25
|
-
}));
|
|
20
|
+
return ChainMap.values(chainFetchers).every(ChainFetcher.hasProcessedToEndblock);
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
function computeChainsState(chainFetchers) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
let chains = {};
|
|
25
|
+
ChainMap.entries(chainFetchers).forEach(param => {
|
|
26
|
+
let chain = param[0];
|
|
27
|
+
let chainId = chain.toString();
|
|
28
|
+
let isLive = ChainFetcher.isReady(param[1]);
|
|
29
|
+
chains[chainId] = {
|
|
30
|
+
id: chain,
|
|
31
|
+
isLive: isLive
|
|
32
|
+
};
|
|
33
|
+
});
|
|
39
34
|
return chains;
|
|
40
35
|
}
|
|
41
36
|
|
|
42
37
|
function convertFieldsToJson(fields) {
|
|
43
|
-
if (fields
|
|
38
|
+
if (fields !== undefined) {
|
|
39
|
+
return Utils.Dict.mapValues(fields, value => {
|
|
40
|
+
if (typeof value === "bigint") {
|
|
41
|
+
return value.toString();
|
|
42
|
+
} else {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
44
47
|
return {};
|
|
45
48
|
}
|
|
46
|
-
var keys = Object.keys(fields);
|
|
47
|
-
var $$new = {};
|
|
48
|
-
for(var i = 0 ,i_finish = keys.length; i < i_finish; ++i){
|
|
49
|
-
var key = keys[i];
|
|
50
|
-
var value = fields[key];
|
|
51
|
-
$$new[key] = typeof value === "bigint" ? value.toString() : value;
|
|
52
|
-
}
|
|
53
|
-
return $$new;
|
|
54
49
|
}
|
|
55
50
|
|
|
56
51
|
function addItemToRawEvents(eventItem, inMemoryStore, config) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
let event = eventItem.event;
|
|
53
|
+
let block = event.block;
|
|
54
|
+
let logIndex = event.logIndex;
|
|
55
|
+
let blockNumber = eventItem.blockNumber;
|
|
56
|
+
let chain = eventItem.chain;
|
|
57
|
+
let eventConfig = eventItem.eventConfig;
|
|
58
|
+
let eventId = EventUtils.packEventIndex(blockNumber, logIndex);
|
|
59
|
+
let blockFields = convertFieldsToJson(block);
|
|
60
|
+
let transactionFields = convertFieldsToJson(event.transaction);
|
|
66
61
|
config.ecosystem.cleanUpRawEventFieldsInPlace(blockFields);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
let params = S$RescriptSchema.reverseConvertOrThrow(event.params, eventConfig.paramsRawEventSchema);
|
|
63
|
+
let params$1 = params === null ? "null" : params;
|
|
64
|
+
let rawEvent_event_name = eventConfig.name;
|
|
65
|
+
let rawEvent_contract_name = eventConfig.contractName;
|
|
66
|
+
let rawEvent_src_address = event.srcAddress;
|
|
67
|
+
let rawEvent_block_hash = config.ecosystem.getId(block);
|
|
68
|
+
let rawEvent_block_timestamp = eventItem.timestamp;
|
|
69
|
+
let rawEvent = {
|
|
75
70
|
chain_id: chain,
|
|
76
71
|
event_id: eventId,
|
|
77
72
|
event_name: rawEvent_event_name,
|
|
@@ -85,19 +80,19 @@ function addItemToRawEvents(eventItem, inMemoryStore, config) {
|
|
|
85
80
|
transaction_fields: transactionFields,
|
|
86
81
|
params: params$1
|
|
87
82
|
};
|
|
88
|
-
|
|
83
|
+
let eventIdStr = eventId.toString();
|
|
89
84
|
InMemoryTable.set(inMemoryStore.rawEvents, {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
chainId: chain,
|
|
86
|
+
eventId: eventIdStr
|
|
87
|
+
}, rawEvent);
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
|
|
90
|
+
let ProcessingError = /* @__PURE__ */Primitive_exceptions.create("EventProcessing.ProcessingError");
|
|
96
91
|
|
|
97
92
|
async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, persistence, shouldSaveHistory, chains, config) {
|
|
98
|
-
|
|
93
|
+
let timeBeforeHandler = Hrtime.makeTimer();
|
|
99
94
|
try {
|
|
100
|
-
|
|
95
|
+
let contextParams = {
|
|
101
96
|
item: item,
|
|
102
97
|
checkpointId: checkpointId,
|
|
103
98
|
inMemoryStore: inMemoryStore,
|
|
@@ -110,39 +105,38 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore
|
|
|
110
105
|
isResolved: false
|
|
111
106
|
};
|
|
112
107
|
await handler({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
event: item.event,
|
|
109
|
+
context: UserContext.getHandlerContext(contextParams)
|
|
110
|
+
});
|
|
116
111
|
contextParams.isResolved = true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
112
|
+
} catch (raw_exn) {
|
|
113
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
120
114
|
throw {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
RE_EXN_ID: ProcessingError,
|
|
116
|
+
message: "Unexpected error in the event handler. Please handle the error to keep the indexer running smoothly.",
|
|
117
|
+
exn: exn,
|
|
118
|
+
item: item,
|
|
119
|
+
Error: new Error()
|
|
120
|
+
};
|
|
127
121
|
}
|
|
128
|
-
|
|
122
|
+
let handlerDuration = Hrtime.toSecondsFloat(Hrtime.timeSince(timeBeforeHandler));
|
|
129
123
|
return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
|
|
130
124
|
}
|
|
131
125
|
|
|
132
126
|
async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains) {
|
|
133
127
|
if (item.kind === 0) {
|
|
134
|
-
|
|
128
|
+
let handler = item.eventConfig.handler;
|
|
135
129
|
if (handler !== undefined) {
|
|
136
130
|
await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, ctx.persistence, shouldSaveHistory, chains, ctx.config);
|
|
137
131
|
}
|
|
138
132
|
if (ctx.config.enableRawEvents) {
|
|
139
133
|
return addItemToRawEvents(item, inMemoryStore, ctx.config);
|
|
140
134
|
} else {
|
|
141
|
-
return
|
|
135
|
+
return;
|
|
142
136
|
}
|
|
143
137
|
}
|
|
144
138
|
try {
|
|
145
|
-
|
|
139
|
+
let contextParams = {
|
|
146
140
|
item: item,
|
|
147
141
|
checkpointId: checkpointId,
|
|
148
142
|
inMemoryStore: inMemoryStore,
|
|
@@ -156,77 +150,69 @@ async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
|
|
|
156
150
|
};
|
|
157
151
|
await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, ctx.config.ecosystem, UserContext.getHandlerContext(contextParams)));
|
|
158
152
|
contextParams.isResolved = true;
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
153
|
+
return;
|
|
154
|
+
} catch (raw_exn) {
|
|
155
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
163
156
|
throw {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
157
|
+
RE_EXN_ID: ProcessingError,
|
|
158
|
+
message: "Unexpected error in the block handler. Please handle the error to keep the indexer running smoothly.",
|
|
159
|
+
exn: exn,
|
|
160
|
+
item: item,
|
|
161
|
+
Error: new Error()
|
|
162
|
+
};
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
165
|
|
|
173
166
|
async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMemoryStore, chains) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
for(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
for(
|
|
180
|
-
|
|
167
|
+
let promises = [];
|
|
168
|
+
let itemIdx = 0;
|
|
169
|
+
for (let checkpointIdx = 0, checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx) {
|
|
170
|
+
let checkpointId = batch.checkpointIds[checkpointIdx];
|
|
171
|
+
let checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
|
|
172
|
+
for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
|
|
173
|
+
let item = batch.items[itemIdx + idx | 0];
|
|
181
174
|
if (item.kind === 0) {
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
let match = item.eventConfig;
|
|
176
|
+
let handler = match.handler;
|
|
184
177
|
if (handler !== undefined) {
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
let contractName = match.contractName;
|
|
179
|
+
let eventName = match.name;
|
|
187
180
|
try {
|
|
188
|
-
|
|
189
|
-
promises.push(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
Prometheus.PreloadHandler.endOperation(timerRef, contractName, eventName);
|
|
206
|
-
}
|
|
207
|
-
}(eventName,contractName,timerRef)))));
|
|
208
|
-
}
|
|
209
|
-
catch (exn){
|
|
181
|
+
let timerRef = Prometheus.PreloadHandler.startOperation(contractName, eventName);
|
|
182
|
+
promises.push(Utils.$$Promise.silentCatch(handler({
|
|
183
|
+
event: item.event,
|
|
184
|
+
context: UserContext.getHandlerContext({
|
|
185
|
+
item: item,
|
|
186
|
+
checkpointId: checkpointId,
|
|
187
|
+
inMemoryStore: inMemoryStore,
|
|
188
|
+
loadManager: loadManager,
|
|
189
|
+
persistence: persistence,
|
|
190
|
+
isPreload: true,
|
|
191
|
+
shouldSaveHistory: false,
|
|
192
|
+
chains: chains,
|
|
193
|
+
config: config,
|
|
194
|
+
isResolved: false
|
|
195
|
+
})
|
|
196
|
+
}).then(() => Prometheus.PreloadHandler.endOperation(timerRef, contractName, eventName))));
|
|
197
|
+
} catch (exn) {
|
|
210
198
|
|
|
211
199
|
}
|
|
212
200
|
}
|
|
213
|
-
|
|
214
201
|
} else {
|
|
215
202
|
try {
|
|
216
|
-
promises.push(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
catch (exn$1){
|
|
203
|
+
promises.push(Utils.$$Promise.silentCatch(item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext({
|
|
204
|
+
item: item,
|
|
205
|
+
checkpointId: checkpointId,
|
|
206
|
+
inMemoryStore: inMemoryStore,
|
|
207
|
+
loadManager: loadManager,
|
|
208
|
+
persistence: persistence,
|
|
209
|
+
isPreload: true,
|
|
210
|
+
shouldSaveHistory: false,
|
|
211
|
+
chains: chains,
|
|
212
|
+
config: config,
|
|
213
|
+
isResolved: false
|
|
214
|
+
})))));
|
|
215
|
+
} catch (exn$1) {
|
|
230
216
|
|
|
231
217
|
}
|
|
232
218
|
}
|
|
@@ -237,12 +223,12 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
|
|
|
237
223
|
}
|
|
238
224
|
|
|
239
225
|
async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains) {
|
|
240
|
-
|
|
241
|
-
for(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
for(
|
|
245
|
-
|
|
226
|
+
let itemIdx = 0;
|
|
227
|
+
for (let checkpointIdx = 0, checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx) {
|
|
228
|
+
let checkpointId = batch.checkpointIds[checkpointIdx];
|
|
229
|
+
let checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
|
|
230
|
+
for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
|
|
231
|
+
let item = batch.items[itemIdx + idx | 0];
|
|
246
232
|
await runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains);
|
|
247
233
|
}
|
|
248
234
|
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
@@ -251,87 +237,83 @@ async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, s
|
|
|
251
237
|
|
|
252
238
|
function registerProcessEventBatchMetrics(logger, loadDuration, handlerDuration, dbWriteDuration) {
|
|
253
239
|
Logging.childTrace(logger, {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration
|
|
240
|
+
msg: "Finished processing batch",
|
|
241
|
+
loader_time_elapsed: loadDuration,
|
|
242
|
+
handlers_time_elapsed: handlerDuration,
|
|
243
|
+
write_time_elapsed: dbWriteDuration
|
|
244
|
+
});
|
|
245
|
+
Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration);
|
|
260
246
|
}
|
|
261
247
|
|
|
262
248
|
async function processEventBatch(batch, inMemoryStore, isInReorgThreshold, loadManager, ctx, chainFetchers) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
249
|
+
let totalBatchSize = batch.totalBatchSize;
|
|
250
|
+
let chains = computeChainsState(chainFetchers);
|
|
251
|
+
let logger = Logging.getLogger();
|
|
266
252
|
Logging.childTrace(logger, {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}))
|
|
275
|
-
});
|
|
253
|
+
msg: "Started processing batch",
|
|
254
|
+
totalBatchSize: totalBatchSize,
|
|
255
|
+
chains: Utils.Dict.mapValues(batch.progressedChainsById, chainAfterBatch => ({
|
|
256
|
+
batchSize: chainAfterBatch.batchSize,
|
|
257
|
+
progress: chainAfterBatch.progressBlockNumber
|
|
258
|
+
}))
|
|
259
|
+
});
|
|
276
260
|
try {
|
|
277
|
-
|
|
261
|
+
let timeRef = Hrtime.makeTimer();
|
|
278
262
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
279
263
|
await preloadBatchOrThrow(batch, loadManager, ctx.persistence, ctx.config, inMemoryStore, chains);
|
|
280
264
|
}
|
|
281
|
-
|
|
265
|
+
let elapsedTimeAfterLoaders = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
282
266
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
283
267
|
await runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, Config.shouldSaveHistory(ctx.config, isInReorgThreshold), chains);
|
|
284
268
|
}
|
|
285
|
-
|
|
269
|
+
let elapsedTimeAfterProcessing = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
286
270
|
try {
|
|
287
271
|
await Persistence.writeBatch(ctx.persistence, batch, ctx.config, inMemoryStore, isInReorgThreshold);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
272
|
+
let elapsedTimeAfterDbWrite = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
273
|
+
let handlerDuration = elapsedTimeAfterProcessing - elapsedTimeAfterLoaders;
|
|
274
|
+
let dbWriteDuration = elapsedTimeAfterDbWrite - elapsedTimeAfterProcessing;
|
|
291
275
|
registerProcessEventBatchMetrics(logger, elapsedTimeAfterLoaders, handlerDuration, dbWriteDuration);
|
|
292
276
|
return {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
277
|
+
TAG: "Ok",
|
|
278
|
+
_0: undefined
|
|
279
|
+
};
|
|
280
|
+
} catch (raw_exn) {
|
|
281
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
299
282
|
if (exn.RE_EXN_ID === Persistence.StorageError) {
|
|
300
283
|
return {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
284
|
+
TAG: "Error",
|
|
285
|
+
_0: ErrorHandling.make(exn.reason, logger, exn.message)
|
|
286
|
+
};
|
|
304
287
|
} else {
|
|
305
288
|
return {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
289
|
+
TAG: "Error",
|
|
290
|
+
_0: ErrorHandling.make(exn, logger, "Failed writing batch to database")
|
|
291
|
+
};
|
|
309
292
|
}
|
|
310
293
|
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
|
|
294
|
+
} catch (raw_exn$1) {
|
|
295
|
+
let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
|
|
314
296
|
if (exn$1.RE_EXN_ID === ProcessingError) {
|
|
315
297
|
return {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
298
|
+
TAG: "Error",
|
|
299
|
+
_0: ErrorHandling.make(exn$1.exn, Logging.getItemLogger(exn$1.item), exn$1.message)
|
|
300
|
+
};
|
|
319
301
|
}
|
|
320
302
|
throw exn$1;
|
|
321
303
|
}
|
|
322
304
|
}
|
|
323
305
|
|
|
324
306
|
export {
|
|
325
|
-
allChainsEventsProcessedToEndblock
|
|
326
|
-
computeChainsState
|
|
327
|
-
convertFieldsToJson
|
|
328
|
-
addItemToRawEvents
|
|
329
|
-
ProcessingError
|
|
330
|
-
runEventHandlerOrThrow
|
|
331
|
-
runHandlerOrThrow
|
|
332
|
-
preloadBatchOrThrow
|
|
333
|
-
runBatchHandlersOrThrow
|
|
334
|
-
registerProcessEventBatchMetrics
|
|
335
|
-
processEventBatch
|
|
307
|
+
allChainsEventsProcessedToEndblock,
|
|
308
|
+
computeChainsState,
|
|
309
|
+
convertFieldsToJson,
|
|
310
|
+
addItemToRawEvents,
|
|
311
|
+
ProcessingError,
|
|
312
|
+
runEventHandlerOrThrow,
|
|
313
|
+
runHandlerOrThrow,
|
|
314
|
+
preloadBatchOrThrow,
|
|
315
|
+
runBatchHandlersOrThrow,
|
|
316
|
+
registerProcessEventBatchMetrics,
|
|
317
|
+
processEventBatch,
|
|
336
318
|
}
|
|
337
319
|
/* Utils Not a pure module */
|