envio 3.0.0-alpha.3 → 3.0.0-alpha.5
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 +2 -2
- package/evm.schema.json +0 -1
- package/index.d.ts +333 -2
- package/index.js +4 -0
- package/package.json +13 -6
- package/rescript.json +4 -1
- package/src/ChainFetcher.res +25 -1
- package/src/ChainFetcher.res.mjs +19 -1
- package/src/Config.res +212 -19
- package/src/Config.res.mjs +228 -29
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +2 -2
- package/src/Ecosystem.res.mjs +1 -1
- package/src/Envio.gen.ts +1 -1
- package/src/Envio.res +1 -1
- package/src/EventProcessing.res +18 -18
- package/src/EventProcessing.res.mjs +14 -14
- package/src/GlobalState.res +29 -35
- package/src/GlobalState.res.mjs +47 -47
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/Internal.res +41 -1
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Main.res +342 -0
- package/src/Main.res.mjs +289 -0
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +24 -2
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +22 -1
- package/src/Types.ts +1 -1
- package/src/UserContext.res +0 -1
- package/src/UserContext.res.mjs +0 -2
- package/src/Utils.res +28 -0
- package/src/Utils.res.mjs +18 -0
- package/src/bindings/ClickHouse.res +31 -1
- package/src/bindings/ClickHouse.res.mjs +27 -1
- package/src/bindings/Ethers.res +27 -67
- package/src/bindings/Ethers.res.mjs +18 -70
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +3 -0
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/RescriptMocha.res +123 -0
- package/src/bindings/RescriptMocha.res.mjs +18 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/sources/FuelSDK.res +4 -3
- package/src/sources/HyperSyncHeightStream.res +28 -110
- package/src/sources/HyperSyncHeightStream.res.mjs +30 -63
- package/src/sources/HyperSyncSource.res +11 -13
- package/src/sources/HyperSyncSource.res.mjs +20 -20
- package/src/sources/Rpc.res +43 -0
- package/src/sources/Rpc.res.mjs +31 -0
- package/src/sources/RpcSource.res +9 -4
- package/src/sources/RpcSource.res.mjs +9 -4
- package/src/sources/Source.res +1 -0
- package/src/sources/SourceManager.res +164 -81
- package/src/sources/SourceManager.res.mjs +146 -83
- package/src/sources/{Solana.res → Svm.res} +4 -4
- package/src/sources/{Solana.res.mjs → Svm.res.mjs} +4 -4
- package/src/tui/Tui.res +266 -0
- package/src/tui/Tui.res.mjs +342 -0
- package/src/tui/bindings/Ink.res +376 -0
- package/src/tui/bindings/Ink.res.mjs +75 -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 +114 -0
- package/src/tui/components/CustomHooks.res.mjs +162 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +193 -0
- package/src/tui/components/SyncETA.res.mjs +269 -0
- package/src/tui/components/TuiData.res +46 -0
- package/src/tui/components/TuiData.res.mjs +29 -0
- package/src/bindings/Ethers.gen.ts +0 -14
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/src/EventProcessing.res
CHANGED
|
@@ -13,7 +13,7 @@ let computeChainsState = (chainFetchers: ChainMap.t<ChainFetcher.t>): Internal.c
|
|
|
13
13
|
->ChainMap.entries
|
|
14
14
|
->Array.forEach(((chain, chainFetcher)) => {
|
|
15
15
|
let chainId = chain->ChainMap.Chain.toChainId->Int.toString
|
|
16
|
-
let isLive = chainFetcher.
|
|
16
|
+
let isLive = chainFetcher->ChainFetcher.isLive
|
|
17
17
|
|
|
18
18
|
chains->Js.Dict.set(
|
|
19
19
|
chainId,
|
|
@@ -169,7 +169,7 @@ let runHandlerOrThrow = async (
|
|
|
169
169
|
~checkpointId,
|
|
170
170
|
~inMemoryStore,
|
|
171
171
|
~loadManager,
|
|
172
|
-
~
|
|
172
|
+
~ctx: Ctx.t,
|
|
173
173
|
~shouldSaveHistory,
|
|
174
174
|
~shouldBenchmark,
|
|
175
175
|
~chains: Internal.chains,
|
|
@@ -181,18 +181,18 @@ let runHandlerOrThrow = async (
|
|
|
181
181
|
item,
|
|
182
182
|
inMemoryStore,
|
|
183
183
|
loadManager,
|
|
184
|
-
persistence:
|
|
184
|
+
persistence: ctx.persistence,
|
|
185
185
|
shouldSaveHistory,
|
|
186
186
|
checkpointId,
|
|
187
187
|
isPreload: false,
|
|
188
188
|
chains,
|
|
189
|
-
config:
|
|
189
|
+
config: ctx.config,
|
|
190
190
|
isResolved: false,
|
|
191
191
|
}
|
|
192
192
|
await handler(
|
|
193
193
|
Ecosystem.makeOnBlockArgs(
|
|
194
194
|
~blockNumber,
|
|
195
|
-
~ecosystem=
|
|
195
|
+
~ecosystem=ctx.config.ecosystem,
|
|
196
196
|
~context=UserContext.getHandlerContext(contextParams),
|
|
197
197
|
),
|
|
198
198
|
)
|
|
@@ -215,19 +215,19 @@ let runHandlerOrThrow = async (
|
|
|
215
215
|
~checkpointId,
|
|
216
216
|
~inMemoryStore,
|
|
217
217
|
~loadManager,
|
|
218
|
-
~persistence=
|
|
218
|
+
~persistence=ctx.persistence,
|
|
219
219
|
~shouldSaveHistory,
|
|
220
220
|
~shouldBenchmark,
|
|
221
221
|
~chains,
|
|
222
|
-
~config=
|
|
222
|
+
~config=ctx.config,
|
|
223
223
|
)
|
|
224
224
|
| None => ()
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
if
|
|
227
|
+
if ctx.config.enableRawEvents {
|
|
228
228
|
item
|
|
229
229
|
->Internal.castUnsafeEventItem
|
|
230
|
-
->addItemToRawEvents(~inMemoryStore, ~config=
|
|
230
|
+
->addItemToRawEvents(~inMemoryStore, ~config=ctx.config)
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
}
|
|
@@ -324,7 +324,7 @@ let runBatchHandlersOrThrow = async (
|
|
|
324
324
|
batch: Batch.t,
|
|
325
325
|
~inMemoryStore,
|
|
326
326
|
~loadManager,
|
|
327
|
-
~
|
|
327
|
+
~ctx,
|
|
328
328
|
~shouldSaveHistory,
|
|
329
329
|
~shouldBenchmark,
|
|
330
330
|
~chains: Internal.chains,
|
|
@@ -344,7 +344,7 @@ let runBatchHandlersOrThrow = async (
|
|
|
344
344
|
~checkpointId,
|
|
345
345
|
~inMemoryStore,
|
|
346
346
|
~loadManager,
|
|
347
|
-
~
|
|
347
|
+
~ctx,
|
|
348
348
|
~shouldSaveHistory,
|
|
349
349
|
~shouldBenchmark,
|
|
350
350
|
~chains,
|
|
@@ -386,7 +386,7 @@ let processEventBatch = async (
|
|
|
386
386
|
~inMemoryStore: InMemoryStore.t,
|
|
387
387
|
~isInReorgThreshold,
|
|
388
388
|
~loadManager,
|
|
389
|
-
~
|
|
389
|
+
~ctx: Ctx.t,
|
|
390
390
|
~chainFetchers: ChainMap.t<ChainFetcher.t>,
|
|
391
391
|
) => {
|
|
392
392
|
let totalBatchSize = batch.totalBatchSize
|
|
@@ -411,10 +411,10 @@ let processEventBatch = async (
|
|
|
411
411
|
if batch.items->Utils.Array.notEmpty {
|
|
412
412
|
await batch->preloadBatchOrThrow(
|
|
413
413
|
~loadManager,
|
|
414
|
-
~persistence=
|
|
414
|
+
~persistence=ctx.persistence,
|
|
415
415
|
~inMemoryStore,
|
|
416
416
|
~chains,
|
|
417
|
-
~config=
|
|
417
|
+
~config=ctx.config,
|
|
418
418
|
)
|
|
419
419
|
}
|
|
420
420
|
|
|
@@ -424,8 +424,8 @@ let processEventBatch = async (
|
|
|
424
424
|
await batch->runBatchHandlersOrThrow(
|
|
425
425
|
~inMemoryStore,
|
|
426
426
|
~loadManager,
|
|
427
|
-
~
|
|
428
|
-
~shouldSaveHistory=
|
|
427
|
+
~ctx,
|
|
428
|
+
~shouldSaveHistory=ctx.config->Config.shouldSaveHistory(~isInReorgThreshold),
|
|
429
429
|
~shouldBenchmark=Env.Benchmark.shouldSaveData,
|
|
430
430
|
~chains,
|
|
431
431
|
)
|
|
@@ -435,9 +435,9 @@ let processEventBatch = async (
|
|
|
435
435
|
timeRef->Hrtime.timeSince->Hrtime.toMillis->Hrtime.intFromMillis
|
|
436
436
|
|
|
437
437
|
try {
|
|
438
|
-
await
|
|
438
|
+
await ctx.persistence->Persistence.writeBatch(
|
|
439
439
|
~batch,
|
|
440
|
-
~config=
|
|
440
|
+
~config=ctx.config,
|
|
441
441
|
~inMemoryStore,
|
|
442
442
|
~isInReorgThreshold,
|
|
443
443
|
)
|
|
@@ -32,7 +32,7 @@ function computeChainsState(chainFetchers) {
|
|
|
32
32
|
Belt_Array.forEach(ChainMap.entries(chainFetchers), (function (param) {
|
|
33
33
|
var chain = param[0];
|
|
34
34
|
var chainId = String(chain);
|
|
35
|
-
var isLive = param[1]
|
|
35
|
+
var isLive = ChainFetcher.isLive(param[1]);
|
|
36
36
|
chains[chainId] = {
|
|
37
37
|
id: chain,
|
|
38
38
|
isLive: isLive
|
|
@@ -134,14 +134,14 @@ async function runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore
|
|
|
134
134
|
return Benchmark.addSummaryData("Handlers Per Event", item.eventConfig.contractName + " " + item.eventConfig.name + " Handler (ms)", timeEnd, 4);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
|
|
137
|
+
async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, shouldBenchmark, chains) {
|
|
138
138
|
if (item.kind === 0) {
|
|
139
139
|
var handler = item.eventConfig.handler;
|
|
140
140
|
if (handler !== undefined) {
|
|
141
|
-
await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager,
|
|
141
|
+
await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, ctx.persistence, shouldSaveHistory, shouldBenchmark, chains, ctx.config);
|
|
142
142
|
}
|
|
143
|
-
if (
|
|
144
|
-
return addItemToRawEvents(item, inMemoryStore,
|
|
143
|
+
if (ctx.config.enableRawEvents) {
|
|
144
|
+
return addItemToRawEvents(item, inMemoryStore, ctx.config);
|
|
145
145
|
} else {
|
|
146
146
|
return ;
|
|
147
147
|
}
|
|
@@ -152,14 +152,14 @@ async function runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
|
|
|
152
152
|
checkpointId: checkpointId,
|
|
153
153
|
inMemoryStore: inMemoryStore,
|
|
154
154
|
loadManager: loadManager,
|
|
155
|
-
persistence:
|
|
155
|
+
persistence: ctx.persistence,
|
|
156
156
|
isPreload: false,
|
|
157
157
|
shouldSaveHistory: shouldSaveHistory,
|
|
158
158
|
chains: chains,
|
|
159
|
-
config:
|
|
159
|
+
config: ctx.config,
|
|
160
160
|
isResolved: false
|
|
161
161
|
};
|
|
162
|
-
await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber,
|
|
162
|
+
await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, ctx.config.ecosystem, UserContext.getHandlerContext(contextParams)));
|
|
163
163
|
contextParams.isResolved = true;
|
|
164
164
|
return ;
|
|
165
165
|
}
|
|
@@ -233,14 +233,14 @@ async function preloadBatchOrThrow(batch, loadManager, persistence, config, inMe
|
|
|
233
233
|
await Promise.all(promises);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager,
|
|
236
|
+
async function runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, shouldSaveHistory, shouldBenchmark, chains) {
|
|
237
237
|
var itemIdx = 0;
|
|
238
238
|
for(var checkpointIdx = 0 ,checkpointIdx_finish = batch.checkpointIds.length; checkpointIdx < checkpointIdx_finish; ++checkpointIdx){
|
|
239
239
|
var checkpointId = batch.checkpointIds[checkpointIdx];
|
|
240
240
|
var checkpointEventsProcessed = batch.checkpointEventsProcessed[checkpointIdx];
|
|
241
241
|
for(var idx = 0; idx < checkpointEventsProcessed; ++idx){
|
|
242
242
|
var item = batch.items[itemIdx + idx | 0];
|
|
243
|
-
await runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager,
|
|
243
|
+
await runHandlerOrThrow(item, checkpointId, inMemoryStore, loadManager, ctx, shouldSaveHistory, shouldBenchmark, chains);
|
|
244
244
|
}
|
|
245
245
|
itemIdx = itemIdx + checkpointEventsProcessed | 0;
|
|
246
246
|
}
|
|
@@ -260,7 +260,7 @@ function registerProcessEventBatchMetrics(logger, loadDuration, handlerDuration,
|
|
|
260
260
|
Prometheus.incrementStorageWriteCounter();
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
async function processEventBatch(batch, inMemoryStore, isInReorgThreshold, loadManager,
|
|
263
|
+
async function processEventBatch(batch, inMemoryStore, isInReorgThreshold, loadManager, ctx, chainFetchers) {
|
|
264
264
|
var totalBatchSize = batch.totalBatchSize;
|
|
265
265
|
var chains = computeChainsState(chainFetchers);
|
|
266
266
|
var logger = Logging.getLogger();
|
|
@@ -277,15 +277,15 @@ async function processEventBatch(batch, inMemoryStore, isInReorgThreshold, loadM
|
|
|
277
277
|
try {
|
|
278
278
|
var timeRef = Hrtime.makeTimer();
|
|
279
279
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
280
|
-
await preloadBatchOrThrow(batch, loadManager,
|
|
280
|
+
await preloadBatchOrThrow(batch, loadManager, ctx.persistence, ctx.config, inMemoryStore, chains);
|
|
281
281
|
}
|
|
282
282
|
var elapsedTimeAfterLoaders = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(timeRef)));
|
|
283
283
|
if (Utils.$$Array.notEmpty(batch.items)) {
|
|
284
|
-
await runBatchHandlersOrThrow(batch, inMemoryStore, loadManager,
|
|
284
|
+
await runBatchHandlersOrThrow(batch, inMemoryStore, loadManager, ctx, Config.shouldSaveHistory(ctx.config, isInReorgThreshold), Env.Benchmark.shouldSaveData, chains);
|
|
285
285
|
}
|
|
286
286
|
var elapsedTimeAfterProcessing = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(timeRef)));
|
|
287
287
|
try {
|
|
288
|
-
await Persistence.writeBatch(
|
|
288
|
+
await Persistence.writeBatch(ctx.persistence, batch, ctx.config, inMemoryStore, isInReorgThreshold);
|
|
289
289
|
var elapsedTimeAfterDbWrite = Hrtime.intFromMillis(Hrtime.toMillis(Hrtime.timeSince(timeRef)));
|
|
290
290
|
var handlerDuration = elapsedTimeAfterProcessing - elapsedTimeAfterLoaders | 0;
|
|
291
291
|
var dbWriteDuration = elapsedTimeAfterDbWrite - elapsedTimeAfterProcessing | 0;
|
package/src/GlobalState.res
CHANGED
|
@@ -40,7 +40,7 @@ module WriteThrottlers = {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
type t = {
|
|
43
|
-
|
|
43
|
+
ctx: Ctx.t,
|
|
44
44
|
chainManager: ChainManager.t,
|
|
45
45
|
processedBatches: int,
|
|
46
46
|
currentlyProcessingBatch: bool,
|
|
@@ -55,13 +55,13 @@ type t = {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
let make = (
|
|
58
|
-
~
|
|
58
|
+
~ctx: Ctx.t,
|
|
59
59
|
~chainManager: ChainManager.t,
|
|
60
60
|
~isDevelopmentMode=false,
|
|
61
61
|
~shouldUseTui=false,
|
|
62
62
|
) => {
|
|
63
63
|
{
|
|
64
|
-
|
|
64
|
+
ctx,
|
|
65
65
|
currentlyProcessingBatch: false,
|
|
66
66
|
processedBatches: 0,
|
|
67
67
|
chainManager,
|
|
@@ -179,11 +179,7 @@ let updateChainMetadataTable = (
|
|
|
179
179
|
Takes in a chain manager and sets all chains timestamp caught up to head
|
|
180
180
|
when valid state lines up and returns an updated chain manager
|
|
181
181
|
*/
|
|
182
|
-
let updateProgressedChains = (
|
|
183
|
-
chainManager: ChainManager.t,
|
|
184
|
-
~batch: Batch.t,
|
|
185
|
-
~indexer: Indexer.t,
|
|
186
|
-
) => {
|
|
182
|
+
let updateProgressedChains = (chainManager: ChainManager.t, ~batch: Batch.t, ~ctx: Ctx.t) => {
|
|
187
183
|
Prometheus.ProgressBatchCount.increment()
|
|
188
184
|
|
|
189
185
|
let nextQueueItemIsNone = chainManager->ChainManager.nextItemIsNone
|
|
@@ -216,7 +212,7 @@ let updateProgressedChains = (
|
|
|
216
212
|
// Calculate and set latency metrics
|
|
217
213
|
switch batch->Batch.findLastEventItem(~chainId=chain->ChainMap.Chain.toChainId) {
|
|
218
214
|
| Some(eventItem) => {
|
|
219
|
-
let blockTimestamp = eventItem.event.block->
|
|
215
|
+
let blockTimestamp = eventItem.event.block->ctx.config.ecosystem.getTimestamp
|
|
220
216
|
let currentTimeMs = Js.Date.now()->Float.toInt
|
|
221
217
|
let blockTimestampMs = blockTimestamp * 1000
|
|
222
218
|
let latencyMs = currentTimeMs - blockTimestampMs
|
|
@@ -276,14 +272,12 @@ let updateProgressedChains = (
|
|
|
276
272
|
if cf->ChainFetcher.hasProcessedToEndblock {
|
|
277
273
|
// in the case this is already set, don't reset and instead propagate the existing value
|
|
278
274
|
let timestampCaughtUpToHeadOrEndblock =
|
|
279
|
-
cf.timestampCaughtUpToHeadOrEndblock->
|
|
280
|
-
? cf.timestampCaughtUpToHeadOrEndblock
|
|
281
|
-
: Js.Date.make()->Some
|
|
275
|
+
cf->ChainFetcher.isLive ? cf.timestampCaughtUpToHeadOrEndblock : Js.Date.make()->Some
|
|
282
276
|
{
|
|
283
277
|
...cf,
|
|
284
278
|
timestampCaughtUpToHeadOrEndblock,
|
|
285
279
|
}
|
|
286
|
-
} else if cf
|
|
280
|
+
} else if !(cf->ChainFetcher.isLive) && cf.isProgressAtHead {
|
|
287
281
|
//Only calculate and set timestampCaughtUpToHeadOrEndblock if chain fetcher is at the head and
|
|
288
282
|
//its not already set
|
|
289
283
|
//CASE1
|
|
@@ -319,7 +313,7 @@ let updateProgressedChains = (
|
|
|
319
313
|
let allChainsSyncedAtHead =
|
|
320
314
|
chainFetchers
|
|
321
315
|
->ChainMap.values
|
|
322
|
-
->Array.every(cf => cf
|
|
316
|
+
->Array.every(cf => cf->ChainFetcher.isLive)
|
|
323
317
|
|
|
324
318
|
if allChainsSyncedAtHead {
|
|
325
319
|
Prometheus.setAllChainsSyncedToHead()
|
|
@@ -398,7 +392,7 @@ let validatePartitionQueryResponse = (
|
|
|
398
392
|
| ReorgDetected(reorgDetected) => {
|
|
399
393
|
chainFetcher.logger->Logging.childInfo(
|
|
400
394
|
reorgDetected->ReorgDetection.reorgDetectedToLogParams(
|
|
401
|
-
~shouldRollbackOnReorg=state.
|
|
395
|
+
~shouldRollbackOnReorg=state.ctx.config.shouldRollbackOnReorg,
|
|
402
396
|
),
|
|
403
397
|
)
|
|
404
398
|
Prometheus.ReorgCount.increment(~chain)
|
|
@@ -406,7 +400,7 @@ let validatePartitionQueryResponse = (
|
|
|
406
400
|
~blockNumber=reorgDetected.scannedBlock.blockNumber,
|
|
407
401
|
~chain,
|
|
408
402
|
)
|
|
409
|
-
if state.
|
|
403
|
+
if state.ctx.config.shouldRollbackOnReorg {
|
|
410
404
|
Some(reorgDetected.scannedBlock.blockNumber)
|
|
411
405
|
} else {
|
|
412
406
|
None
|
|
@@ -531,7 +525,7 @@ let processPartitionQueryResponse = async (
|
|
|
531
525
|
await ChainFetcher.runContractRegistersOrThrow(
|
|
532
526
|
~itemsWithContractRegister,
|
|
533
527
|
~chain,
|
|
534
|
-
~config=state.
|
|
528
|
+
~config=state.ctx.config,
|
|
535
529
|
)
|
|
536
530
|
}
|
|
537
531
|
|
|
@@ -606,7 +600,7 @@ let actionReducer = (state: t, action: action) => {
|
|
|
606
600
|
)
|
|
607
601
|
|
|
608
602
|
let isBelowReorgThreshold =
|
|
609
|
-
!state.chainManager.isInReorgThreshold && state.
|
|
603
|
+
!state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg
|
|
610
604
|
let shouldEnterReorgThreshold =
|
|
611
605
|
isBelowReorgThreshold &&
|
|
612
606
|
updatedChainFetchers
|
|
@@ -650,7 +644,7 @@ let actionReducer = (state: t, action: action) => {
|
|
|
650
644
|
)
|
|
651
645
|
| EventBatchProcessed({batch}) =>
|
|
652
646
|
let maybePruneEntityHistory =
|
|
653
|
-
state.
|
|
647
|
+
state.ctx.config->Config.shouldPruneHistory(
|
|
654
648
|
~isInReorgThreshold=state.chainManager.isInReorgThreshold,
|
|
655
649
|
)
|
|
656
650
|
? [PruneStaleEntityHistory]
|
|
@@ -661,7 +655,7 @@ let actionReducer = (state: t, action: action) => {
|
|
|
661
655
|
// Can safely reset rollback state, since overwrite is not possible.
|
|
662
656
|
// If rollback is pending, the EventBatchProcessed will be handled by the invalid action reducer instead.
|
|
663
657
|
rollbackState: NoRollback,
|
|
664
|
-
chainManager: state.chainManager->updateProgressedChains(~batch, ~
|
|
658
|
+
chainManager: state.chainManager->updateProgressedChains(~batch, ~ctx=state.ctx),
|
|
665
659
|
currentlyProcessingBatch: false,
|
|
666
660
|
processedBatches: state.processedBatches + 1,
|
|
667
661
|
}
|
|
@@ -760,7 +754,7 @@ let invalidatedActionReducer = (state: t, action: action) =>
|
|
|
760
754
|
(
|
|
761
755
|
{
|
|
762
756
|
...state,
|
|
763
|
-
chainManager: state.chainManager->updateProgressedChains(~batch, ~
|
|
757
|
+
chainManager: state.chainManager->updateProgressedChains(~batch, ~ctx=state.ctx),
|
|
764
758
|
currentlyProcessingBatch: false,
|
|
765
759
|
processedBatches: state.processedBatches + 1,
|
|
766
760
|
},
|
|
@@ -827,18 +821,18 @@ let injectedTaskReducer = (
|
|
|
827
821
|
switch state.chainManager->ChainManager.getSafeCheckpointId {
|
|
828
822
|
| None => ()
|
|
829
823
|
| Some(safeCheckpointId) =>
|
|
830
|
-
await state.
|
|
824
|
+
await state.ctx.persistence.storage.pruneStaleCheckpoints(~safeCheckpointId)
|
|
831
825
|
|
|
832
|
-
for idx in 0 to state.
|
|
826
|
+
for idx in 0 to state.ctx.persistence.allEntities->Array.length - 1 {
|
|
833
827
|
if idx !== 0 {
|
|
834
828
|
// Add some delay between entities
|
|
835
829
|
// To unblock the pg client if it's needed for something else
|
|
836
830
|
await Utils.delay(1000)
|
|
837
831
|
}
|
|
838
|
-
let entityConfig = state.
|
|
832
|
+
let entityConfig = state.ctx.persistence.allEntities->Array.getUnsafe(idx)
|
|
839
833
|
let timeRef = Hrtime.makeTimer()
|
|
840
834
|
try {
|
|
841
|
-
let () = await state.
|
|
835
|
+
let () = await state.ctx.persistence.storage.pruneStaleEntityHistory(
|
|
842
836
|
~entityName=entityConfig.name,
|
|
843
837
|
~entityIndex=entityConfig.index,
|
|
844
838
|
~safeCheckpointId,
|
|
@@ -871,14 +865,14 @@ let injectedTaskReducer = (
|
|
|
871
865
|
updateChainMetadataTable(
|
|
872
866
|
chainManager,
|
|
873
867
|
~throttler=writeThrottlers.chainMetaData,
|
|
874
|
-
~persistence=state.
|
|
868
|
+
~persistence=state.ctx.persistence,
|
|
875
869
|
)
|
|
876
870
|
dispatchAction(SuccessExit)
|
|
877
871
|
| NoExit =>
|
|
878
872
|
updateChainMetadataTable(
|
|
879
873
|
chainManager,
|
|
880
874
|
~throttler=writeThrottlers.chainMetaData,
|
|
881
|
-
~persistence=state.
|
|
875
|
+
~persistence=state.ctx.persistence,
|
|
882
876
|
)->ignore
|
|
883
877
|
}
|
|
884
878
|
| NextQuery(chainCheck) =>
|
|
@@ -911,7 +905,7 @@ let injectedTaskReducer = (
|
|
|
911
905
|
|
|
912
906
|
let batch =
|
|
913
907
|
state.chainManager->ChainManager.createBatch(
|
|
914
|
-
~batchSizeTarget=state.
|
|
908
|
+
~batchSizeTarget=state.ctx.config.batchSize,
|
|
915
909
|
~isRollback=rollbackInMemStore !== None,
|
|
916
910
|
)
|
|
917
911
|
|
|
@@ -919,10 +913,10 @@ let injectedTaskReducer = (
|
|
|
919
913
|
let totalBatchSize = batch.totalBatchSize
|
|
920
914
|
|
|
921
915
|
let isInReorgThreshold = state.chainManager.isInReorgThreshold
|
|
922
|
-
let shouldSaveHistory = state.
|
|
916
|
+
let shouldSaveHistory = state.ctx.config->Config.shouldSaveHistory(~isInReorgThreshold)
|
|
923
917
|
|
|
924
918
|
let isBelowReorgThreshold =
|
|
925
|
-
!state.chainManager.isInReorgThreshold && state.
|
|
919
|
+
!state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg
|
|
926
920
|
let shouldEnterReorgThreshold =
|
|
927
921
|
isBelowReorgThreshold &&
|
|
928
922
|
state.chainManager.chainFetchers
|
|
@@ -958,7 +952,7 @@ let injectedTaskReducer = (
|
|
|
958
952
|
|
|
959
953
|
let inMemoryStore =
|
|
960
954
|
rollbackInMemStore->Option.getWithDefault(
|
|
961
|
-
InMemoryStore.make(~entities=state.
|
|
955
|
+
InMemoryStore.make(~entities=state.ctx.persistence.allEntities),
|
|
962
956
|
)
|
|
963
957
|
|
|
964
958
|
inMemoryStore->InMemoryStore.setBatchDcs(~batch, ~shouldSaveHistory)
|
|
@@ -968,7 +962,7 @@ let injectedTaskReducer = (
|
|
|
968
962
|
~inMemoryStore,
|
|
969
963
|
~isInReorgThreshold,
|
|
970
964
|
~loadManager=state.loadManager,
|
|
971
|
-
~
|
|
965
|
+
~ctx=state.ctx,
|
|
972
966
|
~chainFetchers=state.chainManager.chainFetchers,
|
|
973
967
|
) {
|
|
974
968
|
| exception exn =>
|
|
@@ -1027,7 +1021,7 @@ let injectedTaskReducer = (
|
|
|
1027
1021
|
let reorgChainId = reorgChain->ChainMap.Chain.toChainId
|
|
1028
1022
|
|
|
1029
1023
|
let rollbackTargetCheckpointId = {
|
|
1030
|
-
switch await state.
|
|
1024
|
+
switch await state.ctx.persistence.storage.getRollbackTargetCheckpoint(
|
|
1031
1025
|
~reorgChainId,
|
|
1032
1026
|
~lastKnownValidBlockNumber=rollbackTargetBlockNumber,
|
|
1033
1027
|
) {
|
|
@@ -1041,7 +1035,7 @@ let injectedTaskReducer = (
|
|
|
1041
1035
|
let rollbackedProcessedEvents = ref(0)
|
|
1042
1036
|
|
|
1043
1037
|
{
|
|
1044
|
-
let rollbackProgressDiff = await state.
|
|
1038
|
+
let rollbackProgressDiff = await state.ctx.persistence.storage.getRollbackProgressDiff(
|
|
1045
1039
|
~rollbackTargetCheckpointId,
|
|
1046
1040
|
)
|
|
1047
1041
|
for idx in 0 to rollbackProgressDiff->Js.Array2.length - 1 {
|
|
@@ -1125,7 +1119,7 @@ let injectedTaskReducer = (
|
|
|
1125
1119
|
|
|
1126
1120
|
// Construct in Memory store with rollback diff
|
|
1127
1121
|
let diff =
|
|
1128
|
-
await state.
|
|
1122
|
+
await state.ctx.persistence->Persistence.prepareRollbackDiff(
|
|
1129
1123
|
~rollbackTargetCheckpointId,
|
|
1130
1124
|
~rollbackDiffCheckpointId=state.chainManager.committedCheckpointId +. 1.,
|
|
1131
1125
|
)
|