envio 3.1.0-rc.1 → 3.1.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.
@@ -7,22 +7,8 @@ type rollbackState =
7
7
  | RollbackReady({eventsProcessedDiffByChain: dict<float>})
8
8
 
9
9
  module WriteThrottlers = {
10
- type t = {
11
- chainMetaData: Throttler.t,
12
- pruneStaleEntityHistory: Throttler.t,
13
- }
10
+ type t = {pruneStaleEntityHistory: Throttler.t}
14
11
  let make = (): t => {
15
- let chainMetaData = {
16
- let intervalMillis = Env.ThrottleWrites.chainMetadataIntervalMillis
17
- let logger = Logging.createChild(
18
- ~params={
19
- "context": "Throttler for chain metadata writes",
20
- "intervalMillis": intervalMillis,
21
- },
22
- )
23
- Throttler.make(~intervalMillis, ~logger)
24
- }
25
-
26
12
  let pruneStaleEntityHistory = {
27
13
  let intervalMillis = Env.ThrottleWrites.pruneStaleDataIntervalMillis
28
14
  let logger = Logging.createChild(
@@ -33,7 +19,7 @@ module WriteThrottlers = {
33
19
  )
34
20
  Throttler.make(~intervalMillis, ~logger)
35
21
  }
36
- {chainMetaData, pruneStaleEntityHistory}
22
+ {pruneStaleEntityHistory: pruneStaleEntityHistory}
37
23
  }
38
24
  }
39
25
 
@@ -48,6 +34,8 @@ type t = {
48
34
  loadManager: LoadManager.t,
49
35
  keepProcessAlive: bool,
50
36
  exitAfterFirstEventBlock: bool,
37
+ // The single fatal-error handler ErrorExit delegates to.
38
+ onError: ErrorHandling.t => unit,
51
39
  //Initialized as 0, increments, when rollbacks occur to invalidate
52
40
  //responses based on the wrong stateId
53
41
  id: int,
@@ -59,6 +47,7 @@ let make = (
59
47
  ~isDevelopmentMode=false,
60
48
  ~shouldUseTui=false,
61
49
  ~exitAfterFirstEventBlock=false,
50
+ ~onError: ErrorHandling.t => unit,
62
51
  ) => {
63
52
  {
64
53
  ctx,
@@ -71,6 +60,7 @@ let make = (
71
60
  loadManager: LoadManager.make(),
72
61
  keepProcessAlive: isDevelopmentMode || shouldUseTui,
73
62
  exitAfterFirstEventBlock,
63
+ onError,
74
64
  id: 0,
75
65
  }
76
66
  }
@@ -145,11 +135,7 @@ type task =
145
135
  | Rollback
146
136
  | PruneStaleEntityHistory
147
137
 
148
- let updateChainMetadataTable = (
149
- cm: ChainManager.t,
150
- ~persistence: Persistence.t,
151
- ~throttler: Throttler.t,
152
- ) => {
138
+ let updateChainMetadataTable = (cm: ChainManager.t, ~inMemoryStore: InMemoryStore.t) => {
153
139
  let chainsData: dict<InternalTable.Chains.metaFields> = Dict.make()
154
140
 
155
141
  cm.chainFetchers
@@ -166,10 +152,8 @@ let updateChainMetadataTable = (
166
152
  )
167
153
  })
168
154
 
169
- //Don't await this set, it can happen in its own time
170
- throttler->Throttler.schedule(() =>
171
- persistence.storage.setChainMeta(chainsData)->Utils.Promise.ignoreValue
172
- )
155
+ // Staged; the cycle folds the stale diff into the next batch write.
156
+ inMemoryStore->InMemoryStore.setChainMeta(chainsData)
173
157
  }
174
158
 
175
159
  /**
@@ -711,12 +695,17 @@ let actionReducer = (state: t, action: action) => {
711
695
  NoExit
712
696
  }
713
697
 
714
- (
715
- state,
698
+ // On exit, stop dispatching ProcessEventBatch: the flush is async and would
699
+ // otherwise keep processing further batches while it runs.
700
+ let tasks = switch shouldExit {
701
+ | ExitWithSuccess
702
+ | ExitWithError(_) => [UpdateChainMetaDataAndCheckForExit(shouldExit)]
703
+ | NoExit =>
716
704
  [UpdateChainMetaDataAndCheckForExit(shouldExit), ProcessEventBatch]->Array.concat(
717
705
  maybePruneEntityHistory,
718
- ),
719
- )
706
+ )
707
+ }
708
+ (state, tasks)
720
709
 
721
710
  | StartProcessingBatch => ({...state, currentlyProcessingBatch: true}, [])
722
711
  | StartFindingReorgDepth => ({...state, rollbackState: FindingReorgDepth}, [])
@@ -775,8 +764,7 @@ let actionReducer = (state: t, action: action) => {
775
764
  (state, [])
776
765
  }
777
766
  | ErrorExit(errHandler) =>
778
- errHandler->ErrorHandling.log
779
- NodeJs.process->NodeJs.exitWithCode(Failure)
767
+ state.onError(errHandler)
780
768
  (state, [])
781
769
  }
782
770
  }
@@ -902,23 +890,15 @@ let injectedTaskReducer = (
902
890
  state.writeThrottlers.pruneStaleEntityHistory->Throttler.schedule(runPrune)
903
891
 
904
892
  | UpdateChainMetaDataAndCheckForExit(shouldExit) =>
905
- let {chainManager, writeThrottlers} = state
893
+ let {chainManager} = state
906
894
  switch shouldExit {
907
895
  | ExitWithSuccess =>
908
- updateChainMetadataTable(
909
- chainManager,
910
- ~throttler=writeThrottlers.chainMetaData,
911
- ~persistence=state.ctx.persistence,
912
- )
896
+ updateChainMetadataTable(chainManager, ~inMemoryStore=state.ctx.inMemoryStore)
897
+ await state.ctx.inMemoryStore->InMemoryStore.flush
913
898
  dispatchAction(SuccessExit)
914
899
  | ExitWithError(msg) =>
915
900
  dispatchAction(ErrorExit(ErrorHandling.make(JsError.throwWithMessage(msg))))
916
- | NoExit =>
917
- updateChainMetadataTable(
918
- chainManager,
919
- ~throttler=writeThrottlers.chainMetaData,
920
- ~persistence=state.ctx.persistence,
921
- )->ignore
901
+ | NoExit => updateChainMetadataTable(chainManager, ~inMemoryStore=state.ctx.inMemoryStore)
922
902
  }
923
903
  | NextQuery(chainCheck) =>
924
904
  let fetchForChain = checkAndFetchForChain(
@@ -947,15 +927,13 @@ let injectedTaskReducer = (
947
927
 
948
928
  let batch =
949
929
  state.chainManager->ChainManager.createBatch(
950
- ~committedCheckpointId=state.ctx.inMemoryStore.committedCheckpointId,
930
+ ~processedCheckpointId=state.ctx.inMemoryStore.processedCheckpointId,
951
931
  ~batchSizeTarget=state.ctx.config.batchSize,
952
932
  ~isRollback=isRollbackBatch,
953
933
  )
954
934
 
955
935
  let progressedChainsById = batch.progressedChainsById
956
936
 
957
- let isInReorgThreshold = state.chainManager.isInReorgThreshold
958
-
959
937
  let isBelowReorgThreshold =
960
938
  !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg
961
939
  let shouldEnterReorgThreshold =
@@ -982,11 +960,8 @@ let injectedTaskReducer = (
982
960
  if EventProcessing.allChainsEventsProcessedToEndblock(state.chainManager.chainFetchers) {
983
961
  Logging.info("All chains are caught up to end blocks.")
984
962
  if !state.keepProcessAlive {
985
- updateChainMetadataTable(
986
- state.chainManager,
987
- ~persistence=state.ctx.persistence,
988
- ~throttler=state.writeThrottlers.chainMetaData,
989
- )
963
+ updateChainMetadataTable(state.chainManager, ~inMemoryStore=state.ctx.inMemoryStore)
964
+ await state.ctx.inMemoryStore->InMemoryStore.flush
990
965
  dispatchAction(SuccessExit)
991
966
  }
992
967
  }
@@ -1000,7 +975,6 @@ let injectedTaskReducer = (
1000
975
  switch await EventProcessing.processEventBatch(
1001
976
  ~batch,
1002
977
  ~inMemoryStore,
1003
- ~isInReorgThreshold,
1004
978
  ~loadManager=state.loadManager,
1005
979
  ~ctx=state.ctx,
1006
980
  ~chainFetchers=state.chainManager.chainFetchers,
@@ -1177,10 +1151,15 @@ let injectedTaskReducer = (
1177
1151
  }
1178
1152
  })
1179
1153
 
1154
+ // Finish pending writes so committedCheckpointId reflects the db before
1155
+ // computing the rollback diff against it.
1156
+ await state.ctx.inMemoryStore->InMemoryStore.flush
1157
+
1180
1158
  let diff = await state.ctx.inMemoryStore->InMemoryStore.prepareRollbackDiff(
1181
1159
  ~persistence=state.ctx.persistence,
1182
1160
  ~rollbackTargetCheckpointId,
1183
1161
  ~rollbackDiffCheckpointId=state.ctx.inMemoryStore.committedCheckpointId->BigInt.add(1n),
1162
+ ~progressBlockNumberByChainId=newProgressBlockNumberPerChain,
1184
1163
  )
1185
1164
 
1186
1165
  let chainManager = {
@@ -32,20 +32,13 @@ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_excep
32
32
  import * as SafeCheckpointTracking from "./SafeCheckpointTracking.res.mjs";
33
33
 
34
34
  function make() {
35
- let intervalMillis = Env.ThrottleWrites.chainMetadataIntervalMillis;
35
+ let intervalMillis = Env.ThrottleWrites.pruneStaleDataIntervalMillis;
36
36
  let logger = Logging.createChild({
37
- context: "Throttler for chain metadata writes",
38
- intervalMillis: intervalMillis
39
- });
40
- let chainMetaData = Throttler.make(intervalMillis, logger);
41
- let intervalMillis$1 = Env.ThrottleWrites.pruneStaleDataIntervalMillis;
42
- let logger$1 = Logging.createChild({
43
37
  context: "Throttler for pruning stale entity history data",
44
- intervalMillis: intervalMillis$1
38
+ intervalMillis: intervalMillis
45
39
  });
46
- let pruneStaleEntityHistory = Throttler.make(intervalMillis$1, logger$1);
40
+ let pruneStaleEntityHistory = Throttler.make(intervalMillis, logger);
47
41
  return {
48
- chainMetaData: chainMetaData,
49
42
  pruneStaleEntityHistory: pruneStaleEntityHistory
50
43
  };
51
44
  }
@@ -54,7 +47,7 @@ let WriteThrottlers = {
54
47
  make: make
55
48
  };
56
49
 
57
- function make$1(ctx, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt, exitAfterFirstEventBlockOpt) {
50
+ function make$1(ctx, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt, exitAfterFirstEventBlockOpt, onError) {
58
51
  let isDevelopmentMode = isDevelopmentModeOpt !== undefined ? isDevelopmentModeOpt : false;
59
52
  let shouldUseTui = shouldUseTuiOpt !== undefined ? shouldUseTuiOpt : false;
60
53
  let exitAfterFirstEventBlock = exitAfterFirstEventBlockOpt !== undefined ? exitAfterFirstEventBlockOpt : false;
@@ -69,6 +62,7 @@ function make$1(ctx, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt, exitAf
69
62
  loadManager: LoadManager.make(),
70
63
  keepProcessAlive: isDevelopmentMode || shouldUseTui,
71
64
  exitAfterFirstEventBlock: exitAfterFirstEventBlock,
65
+ onError: onError,
72
66
  id: 0
73
67
  };
74
68
  }
@@ -89,6 +83,7 @@ function setChainManager(self, chainManager) {
89
83
  loadManager: self.loadManager,
90
84
  keepProcessAlive: self.keepProcessAlive,
91
85
  exitAfterFirstEventBlock: self.exitAfterFirstEventBlock,
86
+ onError: self.onError,
92
87
  id: self.id
93
88
  };
94
89
  }
@@ -102,7 +97,7 @@ function isPreparingRollback(state) {
102
97
  }
103
98
  }
104
99
 
105
- function updateChainMetadataTable(cm, persistence, throttler) {
100
+ function updateChainMetadataTable(cm, inMemoryStore) {
106
101
  let chainsData = {};
107
102
  Belt_Array.forEach(ChainMap.values(cm.chainFetchers), cf => {
108
103
  chainsData[String(cf.chainConfig.id)] = {
@@ -112,7 +107,7 @@ function updateChainMetadataTable(cm, persistence, throttler) {
112
107
  _is_hyper_sync: SourceManager.getActiveSource(cf.sourceManager).poweredByHyperSync
113
108
  };
114
109
  });
115
- Throttler.schedule(throttler, () => persistence.storage.setChainMeta(chainsData));
110
+ InMemoryStore.setChainMeta(inMemoryStore, chainsData);
116
111
  }
117
112
 
118
113
  function updateProgressedChains(chainManager, batch, ctx) {
@@ -299,6 +294,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
299
294
  let nextState_loadManager = state.loadManager;
300
295
  let nextState_keepProcessAlive = state.keepProcessAlive;
301
296
  let nextState_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
297
+ let nextState_onError = state.onError;
302
298
  let nextState_id = state.id;
303
299
  let nextState = {
304
300
  ctx: nextState_ctx,
@@ -311,6 +307,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
311
307
  loadManager: nextState_loadManager,
312
308
  keepProcessAlive: nextState_keepProcessAlive,
313
309
  exitAfterFirstEventBlock: nextState_exitAfterFirstEventBlock,
310
+ onError: nextState_onError,
314
311
  id: nextState_id
315
312
  };
316
313
  let rollbackWithReorgDetectedBlockNumber;
@@ -394,6 +391,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
394
391
  loadManager: nextState_loadManager,
395
392
  keepProcessAlive: nextState_keepProcessAlive,
396
393
  exitAfterFirstEventBlock: nextState_exitAfterFirstEventBlock,
394
+ onError: nextState_onError,
397
395
  id: nextState_id + 1 | 0
398
396
  },
399
397
  ["Rollback"]
@@ -491,6 +489,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
491
489
  let nextState_loadManager = state.loadManager;
492
490
  let nextState_keepProcessAlive = state.keepProcessAlive;
493
491
  let nextState_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
492
+ let nextState_onError = state.onError;
494
493
  let nextState_id = state.id;
495
494
  let nextState = {
496
495
  ctx: nextState_ctx,
@@ -503,6 +502,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
503
502
  loadManager: nextState_loadManager,
504
503
  keepProcessAlive: nextState_keepProcessAlive,
505
504
  exitAfterFirstEventBlock: nextState_exitAfterFirstEventBlock,
505
+ onError: nextState_onError,
506
506
  id: nextState_id
507
507
  };
508
508
  return [
@@ -569,6 +569,7 @@ function updateChainFetcher(chainFetcherUpdate, state, chain) {
569
569
  loadManager: state.loadManager,
570
570
  keepProcessAlive: state.keepProcessAlive,
571
571
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
572
+ onError: state.onError,
572
573
  id: state.id
573
574
  },
574
575
  []
@@ -606,6 +607,7 @@ function onEnterReorgThreshold(state) {
606
607
  loadManager: state.loadManager,
607
608
  keepProcessAlive: state.keepProcessAlive,
608
609
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
610
+ onError: state.onError,
609
611
  id: state.id
610
612
  };
611
613
  }
@@ -626,6 +628,7 @@ function actionReducer(state, action) {
626
628
  loadManager: state.loadManager,
627
629
  keepProcessAlive: state.keepProcessAlive,
628
630
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
631
+ onError: state.onError,
629
632
  id: state.id
630
633
  },
631
634
  []
@@ -643,6 +646,7 @@ function actionReducer(state, action) {
643
646
  loadManager: state.loadManager,
644
647
  keepProcessAlive: state.keepProcessAlive,
645
648
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
649
+ onError: state.onError,
646
650
  id: state.id
647
651
  },
648
652
  []
@@ -708,6 +712,7 @@ function actionReducer(state, action) {
708
712
  let state_loadManager = state.loadManager;
709
713
  let state_keepProcessAlive = state.keepProcessAlive;
710
714
  let state_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
715
+ let state_onError = state.onError;
711
716
  let state_id = state.id;
712
717
  let state$1 = {
713
718
  ctx: state_ctx,
@@ -720,6 +725,7 @@ function actionReducer(state, action) {
720
725
  loadManager: state_loadManager,
721
726
  keepProcessAlive: state_keepProcessAlive,
722
727
  exitAfterFirstEventBlock: state_exitAfterFirstEventBlock,
728
+ onError: state_onError,
723
729
  id: state_id
724
730
  };
725
731
  if (shouldEnterReorgThreshold) {
@@ -758,6 +764,7 @@ function actionReducer(state, action) {
758
764
  let state_loadManager$1 = state.loadManager;
759
765
  let state_keepProcessAlive$1 = state.keepProcessAlive;
760
766
  let state_exitAfterFirstEventBlock$1 = state.exitAfterFirstEventBlock;
767
+ let state_onError$1 = state.onError;
761
768
  let state_id$1 = state.id;
762
769
  let state$2 = {
763
770
  ctx: state_ctx$1,
@@ -770,6 +777,7 @@ function actionReducer(state, action) {
770
777
  loadManager: state_loadManager$1,
771
778
  keepProcessAlive: state_keepProcessAlive$1,
772
779
  exitAfterFirstEventBlock: state_exitAfterFirstEventBlock$1,
780
+ onError: state_onError$1,
773
781
  id: state_id$1
774
782
  };
775
783
  let shouldExit = EventProcessing.allChainsEventsProcessedToEndblock(state_chainManager$1.chainFetchers) ? (Logging.info("All chains are caught up to end blocks."), state_keepProcessAlive$1 ? "NoExit" : "ExitWithSuccess") : (
@@ -784,15 +792,25 @@ function actionReducer(state, action) {
784
792
  _0: "No events found between startBlock and chain head. Cannot auto-detect endBlock."
785
793
  }) : "NoExit"
786
794
  );
787
- return [
788
- state$2,
789
- [
790
- {
795
+ let tasks;
796
+ tasks = typeof shouldExit !== "object" ? (
797
+ shouldExit === "ExitWithSuccess" ? [{
798
+ TAG: "UpdateChainMetaDataAndCheckForExit",
799
+ _0: shouldExit
800
+ }] : [
801
+ {
802
+ TAG: "UpdateChainMetaDataAndCheckForExit",
803
+ _0: shouldExit
804
+ },
805
+ "ProcessEventBatch"
806
+ ].concat(maybePruneEntityHistory)
807
+ ) : [{
791
808
  TAG: "UpdateChainMetaDataAndCheckForExit",
792
809
  _0: shouldExit
793
- },
794
- "ProcessEventBatch"
795
- ].concat(maybePruneEntityHistory)
810
+ }];
811
+ return [
812
+ state$2,
813
+ tasks
796
814
  ];
797
815
  case "FindReorgDepth" :
798
816
  return [
@@ -811,6 +829,7 @@ function actionReducer(state, action) {
811
829
  loadManager: state.loadManager,
812
830
  keepProcessAlive: state.keepProcessAlive,
813
831
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
832
+ onError: state.onError,
814
833
  id: state.id
815
834
  },
816
835
  ["Rollback"]
@@ -854,6 +873,7 @@ function actionReducer(state, action) {
854
873
  loadManager: state.loadManager,
855
874
  keepProcessAlive: state.keepProcessAlive,
856
875
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
876
+ onError: state.onError,
857
877
  id: state.id
858
878
  },
859
879
  [{
@@ -862,8 +882,7 @@ function actionReducer(state, action) {
862
882
  }]
863
883
  ];
864
884
  case "ErrorExit" :
865
- ErrorHandling.log(action._0);
866
- Process.exit(1);
885
+ state.onError(action._0);
867
886
  return [
868
887
  state,
869
888
  []
@@ -884,6 +903,7 @@ function actionReducer(state, action) {
884
903
  loadManager: state.loadManager,
885
904
  keepProcessAlive: state.keepProcessAlive,
886
905
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
906
+ onError: state.onError,
887
907
  id: state.id
888
908
  },
889
909
  [
@@ -916,6 +936,7 @@ function invalidatedActionReducer(state, action) {
916
936
  loadManager: state.loadManager,
917
937
  keepProcessAlive: state.keepProcessAlive,
918
938
  exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
939
+ onError: state.onError,
919
940
  id: state.id
920
941
  },
921
942
  ["Rollback"]
@@ -982,9 +1003,8 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
982
1003
  let match = state.rollbackState;
983
1004
  let isRollbackBatch;
984
1005
  isRollbackBatch = typeof match !== "object" ? false : match.TAG === "RollbackReady";
985
- let batch = ChainManager.createBatch(state.chainManager, state.ctx.inMemoryStore.committedCheckpointId, state.ctx.config.batchSize, isRollbackBatch);
1006
+ let batch = ChainManager.createBatch(state.chainManager, state.ctx.inMemoryStore.processedCheckpointId, state.ctx.config.batchSize, isRollbackBatch);
986
1007
  let progressedChainsById = batch.progressedChainsById;
987
- let isInReorgThreshold = state.chainManager.isInReorgThreshold;
988
1008
  let isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
989
1009
  let shouldEnterReorgThreshold = isBelowReorgThreshold && ChainMap.values(state.chainManager.chainFetchers).every(chainFetcher => {
990
1010
  let chainAfterBatch = progressedChainsById[chainFetcher.fetchState.chainId];
@@ -997,7 +1017,8 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
997
1017
  if (EventProcessing.allChainsEventsProcessedToEndblock(state.chainManager.chainFetchers)) {
998
1018
  Logging.info("All chains are caught up to end blocks.");
999
1019
  if (!state.keepProcessAlive) {
1000
- updateChainMetadataTable(state.chainManager, state.ctx.persistence, state.writeThrottlers.chainMetaData);
1020
+ updateChainMetadataTable(state.chainManager, state.ctx.inMemoryStore);
1021
+ await InMemoryStore.flush(state.ctx.inMemoryStore);
1001
1022
  return dispatchAction("SuccessExit");
1002
1023
  } else {
1003
1024
  return;
@@ -1016,7 +1037,7 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1016
1037
  InMemoryStore.setBatchDcs(inMemoryStore, batch);
1017
1038
  let res;
1018
1039
  try {
1019
- res = await EventProcessing.processEventBatch(batch, inMemoryStore, isInReorgThreshold, state.loadManager, state.ctx, state.chainManager.chainFetchers);
1040
+ res = await EventProcessing.processEventBatch(batch, inMemoryStore, state.loadManager, state.ctx, state.chainManager.chainFetchers);
1020
1041
  } catch (raw_exn) {
1021
1042
  let exn = Primitive_exceptions.internalToException(raw_exn);
1022
1043
  let errHandler = ErrorHandling.make(exn, undefined, "A top level unexpected error occurred during processing");
@@ -1129,7 +1150,8 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1129
1150
  safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber) : undefined
1130
1151
  };
1131
1152
  });
1132
- let diff$1 = await InMemoryStore.prepareRollbackDiff(state.ctx.inMemoryStore, state.ctx.persistence, rollbackTargetCheckpointId, state.ctx.inMemoryStore.committedCheckpointId + 1n);
1153
+ await InMemoryStore.flush(state.ctx.inMemoryStore);
1154
+ let diff$1 = await InMemoryStore.prepareRollbackDiff(state.ctx.inMemoryStore, state.ctx.persistence, rollbackTargetCheckpointId, state.ctx.inMemoryStore.committedCheckpointId + 1n, newProgressBlockNumberPerChain);
1133
1155
  let init = state.chainManager;
1134
1156
  let chainManager_isInReorgThreshold = init.isInReorgThreshold;
1135
1157
  let chainManager_isRealtime = init.isRealtime;
@@ -1198,7 +1220,6 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1198
1220
  processPartitionQueryResponse(state, task._0, dispatchAction);
1199
1221
  return;
1200
1222
  case "UpdateChainMetaDataAndCheckForExit" :
1201
- let writeThrottlers = state.writeThrottlers;
1202
1223
  let chainManager$1 = state.chainManager;
1203
1224
  let shouldExit = task._0;
1204
1225
  if (typeof shouldExit === "object") {
@@ -1207,12 +1228,12 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
1207
1228
  _0: ErrorHandling.make(Stdlib_JsError.throwWithMessage(shouldExit._0), undefined, undefined)
1208
1229
  });
1209
1230
  }
1210
- if (shouldExit === "ExitWithSuccess") {
1211
- updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
1212
- return dispatchAction("SuccessExit");
1231
+ if (shouldExit !== "ExitWithSuccess") {
1232
+ return updateChainMetadataTable(chainManager$1, state.ctx.inMemoryStore);
1213
1233
  }
1214
- updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
1215
- return;
1234
+ updateChainMetadataTable(chainManager$1, state.ctx.inMemoryStore);
1235
+ await InMemoryStore.flush(state.ctx.inMemoryStore);
1236
+ return dispatchAction("SuccessExit");
1216
1237
  }
1217
1238
  }
1218
1239
  };
@@ -1,5 +1,3 @@
1
- @val external setImmediate: (unit => unit) => unit = "setImmediate"
2
-
3
1
  module type State = {
4
2
  type t
5
3
  type action
@@ -41,7 +39,7 @@ module MakeManager = (S: State) => {
41
39
  }
42
40
  and dispatchTask = (self, task: S.task) => {
43
41
  let stateId = self.state->S.getId
44
- setImmediate(() => {
42
+ NodeJs.setImmediate(() => {
45
43
  if stateId !== self.state->S.getId {
46
44
  Logging.info("Invalidated task discarded")
47
45
  } else {