envio 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +164 -30
- package/bin.mjs +49 -0
- package/evm.schema.json +79 -169
- package/fuel.schema.json +50 -21
- package/index.d.ts +497 -1
- package/index.js +4 -0
- package/package.json +42 -31
- package/rescript.json +4 -1
- package/src/Batch.res +11 -8
- package/src/Batch.res.mjs +11 -9
- package/src/ChainFetcher.res +531 -0
- package/src/ChainFetcher.res.mjs +339 -0
- package/src/ChainManager.res +190 -0
- package/src/ChainManager.res.mjs +166 -0
- package/src/Change.res +3 -3
- package/src/Config.gen.ts +19 -0
- package/src/Config.res +737 -22
- package/src/Config.res.mjs +703 -26
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +9 -124
- package/src/Ecosystem.res.mjs +19 -160
- package/src/Env.res +30 -74
- package/src/Env.res.mjs +25 -87
- package/src/Envio.gen.ts +3 -1
- package/src/Envio.res +20 -9
- package/src/EventProcessing.res +469 -0
- package/src/EventProcessing.res.mjs +337 -0
- package/src/EvmTypes.gen.ts +6 -0
- package/src/EvmTypes.res +1 -0
- package/src/FetchState.res +1256 -639
- package/src/FetchState.res.mjs +1135 -612
- package/src/GlobalState.res +1190 -0
- package/src/GlobalState.res.mjs +1183 -0
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/HandlerLoader.res +89 -0
- package/src/HandlerLoader.res.mjs +79 -0
- package/src/HandlerRegister.res +357 -0
- package/src/HandlerRegister.res.mjs +299 -0
- package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
- package/src/Hasura.res +111 -175
- package/src/Hasura.res.mjs +88 -150
- package/src/InMemoryStore.res +1 -1
- package/src/InMemoryStore.res.mjs +3 -3
- package/src/InMemoryTable.res +1 -1
- package/src/InMemoryTable.res.mjs +1 -1
- package/src/Internal.gen.ts +4 -0
- package/src/Internal.res +230 -12
- package/src/Internal.res.mjs +115 -1
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Logging.res +21 -7
- package/src/Logging.res.mjs +16 -8
- package/src/Main.res +377 -0
- package/src/Main.res.mjs +339 -0
- package/src/Persistence.res +7 -21
- package/src/Persistence.res.mjs +3 -3
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +116 -69
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +93 -50
- package/src/Prometheus.res +294 -224
- package/src/Prometheus.res.mjs +353 -340
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/Sink.res +4 -2
- package/src/Sink.res.mjs +2 -1
- package/src/TableIndices.res +0 -1
- package/src/TestIndexer.res +692 -0
- package/src/TestIndexer.res.mjs +527 -0
- package/src/TestIndexerProxyStorage.res +205 -0
- package/src/TestIndexerProxyStorage.res.mjs +151 -0
- package/src/TopicFilter.res +1 -1
- package/src/Types.ts +1 -1
- package/src/UserContext.res +424 -0
- package/src/UserContext.res.mjs +279 -0
- package/src/Utils.res +97 -26
- package/src/Utils.res.mjs +91 -44
- package/src/bindings/BigInt.res +10 -0
- package/src/bindings/BigInt.res.mjs +15 -0
- package/src/bindings/ClickHouse.res +120 -23
- package/src/bindings/ClickHouse.res.mjs +118 -28
- package/src/bindings/DateFns.res +74 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/EventSource.res +8 -1
- package/src/bindings/EventSource.res.mjs +8 -1
- package/src/bindings/Express.res +1 -0
- package/src/bindings/Hrtime.res +14 -1
- package/src/bindings/Hrtime.res.mjs +22 -2
- package/src/bindings/Hrtime.resi +4 -0
- package/src/bindings/Lodash.res +0 -1
- package/src/bindings/NodeJs.res +49 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +24 -10
- package/src/bindings/Pino.res.mjs +14 -8
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +5 -1
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/PromClient.res +0 -10
- package/src/bindings/PromClient.res.mjs +0 -3
- package/src/bindings/Vitest.res +142 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/WebSocket.res +27 -0
- package/src/bindings/WebSocket.res.mjs +2 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/EntityHistory.res +7 -7
- package/src/db/EntityHistory.res.mjs +9 -9
- package/src/db/InternalTable.res +59 -111
- package/src/db/InternalTable.res.mjs +73 -104
- package/src/db/Table.res +27 -8
- package/src/db/Table.res.mjs +25 -14
- package/src/sources/Evm.res +84 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +94 -0
- package/src/sources/EvmChain.res.mjs +60 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +38 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +33 -13
- package/src/sources/HyperFuelSource.res.mjs +24 -16
- package/src/sources/HyperSync.res +36 -6
- package/src/sources/HyperSync.res.mjs +9 -7
- package/src/sources/HyperSync.resi +4 -0
- package/src/sources/HyperSyncClient.res +1 -1
- package/src/sources/HyperSyncHeightStream.res +47 -116
- package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
- package/src/sources/HyperSyncSource.res +118 -139
- package/src/sources/HyperSyncSource.res.mjs +104 -121
- package/src/sources/Rpc.res +86 -14
- package/src/sources/Rpc.res.mjs +101 -9
- package/src/sources/RpcSource.res +621 -364
- package/src/sources/RpcSource.res.mjs +843 -410
- package/src/sources/RpcWebSocketHeightStream.res +181 -0
- package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
- package/src/sources/Source.res +7 -5
- package/src/sources/SourceManager.res +325 -225
- package/src/sources/SourceManager.res.mjs +314 -171
- package/src/sources/SourceManager.resi +17 -6
- package/src/sources/Svm.res +81 -0
- package/src/sources/Svm.res.mjs +90 -0
- package/src/tui/Tui.res +247 -0
- package/src/tui/Tui.res.mjs +337 -0
- package/src/tui/bindings/Ink.res +371 -0
- package/src/tui/bindings/Ink.res.mjs +72 -0
- package/src/tui/bindings/Style.res +123 -0
- package/src/tui/bindings/Style.res.mjs +2 -0
- package/src/tui/components/BufferedProgressBar.res +40 -0
- package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
- package/src/tui/components/CustomHooks.res +122 -0
- package/src/tui/components/CustomHooks.res.mjs +179 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +174 -0
- package/src/tui/components/SyncETA.res.mjs +263 -0
- package/src/tui/components/TuiData.res +47 -0
- package/src/tui/components/TuiData.res.mjs +34 -0
- package/svm.schema.json +112 -0
- package/bin.js +0 -48
- package/src/EventRegister.res +0 -241
- package/src/EventRegister.res.mjs +0 -240
- package/src/bindings/Ethers.gen.ts +0 -14
- package/src/bindings/Ethers.res +0 -204
- package/src/bindings/Ethers.res.mjs +0 -130
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Utils from "./Utils.res.mjs";
|
|
4
|
+
import * as Config from "./Config.res.mjs";
|
|
5
|
+
import * as Hrtime from "./bindings/Hrtime.res.mjs";
|
|
6
|
+
import * as Logging from "./Logging.res.mjs";
|
|
7
|
+
import * as $$Promise from "./bindings/Promise.res.mjs";
|
|
8
|
+
import * as ChainMap from "./ChainMap.res.mjs";
|
|
9
|
+
import * as Ecosystem from "./Ecosystem.res.mjs";
|
|
10
|
+
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
11
|
+
import * as EventUtils from "./EventUtils.res.mjs";
|
|
12
|
+
import * as Prometheus from "./Prometheus.res.mjs";
|
|
13
|
+
import * as Persistence from "./Persistence.res.mjs";
|
|
14
|
+
import * as UserContext from "./UserContext.res.mjs";
|
|
15
|
+
import * as ChainFetcher from "./ChainFetcher.res.mjs";
|
|
16
|
+
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
17
|
+
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
18
|
+
import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
|
|
19
|
+
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
20
|
+
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
|
|
21
|
+
|
|
22
|
+
function allChainsEventsProcessedToEndblock(chainFetchers) {
|
|
23
|
+
return Belt_Array.every(ChainMap.values(chainFetchers), (function (cf) {
|
|
24
|
+
return ChainFetcher.hasProcessedToEndblock(cf);
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function computeChainsState(chainFetchers) {
|
|
29
|
+
var chains = {};
|
|
30
|
+
Belt_Array.forEach(ChainMap.entries(chainFetchers), (function (param) {
|
|
31
|
+
var chain = param[0];
|
|
32
|
+
var chainId = String(chain);
|
|
33
|
+
var isLive = ChainFetcher.isReady(param[1]);
|
|
34
|
+
chains[chainId] = {
|
|
35
|
+
id: chain,
|
|
36
|
+
isLive: isLive
|
|
37
|
+
};
|
|
38
|
+
}));
|
|
39
|
+
return chains;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function convertFieldsToJson(fields) {
|
|
43
|
+
if (fields === undefined) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
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
|
+
}
|
|
55
|
+
|
|
56
|
+
function addItemToRawEvents(eventItem, inMemoryStore, config) {
|
|
57
|
+
var $$event = eventItem.event;
|
|
58
|
+
var block = $$event.block;
|
|
59
|
+
var logIndex = $$event.logIndex;
|
|
60
|
+
var blockNumber = eventItem.blockNumber;
|
|
61
|
+
var chain = eventItem.chain;
|
|
62
|
+
var eventConfig = eventItem.eventConfig;
|
|
63
|
+
var eventId = EventUtils.packEventIndex(blockNumber, logIndex);
|
|
64
|
+
var blockFields = convertFieldsToJson(block);
|
|
65
|
+
var transactionFields = convertFieldsToJson($$event.transaction);
|
|
66
|
+
config.ecosystem.cleanUpRawEventFieldsInPlace(blockFields);
|
|
67
|
+
var params = S$RescriptSchema.reverseConvertOrThrow($$event.params, eventConfig.paramsRawEventSchema);
|
|
68
|
+
var params$1 = params === null ? "null" : params;
|
|
69
|
+
var rawEvent_event_name = eventConfig.name;
|
|
70
|
+
var rawEvent_contract_name = eventConfig.contractName;
|
|
71
|
+
var rawEvent_src_address = $$event.srcAddress;
|
|
72
|
+
var rawEvent_block_hash = config.ecosystem.getId(block);
|
|
73
|
+
var rawEvent_block_timestamp = eventItem.timestamp;
|
|
74
|
+
var rawEvent = {
|
|
75
|
+
chain_id: chain,
|
|
76
|
+
event_id: eventId,
|
|
77
|
+
event_name: rawEvent_event_name,
|
|
78
|
+
contract_name: rawEvent_contract_name,
|
|
79
|
+
block_number: blockNumber,
|
|
80
|
+
log_index: logIndex,
|
|
81
|
+
src_address: rawEvent_src_address,
|
|
82
|
+
block_hash: rawEvent_block_hash,
|
|
83
|
+
block_timestamp: rawEvent_block_timestamp,
|
|
84
|
+
block_fields: blockFields,
|
|
85
|
+
transaction_fields: transactionFields,
|
|
86
|
+
params: params$1
|
|
87
|
+
};
|
|
88
|
+
var eventIdStr = eventId.toString();
|
|
89
|
+
InMemoryTable.set(inMemoryStore.rawEvents, {
|
|
90
|
+
chainId: chain,
|
|
91
|
+
eventId: eventIdStr
|
|
92
|
+
}, rawEvent);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var ProcessingError = /* @__PURE__ */Caml_exceptions.create("EventProcessing.ProcessingError");
|
|
96
|
+
|
|
97
|
+
async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, persistence, shouldSaveHistory, chains, config) {
|
|
98
|
+
var timeBeforeHandler = Hrtime.makeTimer();
|
|
99
|
+
try {
|
|
100
|
+
var contextParams = {
|
|
101
|
+
item: item,
|
|
102
|
+
checkpointId: checkpointId,
|
|
103
|
+
inMemoryStore: inMemoryStore,
|
|
104
|
+
loadManager: loadManager,
|
|
105
|
+
persistence: persistence,
|
|
106
|
+
isPreload: false,
|
|
107
|
+
shouldSaveHistory: shouldSaveHistory,
|
|
108
|
+
chains: chains,
|
|
109
|
+
config: config,
|
|
110
|
+
isResolved: false
|
|
111
|
+
};
|
|
112
|
+
await handler({
|
|
113
|
+
event: item.event,
|
|
114
|
+
context: UserContext.getHandlerContext(contextParams)
|
|
115
|
+
});
|
|
116
|
+
contextParams.isResolved = true;
|
|
117
|
+
}
|
|
118
|
+
catch (raw_exn){
|
|
119
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
120
|
+
throw {
|
|
121
|
+
RE_EXN_ID: ProcessingError,
|
|
122
|
+
message: "Unexpected error in the event handler. Please handle the error to keep the indexer running smoothly.",
|
|
123
|
+
exn: exn,
|
|
124
|
+
item: item,
|
|
125
|
+
Error: new Error()
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
var handlerDuration = Hrtime.toSecondsFloat(Hrtime.timeSince(timeBeforeHandler));
|
|
129
|
+
return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains) {
|
|
133
|
+
if (item.kind === 0) {
|
|
134
|
+
var handler = item.eventConfig.handler;
|
|
135
|
+
if (handler !== undefined) {
|
|
136
|
+
await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, ctx.persistence, shouldSaveHistory, chains, ctx.config);
|
|
137
|
+
}
|
|
138
|
+
if (ctx.config.enableRawEvents) {
|
|
139
|
+
return addItemToRawEvents(item, inMemoryStore, ctx.config);
|
|
140
|
+
} else {
|
|
141
|
+
return ;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
var contextParams = {
|
|
146
|
+
item: item,
|
|
147
|
+
checkpointId: checkpointId,
|
|
148
|
+
inMemoryStore: inMemoryStore,
|
|
149
|
+
loadManager: loadManager,
|
|
150
|
+
persistence: ctx.persistence,
|
|
151
|
+
isPreload: false,
|
|
152
|
+
shouldSaveHistory: shouldSaveHistory,
|
|
153
|
+
chains: chains,
|
|
154
|
+
config: ctx.config,
|
|
155
|
+
isResolved: false
|
|
156
|
+
};
|
|
157
|
+
await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, ctx.config.ecosystem, UserContext.getHandlerContext(contextParams)));
|
|
158
|
+
contextParams.isResolved = true;
|
|
159
|
+
return ;
|
|
160
|
+
}
|
|
161
|
+
catch (raw_exn){
|
|
162
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
163
|
+
throw {
|
|
164
|
+
RE_EXN_ID: ProcessingError,
|
|
165
|
+
message: "Unexpected error in the block handler. Please handle the error to keep the indexer running smoothly.",
|
|
166
|
+
exn: exn,
|
|
167
|
+
item: item,
|
|
168
|
+
Error: new Error()
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMemoryStore, chains) {
|
|
174
|
+
var promises = [];
|
|
175
|
+
var itemIdx = 0;
|
|
176
|
+
for(var checkpointIdx = 0 ,checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx){
|
|
177
|
+
var checkpointId = batch.checkpointIds[checkpointIdx];
|
|
178
|
+
var checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
|
|
179
|
+
for(var idx = 0; idx < checkpointEventsProcessed; ++idx){
|
|
180
|
+
var item = batch.items[itemIdx + idx | 0];
|
|
181
|
+
if (item.kind === 0) {
|
|
182
|
+
var match = item.eventConfig;
|
|
183
|
+
var handler = match.handler;
|
|
184
|
+
if (handler !== undefined) {
|
|
185
|
+
var contractName = match.contractName;
|
|
186
|
+
var eventName = match.name;
|
|
187
|
+
try {
|
|
188
|
+
var timerRef = Prometheus.PreloadHandler.startOperation(contractName, eventName);
|
|
189
|
+
promises.push($$Promise.silentCatch(handler({
|
|
190
|
+
event: item.event,
|
|
191
|
+
context: UserContext.getHandlerContext({
|
|
192
|
+
item: item,
|
|
193
|
+
checkpointId: checkpointId,
|
|
194
|
+
inMemoryStore: inMemoryStore,
|
|
195
|
+
loadManager: loadManager,
|
|
196
|
+
persistence: persistence,
|
|
197
|
+
isPreload: true,
|
|
198
|
+
shouldSaveHistory: false,
|
|
199
|
+
chains: chains,
|
|
200
|
+
config: config,
|
|
201
|
+
isResolved: false
|
|
202
|
+
})
|
|
203
|
+
}).then((function(eventName,contractName,timerRef){
|
|
204
|
+
return function () {
|
|
205
|
+
Prometheus.PreloadHandler.endOperation(timerRef, contractName, eventName);
|
|
206
|
+
}
|
|
207
|
+
}(eventName,contractName,timerRef)))));
|
|
208
|
+
}
|
|
209
|
+
catch (exn){
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
} else {
|
|
215
|
+
try {
|
|
216
|
+
promises.push($$Promise.silentCatch(item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext({
|
|
217
|
+
item: item,
|
|
218
|
+
checkpointId: checkpointId,
|
|
219
|
+
inMemoryStore: inMemoryStore,
|
|
220
|
+
loadManager: loadManager,
|
|
221
|
+
persistence: persistence,
|
|
222
|
+
isPreload: true,
|
|
223
|
+
shouldSaveHistory: false,
|
|
224
|
+
chains: chains,
|
|
225
|
+
config: config,
|
|
226
|
+
isResolved: false
|
|
227
|
+
})))));
|
|
228
|
+
}
|
|
229
|
+
catch (exn$1){
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
235
|
+
}
|
|
236
|
+
await Promise.all(promises);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains) {
|
|
240
|
+
var itemIdx = 0;
|
|
241
|
+
for(var checkpointIdx = 0 ,checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx){
|
|
242
|
+
var checkpointId = batch.checkpointIds[checkpointIdx];
|
|
243
|
+
var checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
|
|
244
|
+
for(var idx = 0; idx < checkpointEventsProcessed; ++idx){
|
|
245
|
+
var item = batch.items[itemIdx + idx | 0];
|
|
246
|
+
await runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, chains);
|
|
247
|
+
}
|
|
248
|
+
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function registerProcessEventBatchMetrics(logger, loadDuration, handlerDuration, dbWriteDuration) {
|
|
253
|
+
Logging.childTrace(logger, {
|
|
254
|
+
msg: "Finished processing batch",
|
|
255
|
+
loader_time_elapsed: loadDuration,
|
|
256
|
+
handlers_time_elapsed: handlerDuration,
|
|
257
|
+
write_time_elapsed: dbWriteDuration
|
|
258
|
+
});
|
|
259
|
+
Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration, dbWriteDuration);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function processEventBatch(batch, inMemoryStore, isInReorgThreshold, loadManager, ctx, chainFetchers) {
|
|
263
|
+
var totalBatchSize = batch.totalBatchSize;
|
|
264
|
+
var chains = computeChainsState(chainFetchers);
|
|
265
|
+
var logger = Logging.getLogger();
|
|
266
|
+
Logging.childTrace(logger, {
|
|
267
|
+
msg: "Started processing batch",
|
|
268
|
+
totalBatchSize: totalBatchSize,
|
|
269
|
+
chains: Utils.Dict.mapValues(batch.progressedChainsById, (function (chainAfterBatch) {
|
|
270
|
+
return {
|
|
271
|
+
batchSize: chainAfterBatch.batchSize,
|
|
272
|
+
progress: chainAfterBatch.progressBlockNumber
|
|
273
|
+
};
|
|
274
|
+
}))
|
|
275
|
+
});
|
|
276
|
+
try {
|
|
277
|
+
var timeRef = Hrtime.makeTimer();
|
|
278
|
+
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
279
|
+
await preloadBatchOrThrow(batch, loadManager, ctx.persistence, ctx.config, inMemoryStore, chains);
|
|
280
|
+
}
|
|
281
|
+
var elapsedTimeAfterLoaders = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
282
|
+
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
283
|
+
await runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, Config.shouldSaveHistory(ctx.config, isInReorgThreshold), chains);
|
|
284
|
+
}
|
|
285
|
+
var elapsedTimeAfterProcessing = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
286
|
+
try {
|
|
287
|
+
await Persistence.writeBatch(ctx.persistence, batch, ctx.config, inMemoryStore, isInReorgThreshold);
|
|
288
|
+
var elapsedTimeAfterDbWrite = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
289
|
+
var handlerDuration = elapsedTimeAfterProcessing - elapsedTimeAfterLoaders;
|
|
290
|
+
var dbWriteDuration = elapsedTimeAfterDbWrite - elapsedTimeAfterProcessing;
|
|
291
|
+
registerProcessEventBatchMetrics(logger, elapsedTimeAfterLoaders, handlerDuration, dbWriteDuration);
|
|
292
|
+
return {
|
|
293
|
+
TAG: "Ok",
|
|
294
|
+
_0: undefined
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
catch (raw_exn){
|
|
298
|
+
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
299
|
+
if (exn.RE_EXN_ID === Persistence.StorageError) {
|
|
300
|
+
return {
|
|
301
|
+
TAG: "Error",
|
|
302
|
+
_0: ErrorHandling.make(exn.reason, logger, exn.message)
|
|
303
|
+
};
|
|
304
|
+
} else {
|
|
305
|
+
return {
|
|
306
|
+
TAG: "Error",
|
|
307
|
+
_0: ErrorHandling.make(exn, logger, "Failed writing batch to database")
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (raw_exn$1){
|
|
313
|
+
var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1);
|
|
314
|
+
if (exn$1.RE_EXN_ID === ProcessingError) {
|
|
315
|
+
return {
|
|
316
|
+
TAG: "Error",
|
|
317
|
+
_0: ErrorHandling.make(exn$1.exn, Logging.getItemLogger(exn$1.item), exn$1.message)
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
throw exn$1;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export {
|
|
325
|
+
allChainsEventsProcessedToEndblock ,
|
|
326
|
+
computeChainsState ,
|
|
327
|
+
convertFieldsToJson ,
|
|
328
|
+
addItemToRawEvents ,
|
|
329
|
+
ProcessingError ,
|
|
330
|
+
runEventHandlerOrThrow ,
|
|
331
|
+
runHandlerOrThrow ,
|
|
332
|
+
preloadBatchOrThrow ,
|
|
333
|
+
runBatchHandlersOrThrow ,
|
|
334
|
+
registerProcessEventBatchMetrics ,
|
|
335
|
+
processEventBatch ,
|
|
336
|
+
}
|
|
337
|
+
/* Utils Not a pure module */
|