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.
Files changed (79) hide show
  1. package/README.md +2 -2
  2. package/evm.schema.json +0 -1
  3. package/index.d.ts +333 -2
  4. package/index.js +4 -0
  5. package/package.json +13 -6
  6. package/rescript.json +4 -1
  7. package/src/ChainFetcher.res +25 -1
  8. package/src/ChainFetcher.res.mjs +19 -1
  9. package/src/Config.res +212 -19
  10. package/src/Config.res.mjs +228 -29
  11. package/src/{Indexer.res → Ctx.res} +1 -1
  12. package/src/Ecosystem.res +2 -2
  13. package/src/Ecosystem.res.mjs +1 -1
  14. package/src/Envio.gen.ts +1 -1
  15. package/src/Envio.res +1 -1
  16. package/src/EventProcessing.res +18 -18
  17. package/src/EventProcessing.res.mjs +14 -14
  18. package/src/GlobalState.res +29 -35
  19. package/src/GlobalState.res.mjs +47 -47
  20. package/src/GlobalStateManager.res +68 -0
  21. package/src/GlobalStateManager.res.mjs +75 -0
  22. package/src/GlobalStateManager.resi +7 -0
  23. package/src/Internal.res +41 -1
  24. package/src/LogSelection.res +33 -27
  25. package/src/LogSelection.res.mjs +6 -0
  26. package/src/Main.res +342 -0
  27. package/src/Main.res.mjs +289 -0
  28. package/src/PgStorage.gen.ts +10 -0
  29. package/src/PgStorage.res +24 -2
  30. package/src/PgStorage.res.d.mts +5 -0
  31. package/src/PgStorage.res.mjs +22 -1
  32. package/src/Types.ts +1 -1
  33. package/src/UserContext.res +0 -1
  34. package/src/UserContext.res.mjs +0 -2
  35. package/src/Utils.res +28 -0
  36. package/src/Utils.res.mjs +18 -0
  37. package/src/bindings/ClickHouse.res +31 -1
  38. package/src/bindings/ClickHouse.res.mjs +27 -1
  39. package/src/bindings/Ethers.res +27 -67
  40. package/src/bindings/Ethers.res.mjs +18 -70
  41. package/src/bindings/Postgres.gen.ts +8 -0
  42. package/src/bindings/Postgres.res +3 -0
  43. package/src/bindings/Postgres.res.d.mts +5 -0
  44. package/src/bindings/RescriptMocha.res +123 -0
  45. package/src/bindings/RescriptMocha.res.mjs +18 -0
  46. package/src/bindings/Yargs.res +8 -0
  47. package/src/bindings/Yargs.res.mjs +2 -0
  48. package/src/sources/FuelSDK.res +4 -3
  49. package/src/sources/HyperSyncHeightStream.res +28 -110
  50. package/src/sources/HyperSyncHeightStream.res.mjs +30 -63
  51. package/src/sources/HyperSyncSource.res +11 -13
  52. package/src/sources/HyperSyncSource.res.mjs +20 -20
  53. package/src/sources/Rpc.res +43 -0
  54. package/src/sources/Rpc.res.mjs +31 -0
  55. package/src/sources/RpcSource.res +9 -4
  56. package/src/sources/RpcSource.res.mjs +9 -4
  57. package/src/sources/Source.res +1 -0
  58. package/src/sources/SourceManager.res +164 -81
  59. package/src/sources/SourceManager.res.mjs +146 -83
  60. package/src/sources/{Solana.res → Svm.res} +4 -4
  61. package/src/sources/{Solana.res.mjs → Svm.res.mjs} +4 -4
  62. package/src/tui/Tui.res +266 -0
  63. package/src/tui/Tui.res.mjs +342 -0
  64. package/src/tui/bindings/Ink.res +376 -0
  65. package/src/tui/bindings/Ink.res.mjs +75 -0
  66. package/src/tui/bindings/Style.res +123 -0
  67. package/src/tui/bindings/Style.res.mjs +2 -0
  68. package/src/tui/components/BufferedProgressBar.res +40 -0
  69. package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
  70. package/src/tui/components/CustomHooks.res +114 -0
  71. package/src/tui/components/CustomHooks.res.mjs +162 -0
  72. package/src/tui/components/Messages.res +41 -0
  73. package/src/tui/components/Messages.res.mjs +75 -0
  74. package/src/tui/components/SyncETA.res +193 -0
  75. package/src/tui/components/SyncETA.res.mjs +269 -0
  76. package/src/tui/components/TuiData.res +46 -0
  77. package/src/tui/components/TuiData.res.mjs +29 -0
  78. package/src/bindings/Ethers.gen.ts +0 -14
  79. /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
@@ -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.timestampCaughtUpToHeadOrEndblock !== None
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
- ~indexer: Indexer.t,
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: indexer.persistence,
184
+ persistence: ctx.persistence,
185
185
  shouldSaveHistory,
186
186
  checkpointId,
187
187
  isPreload: false,
188
188
  chains,
189
- config: indexer.config,
189
+ config: ctx.config,
190
190
  isResolved: false,
191
191
  }
192
192
  await handler(
193
193
  Ecosystem.makeOnBlockArgs(
194
194
  ~blockNumber,
195
- ~ecosystem=indexer.config.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=indexer.persistence,
218
+ ~persistence=ctx.persistence,
219
219
  ~shouldSaveHistory,
220
220
  ~shouldBenchmark,
221
221
  ~chains,
222
- ~config=indexer.config,
222
+ ~config=ctx.config,
223
223
  )
224
224
  | None => ()
225
225
  }
