envio 3.2.0 → 3.3.0-alpha.0
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/package.json +6 -7
- package/src/Batch.res +12 -15
- package/src/Batch.res.mjs +4 -5
- package/src/BatchProcessing.res +199 -0
- package/src/BatchProcessing.res.mjs +125 -0
- package/src/ChainFetching.res +375 -0
- package/src/ChainFetching.res.mjs +206 -0
- package/src/ChainMetadata.res +27 -0
- package/src/ChainMetadata.res.mjs +27 -0
- package/src/ChainState.res +618 -0
- package/src/ChainState.res.mjs +461 -0
- package/src/ChainState.resi +85 -0
- package/src/Config.res +13 -4
- package/src/Config.res.mjs +8 -3
- package/src/ContractRegisterContext.res +106 -0
- package/src/ContractRegisterContext.res.mjs +76 -0
- package/src/Core.res +3 -0
- package/src/CrossChainState.res +269 -0
- package/src/CrossChainState.res.mjs +197 -0
- package/src/CrossChainState.resi +47 -0
- package/src/Ecosystem.res +58 -0
- package/src/Ecosystem.res.mjs +43 -1
- package/src/Env.res +7 -2
- package/src/Env.res.mjs +5 -2
- package/src/EventConfigBuilder.res +35 -0
- package/src/EventConfigBuilder.res.mjs +21 -0
- package/src/EventProcessing.res +60 -46
- package/src/EventProcessing.res.mjs +33 -32
- package/src/EventUtils.res +0 -4
- package/src/EventUtils.res.mjs +0 -4
- package/src/ExitOnCaughtUp.res +10 -0
- package/src/ExitOnCaughtUp.res.mjs +22 -0
- package/src/FetchState.res +162 -113
- package/src/FetchState.res.mjs +181 -119
- package/src/HandlerLoader.res +6 -1
- package/src/HandlerLoader.res.mjs +13 -36
- package/src/InMemoryStore.res +36 -451
- package/src/InMemoryStore.res.mjs +20 -369
- package/src/IndexerLoop.res +44 -0
- package/src/IndexerLoop.res.mjs +46 -0
- package/src/IndexerState.res +544 -0
- package/src/IndexerState.res.mjs +547 -0
- package/src/IndexerState.resi +132 -0
- package/src/Internal.res +44 -7
- package/src/LoadLayer.res +20 -18
- package/src/LoadLayer.res.mjs +14 -12
- package/src/LoadLayer.resi +6 -3
- package/src/LogSelection.res +86 -17
- package/src/LogSelection.res.mjs +67 -14
- package/src/Logging.res +11 -44
- package/src/Logging.res.mjs +10 -42
- package/src/Main.res +54 -79
- package/src/Main.res.mjs +44 -56
- package/src/PgStorage.res +8 -71
- package/src/PgStorage.res.mjs +3 -47
- package/src/Prometheus.res +7 -8
- package/src/Prometheus.res.mjs +7 -4
- package/src/PruneStaleHistory.res +45 -0
- package/src/PruneStaleHistory.res.mjs +46 -0
- package/src/RawEvent.res +73 -0
- package/src/RawEvent.res.mjs +51 -0
- package/src/Rollback.res +204 -0
- package/src/Rollback.res.mjs +118 -0
- package/src/SimulateItems.res +12 -10
- package/src/SimulateItems.res.mjs +1 -1
- package/src/TestIndexer.res +34 -27
- package/src/TestIndexer.res.mjs +4 -1
- package/src/UserContext.res +26 -114
- package/src/UserContext.res.mjs +15 -78
- package/src/Writing.res +242 -0
- package/src/Writing.res.mjs +215 -0
- package/src/db/InternalTable.res +14 -27
- package/src/sources/Evm.res +40 -1
- package/src/sources/Evm.res.mjs +94 -84
- package/src/sources/Fuel.res +40 -1
- package/src/sources/Fuel.res.mjs +36 -26
- package/src/sources/HyperFuel.res +41 -120
- package/src/sources/HyperFuel.res.mjs +42 -80
- package/src/sources/HyperFuel.resi +1 -24
- package/src/sources/HyperFuelClient.res +16 -297
- package/src/sources/HyperFuelClient.res.mjs +5 -4
- package/src/sources/HyperFuelSource.res +33 -8
- package/src/sources/HyperFuelSource.res.mjs +56 -10
- package/src/sources/HyperSyncSource.res +7 -5
- package/src/sources/HyperSyncSource.res.mjs +3 -3
- package/src/sources/RpcSource.res +2 -2
- package/src/sources/RpcSource.res.mjs +1 -1
- package/src/sources/SourceManager.res +8 -18
- package/src/sources/SourceManager.res.mjs +8 -5
- package/src/sources/SourceManager.resi +4 -1
- package/src/sources/Svm.res +18 -1
- package/src/sources/Svm.res.mjs +30 -22
- package/src/sources/SvmHyperSyncSource.res +1 -1
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/tui/Tui.res +38 -36
- package/src/tui/Tui.res.mjs +51 -51
- package/src/ChainFetcher.res +0 -519
- package/src/ChainFetcher.res.mjs +0 -314
- package/src/ChainManager.res +0 -358
- package/src/ChainManager.res.mjs +0 -291
- package/src/Ctx.res +0 -6
- package/src/Ctx.res.mjs +0 -2
- package/src/GlobalState.res +0 -1056
- package/src/GlobalState.res.mjs +0 -1086
- package/src/GlobalStateManager.res +0 -57
- package/src/GlobalStateManager.res.mjs +0 -68
- package/src/GlobalStateManager.resi +0 -7
- package/src/Ports.res +0 -5
- package/src/Ports.res.mjs +0 -9
- package/src/adapters/MarkBatchProcessedAdapter.res +0 -5
- package/src/adapters/MarkBatchProcessedAdapter.res.mjs +0 -14
- package/src/sources/EnvioApiClient.res +0 -15
- package/src/sources/EnvioApiClient.res.mjs +0 -24
|
@@ -3,26 +3,27 @@
|
|
|
3
3
|
import * as Utils from "./Utils.res.mjs";
|
|
4
4
|
import * as Hrtime from "./bindings/Hrtime.res.mjs";
|
|
5
5
|
import * as Logging from "./Logging.res.mjs";
|
|
6
|
-
import * as
|
|
6
|
+
import * as Writing from "./Writing.res.mjs";
|
|
7
7
|
import * as Ecosystem from "./Ecosystem.res.mjs";
|
|
8
|
+
import * as ChainState from "./ChainState.res.mjs";
|
|
8
9
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
9
10
|
import * as Persistence from "./Persistence.res.mjs";
|
|
10
11
|
import * as UserContext from "./UserContext.res.mjs";
|
|
11
|
-
import * as ChainFetcher from "./ChainFetcher.res.mjs";
|
|
12
12
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
13
|
-
import * as InMemoryStore from "./InMemoryStore.res.mjs";
|
|
14
13
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
15
14
|
|
|
16
|
-
function allChainsEventsProcessedToEndblock(
|
|
17
|
-
return
|
|
15
|
+
function allChainsEventsProcessedToEndblock(chainStates) {
|
|
16
|
+
return Object.values(chainStates).every(ChainState.hasProcessedToEndblock);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
function computeChainsState(
|
|
19
|
+
function computeChainsState(chainStates) {
|
|
21
20
|
let chains = {};
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
let values = Object.values(chainStates);
|
|
22
|
+
let isRealtime = values.every(ChainState.isReady);
|
|
23
|
+
values.forEach(cs => {
|
|
24
|
+
let chainId = ChainState.chainConfig(cs).id;
|
|
25
|
+
chains[chainId.toString()] = {
|
|
26
|
+
id: chainId,
|
|
26
27
|
isRealtime: isRealtime
|
|
27
28
|
};
|
|
28
29
|
});
|
|
@@ -31,13 +32,13 @@ function computeChainsState(chainFetchers) {
|
|
|
31
32
|
|
|
32
33
|
let ProcessingError = /* @__PURE__ */Primitive_exceptions.create("EventProcessing.ProcessingError");
|
|
33
34
|
|
|
34
|
-
async function runEventHandlerOrThrow(item, checkpointId, handler,
|
|
35
|
+
async function runEventHandlerOrThrow(item, checkpointId, handler, indexerState, loadManager, persistence, chains, config) {
|
|
35
36
|
let timeBeforeHandler = Hrtime.makeTimer();
|
|
36
37
|
try {
|
|
37
38
|
let contextParams = {
|
|
38
39
|
item: item,
|
|
39
40
|
checkpointId: checkpointId,
|
|
40
|
-
|
|
41
|
+
indexerState: indexerState,
|
|
41
42
|
loadManager: loadManager,
|
|
42
43
|
persistence: persistence,
|
|
43
44
|
isPreload: false,
|
|
@@ -46,7 +47,7 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore
|
|
|
46
47
|
isResolved: false
|
|
47
48
|
};
|
|
48
49
|
await handler({
|
|
49
|
-
event: item.
|
|
50
|
+
event: Ecosystem.getItemEvent(item, config.ecosystem),
|
|
50
51
|
context: UserContext.getHandlerContext(contextParams)
|
|
51
52
|
});
|
|
52
53
|
contextParams.isResolved = true;
|
|
@@ -64,11 +65,11 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore
|
|
|
64
65
|
return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
async function runHandlerOrThrow(item, checkpointId,
|
|
68
|
+
async function runHandlerOrThrow(item, checkpointId, indexerState, loadManager, persistence, config, chains) {
|
|
68
69
|
if (item.kind === 0) {
|
|
69
70
|
let handler = item.eventConfig.handler;
|
|
70
71
|
if (handler !== undefined) {
|
|
71
|
-
return await runEventHandlerOrThrow(item, checkpointId, handler,
|
|
72
|
+
return await runEventHandlerOrThrow(item, checkpointId, handler, indexerState, loadManager, persistence, chains, config);
|
|
72
73
|
} else {
|
|
73
74
|
return;
|
|
74
75
|
}
|
|
@@ -77,15 +78,15 @@ async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
|
|
|
77
78
|
let contextParams = {
|
|
78
79
|
item: item,
|
|
79
80
|
checkpointId: checkpointId,
|
|
80
|
-
|
|
81
|
+
indexerState: indexerState,
|
|
81
82
|
loadManager: loadManager,
|
|
82
|
-
persistence:
|
|
83
|
+
persistence: persistence,
|
|
83
84
|
isPreload: false,
|
|
84
85
|
chains: chains,
|
|
85
|
-
config:
|
|
86
|
+
config: config,
|
|
86
87
|
isResolved: false
|
|
87
88
|
};
|
|
88
|
-
await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber,
|
|
89
|
+
await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext(contextParams)));
|
|
89
90
|
contextParams.isResolved = true;
|
|
90
91
|
return;
|
|
91
92
|
} catch (raw_exn) {
|
|
@@ -100,7 +101,7 @@ async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
async function preloadBatchOrThrow(batch, loadManager, persistence, config,
|
|
104
|
+
async function preloadBatchOrThrow(batch, loadManager, persistence, config, indexerState, chains) {
|
|
104
105
|
let promises = [];
|
|
105
106
|
let itemIdx = 0;
|
|
106
107
|
for (let checkpointIdx = 0, checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx) {
|
|
@@ -117,11 +118,11 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
|
|
|
117
118
|
try {
|
|
118
119
|
let timerRef = Prometheus.PreloadHandler.startOperation(contractName, eventName);
|
|
119
120
|
promises.push(Utils.$$Promise.silentCatch(handler({
|
|
120
|
-
event: item.
|
|
121
|
+
event: Ecosystem.getItemEvent(item, config.ecosystem),
|
|
121
122
|
context: UserContext.getHandlerContext({
|
|
122
123
|
item: item,
|
|
123
124
|
checkpointId: checkpointId,
|
|
124
|
-
|
|
125
|
+
indexerState: indexerState,
|
|
125
126
|
loadManager: loadManager,
|
|
126
127
|
persistence: persistence,
|
|
127
128
|
isPreload: true,
|
|
@@ -139,7 +140,7 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
|
|
|
139
140
|
promises.push(Utils.$$Promise.silentCatch(item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext({
|
|
140
141
|
item: item,
|
|
141
142
|
checkpointId: checkpointId,
|
|
142
|
-
|
|
143
|
+
indexerState: indexerState,
|
|
143
144
|
loadManager: loadManager,
|
|
144
145
|
persistence: persistence,
|
|
145
146
|
isPreload: true,
|
|
@@ -157,14 +158,14 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
|
|
|
157
158
|
await Promise.all(promises);
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
async function runBatchHandlersOrThrow(batch,
|
|
161
|
+
async function runBatchHandlersOrThrow(batch, indexerState, loadManager, persistence, config, chains) {
|
|
161
162
|
let itemIdx = 0;
|
|
162
163
|
for (let checkpointIdx = 0, checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx) {
|
|
163
164
|
let checkpointId = batch.checkpointIds[checkpointIdx];
|
|
164
165
|
let checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
|
|
165
166
|
for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
|
|
166
167
|
let item = batch.items[itemIdx + idx | 0];
|
|
167
|
-
await runHandlerOrThrow(item, checkpointId,
|
|
168
|
+
await runHandlerOrThrow(item, checkpointId, indexerState, loadManager, persistence, config, chains);
|
|
168
169
|
}
|
|
169
170
|
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
170
171
|
}
|
|
@@ -179,9 +180,9 @@ function registerProcessEventBatchMetrics(logger, loadDuration, handlerDuration)
|
|
|
179
180
|
Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration);
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
async function processEventBatch(batch,
|
|
183
|
+
async function processEventBatch(batch, indexerState, loadManager, persistence, config, chainStates) {
|
|
183
184
|
let totalBatchSize = batch.totalBatchSize;
|
|
184
|
-
let chains = computeChainsState(
|
|
185
|
+
let chains = computeChainsState(chainStates);
|
|
185
186
|
let logger = Logging.getLogger();
|
|
186
187
|
Logging.childTrace(logger, {
|
|
187
188
|
msg: "Started processing batch",
|
|
@@ -192,17 +193,17 @@ async function processEventBatch(batch, inMemoryStore, loadManager, ctx, chainFe
|
|
|
192
193
|
}))
|
|
193
194
|
});
|
|
194
195
|
try {
|
|
195
|
-
await
|
|
196
|
+
await Writing.awaitCapacity(indexerState);
|
|
196
197
|
let timeRef = Hrtime.makeTimer();
|
|
197
198
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
198
|
-
await preloadBatchOrThrow(batch, loadManager,
|
|
199
|
+
await preloadBatchOrThrow(batch, loadManager, persistence, config, indexerState, chains);
|
|
199
200
|
}
|
|
200
201
|
let elapsedTimeAfterLoaders = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
201
202
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
202
|
-
await runBatchHandlersOrThrow(batch,
|
|
203
|
+
await runBatchHandlersOrThrow(batch, indexerState, loadManager, persistence, config, chains);
|
|
203
204
|
}
|
|
204
205
|
let elapsedTimeAfterProcessing = Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef));
|
|
205
|
-
|
|
206
|
+
Writing.commitBatch(indexerState, batch);
|
|
206
207
|
let handlerDuration = elapsedTimeAfterProcessing - elapsedTimeAfterLoaders;
|
|
207
208
|
registerProcessEventBatchMetrics(logger, elapsedTimeAfterLoaders, handlerDuration);
|
|
208
209
|
return {
|
|
@@ -219,7 +220,7 @@ async function processEventBatch(batch, inMemoryStore, loadManager, ctx, chainFe
|
|
|
219
220
|
} else if (exn.RE_EXN_ID === ProcessingError) {
|
|
220
221
|
return {
|
|
221
222
|
TAG: "Error",
|
|
222
|
-
_0: ErrorHandling.make(exn.exn,
|
|
223
|
+
_0: ErrorHandling.make(exn.exn, Ecosystem.getItemLogger(exn.item, config.ecosystem), exn.message)
|
|
223
224
|
};
|
|
224
225
|
} else {
|
|
225
226
|
return {
|
package/src/EventUtils.res
CHANGED
package/src/EventUtils.res.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
4
|
-
|
|
5
|
-
let isEarlierUnordered = Primitive_object.lessthan;
|
|
6
3
|
|
|
7
4
|
function packEventIndex(blockNumber, logIndex) {
|
|
8
5
|
let blockNumber$1 = BigInt(blockNumber);
|
|
@@ -12,7 +9,6 @@ function packEventIndex(blockNumber, logIndex) {
|
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
export {
|
|
15
|
-
isEarlierUnordered,
|
|
16
12
|
packEventIndex,
|
|
17
13
|
}
|
|
18
14
|
/* No side effect */
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Flush, then exit unless a reorg landed during the flush (which parks a
|
|
2
|
+
// rollback to recover instead).
|
|
3
|
+
let run = async (state: IndexerState.t) => {
|
|
4
|
+
ChainMetadata.stage(state)
|
|
5
|
+
await state->Writing.flush
|
|
6
|
+
if !(state->IndexerState.isStopped) && !(state->IndexerState.isResolvingReorg) {
|
|
7
|
+
Logging.info("Exiting with success")
|
|
8
|
+
NodeJs.process->NodeJs.exitWithCode(Success)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Logging from "./Logging.res.mjs";
|
|
4
|
+
import * as Writing from "./Writing.res.mjs";
|
|
5
|
+
import * as Process from "process";
|
|
6
|
+
import * as IndexerState from "./IndexerState.res.mjs";
|
|
7
|
+
import * as ChainMetadata from "./ChainMetadata.res.mjs";
|
|
8
|
+
|
|
9
|
+
async function run(state) {
|
|
10
|
+
ChainMetadata.stage(state);
|
|
11
|
+
await Writing.flush(state);
|
|
12
|
+
if (!IndexerState.isStopped(state) && !IndexerState.isResolvingReorg(state)) {
|
|
13
|
+
Logging.info("Exiting with success");
|
|
14
|
+
Process.exit(0);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
run,
|
|
21
|
+
}
|
|
22
|
+
/* Logging Not a pure module */
|