envio 3.3.0-alpha.6 → 3.3.0-alpha.8
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 -5
- package/package.json +6 -6
- package/src/Address.res +5 -2
- package/src/Address.res.mjs +3 -1
- package/src/Api.res +1 -1
- package/src/Api.res.mjs +1 -1
- package/src/ChainFetching.res +34 -34
- package/src/ChainFetching.res.mjs +29 -29
- package/src/ChainState.res +328 -165
- package/src/ChainState.res.mjs +205 -100
- package/src/ChainState.resi +16 -7
- package/src/Config.res +55 -27
- package/src/Config.res.mjs +46 -7
- package/src/ContractRegisterContext.res +2 -12
- package/src/ContractRegisterContext.res.mjs +3 -5
- package/src/Core.res +7 -0
- package/src/CrossChainState.res +54 -79
- package/src/CrossChainState.res.mjs +45 -60
- package/src/CrossChainState.resi +1 -1
- package/src/Ecosystem.res +3 -3
- package/src/Ecosystem.res.mjs +3 -3
- package/src/Envio.res +14 -9
- package/src/EventConfigBuilder.res +105 -56
- package/src/EventConfigBuilder.res.mjs +69 -33
- package/src/EventProcessing.res +19 -15
- package/src/EventProcessing.res.mjs +13 -12
- package/src/FetchState.res +383 -182
- package/src/FetchState.res.mjs +260 -264
- package/src/HandlerLoader.res +7 -112
- package/src/HandlerLoader.res.mjs +1 -87
- package/src/HandlerRegister.res +209 -6
- package/src/HandlerRegister.res.mjs +90 -5
- package/src/HandlerRegister.resi +13 -2
- package/src/IndexerState.res +6 -3
- package/src/IndexerState.res.mjs +3 -3
- package/src/IndexerState.resi +1 -1
- package/src/IndexingAddresses.res +10 -7
- package/src/IndexingAddresses.res.mjs +8 -7
- package/src/IndexingAddresses.resi +3 -1
- package/src/Internal.res +82 -36
- package/src/Internal.res.mjs +11 -1
- package/src/Main.res +22 -23
- package/src/Main.res.mjs +15 -17
- package/src/Metrics.res +43 -2
- package/src/Metrics.res.mjs +39 -3
- package/src/Prometheus.res +0 -35
- package/src/Prometheus.res.mjs +33 -68
- package/src/RawEvent.res +7 -2
- package/src/RawEvent.res.mjs +4 -4
- package/src/SimulateItems.res +26 -8
- package/src/SimulateItems.res.mjs +11 -14
- package/src/TestIndexer.res +1 -1
- package/src/TestIndexer.res.mjs +1 -1
- package/src/sources/BlockStore.res +46 -0
- package/src/sources/BlockStore.res.mjs +24 -0
- package/src/sources/EventRouter.res +19 -12
- package/src/sources/EventRouter.res.mjs +7 -5
- package/src/sources/Evm.res +54 -4
- package/src/sources/Evm.res.mjs +43 -4
- package/src/sources/EvmChain.res +14 -18
- package/src/sources/EvmChain.res.mjs +12 -13
- package/src/sources/FieldMask.res +39 -0
- package/src/sources/FieldMask.res.mjs +42 -0
- package/src/sources/Fuel.res +5 -2
- package/src/sources/Fuel.res.mjs +4 -3
- package/src/sources/HyperFuelSource.res +32 -40
- package/src/sources/HyperFuelSource.res.mjs +53 -45
- package/src/sources/HyperSync.res +35 -9
- package/src/sources/HyperSync.res.mjs +52 -35
- package/src/sources/HyperSync.resi +11 -3
- package/src/sources/HyperSyncClient.res +15 -4
- package/src/sources/HyperSyncHeightStream.res +1 -8
- package/src/sources/HyperSyncHeightStream.res.mjs +0 -2
- package/src/sources/HyperSyncSource.res +39 -58
- package/src/sources/HyperSyncSource.res.mjs +44 -44
- package/src/sources/RpcSource.res +114 -92
- package/src/sources/RpcSource.res.mjs +77 -46
- package/src/sources/RpcWebSocketHeightStream.res +0 -5
- package/src/sources/RpcWebSocketHeightStream.res.mjs +0 -2
- package/src/sources/SimulateSource.res +6 -3
- package/src/sources/SimulateSource.res.mjs +13 -5
- package/src/sources/Source.res +25 -5
- package/src/sources/SourceManager.res +66 -3
- package/src/sources/SourceManager.res.mjs +55 -7
- package/src/sources/SourceManager.resi +10 -0
- package/src/sources/Svm.res +15 -10
- package/src/sources/Svm.res.mjs +24 -7
- package/src/sources/SvmHyperSyncClient.res +5 -6
- package/src/sources/SvmHyperSyncSource.res +84 -41
- package/src/sources/SvmHyperSyncSource.res.mjs +90 -43
- package/src/sources/TransactionStore.res +6 -107
- package/src/sources/TransactionStore.res.mjs +5 -86
- package/svm.schema.json +19 -0
package/src/EventProcessing.res
CHANGED
|
@@ -74,8 +74,8 @@ let runEventHandlerOrThrow = async (
|
|
|
74
74
|
}
|
|
75
75
|
let handlerDuration = timeBeforeHandler->Performance.secondsSince
|
|
76
76
|
Prometheus.ProcessingHandler.increment(
|
|
77
|
-
~contract=eventItem.eventConfig.contractName,
|
|
78
|
-
~event=eventItem.eventConfig.name,
|
|
77
|
+
~contract=eventItem.onEventRegistration.eventConfig.contractName,
|
|
78
|
+
~event=eventItem.onEventRegistration.eventConfig.name,
|
|
79
79
|
~duration=handlerDuration,
|
|
80
80
|
)
|
|
81
81
|
}
|
|
@@ -90,7 +90,7 @@ let runHandlerOrThrow = async (
|
|
|
90
90
|
~chains: Internal.chains,
|
|
91
91
|
) => {
|
|
92
92
|
switch item {
|
|
93
|
-
| Block({
|
|
93
|
+
| Block({onBlockRegistration: {handler}, blockNumber}) =>
|
|
94
94
|
try {
|
|
95
95
|
let contextParams: UserContext.contextParams = {
|
|
96
96
|
item,
|
|
@@ -121,8 +121,8 @@ let runHandlerOrThrow = async (
|
|
|
121
121
|
}),
|
|
122
122
|
)
|
|
123
123
|
}
|
|
124
|
-
| Event({
|
|
125
|
-
switch
|
|
124
|
+
| Event({onEventRegistration}) =>
|
|
125
|
+
switch onEventRegistration.handler {
|
|
126
126
|
| Some(handler) =>
|
|
127
127
|
await item->runEventHandlerOrThrow(
|
|
128
128
|
~handler,
|
|
@@ -161,7 +161,7 @@ let preloadBatchOrThrow = async (
|
|
|
161
161
|
for idx in 0 to checkpointEventsProcessed - 1 {
|
|
162
162
|
let item = batch.items->Array.getUnsafe(itemIdx.contents + idx)
|
|
163
163
|
switch item {
|
|
164
|
-
| Event({
|
|
164
|
+
| Event({onEventRegistration: {handler, eventConfig: {contractName, name: eventName}}}) =>
|
|
165
165
|
switch handler {
|
|
166
166
|
| None => ()
|
|
167
167
|
| Some(handler) =>
|
|
@@ -200,7 +200,7 @@ let preloadBatchOrThrow = async (
|
|
|
200
200
|
| _ => ()
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
| Block({
|
|
203
|
+
| Block({onBlockRegistration: {handler}, blockNumber}) =>
|
|
204
204
|
try {
|
|
205
205
|
promises->Array.push(
|
|
206
206
|
handler({
|
|
@@ -289,15 +289,19 @@ type logPartitionInfo = {
|
|
|
289
289
|
lastItemBlockNumber?: int,
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
// Off the hot path: bulk-materialise the selected transaction
|
|
293
|
-
// batch's store-backed (HyperSync) items and write them onto the
|
|
294
|
-
// handlers read plain objects. A batch can span chains, each with
|
|
295
|
-
// and field
|
|
296
|
-
let
|
|
292
|
+
// Off the hot path: bulk-materialise the selected transaction and block fields
|
|
293
|
+
// for the batch's store-backed (HyperSync) items and write them onto the
|
|
294
|
+
// payloads, so handlers read plain objects. A batch can span chains, each with
|
|
295
|
+
// its own stores and field masks, so group items by chain before materialising.
|
|
296
|
+
let materializeBatchEvents = async (
|
|
297
|
+
batch: Batch.t,
|
|
298
|
+
~chainStates: dict<ChainState.t>,
|
|
299
|
+
~ecosystem,
|
|
300
|
+
) => {
|
|
297
301
|
switch chainStates->Dict.valuesToArray {
|
|
298
302
|
// Single-chain indexers (the common case): every item belongs to the one
|
|
299
303
|
// chain, so skip the per-chain grouping and its allocations.
|
|
300
|
-
| [cs] => await cs->ChainState.materializeBatchItems(~items=batch.items)
|
|
304
|
+
| [cs] => await cs->ChainState.materializeBatchItems(~items=batch.items, ~ecosystem)
|
|
301
305
|
| _ =>
|
|
302
306
|
let itemsByChain: dict<array<Internal.item>> = Dict.make()
|
|
303
307
|
batch.items->Array.forEach(item => {
|
|
@@ -312,7 +316,7 @@ let materializeBatchTransactions = async (batch: Batch.t, ~chainStates: dict<Cha
|
|
|
312
316
|
->Dict.toArray
|
|
313
317
|
->Array.map(async ((chainId, items)) => {
|
|
314
318
|
let cs = chainStates->Dict.getUnsafe(chainId)
|
|
315
|
-
await cs->ChainState.materializeBatchItems(~items)
|
|
319
|
+
await cs->ChainState.materializeBatchItems(~items, ~ecosystem)
|
|
316
320
|
})
|
|
317
321
|
->Promise.all
|
|
318
322
|
}
|
|
@@ -348,7 +352,7 @@ let processEventBatch = async (
|
|
|
348
352
|
if batch.items->Utils.Array.notEmpty {
|
|
349
353
|
// Materialise store-backed transactions onto payloads before any handler
|
|
350
354
|
// (preload or execute) reads them.
|
|
351
|
-
await
|
|
355
|
+
await materializeBatchEvents(batch, ~chainStates, ~ecosystem=config.ecosystem.name)
|
|
352
356
|
await batch->preloadBatchOrThrow(~loadManager, ~persistence, ~indexerState, ~chains, ~config)
|
|
353
357
|
}
|
|
354
358
|
|
|
@@ -65,12 +65,12 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, indexerState,
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
let handlerDuration = Performance.secondsSince(timeBeforeHandler);
|
|
68
|
-
return Prometheus.ProcessingHandler.increment(item.eventConfig.contractName, item.eventConfig.name, handlerDuration);
|
|
68
|
+
return Prometheus.ProcessingHandler.increment(item.onEventRegistration.eventConfig.contractName, item.onEventRegistration.eventConfig.name, handlerDuration);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async function runHandlerOrThrow(item, checkpointId, indexerState, loadManager, persistence, config, chains) {
|
|
72
72
|
if (item.kind === 0) {
|
|
73
|
-
let handler = item.
|
|
73
|
+
let handler = item.onEventRegistration.handler;
|
|
74
74
|
if (handler !== undefined) {
|
|
75
75
|
return await runEventHandlerOrThrow(item, checkpointId, handler, indexerState, loadManager, persistence, chains, config);
|
|
76
76
|
} else {
|
|
@@ -89,7 +89,7 @@ async function runHandlerOrThrow(item, checkpointId, indexerState, loadManager,
|
|
|
89
89
|
config: config,
|
|
90
90
|
isResolved: false
|
|
91
91
|
};
|
|
92
|
-
await item.
|
|
92
|
+
await item.onBlockRegistration.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext(contextParams)));
|
|
93
93
|
contextParams.isResolved = true;
|
|
94
94
|
return;
|
|
95
95
|
} catch (raw_exn) {
|
|
@@ -113,11 +113,12 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inde
|
|
|
113
113
|
for (let idx = 0; idx < checkpointEventsProcessed; ++idx) {
|
|
114
114
|
let item = batch.items[itemIdx + idx | 0];
|
|
115
115
|
if (item.kind === 0) {
|
|
116
|
-
let match = item.
|
|
116
|
+
let match = item.onEventRegistration;
|
|
117
117
|
let handler = match.handler;
|
|
118
118
|
if (handler !== undefined) {
|
|
119
|
-
let
|
|
120
|
-
let
|
|
119
|
+
let match$1 = match.eventConfig;
|
|
120
|
+
let contractName = match$1.contractName;
|
|
121
|
+
let eventName = match$1.name;
|
|
121
122
|
try {
|
|
122
123
|
let timerRef = Prometheus.PreloadHandler.startOperation(contractName, eventName);
|
|
123
124
|
promises.push(Utils.$$Promise.silentCatch(handler({
|
|
@@ -140,7 +141,7 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inde
|
|
|
140
141
|
}
|
|
141
142
|
} else {
|
|
142
143
|
try {
|
|
143
|
-
promises.push(Utils.$$Promise.silentCatch(item.
|
|
144
|
+
promises.push(Utils.$$Promise.silentCatch(item.onBlockRegistration.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, config.ecosystem, UserContext.getHandlerContext({
|
|
144
145
|
item: item,
|
|
145
146
|
checkpointId: checkpointId,
|
|
146
147
|
indexerState: indexerState,
|
|
@@ -184,7 +185,7 @@ function registerProcessEventBatchMetrics(logger, batch, loadDuration, handlerDu
|
|
|
184
185
|
Prometheus.ProcessingBatch.registerMetrics(loadDuration, handlerDuration);
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
async function
|
|
188
|
+
async function materializeBatchEvents(batch, chainStates, ecosystem) {
|
|
188
189
|
let match = Object.values(chainStates);
|
|
189
190
|
if (match.length !== 1) {
|
|
190
191
|
let itemsByChain = {};
|
|
@@ -199,12 +200,12 @@ async function materializeBatchTransactions(batch, chainStates) {
|
|
|
199
200
|
});
|
|
200
201
|
await Promise.all(Object.entries(itemsByChain).map(async param => {
|
|
201
202
|
let cs = chainStates[param[0]];
|
|
202
|
-
return await ChainState.materializeBatchItems(cs, param[1]);
|
|
203
|
+
return await ChainState.materializeBatchItems(cs, param[1], ecosystem);
|
|
203
204
|
}));
|
|
204
205
|
return;
|
|
205
206
|
}
|
|
206
207
|
let cs = match[0];
|
|
207
|
-
return await ChainState.materializeBatchItems(cs, batch.items);
|
|
208
|
+
return await ChainState.materializeBatchItems(cs, batch.items, ecosystem);
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
async function processEventBatch(batch, indexerState, loadManager, persistence, config, chainStates) {
|
|
@@ -219,7 +220,7 @@ async function processEventBatch(batch, indexerState, loadManager, persistence,
|
|
|
219
220
|
await Writing.awaitCapacity(indexerState);
|
|
220
221
|
let timeRef = Performance.now();
|
|
221
222
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
222
|
-
await
|
|
223
|
+
await materializeBatchEvents(batch, chainStates, config.ecosystem.name);
|
|
223
224
|
await preloadBatchOrThrow(batch, loadManager, persistence, config, indexerState, chains);
|
|
224
225
|
}
|
|
225
226
|
let elapsedTimeAfterLoaders = Performance.secondsSince(timeRef);
|
|
@@ -264,7 +265,7 @@ export {
|
|
|
264
265
|
preloadBatchOrThrow,
|
|
265
266
|
runBatchHandlersOrThrow,
|
|
266
267
|
registerProcessEventBatchMetrics,
|
|
267
|
-
|
|
268
|
+
materializeBatchEvents,
|
|
268
269
|
processEventBatch,
|
|
269
270
|
}
|
|
270
271
|
/* Utils Not a pure module */
|