envio 3.0.0-alpha.21 → 3.0.0-alpha.22
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/bin.mjs +2 -48
- package/evm.schema.json +67 -0
- package/fuel.schema.json +67 -0
- package/index.d.ts +822 -38
- package/index.js +5 -3
- package/package.json +10 -8
- package/rescript.json +5 -9
- package/src/Address.res +4 -5
- package/src/Address.res.mjs +9 -12
- package/src/Api.res +15 -0
- package/src/Api.res.mjs +20 -0
- package/src/Batch.res +32 -34
- package/src/Batch.res.mjs +172 -187
- package/src/Bin.res +89 -0
- package/src/Bin.res.mjs +97 -0
- package/src/ChainFetcher.res +33 -57
- package/src/ChainFetcher.res.mjs +197 -227
- package/src/ChainManager.res +6 -14
- package/src/ChainManager.res.mjs +74 -85
- package/src/ChainMap.res +14 -16
- package/src/ChainMap.res.mjs +38 -38
- package/src/Config.res +193 -135
- package/src/Config.res.mjs +566 -592
- package/src/Core.res +182 -0
- package/src/Core.res.mjs +207 -0
- package/src/Ecosystem.res +25 -4
- package/src/Ecosystem.res.mjs +12 -13
- package/src/Env.res +20 -13
- package/src/Env.res.mjs +124 -113
- package/src/EnvSafe.res +269 -0
- package/src/EnvSafe.res.mjs +296 -0
- package/src/EnvSafe.resi +18 -0
- package/src/Envio.res +37 -26
- package/src/Envio.res.mjs +59 -60
- package/src/ErrorHandling.res +2 -2
- package/src/ErrorHandling.res.mjs +15 -15
- package/src/EventConfigBuilder.res +219 -81
- package/src/EventConfigBuilder.res.mjs +259 -202
- package/src/EventProcessing.res +27 -38
- package/src/EventProcessing.res.mjs +165 -183
- package/src/EventUtils.res +11 -11
- package/src/EventUtils.res.mjs +21 -22
- package/src/EvmTypes.res +0 -1
- package/src/EvmTypes.res.mjs +5 -5
- package/src/FetchState.res +360 -256
- package/src/FetchState.res.mjs +958 -914
- package/src/GlobalState.res +365 -351
- package/src/GlobalState.res.mjs +958 -992
- package/src/GlobalStateManager.res +1 -2
- package/src/GlobalStateManager.res.mjs +36 -44
- package/src/HandlerLoader.res +107 -23
- package/src/HandlerLoader.res.mjs +128 -38
- package/src/HandlerRegister.res +127 -103
- package/src/HandlerRegister.res.mjs +164 -164
- package/src/HandlerRegister.resi +12 -4
- package/src/Hasura.res +35 -22
- package/src/Hasura.res.mjs +158 -167
- package/src/InMemoryStore.res +20 -27
- package/src/InMemoryStore.res.mjs +64 -80
- package/src/InMemoryTable.res +34 -39
- package/src/InMemoryTable.res.mjs +165 -170
- package/src/Internal.res +52 -33
- package/src/Internal.res.mjs +84 -81
- package/src/LazyLoader.res.mjs +55 -61
- package/src/LoadLayer.res +77 -78
- package/src/LoadLayer.res.mjs +160 -189
- package/src/LoadManager.res +16 -21
- package/src/LoadManager.res.mjs +79 -84
- package/src/LogSelection.res +236 -68
- package/src/LogSelection.res.mjs +211 -141
- package/src/Logging.res +13 -9
- package/src/Logging.res.mjs +130 -143
- package/src/Main.res +428 -51
- package/src/Main.res.mjs +528 -271
- package/src/Persistence.res +77 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +291 -167
- package/src/PgStorage.res.mjs +797 -817
- package/src/Prometheus.res +50 -58
- package/src/Prometheus.res.mjs +345 -373
- package/src/ReorgDetection.res +22 -24
- package/src/ReorgDetection.res.mjs +100 -106
- package/src/SafeCheckpointTracking.res +7 -7
- package/src/SafeCheckpointTracking.res.mjs +40 -43
- package/src/SimulateItems.res +41 -49
- package/src/SimulateItems.res.mjs +257 -272
- package/src/Sink.res +2 -2
- package/src/Sink.res.mjs +22 -26
- package/src/TableIndices.res +1 -2
- package/src/TableIndices.res.mjs +42 -48
- package/src/TestIndexer.res +196 -189
- package/src/TestIndexer.res.mjs +536 -536
- package/src/TestIndexerProxyStorage.res +15 -16
- package/src/TestIndexerProxyStorage.res.mjs +98 -122
- package/src/TestIndexerWorker.res +4 -0
- package/src/TestIndexerWorker.res.mjs +7 -0
- package/src/Throttler.res +3 -3
- package/src/Throttler.res.mjs +23 -24
- package/src/Time.res +1 -1
- package/src/Time.res.mjs +18 -21
- package/src/TopicFilter.res +3 -3
- package/src/TopicFilter.res.mjs +29 -30
- package/src/UserContext.res +93 -54
- package/src/UserContext.res.mjs +197 -182
- package/src/Utils.res +141 -86
- package/src/Utils.res.mjs +334 -295
- package/src/bindings/BigDecimal.res +0 -2
- package/src/bindings/BigDecimal.res.mjs +19 -23
- package/src/bindings/ClickHouse.res +28 -27
- package/src/bindings/ClickHouse.res.mjs +243 -240
- package/src/bindings/DateFns.res +11 -11
- package/src/bindings/DateFns.res.mjs +7 -7
- package/src/bindings/EventSource.res.mjs +2 -2
- package/src/bindings/Express.res +2 -5
- package/src/bindings/Hrtime.res +2 -2
- package/src/bindings/Hrtime.res.mjs +30 -32
- package/src/bindings/Lodash.res.mjs +1 -1
- package/src/bindings/NodeJs.res +14 -9
- package/src/bindings/NodeJs.res.mjs +20 -20
- package/src/bindings/Pino.res +8 -10
- package/src/bindings/Pino.res.mjs +40 -43
- package/src/bindings/Postgres.res +2 -5
- package/src/bindings/Postgres.res.mjs +9 -9
- package/src/bindings/PromClient.res +17 -2
- package/src/bindings/PromClient.res.mjs +30 -7
- package/src/bindings/SDSL.res.mjs +2 -2
- package/src/bindings/Viem.res +4 -4
- package/src/bindings/Viem.res.mjs +20 -22
- package/src/bindings/Vitest.res +1 -1
- package/src/bindings/Vitest.res.mjs +2 -2
- package/src/bindings/WebSocket.res +1 -1
- package/src/db/EntityHistory.res +9 -3
- package/src/db/EntityHistory.res.mjs +84 -59
- package/src/db/InternalTable.res +62 -60
- package/src/db/InternalTable.res.mjs +271 -203
- package/src/db/Schema.res +1 -2
- package/src/db/Schema.res.mjs +28 -32
- package/src/db/Table.res +28 -27
- package/src/db/Table.res.mjs +276 -292
- package/src/sources/EventRouter.res +21 -16
- package/src/sources/EventRouter.res.mjs +55 -57
- package/src/sources/Evm.res +17 -1
- package/src/sources/Evm.res.mjs +16 -8
- package/src/sources/EvmChain.res +15 -17
- package/src/sources/EvmChain.res.mjs +40 -42
- package/src/sources/Fuel.res +14 -1
- package/src/sources/Fuel.res.mjs +16 -8
- package/src/sources/FuelSDK.res +1 -1
- package/src/sources/FuelSDK.res.mjs +6 -8
- package/src/sources/HyperFuel.res +8 -10
- package/src/sources/HyperFuel.res.mjs +113 -123
- package/src/sources/HyperFuelClient.res.mjs +6 -7
- package/src/sources/HyperFuelSource.res +19 -20
- package/src/sources/HyperFuelSource.res.mjs +339 -356
- package/src/sources/HyperSync.res +11 -13
- package/src/sources/HyperSync.res.mjs +206 -220
- package/src/sources/HyperSyncClient.res +5 -7
- package/src/sources/HyperSyncClient.res.mjs +70 -75
- package/src/sources/HyperSyncHeightStream.res +8 -9
- package/src/sources/HyperSyncHeightStream.res.mjs +78 -86
- package/src/sources/HyperSyncJsonApi.res +18 -15
- package/src/sources/HyperSyncJsonApi.res.mjs +201 -231
- package/src/sources/HyperSyncSource.res +17 -21
- package/src/sources/HyperSyncSource.res.mjs +268 -290
- package/src/sources/Rpc.res +5 -5
- package/src/sources/Rpc.res.mjs +168 -192
- package/src/sources/RpcSource.res +166 -167
- package/src/sources/RpcSource.res.mjs +972 -1046
- package/src/sources/RpcWebSocketHeightStream.res +10 -11
- package/src/sources/RpcWebSocketHeightStream.res.mjs +131 -145
- package/src/sources/SimulateSource.res +1 -1
- package/src/sources/SimulateSource.res.mjs +35 -38
- package/src/sources/Source.res +1 -1
- package/src/sources/Source.res.mjs +3 -3
- package/src/sources/SourceManager.res +39 -20
- package/src/sources/SourceManager.res.mjs +340 -371
- package/src/sources/SourceManager.resi +2 -1
- package/src/sources/Svm.res +12 -5
- package/src/sources/Svm.res.mjs +44 -41
- package/src/tui/Tui.res +23 -12
- package/src/tui/Tui.res.mjs +292 -290
- package/src/tui/bindings/Ink.res +2 -4
- package/src/tui/bindings/Ink.res.mjs +35 -41
- package/src/tui/components/BufferedProgressBar.res +7 -7
- package/src/tui/components/BufferedProgressBar.res.mjs +46 -46
- package/src/tui/components/CustomHooks.res +1 -2
- package/src/tui/components/CustomHooks.res.mjs +102 -122
- package/src/tui/components/Messages.res +1 -2
- package/src/tui/components/Messages.res.mjs +38 -42
- package/src/tui/components/SyncETA.res +10 -11
- package/src/tui/components/SyncETA.res.mjs +178 -196
- package/src/tui/components/TuiData.res +1 -1
- package/src/tui/components/TuiData.res.mjs +7 -6
- package/src/vendored/Rest.res +52 -66
- package/src/vendored/Rest.res.mjs +324 -364
- package/svm.schema.json +67 -0
- package/src/Address.gen.ts +0 -8
- package/src/Config.gen.ts +0 -19
- package/src/Envio.gen.ts +0 -55
- package/src/EvmTypes.gen.ts +0 -6
- package/src/InMemoryStore.gen.ts +0 -6
- package/src/Internal.gen.ts +0 -64
- package/src/PgStorage.gen.ts +0 -10
- package/src/PgStorage.res.d.mts +0 -5
- package/src/Types.ts +0 -56
- package/src/bindings/BigDecimal.gen.ts +0 -14
- package/src/bindings/BigDecimal.res.d.mts +0 -5
- package/src/bindings/BigInt.gen.ts +0 -10
- package/src/bindings/BigInt.res +0 -70
- package/src/bindings/BigInt.res.d.mts +0 -5
- package/src/bindings/BigInt.res.mjs +0 -154
- package/src/bindings/Ethers.res.d.mts +0 -5
- package/src/bindings/Pino.gen.ts +0 -17
- package/src/bindings/Postgres.gen.ts +0 -8
- package/src/bindings/Postgres.res.d.mts +0 -5
- package/src/bindings/Promise.res +0 -67
- package/src/bindings/Promise.res.mjs +0 -26
- package/src/db/InternalTable.gen.ts +0 -36
- package/src/sources/HyperSyncClient.gen.ts +0 -19
package/src/GlobalState.res.mjs
CHANGED
|
@@ -3,75 +3,75 @@
|
|
|
3
3
|
import * as Env from "./Env.res.mjs";
|
|
4
4
|
import * as Batch from "./Batch.res.mjs";
|
|
5
5
|
import * as Utils from "./Utils.res.mjs";
|
|
6
|
-
import * as $$BigInt from "./bindings/BigInt.res.mjs";
|
|
7
6
|
import * as Config from "./Config.res.mjs";
|
|
8
7
|
import * as Hrtime from "./bindings/Hrtime.res.mjs";
|
|
9
|
-
import * as Js_exn from "rescript/lib/es6/js_exn.js";
|
|
10
|
-
import * as Js_null from "rescript/lib/es6/js_null.js";
|
|
11
8
|
import * as Logging from "./Logging.res.mjs";
|
|
12
9
|
import * as Process from "process";
|
|
13
|
-
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
|
|
14
10
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
15
11
|
import * as Throttler from "./Throttler.res.mjs";
|
|
16
|
-
import * as Belt_Array from "rescript/lib/es6/
|
|
17
|
-
import * as Belt_Float from "rescript/lib/es6/belt_Float.js";
|
|
12
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
18
13
|
import * as FetchState from "./FetchState.res.mjs";
|
|
19
14
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
20
|
-
import * as Belt_Option from "rescript/lib/es6/
|
|
21
|
-
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
15
|
+
import * as Belt_Option from "@rescript/runtime/lib/es6/Belt_Option.js";
|
|
22
16
|
import * as LoadManager from "./LoadManager.res.mjs";
|
|
23
17
|
import * as Persistence from "./Persistence.res.mjs";
|
|
18
|
+
import * as Stdlib_Null from "@rescript/runtime/lib/es6/Stdlib_Null.js";
|
|
24
19
|
import * as ChainFetcher from "./ChainFetcher.res.mjs";
|
|
25
20
|
import * as ChainManager from "./ChainManager.res.mjs";
|
|
21
|
+
import * as Stdlib_Float from "@rescript/runtime/lib/es6/Stdlib_Float.js";
|
|
26
22
|
import * as ErrorHandling from "./ErrorHandling.res.mjs";
|
|
27
23
|
import * as InMemoryStore from "./InMemoryStore.res.mjs";
|
|
24
|
+
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
28
25
|
import * as SourceManager from "./sources/SourceManager.res.mjs";
|
|
26
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
29
27
|
import * as ReorgDetection from "./ReorgDetection.res.mjs";
|
|
28
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
30
29
|
import * as EventProcessing from "./EventProcessing.res.mjs";
|
|
30
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
31
31
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
32
|
-
import * as
|
|
32
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
33
33
|
import * as SafeCheckpointTracking from "./SafeCheckpointTracking.res.mjs";
|
|
34
34
|
|
|
35
35
|
function make() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
let intervalMillis = Env.ThrottleWrites.chainMetadataIntervalMillis;
|
|
37
|
+
let logger = Logging.createChild({
|
|
38
|
+
context: "Throttler for chain metadata writes",
|
|
39
|
+
intervalMillis: intervalMillis
|
|
40
|
+
});
|
|
41
|
+
let chainMetaData = Throttler.make(intervalMillis, logger);
|
|
42
|
+
let intervalMillis$1 = Env.ThrottleWrites.pruneStaleDataIntervalMillis;
|
|
43
|
+
let logger$1 = Logging.createChild({
|
|
44
|
+
context: "Throttler for pruning stale entity history data",
|
|
45
|
+
intervalMillis: intervalMillis$1
|
|
46
|
+
});
|
|
47
|
+
let pruneStaleEntityHistory = Throttler.make(intervalMillis$1, logger$1);
|
|
48
48
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
chainMetaData: chainMetaData,
|
|
50
|
+
pruneStaleEntityHistory: pruneStaleEntityHistory
|
|
51
|
+
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
let WriteThrottlers = {
|
|
55
55
|
make: make
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
function make$1(ctx, chainManager, isDevelopmentModeOpt, shouldUseTuiOpt, exitAfterFirstEventBlockOpt) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
let isDevelopmentMode = isDevelopmentModeOpt !== undefined ? isDevelopmentModeOpt : false;
|
|
60
|
+
let shouldUseTui = shouldUseTuiOpt !== undefined ? shouldUseTuiOpt : false;
|
|
61
|
+
let exitAfterFirstEventBlock = exitAfterFirstEventBlockOpt !== undefined ? exitAfterFirstEventBlockOpt : false;
|
|
62
62
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
ctx: ctx,
|
|
64
|
+
chainManager: chainManager,
|
|
65
|
+
processedBatches: 0,
|
|
66
|
+
currentlyProcessingBatch: false,
|
|
67
|
+
rollbackState: "NoRollback",
|
|
68
|
+
indexerStartTime: new Date(),
|
|
69
|
+
writeThrottlers: make(),
|
|
70
|
+
loadManager: LoadManager.make(),
|
|
71
|
+
keepProcessAlive: isDevelopmentMode || shouldUseTui,
|
|
72
|
+
exitAfterFirstEventBlock: exitAfterFirstEventBlock,
|
|
73
|
+
id: 0
|
|
74
|
+
};
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function getId(self) {
|
|
@@ -80,211 +80,202 @@ function getId(self) {
|
|
|
80
80
|
|
|
81
81
|
function setChainManager(self, chainManager) {
|
|
82
82
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
ctx: self.ctx,
|
|
84
|
+
chainManager: chainManager,
|
|
85
|
+
processedBatches: self.processedBatches,
|
|
86
|
+
currentlyProcessingBatch: self.currentlyProcessingBatch,
|
|
87
|
+
rollbackState: self.rollbackState,
|
|
88
|
+
indexerStartTime: self.indexerStartTime,
|
|
89
|
+
writeThrottlers: self.writeThrottlers,
|
|
90
|
+
loadManager: self.loadManager,
|
|
91
|
+
keepProcessAlive: self.keepProcessAlive,
|
|
92
|
+
exitAfterFirstEventBlock: self.exitAfterFirstEventBlock,
|
|
93
|
+
id: self.id
|
|
94
|
+
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
function isPreparingRollback(state) {
|
|
98
|
-
|
|
98
|
+
let match = state.rollbackState;
|
|
99
99
|
if (typeof match !== "object") {
|
|
100
|
-
|
|
101
|
-
return false;
|
|
102
|
-
} else {
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
} else if (match.TAG === "RollbackReady") {
|
|
106
|
-
return false;
|
|
100
|
+
return match !== "NoRollback";
|
|
107
101
|
} else {
|
|
108
|
-
return
|
|
102
|
+
return match.TAG !== "RollbackReady";
|
|
109
103
|
}
|
|
110
104
|
}
|
|
111
105
|
|
|
112
106
|
function updateChainMetadataTable(cm, persistence, throttler) {
|
|
113
|
-
|
|
114
|
-
Belt_Array.forEach(ChainMap.values(cm.chainFetchers),
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Throttler.schedule(throttler, (
|
|
123
|
-
return persistence.storage.setChainMeta(chainsData);
|
|
124
|
-
}));
|
|
107
|
+
let chainsData = {};
|
|
108
|
+
Belt_Array.forEach(ChainMap.values(cm.chainFetchers), cf => {
|
|
109
|
+
chainsData[String(cf.chainConfig.id)] = {
|
|
110
|
+
first_event_block: Stdlib_Null.fromOption(cf.fetchState.firstEventBlock),
|
|
111
|
+
buffer_block: FetchState.bufferBlockNumber(cf.fetchState),
|
|
112
|
+
ready_at: Stdlib_Null.fromOption(cf.timestampCaughtUpToHeadOrEndblock),
|
|
113
|
+
_is_hyper_sync: SourceManager.getActiveSource(cf.sourceManager).poweredByHyperSync
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
Throttler.schedule(throttler, () => persistence.storage.setChainMeta(chainsData));
|
|
125
117
|
}
|
|
126
118
|
|
|
127
119
|
function updateProgressedChains(chainManager, batch, ctx) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
120
|
+
let nextQueueItemIsNone = ChainManager.nextItemIsNone(chainManager);
|
|
121
|
+
let allChainsAtHead = ChainManager.isProgressAtHead(chainManager);
|
|
122
|
+
let allChainsReady = {
|
|
131
123
|
contents: true
|
|
132
124
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}));
|
|
125
|
+
let chainFetchers = ChainMap.map(chainManager.chainFetchers, prev => {
|
|
126
|
+
let chain = ChainMap.Chain.makeUnsafe(prev.chainConfig.id);
|
|
127
|
+
let maybeChainAfterBatch = batch.progressedChainsById[chain];
|
|
128
|
+
let cf;
|
|
129
|
+
if (maybeChainAfterBatch !== undefined) {
|
|
130
|
+
if (prev.committedProgressBlockNumber !== maybeChainAfterBatch.progressBlockNumber) {
|
|
131
|
+
Prometheus.ProgressBlockNumber.set(maybeChainAfterBatch.progressBlockNumber, chain);
|
|
132
|
+
}
|
|
133
|
+
if (prev.numEventsProcessed !== maybeChainAfterBatch.totalEventsProcessed) {
|
|
134
|
+
Prometheus.ProgressEventsCount.set(maybeChainAfterBatch.totalEventsProcessed, chain);
|
|
135
|
+
}
|
|
136
|
+
let eventItem = Batch.findLastEventItem(batch, chain);
|
|
137
|
+
if (eventItem !== undefined) {
|
|
138
|
+
let blockTimestamp = ctx.config.ecosystem.getTimestamp(eventItem.event.block);
|
|
139
|
+
let currentTimeMs = Date.now() | 0;
|
|
140
|
+
let blockTimestampMs = blockTimestamp * 1000 | 0;
|
|
141
|
+
let latencyMs = currentTimeMs - blockTimestampMs | 0;
|
|
142
|
+
Prometheus.ProgressLatency.set(latencyMs, chain);
|
|
143
|
+
}
|
|
144
|
+
let match = prev.fetchState.firstEventBlock;
|
|
145
|
+
let tmp;
|
|
146
|
+
if (match !== undefined) {
|
|
147
|
+
tmp = prev.fetchState;
|
|
148
|
+
} else {
|
|
149
|
+
let firstEventBlock = Batch.findFirstEventBlockNumber(batch, chain);
|
|
150
|
+
if (firstEventBlock !== undefined) {
|
|
151
|
+
let init = prev.fetchState;
|
|
152
|
+
tmp = {
|
|
153
|
+
optimizedPartitions: init.optimizedPartitions,
|
|
154
|
+
startBlock: init.startBlock,
|
|
155
|
+
endBlock: init.endBlock,
|
|
156
|
+
normalSelection: init.normalSelection,
|
|
157
|
+
indexingAddresses: init.indexingAddresses,
|
|
158
|
+
contractConfigs: init.contractConfigs,
|
|
159
|
+
chainId: init.chainId,
|
|
160
|
+
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
161
|
+
blockLag: init.blockLag,
|
|
162
|
+
buffer: init.buffer,
|
|
163
|
+
targetBufferSize: init.targetBufferSize,
|
|
164
|
+
onBlockConfigs: init.onBlockConfigs,
|
|
165
|
+
knownHeight: init.knownHeight,
|
|
166
|
+
firstEventBlock: firstEventBlock
|
|
167
|
+
};
|
|
168
|
+
} else {
|
|
169
|
+
tmp = prev.fetchState;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let safeCheckpointTracking = prev.safeCheckpointTracking;
|
|
173
|
+
cf = {
|
|
174
|
+
logger: prev.logger,
|
|
175
|
+
fetchState: tmp,
|
|
176
|
+
sourceManager: prev.sourceManager,
|
|
177
|
+
chainConfig: prev.chainConfig,
|
|
178
|
+
isProgressAtHead: prev.isProgressAtHead || maybeChainAfterBatch.isProgressAtHeadWhenBatchCreated,
|
|
179
|
+
timestampCaughtUpToHeadOrEndblock: prev.timestampCaughtUpToHeadOrEndblock,
|
|
180
|
+
committedProgressBlockNumber: maybeChainAfterBatch.progressBlockNumber,
|
|
181
|
+
numEventsProcessed: maybeChainAfterBatch.totalEventsProcessed,
|
|
182
|
+
reorgDetection: prev.reorgDetection,
|
|
183
|
+
safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.updateOnNewBatch(safeCheckpointTracking, prev.fetchState.knownHeight, chain, batch.checkpointIds, batch.checkpointBlockNumbers, batch.checkpointChainIds) : undefined
|
|
184
|
+
};
|
|
185
|
+
} else {
|
|
186
|
+
cf = prev;
|
|
187
|
+
}
|
|
188
|
+
let cf$1;
|
|
189
|
+
if (ChainFetcher.hasProcessedToEndblock(cf)) {
|
|
190
|
+
let timestampCaughtUpToHeadOrEndblock = ChainFetcher.isReady(cf) ? cf.timestampCaughtUpToHeadOrEndblock : new Date();
|
|
191
|
+
cf$1 = {
|
|
192
|
+
logger: cf.logger,
|
|
193
|
+
fetchState: cf.fetchState,
|
|
194
|
+
sourceManager: cf.sourceManager,
|
|
195
|
+
chainConfig: cf.chainConfig,
|
|
196
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
197
|
+
timestampCaughtUpToHeadOrEndblock: timestampCaughtUpToHeadOrEndblock,
|
|
198
|
+
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
199
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
200
|
+
reorgDetection: cf.reorgDetection,
|
|
201
|
+
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
202
|
+
};
|
|
203
|
+
} else if (!ChainFetcher.isReady(cf) && cf.isProgressAtHead) {
|
|
204
|
+
if (nextQueueItemIsNone && allChainsAtHead) {
|
|
205
|
+
cf$1 = {
|
|
206
|
+
logger: cf.logger,
|
|
207
|
+
fetchState: cf.fetchState,
|
|
208
|
+
sourceManager: cf.sourceManager,
|
|
209
|
+
chainConfig: cf.chainConfig,
|
|
210
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
211
|
+
timestampCaughtUpToHeadOrEndblock: new Date(),
|
|
212
|
+
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
213
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
214
|
+
reorgDetection: cf.reorgDetection,
|
|
215
|
+
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
216
|
+
};
|
|
217
|
+
} else {
|
|
218
|
+
let hasNoMoreEventsToProcess = ChainFetcher.hasNoMoreEventsToProcess(cf);
|
|
219
|
+
cf$1 = hasNoMoreEventsToProcess ? ({
|
|
220
|
+
logger: cf.logger,
|
|
221
|
+
fetchState: cf.fetchState,
|
|
222
|
+
sourceManager: cf.sourceManager,
|
|
223
|
+
chainConfig: cf.chainConfig,
|
|
224
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
225
|
+
timestampCaughtUpToHeadOrEndblock: new Date(),
|
|
226
|
+
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
227
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
228
|
+
reorgDetection: cf.reorgDetection,
|
|
229
|
+
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
230
|
+
}) : cf;
|
|
231
|
+
}
|
|
232
|
+
} else {
|
|
233
|
+
cf$1 = cf;
|
|
234
|
+
}
|
|
235
|
+
if (ChainFetcher.isReady(cf$1)) {
|
|
236
|
+
if (!ChainFetcher.isReady(prev)) {
|
|
237
|
+
Prometheus.ProgressReady.set(chain);
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
allChainsReady.contents = false;
|
|
241
|
+
}
|
|
242
|
+
return cf$1;
|
|
243
|
+
});
|
|
253
244
|
if (allChainsReady.contents) {
|
|
254
245
|
Prometheus.ProgressReady.setAllReady();
|
|
255
246
|
}
|
|
256
|
-
|
|
247
|
+
let checkpointId = Utils.$$Array.last(batch.checkpointIds);
|
|
257
248
|
return {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
249
|
+
committedCheckpointId: checkpointId !== undefined ? checkpointId : chainManager.committedCheckpointId,
|
|
250
|
+
chainFetchers: chainFetchers,
|
|
251
|
+
multichain: chainManager.multichain,
|
|
252
|
+
isInReorgThreshold: chainManager.isInReorgThreshold
|
|
253
|
+
};
|
|
263
254
|
}
|
|
264
255
|
|
|
265
256
|
function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
257
|
+
let response = partitionQueryResponse.response;
|
|
258
|
+
let chain = partitionQueryResponse.chain;
|
|
259
|
+
let chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
260
|
+
let stats = response.stats;
|
|
261
|
+
let knownHeight = response.knownHeight;
|
|
271
262
|
if (knownHeight > chainFetcher.fetchState.knownHeight) {
|
|
272
263
|
Prometheus.SourceHeight.set(SourceManager.getActiveSource(chainFetcher.sourceManager).name, chainFetcher.chainConfig.id, knownHeight);
|
|
273
264
|
}
|
|
274
265
|
Prometheus.FetchingBlockRange.increment(chain, stats["total time elapsed (s)"], Belt_Option.getWithDefault(stats["parsing time (s)"], 0), response.parsedQueueItems.length, (response.latestFetchedBlockNumber - response.fromBlockQueried | 0) + 1 | 0);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
266
|
+
let match = ReorgDetection.registerReorgGuard(chainFetcher.reorgDetection, response.reorgGuard, knownHeight);
|
|
267
|
+
let reorgResult = match[1];
|
|
268
|
+
let updatedChainFetcher_logger = chainFetcher.logger;
|
|
269
|
+
let updatedChainFetcher_fetchState = chainFetcher.fetchState;
|
|
270
|
+
let updatedChainFetcher_sourceManager = chainFetcher.sourceManager;
|
|
271
|
+
let updatedChainFetcher_chainConfig = chainFetcher.chainConfig;
|
|
272
|
+
let updatedChainFetcher_isProgressAtHead = chainFetcher.isProgressAtHead;
|
|
273
|
+
let updatedChainFetcher_timestampCaughtUpToHeadOrEndblock = chainFetcher.timestampCaughtUpToHeadOrEndblock;
|
|
274
|
+
let updatedChainFetcher_committedProgressBlockNumber = chainFetcher.committedProgressBlockNumber;
|
|
275
|
+
let updatedChainFetcher_numEventsProcessed = chainFetcher.numEventsProcessed;
|
|
276
|
+
let updatedChainFetcher_reorgDetection = match[0];
|
|
277
|
+
let updatedChainFetcher_safeCheckpointTracking = chainFetcher.safeCheckpointTracking;
|
|
278
|
+
let updatedChainFetcher = {
|
|
288
279
|
logger: updatedChainFetcher_logger,
|
|
289
280
|
fetchState: updatedChainFetcher_fetchState,
|
|
290
281
|
sourceManager: updatedChainFetcher_sourceManager,
|
|
@@ -296,24 +287,24 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
296
287
|
reorgDetection: updatedChainFetcher_reorgDetection,
|
|
297
288
|
safeCheckpointTracking: updatedChainFetcher_safeCheckpointTracking
|
|
298
289
|
};
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
290
|
+
let init = state.chainManager;
|
|
291
|
+
let nextState_ctx = state.ctx;
|
|
292
|
+
let nextState_chainManager = {
|
|
302
293
|
committedCheckpointId: init.committedCheckpointId,
|
|
303
294
|
chainFetchers: ChainMap.set(state.chainManager.chainFetchers, chain, updatedChainFetcher),
|
|
304
295
|
multichain: init.multichain,
|
|
305
296
|
isInReorgThreshold: init.isInReorgThreshold
|
|
306
297
|
};
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
298
|
+
let nextState_processedBatches = state.processedBatches;
|
|
299
|
+
let nextState_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
300
|
+
let nextState_rollbackState = state.rollbackState;
|
|
301
|
+
let nextState_indexerStartTime = state.indexerStartTime;
|
|
302
|
+
let nextState_writeThrottlers = state.writeThrottlers;
|
|
303
|
+
let nextState_loadManager = state.loadManager;
|
|
304
|
+
let nextState_keepProcessAlive = state.keepProcessAlive;
|
|
305
|
+
let nextState_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
|
|
306
|
+
let nextState_id = state.id;
|
|
307
|
+
let nextState = {
|
|
317
308
|
ctx: nextState_ctx,
|
|
318
309
|
chainManager: nextState_chainManager,
|
|
319
310
|
processedBatches: nextState_processedBatches,
|
|
@@ -326,11 +317,11 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
326
317
|
exitAfterFirstEventBlock: nextState_exitAfterFirstEventBlock,
|
|
327
318
|
id: nextState_id
|
|
328
319
|
};
|
|
329
|
-
|
|
320
|
+
let rollbackWithReorgDetectedBlockNumber;
|
|
330
321
|
if (typeof reorgResult !== "object") {
|
|
331
322
|
rollbackWithReorgDetectedBlockNumber = undefined;
|
|
332
323
|
} else {
|
|
333
|
-
|
|
324
|
+
let reorgDetected = reorgResult._0;
|
|
334
325
|
Logging.childInfo(chainFetcher.logger, ReorgDetection.reorgDetectedToLogParams(reorgDetected, state.ctx.config.shouldRollbackOnReorg));
|
|
335
326
|
Prometheus.ReorgCount.increment(chain);
|
|
336
327
|
Prometheus.ReorgDetectionBlockNumber.set(reorgDetected.scannedBlock.blockNumber, chain);
|
|
@@ -338,95 +329,93 @@ function validatePartitionQueryResponse(state, partitionQueryResponse) {
|
|
|
338
329
|
}
|
|
339
330
|
if (rollbackWithReorgDetectedBlockNumber === undefined) {
|
|
340
331
|
return [
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
332
|
+
nextState,
|
|
333
|
+
[{
|
|
334
|
+
TAG: "ProcessPartitionQueryResponse",
|
|
335
|
+
_0: partitionQueryResponse
|
|
336
|
+
}]
|
|
337
|
+
];
|
|
347
338
|
}
|
|
348
|
-
|
|
349
|
-
|
|
339
|
+
let match$1 = state.rollbackState;
|
|
340
|
+
let chainManager;
|
|
350
341
|
if (typeof match$1 !== "object" || match$1.TAG !== "RollbackReady") {
|
|
351
342
|
chainManager = state.chainManager;
|
|
352
343
|
} else {
|
|
353
|
-
|
|
354
|
-
|
|
344
|
+
let eventsProcessedDiffByChain = match$1.eventsProcessedDiffByChain;
|
|
345
|
+
let init$1 = state.chainManager;
|
|
355
346
|
chainManager = {
|
|
356
347
|
committedCheckpointId: init$1.committedCheckpointId,
|
|
357
|
-
chainFetchers: ChainMap.mapWithKey(state.chainManager.chainFetchers, (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
348
|
+
chainFetchers: ChainMap.mapWithKey(state.chainManager.chainFetchers, (c, chainFetcher) => {
|
|
349
|
+
let eventsProcessedDiff = eventsProcessedDiffByChain[c];
|
|
350
|
+
if (eventsProcessedDiff !== undefined) {
|
|
351
|
+
return {
|
|
352
|
+
logger: chainFetcher.logger,
|
|
353
|
+
fetchState: chainFetcher.fetchState,
|
|
354
|
+
sourceManager: chainFetcher.sourceManager,
|
|
355
|
+
chainConfig: chainFetcher.chainConfig,
|
|
356
|
+
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
357
|
+
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
358
|
+
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
359
|
+
numEventsProcessed: chainFetcher.numEventsProcessed + eventsProcessedDiff,
|
|
360
|
+
reorgDetection: chainFetcher.reorgDetection,
|
|
361
|
+
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
362
|
+
};
|
|
363
|
+
} else {
|
|
364
|
+
return chainFetcher;
|
|
365
|
+
}
|
|
366
|
+
}),
|
|
376
367
|
multichain: init$1.multichain,
|
|
377
368
|
isInReorgThreshold: init$1.isInReorgThreshold
|
|
378
369
|
};
|
|
379
370
|
}
|
|
380
371
|
return [
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
["Rollback"]
|
|
417
|
-
];
|
|
372
|
+
{
|
|
373
|
+
ctx: nextState_ctx,
|
|
374
|
+
chainManager: {
|
|
375
|
+
committedCheckpointId: chainManager.committedCheckpointId,
|
|
376
|
+
chainFetchers: ChainMap.map(chainManager.chainFetchers, chainFetcher => ({
|
|
377
|
+
logger: chainFetcher.logger,
|
|
378
|
+
fetchState: FetchState.resetPendingQueries(chainFetcher.fetchState),
|
|
379
|
+
sourceManager: chainFetcher.sourceManager,
|
|
380
|
+
chainConfig: chainFetcher.chainConfig,
|
|
381
|
+
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
382
|
+
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
383
|
+
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
384
|
+
numEventsProcessed: chainFetcher.numEventsProcessed,
|
|
385
|
+
reorgDetection: chainFetcher.reorgDetection,
|
|
386
|
+
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
387
|
+
})),
|
|
388
|
+
multichain: chainManager.multichain,
|
|
389
|
+
isInReorgThreshold: chainManager.isInReorgThreshold
|
|
390
|
+
},
|
|
391
|
+
processedBatches: nextState_processedBatches,
|
|
392
|
+
currentlyProcessingBatch: nextState_currentlyProcessingBatch,
|
|
393
|
+
rollbackState: {
|
|
394
|
+
TAG: "ReorgDetected",
|
|
395
|
+
chain: chain,
|
|
396
|
+
blockNumber: rollbackWithReorgDetectedBlockNumber
|
|
397
|
+
},
|
|
398
|
+
indexerStartTime: nextState_indexerStartTime,
|
|
399
|
+
writeThrottlers: nextState_writeThrottlers,
|
|
400
|
+
loadManager: nextState_loadManager,
|
|
401
|
+
keepProcessAlive: nextState_keepProcessAlive,
|
|
402
|
+
exitAfterFirstEventBlock: nextState_exitAfterFirstEventBlock,
|
|
403
|
+
id: nextState_id + 1 | 0
|
|
404
|
+
},
|
|
405
|
+
["Rollback"]
|
|
406
|
+
];
|
|
418
407
|
}
|
|
419
408
|
|
|
420
409
|
function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHeight, latestFetchedBlock, query, chain) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
410
|
+
let chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
411
|
+
let updatedChainFetcher = ChainFetcher.handleQueryResult(chainFetcher, query, newItems, newItemsWithDcs, latestFetchedBlock, knownHeight);
|
|
412
|
+
let updatedChainFetcher$1;
|
|
424
413
|
if (state.exitAfterFirstEventBlock && newItems.length !== 0) {
|
|
425
|
-
|
|
426
|
-
|
|
414
|
+
let firstEventBlock = newItems[0].blockNumber;
|
|
415
|
+
let currentEndBlock = updatedChainFetcher.fetchState.endBlock;
|
|
427
416
|
if (currentEndBlock !== undefined) {
|
|
428
417
|
if (firstEventBlock < currentEndBlock) {
|
|
429
|
-
|
|
418
|
+
let init = updatedChainFetcher.fetchState;
|
|
430
419
|
updatedChainFetcher$1 = {
|
|
431
420
|
logger: updatedChainFetcher.logger,
|
|
432
421
|
fetchState: {
|
|
@@ -434,7 +423,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
434
423
|
startBlock: init.startBlock,
|
|
435
424
|
endBlock: firstEventBlock,
|
|
436
425
|
normalSelection: init.normalSelection,
|
|
437
|
-
|
|
426
|
+
indexingAddresses: init.indexingAddresses,
|
|
438
427
|
contractConfigs: init.contractConfigs,
|
|
439
428
|
chainId: init.chainId,
|
|
440
429
|
latestOnBlockBlockNumber: init.latestOnBlockBlockNumber,
|
|
@@ -458,7 +447,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
458
447
|
updatedChainFetcher$1 = updatedChainFetcher;
|
|
459
448
|
}
|
|
460
449
|
} else {
|
|
461
|
-
|
|
450
|
+
let init$1 = updatedChainFetcher.fetchState;
|
|
462
451
|
updatedChainFetcher$1 = {
|
|
463
452
|
logger: updatedChainFetcher.logger,
|
|
464
453
|
fetchState: {
|
|
@@ -466,7 +455,7 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
466
455
|
startBlock: init$1.startBlock,
|
|
467
456
|
endBlock: firstEventBlock,
|
|
468
457
|
normalSelection: init$1.normalSelection,
|
|
469
|
-
|
|
458
|
+
indexingAddresses: init$1.indexingAddresses,
|
|
470
459
|
contractConfigs: init$1.contractConfigs,
|
|
471
460
|
chainId: init$1.chainId,
|
|
472
461
|
latestOnBlockBlockNumber: init$1.latestOnBlockBlockNumber,
|
|
@@ -493,24 +482,24 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
493
482
|
if (!chainFetcher.isProgressAtHead && updatedChainFetcher$1.isProgressAtHead) {
|
|
494
483
|
Logging.childInfo(updatedChainFetcher$1.logger, "All events have been fetched");
|
|
495
484
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
485
|
+
let init$2 = state.chainManager;
|
|
486
|
+
let nextState_ctx = state.ctx;
|
|
487
|
+
let nextState_chainManager = {
|
|
499
488
|
committedCheckpointId: init$2.committedCheckpointId,
|
|
500
489
|
chainFetchers: ChainMap.set(state.chainManager.chainFetchers, chain, updatedChainFetcher$1),
|
|
501
490
|
multichain: init$2.multichain,
|
|
502
491
|
isInReorgThreshold: init$2.isInReorgThreshold
|
|
503
492
|
};
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
493
|
+
let nextState_processedBatches = state.processedBatches;
|
|
494
|
+
let nextState_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
495
|
+
let nextState_rollbackState = state.rollbackState;
|
|
496
|
+
let nextState_indexerStartTime = state.indexerStartTime;
|
|
497
|
+
let nextState_writeThrottlers = state.writeThrottlers;
|
|
498
|
+
let nextState_loadManager = state.loadManager;
|
|
499
|
+
let nextState_keepProcessAlive = state.keepProcessAlive;
|
|
500
|
+
let nextState_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
|
|
501
|
+
let nextState_id = state.id;
|
|
502
|
+
let nextState = {
|
|
514
503
|
ctx: nextState_ctx,
|
|
515
504
|
chainManager: nextState_chainManager,
|
|
516
505
|
processedBatches: nextState_processedBatches,
|
|
@@ -524,65 +513,122 @@ function submitPartitionQueryResponse(state, newItems, newItemsWithDcs, knownHei
|
|
|
524
513
|
id: nextState_id
|
|
525
514
|
};
|
|
526
515
|
return [
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
516
|
+
nextState,
|
|
517
|
+
[
|
|
518
|
+
{
|
|
519
|
+
TAG: "UpdateChainMetaDataAndCheckForExit",
|
|
520
|
+
_0: "NoExit"
|
|
521
|
+
},
|
|
522
|
+
"ProcessEventBatch",
|
|
523
|
+
{
|
|
524
|
+
TAG: "NextQuery",
|
|
525
|
+
_0: {
|
|
526
|
+
TAG: "Chain",
|
|
527
|
+
_0: chain
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
];
|
|
543
532
|
}
|
|
544
533
|
|
|
545
534
|
async function processPartitionQueryResponse(state, param, dispatchAction) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
var item = parsedQueueItems[idx];
|
|
535
|
+
let response = param.response;
|
|
536
|
+
let parsedQueueItems = response.parsedQueueItems;
|
|
537
|
+
let itemsWithContractRegister = [];
|
|
538
|
+
let newItems = [];
|
|
539
|
+
for (let idx = 0, idx_finish = parsedQueueItems.length; idx < idx_finish; ++idx) {
|
|
540
|
+
let item = parsedQueueItems[idx];
|
|
553
541
|
if (item.eventConfig.contractRegister !== undefined) {
|
|
554
542
|
itemsWithContractRegister.push(item);
|
|
555
543
|
}
|
|
556
544
|
newItems.push(item);
|
|
557
545
|
}
|
|
558
|
-
|
|
546
|
+
let newItemsWithDcs = itemsWithContractRegister.length !== 0 ? await ChainFetcher.runContractRegistersOrThrow(itemsWithContractRegister, state.ctx.config) : itemsWithContractRegister;
|
|
559
547
|
return dispatchAction({
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
548
|
+
TAG: "SubmitPartitionQueryResponse",
|
|
549
|
+
newItems: newItems,
|
|
550
|
+
newItemsWithDcs: newItemsWithDcs,
|
|
551
|
+
knownHeight: response.knownHeight,
|
|
552
|
+
latestFetchedBlock: {
|
|
553
|
+
blockNumber: response.latestFetchedBlockNumber,
|
|
554
|
+
blockTimestamp: response.latestFetchedBlockTimestamp
|
|
555
|
+
},
|
|
556
|
+
query: param.query,
|
|
557
|
+
chain: param.chain
|
|
558
|
+
});
|
|
571
559
|
}
|
|
572
560
|
|
|
573
561
|
function updateChainFetcher(chainFetcherUpdate, state, chain) {
|
|
574
|
-
|
|
562
|
+
let init = state.chainManager;
|
|
575
563
|
return [
|
|
564
|
+
{
|
|
565
|
+
ctx: state.ctx,
|
|
566
|
+
chainManager: {
|
|
567
|
+
committedCheckpointId: init.committedCheckpointId,
|
|
568
|
+
chainFetchers: ChainMap.update(state.chainManager.chainFetchers, chain, chainFetcherUpdate),
|
|
569
|
+
multichain: init.multichain,
|
|
570
|
+
isInReorgThreshold: init.isInReorgThreshold
|
|
571
|
+
},
|
|
572
|
+
processedBatches: state.processedBatches,
|
|
573
|
+
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
574
|
+
rollbackState: state.rollbackState,
|
|
575
|
+
indexerStartTime: state.indexerStartTime,
|
|
576
|
+
writeThrottlers: state.writeThrottlers,
|
|
577
|
+
loadManager: state.loadManager,
|
|
578
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
579
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
580
|
+
id: state.id
|
|
581
|
+
},
|
|
582
|
+
[]
|
|
583
|
+
];
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function onEnterReorgThreshold(state) {
|
|
587
|
+
Logging.info("Reorg threshold reached");
|
|
588
|
+
Prometheus.ReorgThreshold.set(true);
|
|
589
|
+
let chainFetchers = ChainMap.map(state.chainManager.chainFetchers, chainFetcher => ({
|
|
590
|
+
logger: chainFetcher.logger,
|
|
591
|
+
fetchState: FetchState.updateInternal(chainFetcher.fetchState, undefined, undefined, undefined, chainFetcher.chainConfig.blockLag, undefined),
|
|
592
|
+
sourceManager: chainFetcher.sourceManager,
|
|
593
|
+
chainConfig: chainFetcher.chainConfig,
|
|
594
|
+
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
595
|
+
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
596
|
+
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
597
|
+
numEventsProcessed: chainFetcher.numEventsProcessed,
|
|
598
|
+
reorgDetection: chainFetcher.reorgDetection,
|
|
599
|
+
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
600
|
+
}));
|
|
601
|
+
let init = state.chainManager;
|
|
602
|
+
return {
|
|
603
|
+
ctx: state.ctx,
|
|
604
|
+
chainManager: {
|
|
605
|
+
committedCheckpointId: init.committedCheckpointId,
|
|
606
|
+
chainFetchers: chainFetchers,
|
|
607
|
+
multichain: init.multichain,
|
|
608
|
+
isInReorgThreshold: true
|
|
609
|
+
},
|
|
610
|
+
processedBatches: state.processedBatches,
|
|
611
|
+
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
612
|
+
rollbackState: state.rollbackState,
|
|
613
|
+
indexerStartTime: state.indexerStartTime,
|
|
614
|
+
writeThrottlers: state.writeThrottlers,
|
|
615
|
+
loadManager: state.loadManager,
|
|
616
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
617
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
618
|
+
id: state.id
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function actionReducer(state, action) {
|
|
623
|
+
if (typeof action !== "object") {
|
|
624
|
+
switch (action) {
|
|
625
|
+
case "StartProcessingBatch" :
|
|
626
|
+
return [
|
|
576
627
|
{
|
|
577
628
|
ctx: state.ctx,
|
|
578
|
-
chainManager:
|
|
579
|
-
committedCheckpointId: init.committedCheckpointId,
|
|
580
|
-
chainFetchers: ChainMap.update(state.chainManager.chainFetchers, chain, chainFetcherUpdate),
|
|
581
|
-
multichain: init.multichain,
|
|
582
|
-
isInReorgThreshold: init.isInReorgThreshold
|
|
583
|
-
},
|
|
629
|
+
chainManager: state.chainManager,
|
|
584
630
|
processedBatches: state.processedBatches,
|
|
585
|
-
currentlyProcessingBatch:
|
|
631
|
+
currentlyProcessingBatch: true,
|
|
586
632
|
rollbackState: state.rollbackState,
|
|
587
633
|
indexerStartTime: state.indexerStartTime,
|
|
588
634
|
writeThrottlers: state.writeThrottlers,
|
|
@@ -593,338 +639,274 @@ function updateChainFetcher(chainFetcherUpdate, state, chain) {
|
|
|
593
639
|
},
|
|
594
640
|
[]
|
|
595
641
|
];
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
function onEnterReorgThreshold(state) {
|
|
599
|
-
Logging.info("Reorg threshold reached");
|
|
600
|
-
Prometheus.ReorgThreshold.set(true);
|
|
601
|
-
var chainFetchers = ChainMap.map(state.chainManager.chainFetchers, (function (chainFetcher) {
|
|
602
|
-
return {
|
|
603
|
-
logger: chainFetcher.logger,
|
|
604
|
-
fetchState: FetchState.updateInternal(chainFetcher.fetchState, undefined, undefined, undefined, chainFetcher.chainConfig.blockLag, undefined),
|
|
605
|
-
sourceManager: chainFetcher.sourceManager,
|
|
606
|
-
chainConfig: chainFetcher.chainConfig,
|
|
607
|
-
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
608
|
-
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
609
|
-
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
610
|
-
numEventsProcessed: chainFetcher.numEventsProcessed,
|
|
611
|
-
reorgDetection: chainFetcher.reorgDetection,
|
|
612
|
-
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
613
|
-
};
|
|
614
|
-
}));
|
|
615
|
-
var init = state.chainManager;
|
|
616
|
-
return {
|
|
617
|
-
ctx: state.ctx,
|
|
618
|
-
chainManager: {
|
|
619
|
-
committedCheckpointId: init.committedCheckpointId,
|
|
620
|
-
chainFetchers: chainFetchers,
|
|
621
|
-
multichain: init.multichain,
|
|
622
|
-
isInReorgThreshold: true
|
|
623
|
-
},
|
|
624
|
-
processedBatches: state.processedBatches,
|
|
625
|
-
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
626
|
-
rollbackState: state.rollbackState,
|
|
627
|
-
indexerStartTime: state.indexerStartTime,
|
|
628
|
-
writeThrottlers: state.writeThrottlers,
|
|
629
|
-
loadManager: state.loadManager,
|
|
630
|
-
keepProcessAlive: state.keepProcessAlive,
|
|
631
|
-
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
632
|
-
id: state.id
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
function actionReducer(state, action) {
|
|
637
|
-
if (typeof action !== "object") {
|
|
638
|
-
switch (action) {
|
|
639
|
-
case "StartProcessingBatch" :
|
|
640
|
-
return [
|
|
641
|
-
{
|
|
642
|
-
ctx: state.ctx,
|
|
643
|
-
chainManager: state.chainManager,
|
|
644
|
-
processedBatches: state.processedBatches,
|
|
645
|
-
currentlyProcessingBatch: true,
|
|
646
|
-
rollbackState: state.rollbackState,
|
|
647
|
-
indexerStartTime: state.indexerStartTime,
|
|
648
|
-
writeThrottlers: state.writeThrottlers,
|
|
649
|
-
loadManager: state.loadManager,
|
|
650
|
-
keepProcessAlive: state.keepProcessAlive,
|
|
651
|
-
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
652
|
-
id: state.id
|
|
653
|
-
},
|
|
654
|
-
[]
|
|
655
|
-
];
|
|
656
642
|
case "StartFindingReorgDepth" :
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
643
|
+
return [
|
|
644
|
+
{
|
|
645
|
+
ctx: state.ctx,
|
|
646
|
+
chainManager: state.chainManager,
|
|
647
|
+
processedBatches: state.processedBatches,
|
|
648
|
+
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
649
|
+
rollbackState: "FindingReorgDepth",
|
|
650
|
+
indexerStartTime: state.indexerStartTime,
|
|
651
|
+
writeThrottlers: state.writeThrottlers,
|
|
652
|
+
loadManager: state.loadManager,
|
|
653
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
654
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
655
|
+
id: state.id
|
|
656
|
+
},
|
|
657
|
+
[]
|
|
658
|
+
];
|
|
673
659
|
case "EnterReorgThreshold" :
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
660
|
+
return [
|
|
661
|
+
onEnterReorgThreshold(state),
|
|
662
|
+
[{
|
|
663
|
+
TAG: "NextQuery",
|
|
664
|
+
_0: "CheckAllChains"
|
|
665
|
+
}]
|
|
666
|
+
];
|
|
681
667
|
case "SuccessExit" :
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
668
|
+
Logging.info("Exiting with success");
|
|
669
|
+
Process.exit(0);
|
|
670
|
+
return [
|
|
671
|
+
state,
|
|
672
|
+
[]
|
|
673
|
+
];
|
|
689
674
|
}
|
|
690
675
|
} else {
|
|
691
676
|
switch (action.TAG) {
|
|
692
677
|
case "ValidatePartitionQueryResponse" :
|
|
693
|
-
|
|
678
|
+
return validatePartitionQueryResponse(state, action._0);
|
|
694
679
|
case "SubmitPartitionQueryResponse" :
|
|
695
|
-
|
|
680
|
+
return submitPartitionQueryResponse(state, action.newItems, action.newItemsWithDcs, action.knownHeight, action.latestFetchedBlock, action.query, action.chain);
|
|
696
681
|
case "FinishWaitingForNewBlock" :
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
} else {
|
|
715
|
-
return chainFetcher;
|
|
716
|
-
}
|
|
717
|
-
}));
|
|
718
|
-
var isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
|
|
719
|
-
var shouldEnterReorgThreshold = isBelowReorgThreshold && Belt_Array.every(ChainMap.values(updatedChainFetchers), (function (chainFetcher) {
|
|
720
|
-
return FetchState.isReadyToEnterReorgThreshold(chainFetcher.fetchState);
|
|
721
|
-
}));
|
|
722
|
-
var init = state.chainManager;
|
|
723
|
-
var state_ctx = state.ctx;
|
|
724
|
-
var state_chainManager = {
|
|
725
|
-
committedCheckpointId: init.committedCheckpointId,
|
|
726
|
-
chainFetchers: updatedChainFetchers,
|
|
727
|
-
multichain: init.multichain,
|
|
728
|
-
isInReorgThreshold: init.isInReorgThreshold
|
|
729
|
-
};
|
|
730
|
-
var state_processedBatches = state.processedBatches;
|
|
731
|
-
var state_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
732
|
-
var state_rollbackState = state.rollbackState;
|
|
733
|
-
var state_indexerStartTime = state.indexerStartTime;
|
|
734
|
-
var state_writeThrottlers = state.writeThrottlers;
|
|
735
|
-
var state_loadManager = state.loadManager;
|
|
736
|
-
var state_keepProcessAlive = state.keepProcessAlive;
|
|
737
|
-
var state_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
|
|
738
|
-
var state_id = state.id;
|
|
739
|
-
var state$1 = {
|
|
740
|
-
ctx: state_ctx,
|
|
741
|
-
chainManager: state_chainManager,
|
|
742
|
-
processedBatches: state_processedBatches,
|
|
743
|
-
currentlyProcessingBatch: state_currentlyProcessingBatch,
|
|
744
|
-
rollbackState: state_rollbackState,
|
|
745
|
-
indexerStartTime: state_indexerStartTime,
|
|
746
|
-
writeThrottlers: state_writeThrottlers,
|
|
747
|
-
loadManager: state_loadManager,
|
|
748
|
-
keepProcessAlive: state_keepProcessAlive,
|
|
749
|
-
exitAfterFirstEventBlock: state_exitAfterFirstEventBlock,
|
|
750
|
-
id: state_id
|
|
751
|
-
};
|
|
752
|
-
if (shouldEnterReorgThreshold) {
|
|
753
|
-
return [
|
|
754
|
-
onEnterReorgThreshold(state$1),
|
|
755
|
-
[
|
|
756
|
-
{
|
|
757
|
-
TAG: "NextQuery",
|
|
758
|
-
_0: "CheckAllChains"
|
|
759
|
-
},
|
|
760
|
-
"ProcessEventBatch"
|
|
761
|
-
]
|
|
762
|
-
];
|
|
682
|
+
let knownHeight = action.knownHeight;
|
|
683
|
+
let chain = action.chain;
|
|
684
|
+
let updatedChainFetchers = ChainMap.update(state.chainManager.chainFetchers, chain, chainFetcher => {
|
|
685
|
+
let updatedFetchState = FetchState.updateKnownHeight(chainFetcher.fetchState, knownHeight);
|
|
686
|
+
if (updatedFetchState !== chainFetcher.fetchState) {
|
|
687
|
+
return {
|
|
688
|
+
logger: chainFetcher.logger,
|
|
689
|
+
fetchState: updatedFetchState,
|
|
690
|
+
sourceManager: chainFetcher.sourceManager,
|
|
691
|
+
chainConfig: chainFetcher.chainConfig,
|
|
692
|
+
isProgressAtHead: chainFetcher.isProgressAtHead,
|
|
693
|
+
timestampCaughtUpToHeadOrEndblock: chainFetcher.timestampCaughtUpToHeadOrEndblock,
|
|
694
|
+
committedProgressBlockNumber: chainFetcher.committedProgressBlockNumber,
|
|
695
|
+
numEventsProcessed: chainFetcher.numEventsProcessed,
|
|
696
|
+
reorgDetection: chainFetcher.reorgDetection,
|
|
697
|
+
safeCheckpointTracking: chainFetcher.safeCheckpointTracking
|
|
698
|
+
};
|
|
763
699
|
} else {
|
|
764
|
-
return
|
|
765
|
-
state$1,
|
|
766
|
-
[
|
|
767
|
-
{
|
|
768
|
-
TAG: "NextQuery",
|
|
769
|
-
_0: {
|
|
770
|
-
TAG: "Chain",
|
|
771
|
-
_0: chain
|
|
772
|
-
}
|
|
773
|
-
},
|
|
774
|
-
"ProcessEventBatch"
|
|
775
|
-
]
|
|
776
|
-
];
|
|
700
|
+
return chainFetcher;
|
|
777
701
|
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
}) : "NoExit"
|
|
813
|
-
);
|
|
702
|
+
});
|
|
703
|
+
let isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
|
|
704
|
+
let shouldEnterReorgThreshold = isBelowReorgThreshold && ChainMap.values(updatedChainFetchers).every(chainFetcher => FetchState.isReadyToEnterReorgThreshold(chainFetcher.fetchState));
|
|
705
|
+
let init = state.chainManager;
|
|
706
|
+
let state_ctx = state.ctx;
|
|
707
|
+
let state_chainManager = {
|
|
708
|
+
committedCheckpointId: init.committedCheckpointId,
|
|
709
|
+
chainFetchers: updatedChainFetchers,
|
|
710
|
+
multichain: init.multichain,
|
|
711
|
+
isInReorgThreshold: init.isInReorgThreshold
|
|
712
|
+
};
|
|
713
|
+
let state_processedBatches = state.processedBatches;
|
|
714
|
+
let state_currentlyProcessingBatch = state.currentlyProcessingBatch;
|
|
715
|
+
let state_rollbackState = state.rollbackState;
|
|
716
|
+
let state_indexerStartTime = state.indexerStartTime;
|
|
717
|
+
let state_writeThrottlers = state.writeThrottlers;
|
|
718
|
+
let state_loadManager = state.loadManager;
|
|
719
|
+
let state_keepProcessAlive = state.keepProcessAlive;
|
|
720
|
+
let state_exitAfterFirstEventBlock = state.exitAfterFirstEventBlock;
|
|
721
|
+
let state_id = state.id;
|
|
722
|
+
let state$1 = {
|
|
723
|
+
ctx: state_ctx,
|
|
724
|
+
chainManager: state_chainManager,
|
|
725
|
+
processedBatches: state_processedBatches,
|
|
726
|
+
currentlyProcessingBatch: state_currentlyProcessingBatch,
|
|
727
|
+
rollbackState: state_rollbackState,
|
|
728
|
+
indexerStartTime: state_indexerStartTime,
|
|
729
|
+
writeThrottlers: state_writeThrottlers,
|
|
730
|
+
loadManager: state_loadManager,
|
|
731
|
+
keepProcessAlive: state_keepProcessAlive,
|
|
732
|
+
exitAfterFirstEventBlock: state_exitAfterFirstEventBlock,
|
|
733
|
+
id: state_id
|
|
734
|
+
};
|
|
735
|
+
if (shouldEnterReorgThreshold) {
|
|
814
736
|
return [
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
737
|
+
onEnterReorgThreshold(state$1),
|
|
738
|
+
[
|
|
739
|
+
{
|
|
740
|
+
TAG: "NextQuery",
|
|
741
|
+
_0: "CheckAllChains"
|
|
742
|
+
},
|
|
743
|
+
"ProcessEventBatch"
|
|
744
|
+
]
|
|
745
|
+
];
|
|
746
|
+
} else {
|
|
825
747
|
return [
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
748
|
+
state$1,
|
|
749
|
+
[
|
|
750
|
+
{
|
|
751
|
+
TAG: "NextQuery",
|
|
752
|
+
_0: {
|
|
753
|
+
TAG: "Chain",
|
|
754
|
+
_0: chain
|
|
755
|
+
}
|
|
756
|
+
},
|
|
757
|
+
"ProcessEventBatch"
|
|
758
|
+
]
|
|
759
|
+
];
|
|
760
|
+
}
|
|
761
|
+
case "EventBatchProcessed" :
|
|
762
|
+
let maybePruneEntityHistory = Config.shouldPruneHistory(state.ctx.config, state.chainManager.isInReorgThreshold) ? ["PruneStaleEntityHistory"] : [];
|
|
763
|
+
let state_ctx$1 = state.ctx;
|
|
764
|
+
let state_chainManager$1 = updateProgressedChains(state.chainManager, action.batch, state.ctx);
|
|
765
|
+
let state_processedBatches$1 = state.processedBatches + 1 | 0;
|
|
766
|
+
let state_indexerStartTime$1 = state.indexerStartTime;
|
|
767
|
+
let state_writeThrottlers$1 = state.writeThrottlers;
|
|
768
|
+
let state_loadManager$1 = state.loadManager;
|
|
769
|
+
let state_keepProcessAlive$1 = state.keepProcessAlive;
|
|
770
|
+
let state_exitAfterFirstEventBlock$1 = state.exitAfterFirstEventBlock;
|
|
771
|
+
let state_id$1 = state.id;
|
|
772
|
+
let state$2 = {
|
|
773
|
+
ctx: state_ctx$1,
|
|
774
|
+
chainManager: state_chainManager$1,
|
|
775
|
+
processedBatches: state_processedBatches$1,
|
|
776
|
+
currentlyProcessingBatch: false,
|
|
777
|
+
rollbackState: "NoRollback",
|
|
778
|
+
indexerStartTime: state_indexerStartTime$1,
|
|
779
|
+
writeThrottlers: state_writeThrottlers$1,
|
|
780
|
+
loadManager: state_loadManager$1,
|
|
781
|
+
keepProcessAlive: state_keepProcessAlive$1,
|
|
782
|
+
exitAfterFirstEventBlock: state_exitAfterFirstEventBlock$1,
|
|
783
|
+
id: state_id$1
|
|
784
|
+
};
|
|
785
|
+
let shouldExit = EventProcessing.allChainsEventsProcessedToEndblock(state_chainManager$1.chainFetchers) ? (Logging.info("All chains are caught up to end blocks."), state_keepProcessAlive$1 ? "NoExit" : "ExitWithSuccess") : (
|
|
786
|
+
state_exitAfterFirstEventBlock$1 && ChainMap.values(state_chainManager$1.chainFetchers).every(cf => {
|
|
787
|
+
if (cf.isProgressAtHead) {
|
|
788
|
+
return Belt_Option.isNone(cf.fetchState.endBlock);
|
|
789
|
+
} else {
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
}) ? ({
|
|
793
|
+
TAG: "ExitWithError",
|
|
794
|
+
_0: "No events found between startBlock and chain head. Cannot auto-detect endBlock."
|
|
795
|
+
}) : "NoExit"
|
|
796
|
+
);
|
|
797
|
+
return [
|
|
798
|
+
state$2,
|
|
799
|
+
[
|
|
800
|
+
{
|
|
801
|
+
TAG: "UpdateChainMetaDataAndCheckForExit",
|
|
802
|
+
_0: shouldExit
|
|
803
|
+
},
|
|
804
|
+
"ProcessEventBatch"
|
|
805
|
+
].concat(maybePruneEntityHistory)
|
|
806
|
+
];
|
|
807
|
+
case "FindReorgDepth" :
|
|
808
|
+
return [
|
|
809
|
+
{
|
|
810
|
+
ctx: state.ctx,
|
|
811
|
+
chainManager: state.chainManager,
|
|
812
|
+
processedBatches: state.processedBatches,
|
|
813
|
+
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
814
|
+
rollbackState: {
|
|
815
|
+
TAG: "FoundReorgDepth",
|
|
816
|
+
chain: action.chain,
|
|
817
|
+
rollbackTargetBlockNumber: action.rollbackTargetBlockNumber
|
|
818
|
+
},
|
|
819
|
+
indexerStartTime: state.indexerStartTime,
|
|
820
|
+
writeThrottlers: state.writeThrottlers,
|
|
821
|
+
loadManager: state.loadManager,
|
|
822
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
823
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
824
|
+
id: state.id
|
|
825
|
+
},
|
|
826
|
+
["Rollback"]
|
|
827
|
+
];
|
|
845
828
|
case "UpdateQueues" :
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
};
|
|
863
|
-
}));
|
|
864
|
-
var init$1 = state.chainManager;
|
|
865
|
-
var chainManager_committedCheckpointId = init$1.committedCheckpointId;
|
|
866
|
-
var chainManager_multichain = init$1.multichain;
|
|
867
|
-
var chainManager_isInReorgThreshold = init$1.isInReorgThreshold;
|
|
868
|
-
var chainManager = {
|
|
869
|
-
committedCheckpointId: chainManager_committedCheckpointId,
|
|
870
|
-
chainFetchers: chainFetchers,
|
|
871
|
-
multichain: chainManager_multichain,
|
|
872
|
-
isInReorgThreshold: chainManager_isInReorgThreshold
|
|
829
|
+
let shouldEnterReorgThreshold$1 = action.shouldEnterReorgThreshold;
|
|
830
|
+
let progressedChainsById = action.progressedChainsById;
|
|
831
|
+
let chainFetchers = ChainMap.mapWithKey(state.chainManager.chainFetchers, (chain, cf) => {
|
|
832
|
+
let chainAfterBatch = progressedChainsById[chain];
|
|
833
|
+
let fs = chainAfterBatch !== undefined ? chainAfterBatch.fetchState : cf.fetchState;
|
|
834
|
+
return {
|
|
835
|
+
logger: cf.logger,
|
|
836
|
+
fetchState: shouldEnterReorgThreshold$1 ? FetchState.updateInternal(fs, undefined, undefined, undefined, cf.chainConfig.blockLag, undefined) : fs,
|
|
837
|
+
sourceManager: cf.sourceManager,
|
|
838
|
+
chainConfig: cf.chainConfig,
|
|
839
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
840
|
+
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
841
|
+
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
842
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
843
|
+
reorgDetection: cf.reorgDetection,
|
|
844
|
+
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
873
845
|
};
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
846
|
+
});
|
|
847
|
+
let init$1 = state.chainManager;
|
|
848
|
+
let chainManager_committedCheckpointId = init$1.committedCheckpointId;
|
|
849
|
+
let chainManager_multichain = init$1.multichain;
|
|
850
|
+
let chainManager_isInReorgThreshold = init$1.isInReorgThreshold;
|
|
851
|
+
let chainManager = {
|
|
852
|
+
committedCheckpointId: chainManager_committedCheckpointId,
|
|
853
|
+
chainFetchers: chainFetchers,
|
|
854
|
+
multichain: chainManager_multichain,
|
|
855
|
+
isInReorgThreshold: chainManager_isInReorgThreshold
|
|
856
|
+
};
|
|
857
|
+
return [
|
|
858
|
+
{
|
|
859
|
+
ctx: state.ctx,
|
|
860
|
+
chainManager: chainManager,
|
|
861
|
+
processedBatches: state.processedBatches,
|
|
862
|
+
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
863
|
+
rollbackState: state.rollbackState,
|
|
864
|
+
indexerStartTime: state.indexerStartTime,
|
|
865
|
+
writeThrottlers: state.writeThrottlers,
|
|
866
|
+
loadManager: state.loadManager,
|
|
867
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
868
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
869
|
+
id: state.id
|
|
870
|
+
},
|
|
871
|
+
[{
|
|
872
|
+
TAG: "NextQuery",
|
|
873
|
+
_0: "CheckAllChains"
|
|
874
|
+
}]
|
|
875
|
+
];
|
|
893
876
|
case "ErrorExit" :
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
877
|
+
ErrorHandling.log(action._0);
|
|
878
|
+
Process.exit(1);
|
|
879
|
+
return [
|
|
880
|
+
state,
|
|
881
|
+
[]
|
|
882
|
+
];
|
|
900
883
|
case "SetRollbackState" :
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
884
|
+
return [
|
|
885
|
+
{
|
|
886
|
+
ctx: state.ctx,
|
|
887
|
+
chainManager: action.rollbackedChainManager,
|
|
888
|
+
processedBatches: state.processedBatches,
|
|
889
|
+
currentlyProcessingBatch: state.currentlyProcessingBatch,
|
|
890
|
+
rollbackState: {
|
|
891
|
+
TAG: "RollbackReady",
|
|
892
|
+
diffInMemoryStore: action.diffInMemoryStore,
|
|
893
|
+
eventsProcessedDiffByChain: action.eventsProcessedDiffByChain
|
|
894
|
+
},
|
|
895
|
+
indexerStartTime: state.indexerStartTime,
|
|
896
|
+
writeThrottlers: state.writeThrottlers,
|
|
897
|
+
loadManager: state.loadManager,
|
|
898
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
899
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
900
|
+
id: state.id
|
|
901
|
+
},
|
|
902
|
+
[
|
|
903
|
+
{
|
|
904
|
+
TAG: "NextQuery",
|
|
905
|
+
_0: "CheckAllChains"
|
|
906
|
+
},
|
|
907
|
+
"ProcessEventBatch"
|
|
908
|
+
]
|
|
909
|
+
];
|
|
928
910
|
}
|
|
929
911
|
}
|
|
930
912
|
}
|
|
@@ -933,359 +915,343 @@ function invalidatedActionReducer(state, action) {
|
|
|
933
915
|
if (typeof action === "object") {
|
|
934
916
|
switch (action.TAG) {
|
|
935
917
|
case "EventBatchProcessed" :
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
918
|
+
if (isPreparingRollback(state)) {
|
|
919
|
+
Logging.info("Finished processing batch before rollback, actioning rollback");
|
|
920
|
+
return [
|
|
921
|
+
{
|
|
922
|
+
ctx: state.ctx,
|
|
923
|
+
chainManager: updateProgressedChains(state.chainManager, action.batch, state.ctx),
|
|
924
|
+
processedBatches: state.processedBatches + 1 | 0,
|
|
925
|
+
currentlyProcessingBatch: false,
|
|
926
|
+
rollbackState: state.rollbackState,
|
|
927
|
+
indexerStartTime: state.indexerStartTime,
|
|
928
|
+
writeThrottlers: state.writeThrottlers,
|
|
929
|
+
loadManager: state.loadManager,
|
|
930
|
+
keepProcessAlive: state.keepProcessAlive,
|
|
931
|
+
exitAfterFirstEventBlock: state.exitAfterFirstEventBlock,
|
|
932
|
+
id: state.id
|
|
933
|
+
},
|
|
934
|
+
["Rollback"]
|
|
935
|
+
];
|
|
936
|
+
}
|
|
937
|
+
break;
|
|
956
938
|
case "ErrorExit" :
|
|
957
|
-
|
|
958
|
-
default:
|
|
959
|
-
|
|
939
|
+
return actionReducer(state, action);
|
|
960
940
|
}
|
|
961
941
|
}
|
|
962
942
|
Logging.trace({
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
943
|
+
msg: "Invalidated action discarded",
|
|
944
|
+
action: S$RescriptSchema.convertOrThrow(action, Utils.Schema.variantTag)
|
|
945
|
+
});
|
|
966
946
|
return [
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
947
|
+
state,
|
|
948
|
+
[]
|
|
949
|
+
];
|
|
970
950
|
}
|
|
971
951
|
|
|
972
952
|
function checkAndFetchForChain(waitForNewBlock, executeQuery, state, dispatchAction) {
|
|
973
|
-
return async
|
|
974
|
-
|
|
953
|
+
return async chain => {
|
|
954
|
+
let chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
975
955
|
if (isPreparingRollback(state)) {
|
|
976
|
-
return
|
|
956
|
+
return;
|
|
977
957
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
chain: chain,
|
|
1004
|
-
knownHeight: knownHeight
|
|
1005
|
-
});
|
|
1006
|
-
}), state.id);
|
|
958
|
+
let fetchState = chainFetcher.fetchState;
|
|
959
|
+
let reducedPolling = state.ctx.config.shouldRollbackOnReorg ? !state.chainManager.isInReorgThreshold && FetchState.isReadyToEnterReorgThreshold(fetchState) : ChainFetcher.isReady(chainFetcher) && ChainMap.values(state.chainManager.chainFetchers).some(cf => !ChainFetcher.isReady(cf));
|
|
960
|
+
return await SourceManager.fetchNext(chainFetcher.sourceManager, fetchState, async query => {
|
|
961
|
+
try {
|
|
962
|
+
let response = await executeQuery(chainFetcher.sourceManager, query, fetchState.knownHeight, ChainFetcher.isReady(chainFetcher));
|
|
963
|
+
return dispatchAction({
|
|
964
|
+
TAG: "ValidatePartitionQueryResponse",
|
|
965
|
+
_0: {
|
|
966
|
+
chain: chain,
|
|
967
|
+
response: response,
|
|
968
|
+
query: query
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
} catch (raw_exn) {
|
|
972
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
973
|
+
return dispatchAction({
|
|
974
|
+
TAG: "ErrorExit",
|
|
975
|
+
_0: ErrorHandling.make(exn, undefined, undefined)
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
}, knownHeight => waitForNewBlock(chainFetcher.sourceManager, knownHeight, ChainFetcher.isReady(chainFetcher), reducedPolling), knownHeight => dispatchAction({
|
|
979
|
+
TAG: "FinishWaitingForNewBlock",
|
|
980
|
+
chain: chain,
|
|
981
|
+
knownHeight: knownHeight
|
|
982
|
+
}), state.id);
|
|
1007
983
|
};
|
|
1008
984
|
}
|
|
1009
985
|
|
|
1010
986
|
function injectedTaskReducer(waitForNewBlock, executeQuery, getLastKnownValidBlock) {
|
|
1011
|
-
return async
|
|
987
|
+
return async (state, task, dispatchAction) => {
|
|
1012
988
|
if (typeof task !== "object") {
|
|
1013
989
|
switch (task) {
|
|
1014
990
|
case "ProcessEventBatch" :
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
if (
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
return dispatchAction("SuccessExit");
|
|
1040
|
-
} else {
|
|
1041
|
-
return ;
|
|
1042
|
-
}
|
|
991
|
+
if (state.currentlyProcessingBatch || isPreparingRollback(state)) {
|
|
992
|
+
return;
|
|
993
|
+
}
|
|
994
|
+
let match = state.rollbackState;
|
|
995
|
+
let rollbackInMemStore;
|
|
996
|
+
rollbackInMemStore = typeof match !== "object" || match.TAG !== "RollbackReady" ? undefined : match.diffInMemoryStore;
|
|
997
|
+
let batch = ChainManager.createBatch(state.chainManager, state.ctx.config.batchSize, rollbackInMemStore !== undefined);
|
|
998
|
+
let progressedChainsById = batch.progressedChainsById;
|
|
999
|
+
let isInReorgThreshold = state.chainManager.isInReorgThreshold;
|
|
1000
|
+
let shouldSaveHistory = Config.shouldSaveHistory(state.ctx.config, isInReorgThreshold);
|
|
1001
|
+
let isBelowReorgThreshold = !state.chainManager.isInReorgThreshold && state.ctx.config.shouldRollbackOnReorg;
|
|
1002
|
+
let shouldEnterReorgThreshold = isBelowReorgThreshold && ChainMap.values(state.chainManager.chainFetchers).every(chainFetcher => {
|
|
1003
|
+
let chainAfterBatch = progressedChainsById[chainFetcher.fetchState.chainId];
|
|
1004
|
+
return FetchState.isReadyToEnterReorgThreshold(chainAfterBatch !== undefined ? chainAfterBatch.fetchState : chainFetcher.fetchState);
|
|
1005
|
+
});
|
|
1006
|
+
if (shouldEnterReorgThreshold) {
|
|
1007
|
+
dispatchAction("EnterReorgThreshold");
|
|
1008
|
+
}
|
|
1009
|
+
if (Utils.Dict.isEmpty(progressedChainsById)) {
|
|
1010
|
+
if (EventProcessing.allChainsEventsProcessedToEndblock(state.chainManager.chainFetchers)) {
|
|
1011
|
+
Logging.info("All chains are caught up to end blocks.");
|
|
1012
|
+
if (!state.keepProcessAlive) {
|
|
1013
|
+
updateChainMetadataTable(state.chainManager, state.ctx.persistence, state.writeThrottlers.chainMetaData);
|
|
1014
|
+
return dispatchAction("SuccessExit");
|
|
1043
1015
|
} else {
|
|
1044
|
-
return
|
|
1016
|
+
return;
|
|
1045
1017
|
}
|
|
1046
|
-
}
|
|
1047
|
-
dispatchAction("StartProcessingBatch");
|
|
1048
|
-
dispatchAction({
|
|
1049
|
-
TAG: "UpdateQueues",
|
|
1050
|
-
progressedChainsById: progressedChainsById,
|
|
1051
|
-
shouldEnterReorgThreshold: shouldEnterReorgThreshold
|
|
1052
|
-
});
|
|
1053
|
-
var inMemoryStore = Belt_Option.getWithDefault(rollbackInMemStore, InMemoryStore.make(state.ctx.persistence.allEntities, undefined));
|
|
1054
|
-
InMemoryStore.setBatchDcs(inMemoryStore, batch, shouldSaveHistory);
|
|
1055
|
-
var res;
|
|
1056
|
-
try {
|
|
1057
|
-
res = await EventProcessing.processEventBatch(batch, inMemoryStore, isInReorgThreshold, state.loadManager, state.ctx, state.chainManager.chainFetchers);
|
|
1058
|
-
}
|
|
1059
|
-
catch (raw_exn){
|
|
1060
|
-
var exn = Caml_js_exceptions.internalToOCamlException(raw_exn);
|
|
1061
|
-
var errHandler = ErrorHandling.make(exn, undefined, "A top level unexpected error occurred during processing");
|
|
1062
|
-
return dispatchAction({
|
|
1063
|
-
TAG: "ErrorExit",
|
|
1064
|
-
_0: errHandler
|
|
1065
|
-
});
|
|
1066
|
-
}
|
|
1067
|
-
if (res.TAG === "Ok") {
|
|
1068
|
-
return dispatchAction({
|
|
1069
|
-
TAG: "EventBatchProcessed",
|
|
1070
|
-
batch: batch
|
|
1071
|
-
});
|
|
1072
1018
|
} else {
|
|
1073
|
-
return
|
|
1074
|
-
TAG: "ErrorExit",
|
|
1075
|
-
_0: res._0
|
|
1076
|
-
});
|
|
1019
|
+
return;
|
|
1077
1020
|
}
|
|
1078
|
-
|
|
1021
|
+
}
|
|
1022
|
+
dispatchAction("StartProcessingBatch");
|
|
1023
|
+
dispatchAction({
|
|
1024
|
+
TAG: "UpdateQueues",
|
|
1025
|
+
progressedChainsById: progressedChainsById,
|
|
1026
|
+
shouldEnterReorgThreshold: shouldEnterReorgThreshold
|
|
1027
|
+
});
|
|
1028
|
+
let inMemoryStore = Stdlib_Option.getOr(rollbackInMemStore, InMemoryStore.make(state.ctx.persistence.allEntities, undefined));
|
|
1029
|
+
InMemoryStore.setBatchDcs(inMemoryStore, batch, shouldSaveHistory);
|
|
1030
|
+
let res;
|
|
1031
|
+
try {
|
|
1032
|
+
res = await EventProcessing.processEventBatch(batch, inMemoryStore, isInReorgThreshold, state.loadManager, state.ctx, state.chainManager.chainFetchers);
|
|
1033
|
+
} catch (raw_exn) {
|
|
1034
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
1035
|
+
let errHandler = ErrorHandling.make(exn, undefined, "A top level unexpected error occurred during processing");
|
|
1036
|
+
return dispatchAction({
|
|
1037
|
+
TAG: "ErrorExit",
|
|
1038
|
+
_0: errHandler
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
if (res.TAG === "Ok") {
|
|
1042
|
+
return dispatchAction({
|
|
1043
|
+
TAG: "EventBatchProcessed",
|
|
1044
|
+
batch: batch
|
|
1045
|
+
});
|
|
1046
|
+
} else {
|
|
1047
|
+
return dispatchAction({
|
|
1048
|
+
TAG: "ErrorExit",
|
|
1049
|
+
_0: res._0
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
break;
|
|
1079
1053
|
case "Rollback" :
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
}
|
|
1087
|
-
}
|
|
1088
|
-
switch (match$1.TAG) {
|
|
1089
|
-
case "ReorgDetected" :
|
|
1090
|
-
var chain = match$1.chain;
|
|
1091
|
-
var chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
1092
|
-
dispatchAction("StartFindingReorgDepth");
|
|
1093
|
-
var rollbackTargetBlockNumber = await getLastKnownValidBlock(chainFetcher, match$1.blockNumber);
|
|
1094
|
-
return dispatchAction({
|
|
1095
|
-
TAG: "FindReorgDepth",
|
|
1096
|
-
chain: chain,
|
|
1097
|
-
rollbackTargetBlockNumber: rollbackTargetBlockNumber
|
|
1098
|
-
});
|
|
1099
|
-
case "FoundReorgDepth" :
|
|
1100
|
-
if (state.currentlyProcessingBatch) {
|
|
1101
|
-
return Logging.info("Waiting for batch to finish processing before executing rollback");
|
|
1102
|
-
}
|
|
1103
|
-
var match$2 = state.rollbackState;
|
|
1104
|
-
var rollbackTargetBlockNumber$1 = match$2.rollbackTargetBlockNumber;
|
|
1105
|
-
var reorgChain = match$2.chain;
|
|
1106
|
-
var startTime = Hrtime.makeTimer();
|
|
1107
|
-
var chainFetcher$1 = ChainMap.get(state.chainManager.chainFetchers, reorgChain);
|
|
1108
|
-
var logger = Logging.createChildFrom(chainFetcher$1.logger, {
|
|
1109
|
-
action: "Rollback",
|
|
1110
|
-
reorgChain: reorgChain,
|
|
1111
|
-
targetBlockNumber: rollbackTargetBlockNumber$1
|
|
1112
|
-
});
|
|
1113
|
-
Logging.childInfo(logger, "Started rollback on reorg");
|
|
1114
|
-
Prometheus.RollbackTargetBlockNumber.set(rollbackTargetBlockNumber$1, reorgChain);
|
|
1115
|
-
var checkpointId = await state.ctx.persistence.storage.getRollbackTargetCheckpoint(reorgChain, rollbackTargetBlockNumber$1);
|
|
1116
|
-
var rollbackTargetCheckpointId = checkpointId !== undefined ? checkpointId : 0n;
|
|
1117
|
-
var eventsProcessedDiffByChain = {};
|
|
1118
|
-
var newProgressBlockNumberPerChain = {};
|
|
1119
|
-
var rollbackedProcessedEvents = 0;
|
|
1120
|
-
var rollbackProgressDiff = await state.ctx.persistence.storage.getRollbackProgressDiff(rollbackTargetCheckpointId);
|
|
1121
|
-
for(var idx = 0 ,idx_finish = rollbackProgressDiff.length; idx < idx_finish; ++idx){
|
|
1122
|
-
var diff = rollbackProgressDiff[idx];
|
|
1123
|
-
var eventsProcessedDiff = Belt_Option.getExn(Belt_Float.fromString(diff.events_processed_diff));
|
|
1124
|
-
rollbackedProcessedEvents = rollbackedProcessedEvents + eventsProcessedDiff;
|
|
1125
|
-
eventsProcessedDiffByChain[diff.chain_id] = eventsProcessedDiff;
|
|
1126
|
-
newProgressBlockNumberPerChain[diff.chain_id] = rollbackTargetCheckpointId === 0n && diff.chain_id === reorgChain && diff.new_progress_block_number >= rollbackTargetBlockNumber$1 ? rollbackTargetBlockNumber$1 : diff.new_progress_block_number;
|
|
1127
|
-
}
|
|
1128
|
-
var chainFetchers = ChainMap.mapWithKey(state.chainManager.chainFetchers, (function (chain, cf) {
|
|
1129
|
-
var newProgressBlockNumber = newProgressBlockNumberPerChain[chain];
|
|
1130
|
-
if (newProgressBlockNumber === undefined) {
|
|
1131
|
-
if (Caml_obj.equal(chain, reorgChain)) {
|
|
1132
|
-
return {
|
|
1133
|
-
logger: cf.logger,
|
|
1134
|
-
fetchState: FetchState.rollback(cf.fetchState, rollbackTargetBlockNumber$1),
|
|
1135
|
-
sourceManager: cf.sourceManager,
|
|
1136
|
-
chainConfig: cf.chainConfig,
|
|
1137
|
-
isProgressAtHead: cf.isProgressAtHead,
|
|
1138
|
-
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
1139
|
-
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
1140
|
-
numEventsProcessed: cf.numEventsProcessed,
|
|
1141
|
-
reorgDetection: ReorgDetection.rollbackToValidBlockNumber(cf.reorgDetection, rollbackTargetBlockNumber$1),
|
|
1142
|
-
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
1143
|
-
};
|
|
1144
|
-
} else {
|
|
1145
|
-
return cf;
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
var fetchState = FetchState.rollback(cf.fetchState, newProgressBlockNumber);
|
|
1149
|
-
var newTotalEventsProcessed = cf.numEventsProcessed - eventsProcessedDiffByChain[chain];
|
|
1150
|
-
if (cf.committedProgressBlockNumber !== newProgressBlockNumber) {
|
|
1151
|
-
Prometheus.ProgressBlockNumber.set(newProgressBlockNumber, chain);
|
|
1152
|
-
}
|
|
1153
|
-
if (cf.numEventsProcessed !== newTotalEventsProcessed) {
|
|
1154
|
-
Prometheus.ProgressEventsCount.set(newTotalEventsProcessed, chain);
|
|
1155
|
-
}
|
|
1156
|
-
var safeCheckpointTracking = cf.safeCheckpointTracking;
|
|
1157
|
-
return {
|
|
1158
|
-
logger: cf.logger,
|
|
1159
|
-
fetchState: fetchState,
|
|
1160
|
-
sourceManager: cf.sourceManager,
|
|
1161
|
-
chainConfig: cf.chainConfig,
|
|
1162
|
-
isProgressAtHead: cf.isProgressAtHead,
|
|
1163
|
-
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
1164
|
-
committedProgressBlockNumber: newProgressBlockNumber,
|
|
1165
|
-
numEventsProcessed: newTotalEventsProcessed,
|
|
1166
|
-
reorgDetection: Caml_obj.equal(chain, reorgChain) ? ReorgDetection.rollbackToValidBlockNumber(cf.reorgDetection, rollbackTargetBlockNumber$1) : cf.reorgDetection,
|
|
1167
|
-
safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber) : undefined
|
|
1168
|
-
};
|
|
1169
|
-
}));
|
|
1170
|
-
var diff$1 = await Persistence.prepareRollbackDiff(state.ctx.persistence, rollbackTargetCheckpointId, $$BigInt.add(state.chainManager.committedCheckpointId, 1n));
|
|
1171
|
-
var init = state.chainManager;
|
|
1172
|
-
var chainManager_committedCheckpointId = init.committedCheckpointId;
|
|
1173
|
-
var chainManager_multichain = init.multichain;
|
|
1174
|
-
var chainManager_isInReorgThreshold = init.isInReorgThreshold;
|
|
1175
|
-
var chainManager = {
|
|
1176
|
-
committedCheckpointId: chainManager_committedCheckpointId,
|
|
1177
|
-
chainFetchers: chainFetchers,
|
|
1178
|
-
multichain: chainManager_multichain,
|
|
1179
|
-
isInReorgThreshold: chainManager_isInReorgThreshold
|
|
1180
|
-
};
|
|
1181
|
-
Logging.childTrace(logger, {
|
|
1182
|
-
msg: "Finished rollback on reorg",
|
|
1183
|
-
entityChanges: {
|
|
1184
|
-
deleted: diff$1.deletedEntities,
|
|
1185
|
-
upserted: diff$1.setEntities
|
|
1186
|
-
},
|
|
1187
|
-
rollbackedEvents: rollbackedProcessedEvents,
|
|
1188
|
-
beforeCheckpointId: state.chainManager.committedCheckpointId,
|
|
1189
|
-
targetCheckpointId: rollbackTargetCheckpointId
|
|
1190
|
-
});
|
|
1191
|
-
Prometheus.RollbackSuccess.increment(Hrtime.toSecondsFloat(Hrtime.timeSince(startTime)), rollbackedProcessedEvents);
|
|
1192
|
-
return dispatchAction({
|
|
1193
|
-
TAG: "SetRollbackState",
|
|
1194
|
-
diffInMemoryStore: diff$1.inMemStore,
|
|
1195
|
-
rollbackedChainManager: chainManager,
|
|
1196
|
-
eventsProcessedDiffByChain: eventsProcessedDiffByChain
|
|
1197
|
-
});
|
|
1198
|
-
case "RollbackReady" :
|
|
1199
|
-
return Js_exn.raiseError("Internal error: Rollback initiated with invalid state");
|
|
1200
|
-
|
|
1054
|
+
let match$1 = state.rollbackState;
|
|
1055
|
+
if (typeof match$1 !== "object") {
|
|
1056
|
+
if (match$1 === "NoRollback") {
|
|
1057
|
+
return Stdlib_JsError.throwWithMessage("Internal error: Rollback initiated with invalid state");
|
|
1058
|
+
} else {
|
|
1059
|
+
return;
|
|
1201
1060
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1061
|
+
}
|
|
1062
|
+
switch (match$1.TAG) {
|
|
1063
|
+
case "ReorgDetected" :
|
|
1064
|
+
let chain = match$1.chain;
|
|
1065
|
+
let chainFetcher = ChainMap.get(state.chainManager.chainFetchers, chain);
|
|
1066
|
+
dispatchAction("StartFindingReorgDepth");
|
|
1067
|
+
let rollbackTargetBlockNumber = await getLastKnownValidBlock(chainFetcher, match$1.blockNumber);
|
|
1068
|
+
return dispatchAction({
|
|
1069
|
+
TAG: "FindReorgDepth",
|
|
1070
|
+
chain: chain,
|
|
1071
|
+
rollbackTargetBlockNumber: rollbackTargetBlockNumber
|
|
1072
|
+
});
|
|
1073
|
+
case "FoundReorgDepth" :
|
|
1074
|
+
if (state.currentlyProcessingBatch) {
|
|
1075
|
+
return Logging.info("Waiting for batch to finish processing before executing rollback");
|
|
1076
|
+
}
|
|
1077
|
+
let match$2 = state.rollbackState;
|
|
1078
|
+
let rollbackTargetBlockNumber$1 = match$2.rollbackTargetBlockNumber;
|
|
1079
|
+
let reorgChain = match$2.chain;
|
|
1080
|
+
let startTime = Hrtime.makeTimer();
|
|
1081
|
+
let chainFetcher$1 = ChainMap.get(state.chainManager.chainFetchers, reorgChain);
|
|
1082
|
+
let logger = Logging.createChildFrom(chainFetcher$1.logger, {
|
|
1083
|
+
action: "Rollback",
|
|
1084
|
+
reorgChain: reorgChain,
|
|
1085
|
+
targetBlockNumber: rollbackTargetBlockNumber$1
|
|
1086
|
+
});
|
|
1087
|
+
Logging.childInfo(logger, "Started rollback on reorg");
|
|
1088
|
+
Prometheus.RollbackTargetBlockNumber.set(rollbackTargetBlockNumber$1, reorgChain);
|
|
1089
|
+
let checkpointId = await state.ctx.persistence.storage.getRollbackTargetCheckpoint(reorgChain, rollbackTargetBlockNumber$1);
|
|
1090
|
+
let rollbackTargetCheckpointId = checkpointId !== undefined ? checkpointId : 0n;
|
|
1091
|
+
let eventsProcessedDiffByChain = {};
|
|
1092
|
+
let newProgressBlockNumberPerChain = {};
|
|
1093
|
+
let rollbackedProcessedEvents = 0;
|
|
1094
|
+
let rollbackProgressDiff = await state.ctx.persistence.storage.getRollbackProgressDiff(rollbackTargetCheckpointId);
|
|
1095
|
+
for (let idx = 0, idx_finish = rollbackProgressDiff.length; idx < idx_finish; ++idx) {
|
|
1096
|
+
let diff = rollbackProgressDiff[idx];
|
|
1097
|
+
let eventsProcessedDiff = Stdlib_Option.getOrThrow(Stdlib_Float.fromString(diff.events_processed_diff), undefined);
|
|
1098
|
+
rollbackedProcessedEvents = rollbackedProcessedEvents + eventsProcessedDiff;
|
|
1099
|
+
eventsProcessedDiffByChain[diff.chain_id] = eventsProcessedDiff;
|
|
1100
|
+
newProgressBlockNumberPerChain[diff.chain_id] = rollbackTargetCheckpointId === 0n && diff.chain_id === reorgChain ? Primitive_int.min(diff.new_progress_block_number, rollbackTargetBlockNumber$1) : diff.new_progress_block_number;
|
|
1207
1101
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
if (
|
|
1211
|
-
|
|
1102
|
+
let chainFetchers = ChainMap.mapWithKey(state.chainManager.chainFetchers, (chain, cf) => {
|
|
1103
|
+
let newProgressBlockNumber = newProgressBlockNumberPerChain[chain];
|
|
1104
|
+
if (newProgressBlockNumber === undefined) {
|
|
1105
|
+
if (Primitive_object.equal(chain, reorgChain)) {
|
|
1106
|
+
return {
|
|
1107
|
+
logger: cf.logger,
|
|
1108
|
+
fetchState: FetchState.rollback(cf.fetchState, rollbackTargetBlockNumber$1),
|
|
1109
|
+
sourceManager: cf.sourceManager,
|
|
1110
|
+
chainConfig: cf.chainConfig,
|
|
1111
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
1112
|
+
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
1113
|
+
committedProgressBlockNumber: cf.committedProgressBlockNumber,
|
|
1114
|
+
numEventsProcessed: cf.numEventsProcessed,
|
|
1115
|
+
reorgDetection: ReorgDetection.rollbackToValidBlockNumber(cf.reorgDetection, rollbackTargetBlockNumber$1),
|
|
1116
|
+
safeCheckpointTracking: cf.safeCheckpointTracking
|
|
1117
|
+
};
|
|
1118
|
+
} else {
|
|
1119
|
+
return cf;
|
|
1120
|
+
}
|
|
1212
1121
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1122
|
+
let fetchState = FetchState.rollback(cf.fetchState, newProgressBlockNumber);
|
|
1123
|
+
let newTotalEventsProcessed = cf.numEventsProcessed - eventsProcessedDiffByChain[chain];
|
|
1124
|
+
if (cf.committedProgressBlockNumber !== newProgressBlockNumber) {
|
|
1125
|
+
Prometheus.ProgressBlockNumber.set(newProgressBlockNumber, chain);
|
|
1217
1126
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
ErrorHandling.mkLogAndRaise(Logging.createChild({
|
|
1221
|
-
entityName: entityConfig.name,
|
|
1222
|
-
safeCheckpointId: safeCheckpointId
|
|
1223
|
-
}), "Failed to prune stale entity history", exn);
|
|
1127
|
+
if (cf.numEventsProcessed !== newTotalEventsProcessed) {
|
|
1128
|
+
Prometheus.ProgressEventsCount.set(newTotalEventsProcessed, chain);
|
|
1224
1129
|
}
|
|
1225
|
-
|
|
1130
|
+
let safeCheckpointTracking = cf.safeCheckpointTracking;
|
|
1131
|
+
return {
|
|
1132
|
+
logger: cf.logger,
|
|
1133
|
+
fetchState: fetchState,
|
|
1134
|
+
sourceManager: cf.sourceManager,
|
|
1135
|
+
chainConfig: cf.chainConfig,
|
|
1136
|
+
isProgressAtHead: cf.isProgressAtHead,
|
|
1137
|
+
timestampCaughtUpToHeadOrEndblock: cf.timestampCaughtUpToHeadOrEndblock,
|
|
1138
|
+
committedProgressBlockNumber: newProgressBlockNumber,
|
|
1139
|
+
numEventsProcessed: newTotalEventsProcessed,
|
|
1140
|
+
reorgDetection: Primitive_object.equal(chain, reorgChain) ? ReorgDetection.rollbackToValidBlockNumber(cf.reorgDetection, rollbackTargetBlockNumber$1) : cf.reorgDetection,
|
|
1141
|
+
safeCheckpointTracking: safeCheckpointTracking !== undefined ? SafeCheckpointTracking.rollback(safeCheckpointTracking, newProgressBlockNumber) : undefined
|
|
1142
|
+
};
|
|
1143
|
+
});
|
|
1144
|
+
let diff$1 = await Persistence.prepareRollbackDiff(state.ctx.persistence, rollbackTargetCheckpointId, state.chainManager.committedCheckpointId + 1n);
|
|
1145
|
+
let init = state.chainManager;
|
|
1146
|
+
let chainManager_committedCheckpointId = init.committedCheckpointId;
|
|
1147
|
+
let chainManager_multichain = init.multichain;
|
|
1148
|
+
let chainManager_isInReorgThreshold = init.isInReorgThreshold;
|
|
1149
|
+
let chainManager = {
|
|
1150
|
+
committedCheckpointId: chainManager_committedCheckpointId,
|
|
1151
|
+
chainFetchers: chainFetchers,
|
|
1152
|
+
multichain: chainManager_multichain,
|
|
1153
|
+
isInReorgThreshold: chainManager_isInReorgThreshold
|
|
1154
|
+
};
|
|
1155
|
+
Logging.childTrace(logger, {
|
|
1156
|
+
msg: "Finished rollback on reorg",
|
|
1157
|
+
entityChanges: {
|
|
1158
|
+
deleted: diff$1.deletedEntities,
|
|
1159
|
+
upserted: diff$1.setEntities
|
|
1160
|
+
},
|
|
1161
|
+
rollbackedEvents: rollbackedProcessedEvents,
|
|
1162
|
+
beforeCheckpointId: state.chainManager.committedCheckpointId,
|
|
1163
|
+
targetCheckpointId: rollbackTargetCheckpointId
|
|
1164
|
+
});
|
|
1165
|
+
Prometheus.RollbackSuccess.increment(Hrtime.toSecondsFloat(Hrtime.timeSince(startTime)), rollbackedProcessedEvents);
|
|
1166
|
+
return dispatchAction({
|
|
1167
|
+
TAG: "SetRollbackState",
|
|
1168
|
+
diffInMemoryStore: diff$1.inMemStore,
|
|
1169
|
+
rollbackedChainManager: chainManager,
|
|
1170
|
+
eventsProcessedDiffByChain: eventsProcessedDiffByChain
|
|
1171
|
+
});
|
|
1172
|
+
case "RollbackReady" :
|
|
1173
|
+
return Stdlib_JsError.throwWithMessage("Internal error: Rollback initiated with invalid state");
|
|
1174
|
+
}
|
|
1175
|
+
case "PruneStaleEntityHistory" :
|
|
1176
|
+
let runPrune = async () => {
|
|
1177
|
+
let safeCheckpointId = ChainManager.getSafeCheckpointId(state.chainManager);
|
|
1178
|
+
if (safeCheckpointId === undefined) {
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
await state.ctx.persistence.storage.pruneStaleCheckpoints(safeCheckpointId);
|
|
1182
|
+
for (let idx = 0, idx_finish = state.ctx.persistence.allEntities.length; idx < idx_finish; ++idx) {
|
|
1183
|
+
if (idx !== 0) {
|
|
1184
|
+
await Utils.delay(1000);
|
|
1226
1185
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1186
|
+
let entityConfig = state.ctx.persistence.allEntities[idx];
|
|
1187
|
+
let timeRef = Hrtime.makeTimer();
|
|
1188
|
+
try {
|
|
1189
|
+
await state.ctx.persistence.storage.pruneStaleEntityHistory(entityConfig.name, entityConfig.index, safeCheckpointId);
|
|
1190
|
+
} catch (raw_exn) {
|
|
1191
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
1192
|
+
ErrorHandling.mkLogAndRaise(Logging.createChild({
|
|
1193
|
+
entityName: entityConfig.name,
|
|
1194
|
+
safeCheckpointId: safeCheckpointId
|
|
1195
|
+
}), `Failed to prune stale entity history`, exn);
|
|
1196
|
+
}
|
|
1197
|
+
Prometheus.RollbackHistoryPrune.increment(Hrtime.toSecondsFloat(Hrtime.timeSince(timeRef)), entityConfig.name);
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
return Throttler.schedule(state.writeThrottlers.pruneStaleEntityHistory, runPrune);
|
|
1230
1201
|
}
|
|
1231
1202
|
} else {
|
|
1232
1203
|
switch (task.TAG) {
|
|
1233
1204
|
case "NextQuery" :
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
})));
|
|
1242
|
-
return ;
|
|
1205
|
+
let chainCheck = task._0;
|
|
1206
|
+
let fetchForChain = checkAndFetchForChain(waitForNewBlock, executeQuery, state, dispatchAction);
|
|
1207
|
+
if (typeof chainCheck === "object") {
|
|
1208
|
+
return await fetchForChain(chainCheck._0);
|
|
1209
|
+
}
|
|
1210
|
+
await Promise.all(ChainMap.keys(state.chainManager.chainFetchers).map(__x => fetchForChain(__x)));
|
|
1211
|
+
return;
|
|
1243
1212
|
case "ProcessPartitionQueryResponse" :
|
|
1244
|
-
|
|
1245
|
-
|
|
1213
|
+
processPartitionQueryResponse(state, task._0, dispatchAction);
|
|
1214
|
+
return;
|
|
1246
1215
|
case "UpdateChainMetaDataAndCheckForExit" :
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
|
|
1258
|
-
return dispatchAction("SuccessExit");
|
|
1259
|
-
}
|
|
1216
|
+
let writeThrottlers = state.writeThrottlers;
|
|
1217
|
+
let chainManager$1 = state.chainManager;
|
|
1218
|
+
let shouldExit = task._0;
|
|
1219
|
+
if (typeof shouldExit === "object") {
|
|
1220
|
+
return dispatchAction({
|
|
1221
|
+
TAG: "ErrorExit",
|
|
1222
|
+
_0: ErrorHandling.make(Stdlib_JsError.throwWithMessage(shouldExit._0), undefined, undefined)
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
if (shouldExit === "ExitWithSuccess") {
|
|
1260
1226
|
updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
|
|
1261
|
-
return ;
|
|
1262
|
-
|
|
1227
|
+
return dispatchAction("SuccessExit");
|
|
1228
|
+
}
|
|
1229
|
+
updateChainMetadataTable(chainManager$1, state.ctx.persistence, writeThrottlers.chainMetaData);
|
|
1230
|
+
return;
|
|
1263
1231
|
}
|
|
1264
1232
|
}
|
|
1265
1233
|
};
|
|
1266
1234
|
}
|
|
1267
1235
|
|
|
1268
|
-
|
|
1269
|
-
return ChainFetcher.getLastKnownValidBlock(chainFetcher, reorgBlockNumber, undefined);
|
|
1270
|
-
}));
|
|
1236
|
+
let taskReducer = injectedTaskReducer(SourceManager.waitForNewBlock, SourceManager.executeQuery, (chainFetcher, reorgBlockNumber) => ChainFetcher.getLastKnownValidBlock(chainFetcher, reorgBlockNumber, undefined));
|
|
1271
1237
|
|
|
1272
1238
|
export {
|
|
1273
|
-
WriteThrottlers
|
|
1239
|
+
WriteThrottlers,
|
|
1274
1240
|
make$1 as make,
|
|
1275
|
-
getId
|
|
1276
|
-
setChainManager
|
|
1277
|
-
isPreparingRollback
|
|
1278
|
-
updateChainMetadataTable
|
|
1279
|
-
updateProgressedChains
|
|
1280
|
-
validatePartitionQueryResponse
|
|
1281
|
-
submitPartitionQueryResponse
|
|
1282
|
-
processPartitionQueryResponse
|
|
1283
|
-
updateChainFetcher
|
|
1284
|
-
onEnterReorgThreshold
|
|
1285
|
-
actionReducer
|
|
1286
|
-
invalidatedActionReducer
|
|
1287
|
-
checkAndFetchForChain
|
|
1288
|
-
injectedTaskReducer
|
|
1289
|
-
taskReducer
|
|
1241
|
+
getId,
|
|
1242
|
+
setChainManager,
|
|
1243
|
+
isPreparingRollback,
|
|
1244
|
+
updateChainMetadataTable,
|
|
1245
|
+
updateProgressedChains,
|
|
1246
|
+
validatePartitionQueryResponse,
|
|
1247
|
+
submitPartitionQueryResponse,
|
|
1248
|
+
processPartitionQueryResponse,
|
|
1249
|
+
updateChainFetcher,
|
|
1250
|
+
onEnterReorgThreshold,
|
|
1251
|
+
actionReducer,
|
|
1252
|
+
invalidatedActionReducer,
|
|
1253
|
+
checkAndFetchForChain,
|
|
1254
|
+
injectedTaskReducer,
|
|
1255
|
+
taskReducer,
|
|
1290
1256
|
}
|
|
1291
1257
|
/* taskReducer Not a pure module */
|