226
226
 
227
- if indexer.config.enableRawEvents {
227
+ if ctx.config.enableRawEvents {
228
228
  item
229
229
  ->Internal.castUnsafeEventItem
230
- ->addItemToRawEvents(~inMemoryStore, ~config=indexer.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
- ~indexer,
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
- ~indexer,
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
- ~indexer: Indexer.t,
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=indexer.persistence,
414
+ ~persistence=ctx.persistence,
415
415
  ~inMemoryStore,
416
416
  ~chains,
417
- ~config=indexer.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
- ~indexer,
428
- ~shouldSaveHistory=indexer.config->Config.shouldSaveHistory(~isInReorgThreshold),
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 indexer.persistence->Persistence.writeBatch(
438
+ await ctx.persistence->Persistence.writeBatch(
439
439
  ~batch,
440
- ~config=indexer.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].timestampCaughtUpToHeadOrEndblock !== undefined;
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, indexer, shouldSaveHistory, shouldBenchmark, chains) {
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, indexer.persistence, shouldSaveHistory, shouldBenchmark, chains, indexer.config);
141
+ await runEventHandlerOrThrow(item, checkpointId, handler, inMemoryStore, loadManager, ctx.persistence, shouldSaveHistory, shouldBenchmark, chains, ctx.config);
142
142
  }
143
- if (indexer.config.enableRawEvents) {
144
- return addItemToRawEvents(item, inMemoryStore, indexer.config);
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: indexer.persistence,
155
+ persistence: ctx.persistence,
156
156
  isPreload: false,
157
157
  shouldSaveHistory: shouldSaveHistory,
158
158
  chains: chains,
159
- config: indexer.config,
159
+ config: ctx.config,
160
160
  isResolved: false
161
161
  };
162
- await item.onBlockConfig.handler(Ecosystem.makeOnBlockArgs(item.blockNumber, indexer.config.ecosystem, UserContext.getHandlerContext(contextParams)));
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, indexer, shouldSaveHistory, shouldBenchmark, chains) {
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, indexer, shouldSaveHistory, shouldBenchmark, chains);
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, indexer, chainFetchers) {
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, indexer.persistence, indexer.config, inMemoryStore, chains);
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, indexer, Config.shouldSaveHistory(indexer.config, isInReorgThreshold), Env.Benchmark.shouldSaveData, chains);
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(indexer.persistence, batch, indexer.config, inMemoryStore, isInReorgThreshold);
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;
@@ -40,7 +40,7 @@ module WriteThrottlers = {
40
40
  }
41
41
 
42
42
  type t = {
43
- indexer: Indexer.t,
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
- ~indexer: Indexer.t,
58
+ ~ctx: Ctx.t,
59
59
  ~chainManager: ChainManager.t,
60
60
  ~isDevelopmentMode=false,
61
61
  ~shouldUseTui=false,
62
62
  ) => {
63
63
  {
64
- indexer,
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->indexer.config.ecosystem.getTimestamp
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->Option.isSome
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.timestampCaughtUpToHeadOrEndblock->Option.isNone && cf.isProgressAtHead {
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.timestampCaughtUpToHeadOrEndblock->Option.isSome)
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.indexer.config.shouldRollbackOnReorg,
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.indexer.config.shouldRollbackOnReorg {
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.indexer.config,
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.indexer.config.shouldRollbackOnReorg
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.indexer.config->Config.shouldPruneHistory(
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, ~indexer=state.indexer),
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, ~indexer=state.indexer),
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.indexer.persistence.storage.pruneStaleCheckpoints(~safeCheckpointId)
824
+ await state.ctx.persistence.storage.pruneStaleCheckpoints(~safeCheckpointId)
831
825
 
832
- for idx in 0 to state.indexer.persistence.allEntities->Array.length - 1 {
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.indexer.persistence.allEntities->Array.getUnsafe(idx)
832
+ let entityConfig = state.ctx.persistence.allEntities->Array.getUnsafe(idx)
839
833
  let timeRef = Hrtime.makeTimer()
840
834
  try {
841
- let () = await state.indexer.persistence.storage.pruneStaleEntityHistory(
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.indexer.persistence,
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.indexer.persistence,
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.indexer.config.batchSize,
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.indexer.config->Config.shouldSaveHistory(~isInReorgThreshold)
916
+ let shouldSaveHistory = state.ctx.config->Config.shouldSaveHistory(~isInReorgThreshold)
923
917
 
924
918
  let isBelowReorgThreshold =
925
- !state.chainManager.isInReorgThreshold && state.indexer.config.shouldRollbackOnReorg
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.indexer.persistence.allEntities),
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
- ~indexer=state.indexer,
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.indexer.persistence.storage.getRollbackTargetCheckpoint(
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.indexer.persistence.storage.getRollbackProgressDiff(
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.indexer.persistence->Persistence.prepareRollbackDiff(
1122
+ await state.ctx.persistence->Persistence.prepareRollbackDiff(
1129
1123
  ~rollbackTargetCheckpointId,
1130
1124
  ~rollbackDiffCheckpointId=state.chainManager.committedCheckpointId +. 1.,
1131
1125
  )