envio 3.1.1 → 3.2.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/evm.schema.json +83 -11
- package/fuel.schema.json +83 -11
- package/index.d.ts +184 -3
- package/package.json +6 -6
- package/src/Batch.res +2 -2
- package/src/ChainFetcher.res +27 -3
- package/src/ChainFetcher.res.mjs +17 -3
- package/src/ChainManager.res +163 -0
- package/src/ChainManager.res.mjs +136 -0
- package/src/Config.res +213 -30
- package/src/Config.res.mjs +102 -41
- package/src/Core.res +16 -10
- package/src/Ecosystem.res +0 -3
- package/src/Env.res +2 -2
- package/src/Env.res.mjs +2 -2
- package/src/Envio.res +101 -2
- package/src/Envio.res.mjs +2 -3
- package/src/EventConfigBuilder.res +52 -0
- package/src/EventConfigBuilder.res.mjs +32 -0
- package/src/EventUtils.res +2 -2
- package/src/FetchState.res +126 -71
- package/src/FetchState.res.mjs +73 -51
- package/src/GlobalState.res +219 -363
- package/src/GlobalState.res.mjs +314 -491
- package/src/GlobalStateManager.res +49 -59
- package/src/GlobalStateManager.res.mjs +5 -4
- package/src/GlobalStateManager.resi +1 -1
- package/src/HandlerLoader.res +12 -1
- package/src/HandlerLoader.res.mjs +6 -1
- package/src/HandlerRegister.res +9 -9
- package/src/HandlerRegister.res.mjs +9 -9
- package/src/Hasura.res +102 -32
- package/src/Hasura.res.mjs +88 -34
- package/src/InMemoryStore.res +10 -1
- package/src/InMemoryStore.res.mjs +4 -1
- package/src/InMemoryTable.res +83 -136
- package/src/InMemoryTable.res.mjs +57 -86
- package/src/Internal.res +54 -5
- package/src/Internal.res.mjs +2 -8
- package/src/LazyLoader.res +2 -2
- package/src/LazyLoader.res.mjs +3 -3
- package/src/LoadLayer.res +47 -60
- package/src/LoadLayer.res.mjs +28 -50
- package/src/LoadLayer.resi +2 -5
- package/src/LogSelection.res +4 -4
- package/src/LogSelection.res.mjs +5 -7
- package/src/Logging.res +1 -1
- package/src/Main.res +61 -2
- package/src/Main.res.mjs +37 -1
- package/src/Persistence.res +3 -16
- package/src/PgStorage.res +125 -114
- package/src/PgStorage.res.mjs +112 -95
- package/src/Ports.res +5 -0
- package/src/Ports.res.mjs +9 -0
- package/src/Prometheus.res +3 -3
- package/src/Prometheus.res.mjs +4 -4
- package/src/ReorgDetection.res +4 -4
- package/src/ReorgDetection.res.mjs +4 -5
- package/src/SafeCheckpointTracking.res +16 -16
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/SimulateItems.res +10 -14
- package/src/SimulateItems.res.mjs +5 -2
- package/src/Sink.res +1 -1
- package/src/Sink.res.mjs +1 -2
- package/src/SvmTypes.res +9 -0
- package/src/SvmTypes.res.mjs +14 -0
- package/src/TestIndexer.res +17 -57
- package/src/TestIndexer.res.mjs +14 -48
- package/src/TestIndexerProxyStorage.res +23 -23
- package/src/TestIndexerProxyStorage.res.mjs +12 -15
- package/src/Throttler.res +2 -2
- package/src/Time.res +2 -2
- package/src/Time.res.mjs +2 -2
- package/src/UserContext.res +19 -118
- package/src/UserContext.res.mjs +10 -66
- package/src/Utils.res +15 -15
- package/src/Utils.res.mjs +7 -8
- package/src/adapters/MarkBatchProcessedAdapter.res +5 -0
- package/src/adapters/MarkBatchProcessedAdapter.res.mjs +14 -0
- package/src/bindings/BigDecimal.res +1 -1
- package/src/bindings/BigDecimal.res.mjs +2 -2
- package/src/bindings/ClickHouse.res +8 -6
- package/src/bindings/ClickHouse.res.mjs +5 -5
- package/src/bindings/Hrtime.res +1 -1
- package/src/bindings/Pino.res +2 -2
- package/src/bindings/Pino.res.mjs +3 -4
- package/src/db/EntityFilter.res +410 -0
- package/src/db/EntityFilter.res.mjs +424 -0
- package/src/db/EntityHistory.res +1 -1
- package/src/db/EntityHistory.res.mjs +1 -1
- package/src/db/InternalTable.res +10 -10
- package/src/db/InternalTable.res.mjs +41 -45
- package/src/db/Schema.res +2 -2
- package/src/db/Schema.res.mjs +3 -3
- package/src/db/Table.res +106 -22
- package/src/db/Table.res.mjs +84 -35
- package/src/sources/EventRouter.res +67 -2
- package/src/sources/EventRouter.res.mjs +45 -3
- package/src/sources/Evm.res +0 -7
- package/src/sources/Evm.res.mjs +0 -15
- package/src/sources/EvmChain.res +1 -1
- package/src/sources/EvmChain.res.mjs +1 -2
- package/src/sources/EvmRpcClient.res +42 -0
- package/src/sources/EvmRpcClient.res.mjs +64 -0
- package/src/sources/Fuel.res +0 -7
- package/src/sources/Fuel.res.mjs +0 -15
- package/src/sources/HyperFuelSource.res +5 -4
- package/src/sources/HyperFuelSource.res.mjs +2 -2
- package/src/sources/HyperSyncClient.res +9 -5
- package/src/sources/HyperSyncClient.res.mjs +2 -2
- package/src/sources/HyperSyncHeightStream.res +2 -2
- package/src/sources/HyperSyncHeightStream.res.mjs +2 -2
- package/src/sources/HyperSyncSource.res +10 -9
- package/src/sources/HyperSyncSource.res.mjs +4 -4
- package/src/sources/Rpc.res +1 -5
- package/src/sources/Rpc.res.mjs +1 -9
- package/src/sources/RpcSource.res +57 -21
- package/src/sources/RpcSource.res.mjs +47 -20
- package/src/sources/RpcWebSocketHeightStream.res +1 -1
- package/src/sources/SourceManager.res +3 -2
- package/src/sources/SourceManager.res.mjs +1 -1
- package/src/sources/Svm.res +3 -10
- package/src/sources/Svm.res.mjs +4 -18
- package/src/sources/SvmHyperSyncClient.res +265 -0
- package/src/sources/SvmHyperSyncClient.res.mjs +28 -0
- package/src/sources/SvmHyperSyncSource.res +638 -0
- package/src/sources/SvmHyperSyncSource.res.mjs +557 -0
- package/src/tui/Tui.res +9 -2
- package/src/tui/Tui.res.mjs +18 -3
- package/src/tui/components/BufferedProgressBar.res +2 -2
- package/src/tui/components/TuiData.res +3 -0
- package/svm.schema.json +523 -14
- package/src/TableIndices.res +0 -115
- package/src/TableIndices.res.mjs +0 -144
package/src/GlobalState.res.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Env from "./Env.res.mjs";
|
|
4
|
-
import * as Batch from "./Batch.res.mjs";
|
|
5
4
|
import * as Utils from "./Utils.res.mjs";
|
|
6
5
|
import * as Config from "./Config.res.mjs";
|
|
7
6
|
import * as Hrtime from "./bindings/Hrtime.res.mjs";
|
|
@@ -9,10 +8,8 @@ import * as Logging from "./Logging.res.mjs";
|
|
|
9
8
|
import * as Process from "process";
|
|
10
9
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
11
10
|
import * as Throttler from "./Throttler.res.mjs";
|
|
12
|
-
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
13
11
|
import * as FetchState from "./FetchState.res.mjs";
|
|
14
12
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
15
|
-
import * as Belt_Option from "@rescript/runtime/lib/es6/Belt_Option.js";
|
|
16
13
|
import * as LoadManager from "./LoadManager.res.mjs";
|
|
17
14
|
import * as Stdlib_Null from "@rescript/runtime/lib/es6/Stdlib_Null.js";
|
|
18
15
|
import * as ChainFetcher from "./ChainFetcher.res.mjs";
|
|
@@ -54,8 +51,6 @@ function make$1(ctx, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt, exitAf
|
|
|
54
51
|
return {
|
|
55
52
|
ctx: ctx,
|
|
56
53
|
chainManager: chainManager,
|
|
57
|
-
processedBatches: 0,
|
|
58
|
-
currentlyProcessingBatch: false,
|
|
59
54
|
rollbackState: "NoRollback",
|
|
60
55
|
indexerStartTime: new Date(),
|
|
61
56
|
writeThrottlers: make(),
|
|
@@ -75,8 +70,6 @@ function setChainManager(self, chainManager) {
|
|
|
75
70
|
return {
|
|
76
71
|
ctx: self.ctx,
|
|
77
72
|
chainManager: chainManager,
|
|
78
|
-
processedBatches: self.processedBatches,
|
|
79
|
-
currentlyProcessingBatch: self.currentlyProcessingBatch,
|
|
80
73
|
rollbackState: self.rollbackState,
|
|
81
74
|
indexerStartTime: self.indexerStartTime,
|
|
82
75
|
writeThrottlers: self.writeThrottlers,
|
|
@@ -99,8 +92,8 @@ function isPreparingRollback(state) {
|
|
|
99
92
|
|
|
100
93
|
function updateChainMetadataTable(cm, inMemoryStore) {
|
|
101
94
|
let chainsData = {};
|
|
102
|
-
|
|
103
|
-
chainsData[
|
|
95
|
+
ChainMap.values(cm.chainFetchers).forEach(cf => {
|
|
96
|
+
chainsData[cf.chainConfig.id.toString()] = {
|
|
104
97
|
first_event_block: Stdlib_Null.fromOption(cf.fetchState.firstEventBlock),
|
|
105
98
|
buffer_block: FetchState.bufferBlockNumber(cf.fetchState),
|
|
106
99
|
ready_at: Stdlib_Null.fromOption(cf.timestampCaughtUpToHeadOrEndblock),
|
|
@@ -110,141 +103,6 @@ function updateChainMetadataTable(cm, inMemoryStore) {
|
|
|
110
103
|
InMemoryStore.setChainMeta(inMemoryStore, chainsData);
|
|
111
104
|
}
|
|
112
105
|
|
|
113
|
-
function updateProgressedChains(chainManager, batch, ctx) {
|
|
114
|
-
let nextQueueItemIsNone = ChainManager.nextItemIsNone(chainManager);
|
|
115
|
-
let allChainsAtHead = ChainManager.isProgressAtHead(chainManager);
|
|
116
|
-
let allChainsReady = {
|
|
117
|
-
contents: true
|
|
118
|
-
};
|
|
119
|
-
let chainFetchers = ChainMap.map(chainManager.chainFetchers, prev => {
|
|
120
|
-
let chain = ChainMap.Chain.makeUnsafe(prev.chainConfig.id);
|
|
121
|
-
let maybeChainAfterBatch = batch.progressedChainsById[chain];
|
|
122
|
-
let cf;
|
|
123
|
-
if (maybeChainAfterBatch !== undefined) {
|
|
124
|
-
if (prev.committedProgressBlockNumber !== maybeChainAfterBatch.progressBlockNumber) {
|
|
125
|
-
Prometheus.ProgressBlockNumber.set(maybeChainAfterBatch.progressBlockNumber, chain);
|
|
126
|
-
}
|
|
127
|
-
if (prev.numEventsProcessed !== maybeChainAfterBatch.totalEventsProcessed) {
|
|
128
|
-
Prometheus.ProgressEventsCount.set(maybeChainAfterBatch.totalEventsProcessed, chain);
|
|
129
|
-
}
|
|
130
|
-
let eventItem = Batch.findLastEventItem(batch, chain);
|
|
131
|
-
if (eventItem !== undefined) {
|
|
132
|
-
let blockTimestamp = ctx.config.ecosystem.getTimestamp(eventItem.event.block);
|
|
133
|
-
let currentTimeMs = Date.now() | 0;
|
|
134
|
-
let blockTimestampMs = blockTimestamp * 1000 | 0;
|
|
135
|
-
let latencyMs = currentTimeMs - blockTimestampMs | 0;
|
|
136
|
-
Prometheus.ProgressLatency.set(latencyMs, chain);
|
|
137
|
-
}
|
|
138
|
-
let match = prev.fetchState.firstEventBlock;
|
|
139
|
-
let tmp;
|
|
140
|
-
if (match !== undefined) {
|
|
141
|
-
tmp = prev.fetchState;
|
|
142
|
-
} else {
|
|
143
|
-
let firstEventBlock = Batch.findFirstEventBlockNumber(batch, chain);
|
|
144
|
-
if (firstEventBlock !== undefined) {
|
|
145
|
-
let init = prev.fetchState;
|
|
146
|
-
tmp = {
|
|
147
|
-
optimizedPartitions: init.optimizedPartitions,
|
|
148
|
-
startBlock: init.startBlock,
|
|
149
|
-
endBlock: init.endBlock,
|
|
150
|
-
normalSelection: init.normalSelection,
|
|
151
|
-
indexingAddresses: init.indexingAddresses,
|
|
152
|
-
contractConfigs: init.contractConfigs,
|
|
153
|
-
chainId: init.chainId,
|
|
154
|
-
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
155
|
-
blockLag: init.blockLag,
|
|
156
|
-
buffer: init.buffer,
|
|
157
|
-
targetBufferSize: init.targetBufferSize,
|
|
158
|
-
onBlockConfigs: init.onBlockConfigs,
|
|
159
|
-
knownHeight: init.knownHeight,
|
|
160
|
-
firstEventBlock: firstEventBlock
|
|
161
|
-
};
|
|
162
|
-
} else {
|
|
163
|
-
tmp = prev.fetchState;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
let safeCheckpointTracking = prev.safeCheckpointTracking;
|
|
167
|
-
cf = {
|
|
168
|
-
logger: prev.logger,
|
|
169
|
-
fetchState: tmp,
|
|
170
|
-
sourceManager: prev.sourceManager,
|
|
171
|
-
chainConfig: prev.chainConfig,
|
|
172
|
-
isProgressAtHead: prev.isProgressAtHead || maybeChainAfterBatch.isProgressAtHeadWhenBatchCreated,
|
|
173
|
-
timestampCaughtUpToHeadOrEndblock: prev.timestampCaughtUpToHeadOrEndblock,
|
|
174
|
-
committedProgressBlockNumber: maybeChainAfterBatch.progressBlockNumber,
|
|
175
|
-
numEventsProcessed: maybeChainAfterBatch.totalEventsProcessed,
|
|
176
|
-
reorgDetection: prev.reorgDetection,
|
|
177
|
-
safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.updateOnNewBatch(safeCheckpointTracking, prev.fetchState.knownHeight, chain, batch.checkpointIds, batch.checkpointBlockNumbers, batch.checkpointChainIds) : undefined
|
|
178
|
-
};
|
|
179
|
-
} else {
|
|
180
|
-
cf = prev;
|
|
181
|
-
}
|
|
182
|
-
let cf$1;
|
|
183
|
-
if (ChainFetcher.hasProcessedToEndblock(cf)) {
|
|
184
|
-
let timestampCaughtUpToHeadOrEndblock = ChainFetcher.isReady(cf) ? cf.timestampCaughtUpToHeadOrEndblock : new Date();
|
|
185
|
-
cf$1 = {
|
|
186
|
-
logger: cf.logger,
|
|
187
|
-
fetchState: cf.fetchState,
|
|
188
|
-
sourceManager: cf.sourceManager,
|
|
189
|
-
chainConfig: cf.chainConfig,
|
|
190
|
-
isProgressAtHead: cf.isProgressAtHead,
|
|
191
|
-
timestampCaughtUpToHeadOrEndblock: timestampCaughtUpToHeadOrEndblock,
|
|
192
|
-
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
193
|
-
numEventsProcessed: cf.numEventsProcessed,
|
|
194
|
-
reorgDetection: cf.reorgDetection,
|
|
195
|
-
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
196
|
-
};
|
|
197
|
-
} else if (!ChainFetcher.isReady(cf) && cf.isProgressAtHead) {
|
|
198
|
-
if (nextQueueItemIsNone && allChainsAtHead) {
|
|
199
|
-
cf$1 = {
|
|
200
|
-
logger: cf.logger,
|
|
201
|
-
fetchState: cf.fetchState,
|
|
202
|
-
sourceManager: cf.sourceManager,
|
|
203
|
-
chainConfig: cf.chainConfig,
|
|
204
|
-
isProgressAtHead: cf.isProgressAtHead,
|
|
205
|
-
timestampCaughtUpToHeadOrEndblock: new Date(),
|
|
206
|
-
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
207
|
-
numEventsProcessed: cf.numEventsProcessed,
|
|
208
|
-
reorgDetection: cf.reorgDetection,
|
|
209
|
-
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
210
|
-
};
|
|
211
|
-
} else {
|
|
212
|
-
let hasNoMoreEventsToProcess = ChainFetcher.hasNoMoreEventsToProcess(cf);
|
|
213
|
-
cf$1 = hasNoMoreEventsToProcess ? ({
|
|
214
|
-
logger: cf.logger,
|
|
215
|
-
fetchState: cf.fetchState,
|
|
216
|
-
sourceManager: cf.sourceManager,
|
|
217
|
-
chainConfig: cf.chainConfig,
|
|
218
|
-
isProgressAtHead: cf.isProgressAtHead,
|
|
219
|
-
timestampCaughtUpToHeadOrEndblock: new Date(),
|
|
220
|
-
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
221
|
-
numEventsProcessed: cf.numEventsProcessed,
|
|
222
|
-
reorgDetection: cf.reorgDetection,
|
|
223
|
-
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
224
|
-
}) : cf;
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
cf$1 = cf;
|
|
228
|
-
}
|
|
229
|
-
if (ChainFetcher.isReady(cf$1)) {
|
|
230
|
-
if (!ChainFetcher.isReady(prev)) {
|
|
231
|
-
Prometheus.ProgressReady.set(chain);
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
allChainsReady.contents = false;
|
|
235
|
-
}
|
|
236
|
-
return cf$1;
|
|
237
|
-
});
|
|
238
|
-
if (allChainsReady.contents) {
|
|
239
|
-
Prometheus.ProgressReady.setAllReady();
|
|
240
|
-
}
|
|
241
|
-
return {
|
|
242
|
-
chainFetchers: chainFetchers,
|
|
243
|
-
isInReorgThreshold: chainManager.isInReorgThreshold,
|
|
244
|
-
isRealtime: chainManager.isRealtime || allChainsReady.contents
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
106
|
function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
249
107
|
let response = partitionQueryResponse.response;
|
|
250
108
|
let chain = partitionQueryResponse.chain;
|
|
@@ -254,7 +112,7 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
254
112
|
if (knownHeight > chainFetcher.fetchState.knownHeight) {
|
|
255
113
|
Prometheus.SourceHeight.set(SourceManager.getActiveSource(chainFetcher.sourceManager).name, chainFetcher.chainConfig.id, knownHeight);
|
|
256
114
|
}
|
|
257
|
-
Prometheus.FetchingBlockRange.increment(chain, stats["total time elapsed (s)"],
|
|
115
|
+
Prometheus.FetchingBlockRange.increment(chain, stats["total time elapsed (s)"], Stdlib_Option.getOr(stats["parsing time (s)"], 0), response.parsedQueueItems.length, (response.latestFetchedBlockNumber - response.fromBlockQueried | 0) + 1 | 0);
|
|
258
116
|
let match = ReorgDetection.registerReorgGuard(chainFetcher.reorgDetection, response.blockHashes, knownHeight);
|
|
259
117
|
let reorgResult = match[1];
|
|
260
118
|
let updatedChainFetcher_logger = chainFetcher.logger;
|
|
@@ -286,8 +144,6 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
286
144
|
isInReorgThreshold: init.isInReorgThreshold,
|
|
287
145
|
isRealtime: init.isRealtime
|
|
288
146
|
};
|
|
289
|
-
let nextState_processedBatches = state.processedBatches;
|
|
290
|
-
let nextState_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
291
147
|
let nextState_rollbackState = state.rollbackState;
|
|
292
148
|
let nextState_indexerStartTime = state.indexerStartTime;
|
|
293
149
|
let nextState_writeThrottlers = state.writeThrottlers;
|
|
@@ -299,8 +155,6 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
299
155
|
let nextState = {
|
|
300
156
|
ctx: nextState_ctx,
|
|
301
157
|
chainManager: nextState_chainManager,
|
|
302
|
-
processedBatches: nextState_processedBatches,
|
|
303
|
-
currentlyProcessingBatch: nextState_currentlyProcessingBatch,
|
|
304
158
|
rollbackState: nextState_rollbackState,
|
|
305
159
|
indexerStartTime: nextState_indexerStartTime,
|
|
306
160
|
writeThrottlers: nextState_writeThrottlers,
|
|
@@ -379,8 +233,6 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
379
233
|
isInReorgThreshold: chainManager.isInReorgThreshold,
|
|
380
234
|
isRealtime: chainManager.isRealtime
|
|
381
235
|
},
|
|
382
|
-
processedBatches: nextState_processedBatches,
|
|
383
|
-
currentlyProcessingBatch: nextState_currentlyProcessingBatch,
|
|
384
236
|
rollbackState: {
|
|
385
237
|
TAG: "ReorgDetected",
|
|
386
238
|
chain: chain,
|
|
@@ -481,8 +333,6 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
481
333
|
isInReorgThreshold: init$2.isInReorgThreshold,
|
|
482
334
|
isRealtime: init$2.isRealtime
|
|
483
335
|
};
|
|
484
|
-
let nextState_processedBatches = state.processedBatches;
|
|
485
|
-
let nextState_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
486
336
|
let nextState_rollbackState = state.rollbackState;
|
|
487
337
|
let nextState_indexerStartTime = state.indexerStartTime;
|
|
488
338
|
let nextState_writeThrottlers = state.writeThrottlers;
|
|
@@ -494,8 +344,6 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
494
344
|
let nextState = {
|
|
495
345
|
ctx: nextState_ctx,
|
|
496
346
|
chainManager: nextState_chainManager,
|
|
497
|
-
processedBatches: nextState_processedBatches,
|
|
498
|
-
currentlyProcessingBatch: nextState_currentlyProcessingBatch,
|
|
499
347
|
rollbackState: nextState_rollbackState,
|
|
500
348
|
indexerStartTime: nextState_indexerStartTime,
|
|
501
349
|
writeThrottlers: nextState_writeThrottlers,
|
|
@@ -561,8 +409,6 @@ function updateChainFetcher(chainFetcherUpdate, state, chain) {
|
|
|
561
409
|
isInReorgThreshold: init.isInReorgThreshold,
|
|
562
410
|
isRealtime: init.isRealtime
|
|
563
411
|
},
|
|
564
|
-
processedBatches: state.processedBatches,
|
|
565
|
-
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
566
412
|
rollbackState: state.rollbackState,
|
|
567
413
|
indexerStartTime: state.indexerStartTime,
|
|
568
414
|
writeThrottlers: state.writeThrottlers,
|
|
@@ -599,8 +445,6 @@ function onEnterReorgThreshold(state) {
|
|
|
599
445
|
isInReorgThreshold: true,
|
|
600
446
|
isRealtime: init.isRealtime
|
|
601
447
|
},
|
|
602
|
-
processedBatches: state.processedBatches,
|
|
603
|
-
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
604
448
|
rollbackState: state.rollbackState,
|
|
605
449
|
indexerStartTime: state.indexerStartTime,
|
|
606
450
|
writeThrottlers: state.writeThrottlers,
|
|
@@ -612,324 +456,232 @@ function onEnterReorgThreshold(state) {
|
|
|
612
456
|
};
|
|
613
457
|
}
|
|
614
458
|
|
|
615
|
-
function
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
{
|
|
621
|
-
ctx: state.ctx,
|
|
622
|
-
chainManager: state.chainManager,
|
|
623
|
-
processedBatches: state.processedBatches,
|
|
624
|
-
currentlyProcessingBatch: true,
|
|
625
|
-
rollbackState: state.rollbackState,
|
|
626
|
-
indexerStartTime: state.indexerStartTime,
|
|
627
|
-
writeThrottlers: state.writeThrottlers,
|
|
628
|
-
loadManager: state.loadManager,
|
|
629
|
-
keepProcessAlive: state.keepProcessAlive,
|
|
630
|
-
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
631
|
-
onError: state.onError,
|
|
632
|
-
id: state.id
|
|
633
|
-
},
|
|
634
|
-
[]
|
|
635
|
-
];
|
|
636
|
-
case "StartFindingReorgDepth" :
|
|
637
|
-
return [
|
|
638
|
-
{
|
|
639
|
-
ctx: state.ctx,
|
|
640
|
-
chainManager: state.chainManager,
|
|
641
|
-
processedBatches: state.processedBatches,
|
|
642
|
-
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
643
|
-
rollbackState: "FindingReorgDepth",
|
|
644
|
-
indexerStartTime: state.indexerStartTime,
|
|
645
|
-
writeThrottlers: state.writeThrottlers,
|
|
646
|
-
loadManager: state.loadManager,
|
|
647
|
-
keepProcessAlive: state.keepProcessAlive,
|
|
648
|
-
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
649
|
-
onError: state.onError,
|
|
650
|
-
id: state.id
|
|
651
|
-
},
|
|
652
|
-
[]
|
|
653
|
-
];
|
|
654
|
-
case "EnterReorgThreshold" :
|
|
655
|
-
return [
|
|
656
|
-
onEnterReorgThreshold(state),
|
|
657
|
-
[{
|
|
658
|
-
TAG: "NextQuery",
|
|
659
|
-
_0: "CheckAllChains"
|
|
660
|
-
}]
|
|
661
|
-
];
|
|
662
|
-
case "SuccessExit" :
|
|
663
|
-
Logging.info("Exiting with success");
|
|
664
|
-
Process.exit(0);
|
|
665
|
-
return [
|
|
666
|
-
state,
|
|
667
|
-
[]
|
|
668
|
-
];
|
|
669
|
-
}
|
|
670
|
-
} else {
|
|
671
|
-
switch (action.TAG) {
|
|
672
|
-
case "ValidatePartitionQueryResponse" :
|
|
673
|
-
return validatePartitionQueryResponse(state, action._0);
|
|
674
|
-
case "SubmitPartitionQueryResponse" :
|
|
675
|
-
return submitPartitionQueryResponse(state, action.newItems, action.newItemsWithDcs, action.knownHeight, action.latestFetchedBlock, action.query, action.chain);
|
|
676
|
-
case "FinishWaitingForNewBlock" :
|
|
677
|
-
let knownHeight = action.knownHeight;
|
|
678
|
-
let chain = action.chain;
|
|
679
|
-
let updatedChainFetchers = ChainMap.update(state.chainManager.chainFetchers, chain, chainFetcher => {
|
|
680
|
-
let updatedFetchState = FetchState.updateKnownHeight(chainFetcher.fetchState, knownHeight);
|
|
681
|
-
if (updatedFetchState !== chainFetcher.fetchState) {
|
|
682
|
-
return {
|
|
683
|
-
logger: chainFetcher.logger,
|
|
684
|
-
fetchState: updatedFetchState,
|
|
685
|
-
sourceManager: chainFetcher.sourceManager,
|
|
686
|
-
chainConfig: chainFetcher.chainConfig,
|
|
687
|
-
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
688
|
-
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
689
|
-
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
690
|
-
numEventsProcessed: chainFetcher.numEventsProcessed,
|
|
691
|
-
reorgDetection: chainFetcher.reorgDetection,
|
|
692
|
-
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
693
|
-
};
|
|
694
|
-
} else {
|
|
695
|
-
return chainFetcher;
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
let isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
|
|
699
|
-
let shouldEnterReorgThreshold = isBelowReorgThreshold && ChainMap.values(updatedChainFetchers).every(chainFetcher => FetchState.isReadyToEnterReorgThreshold(chainFetcher.fetchState));
|
|
700
|
-
let init = state.chainManager;
|
|
701
|
-
let state_ctx = state.ctx;
|
|
702
|
-
let state_chainManager = {
|
|
703
|
-
chainFetchers: updatedChainFetchers,
|
|
704
|
-
isInReorgThreshold: init.isInReorgThreshold,
|
|
705
|
-
isRealtime: init.isRealtime
|
|
706
|
-
};
|
|
707
|
-
let state_processedBatches = state.processedBatches;
|
|
708
|
-
let state_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
709
|
-
let state_rollbackState = state.rollbackState;
|
|
710
|
-
let state_indexerStartTime = state.indexerStartTime;
|
|
711
|
-
let state_writeThrottlers = state.writeThrottlers;
|
|
712
|
-
let state_loadManager = state.loadManager;
|
|
713
|
-
let state_keepProcessAlive = state.keepProcessAlive;
|
|
714
|
-
let state_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
|
|
715
|
-
let state_onError = state.onError;
|
|
716
|
-
let state_id = state.id;
|
|
717
|
-
let state$1 = {
|
|
718
|
-
ctx: state_ctx,
|
|
719
|
-
chainManager: state_chainManager,
|
|
720
|
-
processedBatches: state_processedBatches,
|
|
721
|
-
currentlyProcessingBatch: state_currentlyProcessingBatch,
|
|
722
|
-
rollbackState: state_rollbackState,
|
|
723
|
-
indexerStartTime: state_indexerStartTime,
|
|
724
|
-
writeThrottlers: state_writeThrottlers,
|
|
725
|
-
loadManager: state_loadManager,
|
|
726
|
-
keepProcessAlive: state_keepProcessAlive,
|
|
727
|
-
exitAfterFirstEventBlock: state_exitAfterFirstEventBlock,
|
|
728
|
-
onError: state_onError,
|
|
729
|
-
id: state_id
|
|
730
|
-
};
|
|
731
|
-
if (shouldEnterReorgThreshold) {
|
|
459
|
+
function injectedActionReducer(markBatchProcessed) {
|
|
460
|
+
return (state, action) => {
|
|
461
|
+
if (typeof action !== "object") {
|
|
462
|
+
switch (action) {
|
|
463
|
+
case "StartFindingReorgDepth" :
|
|
732
464
|
return [
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
465
|
+
{
|
|
466
|
+
ctx: state.ctx,
|
|
467
|
+
chainManager: state.chainManager,
|
|
468
|
+
rollbackState: "FindingReorgDepth",
|
|
469
|
+
indexerStartTime: state.indexerStartTime,
|
|
470
|
+
writeThrottlers: state.writeThrottlers,
|
|
471
|
+
loadManager: state.loadManager,
|
|
472
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
473
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
474
|
+
onError: state.onError,
|
|
475
|
+
id: state.id
|
|
476
|
+
},
|
|
477
|
+
[]
|
|
478
|
+
];
|
|
479
|
+
case "EnterReorgThreshold" :
|
|
480
|
+
return [
|
|
481
|
+
onEnterReorgThreshold(state),
|
|
482
|
+
[{
|
|
736
483
|
TAG: "NextQuery",
|
|
737
484
|
_0: "CheckAllChains"
|
|
738
|
-
}
|
|
739
|
-
"ProcessEventBatch"
|
|
740
|
-
]
|
|
485
|
+
}]
|
|
741
486
|
];
|
|
742
|
-
|
|
487
|
+
case "SuccessExit" :
|
|
488
|
+
Logging.info("Exiting with success");
|
|
489
|
+
Process.exit(0);
|
|
743
490
|
return [
|
|
744
|
-
state
|
|
745
|
-
[
|
|
746
|
-
{
|
|
747
|
-
TAG: "NextQuery",
|
|
748
|
-
_0: {
|
|
749
|
-
TAG: "Chain",
|
|
750
|
-
_0: chain
|
|
751
|
-
}
|
|
752
|
-
},
|
|
753
|
-
"ProcessEventBatch"
|
|
754
|
-
]
|
|
491
|
+
state,
|
|
492
|
+
[]
|
|
755
493
|
];
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
494
|
+
}
|
|
495
|
+
} else {
|
|
496
|
+
switch (action.TAG) {
|
|
497
|
+
case "ValidatePartitionQueryResponse" :
|
|
498
|
+
return validatePartitionQueryResponse(state, action._0);
|
|
499
|
+
case "SubmitPartitionQueryResponse" :
|
|
500
|
+
return submitPartitionQueryResponse(state, action.newItems, action.newItemsWithDcs, action.knownHeight, action.latestFetchedBlock, action.query, action.chain);
|
|
501
|
+
case "FinishWaitingForNewBlock" :
|
|
502
|
+
let knownHeight = action.knownHeight;
|
|
503
|
+
let chain = action.chain;
|
|
504
|
+
let updatedChainFetchers = ChainMap.update(state.chainManager.chainFetchers, chain, chainFetcher => {
|
|
505
|
+
let updatedFetchState = FetchState.updateKnownHeight(chainFetcher.fetchState, knownHeight);
|
|
506
|
+
if (updatedFetchState !== chainFetcher.fetchState) {
|
|
507
|
+
return {
|
|
508
|
+
logger: chainFetcher.logger,
|
|
509
|
+
fetchState: updatedFetchState,
|
|
510
|
+
sourceManager: chainFetcher.sourceManager,
|
|
511
|
+
chainConfig: chainFetcher.chainConfig,
|
|
512
|
+
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
513
|
+
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
514
|
+
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
515
|
+
numEventsProcessed: chainFetcher.numEventsProcessed,
|
|
516
|
+
reorgDetection: chainFetcher.reorgDetection,
|
|
517
|
+
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
518
|
+
};
|
|
519
|
+
} else {
|
|
520
|
+
return chainFetcher;
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
let isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
|
|
524
|
+
let shouldEnterReorgThreshold = isBelowReorgThreshold && ChainMap.values(updatedChainFetchers).every(chainFetcher => FetchState.isReadyToEnterReorgThreshold(chainFetcher.fetchState));
|
|
525
|
+
let init = state.chainManager;
|
|
526
|
+
let state_ctx = state.ctx;
|
|
527
|
+
let state_chainManager = {
|
|
528
|
+
chainFetchers: updatedChainFetchers,
|
|
529
|
+
isInReorgThreshold: init.isInReorgThreshold,
|
|
530
|
+
isRealtime: init.isRealtime
|
|
531
|
+
};
|
|
532
|
+
let state_rollbackState = state.rollbackState;
|
|
533
|
+
let state_indexerStartTime = state.indexerStartTime;
|
|
534
|
+
let state_writeThrottlers = state.writeThrottlers;
|
|
535
|
+
let state_loadManager = state.loadManager;
|
|
536
|
+
let state_keepProcessAlive = state.keepProcessAlive;
|
|
537
|
+
let state_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
|
|
538
|
+
let state_onError = state.onError;
|
|
539
|
+
let state_id = state.id;
|
|
540
|
+
let state$1 = {
|
|
541
|
+
ctx: state_ctx,
|
|
542
|
+
chainManager: state_chainManager,
|
|
543
|
+
rollbackState: state_rollbackState,
|
|
544
|
+
indexerStartTime: state_indexerStartTime,
|
|
545
|
+
writeThrottlers: state_writeThrottlers,
|
|
546
|
+
loadManager: state_loadManager,
|
|
547
|
+
keepProcessAlive: state_keepProcessAlive,
|
|
548
|
+
exitAfterFirstEventBlock: state_exitAfterFirstEventBlock,
|
|
549
|
+
onError: state_onError,
|
|
550
|
+
id: state_id
|
|
551
|
+
};
|
|
552
|
+
if (shouldEnterReorgThreshold) {
|
|
553
|
+
return [
|
|
554
|
+
onEnterReorgThreshold(state$1),
|
|
555
|
+
[
|
|
801
556
|
{
|
|
802
|
-
TAG: "
|
|
803
|
-
_0:
|
|
557
|
+
TAG: "NextQuery",
|
|
558
|
+
_0: "CheckAllChains"
|
|
804
559
|
},
|
|
805
560
|
"ProcessEventBatch"
|
|
806
|
-
]
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
sourceManager: cf.sourceManager,
|
|
847
|
-
chainConfig: cf.chainConfig,
|
|
848
|
-
isProgressAtHead: cf.isProgressAtHead,
|
|
849
|
-
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
850
|
-
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
851
|
-
numEventsProcessed: cf.numEventsProcessed,
|
|
852
|
-
reorgDetection: cf.reorgDetection,
|
|
853
|
-
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
561
|
+
]
|
|
562
|
+
];
|
|
563
|
+
} else {
|
|
564
|
+
return [
|
|
565
|
+
state$1,
|
|
566
|
+
[
|
|
567
|
+
{
|
|
568
|
+
TAG: "NextQuery",
|
|
569
|
+
_0: {
|
|
570
|
+
TAG: "Chain",
|
|
571
|
+
_0: chain
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
"ProcessEventBatch"
|
|
575
|
+
]
|
|
576
|
+
];
|
|
577
|
+
}
|
|
578
|
+
case "EventBatchProcessed" :
|
|
579
|
+
let maybePruneEntityHistory = Config.shouldPruneHistory(state.ctx.config, state.chainManager.isInReorgThreshold) ? ["PruneStaleEntityHistory"] : [];
|
|
580
|
+
markBatchProcessed();
|
|
581
|
+
let state_ctx$1 = state.ctx;
|
|
582
|
+
let state_chainManager$1 = ChainManager.updateProgressedChains(state.chainManager, action.batch);
|
|
583
|
+
let state_indexerStartTime$1 = state.indexerStartTime;
|
|
584
|
+
let state_writeThrottlers$1 = state.writeThrottlers;
|
|
585
|
+
let state_loadManager$1 = state.loadManager;
|
|
586
|
+
let state_keepProcessAlive$1 = state.keepProcessAlive;
|
|
587
|
+
let state_exitAfterFirstEventBlock$1 = state.exitAfterFirstEventBlock;
|
|
588
|
+
let state_onError$1 = state.onError;
|
|
589
|
+
let state_id$1 = state.id;
|
|
590
|
+
let state$2 = {
|
|
591
|
+
ctx: state_ctx$1,
|
|
592
|
+
chainManager: state_chainManager$1,
|
|
593
|
+
rollbackState: "NoRollback",
|
|
594
|
+
indexerStartTime: state_indexerStartTime$1,
|
|
595
|
+
writeThrottlers: state_writeThrottlers$1,
|
|
596
|
+
loadManager: state_loadManager$1,
|
|
597
|
+
keepProcessAlive: state_keepProcessAlive$1,
|
|
598
|
+
exitAfterFirstEventBlock: state_exitAfterFirstEventBlock$1,
|
|
599
|
+
onError: state_onError$1,
|
|
600
|
+
id: state_id$1
|
|
854
601
|
};
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
[
|
|
889
|
-
];
|
|
890
|
-
case "SetRollbackState" :
|
|
891
|
-
return [
|
|
892
|
-
{
|
|
893
|
-
ctx: state.ctx,
|
|
894
|
-
chainManager: action.rollbackedChainManager,
|
|
895
|
-
processedBatches: state.processedBatches,
|
|
896
|
-
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
897
|
-
rollbackState: {
|
|
898
|
-
TAG: "RollbackReady",
|
|
899
|
-
eventsProcessedDiffByChain: action.eventsProcessedDiffByChain
|
|
900
|
-
},
|
|
901
|
-
indexerStartTime: state.indexerStartTime,
|
|
902
|
-
writeThrottlers: state.writeThrottlers,
|
|
903
|
-
loadManager: state.loadManager,
|
|
904
|
-
keepProcessAlive: state.keepProcessAlive,
|
|
905
|
-
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
906
|
-
onError: state.onError,
|
|
907
|
-
id: state.id
|
|
908
|
-
},
|
|
909
|
-
[
|
|
602
|
+
let shouldExit = EventProcessing.allChainsEventsProcessedToEndblock(state_chainManager$1.chainFetchers) ? (Logging.info("All chains are caught up to end blocks."), state_keepProcessAlive$1 ? "NoExit" : "ExitWithSuccess") : (
|
|
603
|
+
state_exitAfterFirstEventBlock$1 && ChainMap.values(state_chainManager$1.chainFetchers).every(cf => {
|
|
604
|
+
if (cf.isProgressAtHead) {
|
|
605
|
+
return Stdlib_Option.isNone(cf.fetchState.endBlock);
|
|
606
|
+
} else {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
}) ? ({
|
|
610
|
+
TAG: "ExitWithError",
|
|
611
|
+
_0: "No events found between startBlock and chain head. Cannot auto-detect endBlock."
|
|
612
|
+
}) : "NoExit"
|
|
613
|
+
);
|
|
614
|
+
let tasks;
|
|
615
|
+
tasks = typeof shouldExit !== "object" ? (
|
|
616
|
+
shouldExit === "ExitWithSuccess" ? [{
|
|
617
|
+
TAG: "UpdateChainMetaDataAndCheckForExit",
|
|
618
|
+
_0: shouldExit
|
|
619
|
+
}] : [
|
|
620
|
+
{
|
|
621
|
+
TAG: "UpdateChainMetaDataAndCheckForExit",
|
|
622
|
+
_0: shouldExit
|
|
623
|
+
},
|
|
624
|
+
"ProcessEventBatch"
|
|
625
|
+
].concat(maybePruneEntityHistory)
|
|
626
|
+
) : [{
|
|
627
|
+
TAG: "UpdateChainMetaDataAndCheckForExit",
|
|
628
|
+
_0: shouldExit
|
|
629
|
+
}];
|
|
630
|
+
return [
|
|
631
|
+
state$2,
|
|
632
|
+
tasks
|
|
633
|
+
];
|
|
634
|
+
case "FindReorgDepth" :
|
|
635
|
+
return [
|
|
910
636
|
{
|
|
911
|
-
|
|
912
|
-
|
|
637
|
+
ctx: state.ctx,
|
|
638
|
+
chainManager: state.chainManager,
|
|
639
|
+
rollbackState: {
|
|
640
|
+
TAG: "FoundReorgDepth",
|
|
641
|
+
chain: action.chain,
|
|
642
|
+
rollbackTargetBlockNumber: action.rollbackTargetBlockNumber
|
|
643
|
+
},
|
|
644
|
+
indexerStartTime: state.indexerStartTime,
|
|
645
|
+
writeThrottlers: state.writeThrottlers,
|
|
646
|
+
loadManager: state.loadManager,
|
|
647
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
648
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
649
|
+
onError: state.onError,
|
|
650
|
+
id: state.id
|
|
913
651
|
},
|
|
914
|
-
"
|
|
915
|
-
]
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
652
|
+
["Rollback"]
|
|
653
|
+
];
|
|
654
|
+
case "UpdateQueues" :
|
|
655
|
+
let shouldEnterReorgThreshold$1 = action.shouldEnterReorgThreshold;
|
|
656
|
+
let progressedChainsById = action.progressedChainsById;
|
|
657
|
+
let chainFetchers = ChainMap.mapWithKey(state.chainManager.chainFetchers, (chain, cf) => {
|
|
658
|
+
let chainAfterBatch = progressedChainsById[chain];
|
|
659
|
+
let fs = chainAfterBatch !== undefined ? chainAfterBatch.fetchState : cf.fetchState;
|
|
660
|
+
return {
|
|
661
|
+
logger: cf.logger,
|
|
662
|
+
fetchState: shouldEnterReorgThreshold$1 ? FetchState.updateInternal(fs, undefined, undefined, undefined, cf.chainConfig.blockLag, undefined) : fs,
|
|
663
|
+
sourceManager: cf.sourceManager,
|
|
664
|
+
chainConfig: cf.chainConfig,
|
|
665
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
666
|
+
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
667
|
+
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
668
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
669
|
+
reorgDetection: cf.reorgDetection,
|
|
670
|
+
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
671
|
+
};
|
|
672
|
+
});
|
|
673
|
+
let init$1 = state.chainManager;
|
|
674
|
+
let chainManager_isInReorgThreshold = init$1.isInReorgThreshold;
|
|
675
|
+
let chainManager_isRealtime = init$1.isRealtime;
|
|
676
|
+
let chainManager = {
|
|
677
|
+
chainFetchers: chainFetchers,
|
|
678
|
+
isInReorgThreshold: chainManager_isInReorgThreshold,
|
|
679
|
+
isRealtime: chainManager_isRealtime
|
|
680
|
+
};
|
|
927
681
|
return [
|
|
928
682
|
{
|
|
929
683
|
ctx: state.ctx,
|
|
930
|
-
chainManager:
|
|
931
|
-
processedBatches: state.processedBatches + 1 | 0,
|
|
932
|
-
currentlyProcessingBatch: false,
|
|
684
|
+
chainManager: chainManager,
|
|
933
685
|
rollbackState: state.rollbackState,
|
|
934
686
|
indexerStartTime: state.indexerStartTime,
|
|
935
687
|
writeThrottlers: state.writeThrottlers,
|
|
@@ -939,22 +691,85 @@ function invalidatedActionReducer(state, action) {
|
|
|
939
691
|
onError: state.onError,
|
|
940
692
|
id: state.id
|
|
941
693
|
},
|
|
942
|
-
[
|
|
694
|
+
[{
|
|
695
|
+
TAG: "NextQuery",
|
|
696
|
+
_0: "CheckAllChains"
|
|
697
|
+
}]
|
|
943
698
|
];
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
699
|
+
case "ErrorExit" :
|
|
700
|
+
state.onError(action._0);
|
|
701
|
+
return [
|
|
702
|
+
state,
|
|
703
|
+
[]
|
|
704
|
+
];
|
|
705
|
+
case "SetRollbackState" :
|
|
706
|
+
return [
|
|
707
|
+
{
|
|
708
|
+
ctx: state.ctx,
|
|
709
|
+
chainManager: action.rollbackedChainManager,
|
|
710
|
+
rollbackState: {
|
|
711
|
+
TAG: "RollbackReady",
|
|
712
|
+
eventsProcessedDiffByChain: action.eventsProcessedDiffByChain
|
|
713
|
+
},
|
|
714
|
+
indexerStartTime: state.indexerStartTime,
|
|
715
|
+
writeThrottlers: state.writeThrottlers,
|
|
716
|
+
loadManager: state.loadManager,
|
|
717
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
718
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
719
|
+
onError: state.onError,
|
|
720
|
+
id: state.id
|
|
721
|
+
},
|
|
722
|
+
[
|
|
723
|
+
{
|
|
724
|
+
TAG: "NextQuery",
|
|
725
|
+
_0: "CheckAllChains"
|
|
726
|
+
},
|
|
727
|
+
"ProcessEventBatch"
|
|
728
|
+
]
|
|
729
|
+
];
|
|
730
|
+
}
|
|
948
731
|
}
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function injectedInvalidatedActionReducer(markBatchProcessed, actionReducer) {
|
|
736
|
+
return (state, action) => {
|
|
737
|
+
if (typeof action === "object") {
|
|
738
|
+
switch (action.TAG) {
|
|
739
|
+
case "EventBatchProcessed" :
|
|
740
|
+
if (isPreparingRollback(state)) {
|
|
741
|
+
Logging.info("Finished processing batch before rollback, actioning rollback");
|
|
742
|
+
markBatchProcessed();
|
|
743
|
+
return [
|
|
744
|
+
{
|
|
745
|
+
ctx: state.ctx,
|
|
746
|
+
chainManager: ChainManager.updateProgressedChains(state.chainManager, action.batch),
|
|
747
|
+
rollbackState: state.rollbackState,
|
|
748
|
+
indexerStartTime: state.indexerStartTime,
|
|
749
|
+
writeThrottlers: state.writeThrottlers,
|
|
750
|
+
loadManager: state.loadManager,
|
|
751
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
752
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
753
|
+
onError: state.onError,
|
|
754
|
+
id: state.id
|
|
755
|
+
},
|
|
756
|
+
["Rollback"]
|
|
757
|
+
];
|
|
758
|
+
}
|
|
759
|
+
break;
|
|
760
|
+
case "ErrorExit" :
|
|
761
|
+
return actionReducer(state, action);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
Logging.trace({
|
|
765
|
+
msg: "Invalidated action discarded",
|
|
766
|
+
action: S$RescriptSchema.convertOrThrow(action, Utils.Schema.variantTag)
|
|
767
|
+
});
|
|
768
|
+
return [
|
|
769
|
+
state,
|
|
770
|
+
[]
|
|
771
|
+
];
|
|
772
|
+
};
|
|
958
773
|
}
|
|
959
774
|
|
|
960
775
|
function checkAndFetchForChain(waitForNewBlock, executeQuery, state, dispatchAction) {
|
|
@@ -997,7 +812,7 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
997
812
|
if (typeof task !== "object") {
|
|
998
813
|
switch (task) {
|
|
999
814
|
case "ProcessEventBatch" :
|
|
1000
|
-
if (state.
|
|
815
|
+
if (state.ctx.inMemoryStore.isProcessing || isPreparingRollback(state)) {
|
|
1001
816
|
return;
|
|
1002
817
|
}
|
|
1003
818
|
let match = state.rollbackState;
|
|
@@ -1027,13 +842,13 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
1027
842
|
return;
|
|
1028
843
|
}
|
|
1029
844
|
}
|
|
1030
|
-
|
|
845
|
+
let inMemoryStore = state.ctx.inMemoryStore;
|
|
846
|
+
inMemoryStore.isProcessing = true;
|
|
1031
847
|
dispatchAction({
|
|
1032
848
|
TAG: "UpdateQueues",
|
|
1033
849
|
progressedChainsById: progressedChainsById,
|
|
1034
850
|
shouldEnterReorgThreshold: shouldEnterReorgThreshold
|
|
1035
851
|
});
|
|
1036
|
-
let inMemoryStore = state.ctx.inMemoryStore;
|
|
1037
852
|
InMemoryStore.setBatchDcs(inMemoryStore, batch);
|
|
1038
853
|
let res;
|
|
1039
854
|
try {
|
|
@@ -1080,12 +895,11 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
1080
895
|
rollbackTargetBlockNumber: rollbackTargetBlockNumber
|
|
1081
896
|
});
|
|
1082
897
|
case "FoundReorgDepth" :
|
|
1083
|
-
|
|
898
|
+
let rollbackTargetBlockNumber$1 = match$1.rollbackTargetBlockNumber;
|
|
899
|
+
let reorgChain = match$1.chain;
|
|
900
|
+
if (state.ctx.inMemoryStore.isProcessing) {
|
|
1084
901
|
return Logging.info("Waiting for batch to finish processing before executing rollback");
|
|
1085
902
|
}
|
|
1086
|
-
let match$2 = state.rollbackState;
|
|
1087
|
-
let rollbackTargetBlockNumber$1 = match$2.rollbackTargetBlockNumber;
|
|
1088
|
-
let reorgChain = match$2.chain;
|
|
1089
903
|
let startTime = Hrtime.makeTimer();
|
|
1090
904
|
let chainFetcher$1 = ChainMap.get(state.chainManager.chainFetchers, reorgChain);
|
|
1091
905
|
let logger = Logging.createChildFrom(chainFetcher$1.logger, {
|
|
@@ -1095,6 +909,7 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
1095
909
|
});
|
|
1096
910
|
Logging.childInfo(logger, "Started rollback on reorg");
|
|
1097
911
|
Prometheus.RollbackTargetBlockNumber.set(rollbackTargetBlockNumber$1, reorgChain);
|
|
912
|
+
await InMemoryStore.flush(state.ctx.inMemoryStore);
|
|
1098
913
|
let checkpointId = await state.ctx.persistence.storage.getRollbackTargetCheckpoint(reorgChain, rollbackTargetBlockNumber$1);
|
|
1099
914
|
let rollbackTargetCheckpointId = checkpointId !== undefined ? checkpointId : 0n;
|
|
1100
915
|
let eventsProcessedDiffByChain = {};
|
|
@@ -1119,7 +934,7 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
1119
934
|
chainConfig: cf.chainConfig,
|
|
1120
935
|
isProgressAtHead: cf.isProgressAtHead,
|
|
1121
936
|
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
1122
|
-
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
937
|
+
committedProgressBlockNumber: Primitive_int.min(cf.committedProgressBlockNumber, rollbackTargetBlockNumber$1),
|
|
1123
938
|
numEventsProcessed: cf.numEventsProcessed,
|
|
1124
939
|
reorgDetection: ReorgDetection.rollbackToValidBlockNumber(cf.reorgDetection, rollbackTargetBlockNumber$1),
|
|
1125
940
|
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
@@ -1150,7 +965,6 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
1150
965
|
safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber) : undefined
|
|
1151
966
|
};
|
|
1152
967
|
});
|
|
1153
|
-
await InMemoryStore.flush(state.ctx.inMemoryStore);
|
|
1154
968
|
let diff$1 = await InMemoryStore.prepareRollbackDiff(state.ctx.inMemoryStore, state.ctx.persistence, rollbackTargetCheckpointId, state.ctx.inMemoryStore.committedCheckpointId + 1n, newProgressBlockNumberPerChain);
|
|
1155
969
|
let init = state.chainManager;
|
|
1156
970
|
let chainManager_isInReorgThreshold = init.isInReorgThreshold;
|
|
@@ -1239,7 +1053,17 @@ function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlo
|
|
|
1239
1053
|
};
|
|
1240
1054
|
}
|
|
1241
1055
|
|
|
1242
|
-
|
|
1056
|
+
function makeReducers(waitForNewBlockOpt, executeQueryOpt, getLastKnownValidBlockOpt, markBatchProcessed) {
|
|
1057
|
+
let waitForNewBlock = waitForNewBlockOpt !== undefined ? waitForNewBlockOpt : SourceManager.waitForNewBlock;
|
|
1058
|
+
let executeQuery = executeQueryOpt !== undefined ? executeQueryOpt : SourceManager.executeQuery;
|
|
1059
|
+
let getLastKnownValidBlock = getLastKnownValidBlockOpt !== undefined ? getLastKnownValidBlockOpt : ChainFetcher.getLastKnownValidBlock;
|
|
1060
|
+
let actionReducer = injectedActionReducer(markBatchProcessed);
|
|
1061
|
+
return {
|
|
1062
|
+
actionReducer: actionReducer,
|
|
1063
|
+
invalidatedActionReducer: injectedInvalidatedActionReducer(markBatchProcessed, actionReducer),
|
|
1064
|
+
taskReducer: injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlock)
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1243
1067
|
|
|
1244
1068
|
export {
|
|
1245
1069
|
WriteThrottlers,
|
|
@@ -1248,16 +1072,15 @@ export {
|
|
|
1248
1072
|
setChainManager,
|
|
1249
1073
|
isPreparingRollback,
|
|
1250
1074
|
updateChainMetadataTable,
|
|
1251
|
-
updateProgressedChains,
|
|
1252
1075
|
validatePartitionQueryResponse,
|
|
1253
1076
|
submitPartitionQueryResponse,
|
|
1254
1077
|
processPartitionQueryResponse,
|
|
1255
1078
|
updateChainFetcher,
|
|
1256
1079
|
onEnterReorgThreshold,
|
|
1257
|
-
|
|
1258
|
-
|
|
1080
|
+
injectedActionReducer,
|
|
1081
|
+
injectedInvalidatedActionReducer,
|
|
1259
1082
|
checkAndFetchForChain,
|
|
1260
1083
|
injectedTaskReducer,
|
|
1261
|
-
|
|
1084
|
+
makeReducers,
|
|
1262
1085
|
}
|
|
1263
|
-
/*
|
|
1086
|
+
/* Env Not a pure module */
|