envio 3.0.0-alpha.21 → 3.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- 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 +430 -51
- package/src/Main.res.mjs +530 -271
- package/src/Persistence.res +80 -84
- package/src/Persistence.res.mjs +131 -132
- package/src/PgStorage.res +294 -167
- package/src/PgStorage.res.mjs +799 -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 +16 -16
- package/src/TestIndexerProxyStorage.res.mjs +99 -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 +7 -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/FetchState.res.mjs
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Caml from "rescript/lib/es6/caml.js";
|
|
4
3
|
import * as Utils from "./Utils.res.mjs";
|
|
5
|
-
import * as
|
|
6
|
-
import * as Js_dict from "rescript/lib/es6/js_dict.js";
|
|
7
|
-
import * as Js_math from "rescript/lib/es6/js_math.js";
|
|
4
|
+
import * as Js_math from "@rescript/runtime/lib/es6/Js_math.js";
|
|
8
5
|
import * as Logging from "./Logging.res.mjs";
|
|
9
|
-
import * as
|
|
10
|
-
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
11
|
-
import * as Caml_int32 from "rescript/lib/es6/caml_int32.js";
|
|
6
|
+
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
12
7
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
13
|
-
import * as
|
|
14
|
-
import * as
|
|
8
|
+
import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.js";
|
|
9
|
+
import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js";
|
|
10
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
11
|
+
import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
|
|
12
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
13
|
+
|
|
14
|
+
function deriveEffectiveStartBlock(registrationBlock, contractStartBlock) {
|
|
15
|
+
return Primitive_int.max(Primitive_int.max(registrationBlock, 0), Stdlib_Option.getOr(contractStartBlock, 0));
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
function getMinHistoryRange(p) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
let match = p.prevQueryRange;
|
|
20
|
+
let match$1 = p.prevPrevQueryRange;
|
|
19
21
|
if (match !== 0 && match$1 !== 0) {
|
|
20
22
|
return match < match$1 ? match : match$1;
|
|
21
23
|
}
|
|
22
|
-
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
function getMinQueryRange(partitions) {
|
|
26
|
-
|
|
27
|
-
for(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
let min = 0;
|
|
28
|
+
for (let i = 0, i_finish = partitions.length; i < i_finish; ++i) {
|
|
29
|
+
let p = partitions[i];
|
|
30
|
+
let a = p.prevQueryRange;
|
|
31
|
+
let b = p.prevPrevQueryRange;
|
|
31
32
|
if (a > 0 && (min === 0 || a < min)) {
|
|
32
33
|
min = a;
|
|
33
34
|
}
|
|
34
35
|
if (b > 0 && (min === 0 || b < min)) {
|
|
35
36
|
min = b;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
38
|
}
|
|
39
39
|
return min;
|
|
40
40
|
}
|
|
@@ -44,52 +44,52 @@ function count(optimizedPartitions) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function getOrThrow(optimizedPartitions, partitionId) {
|
|
47
|
-
|
|
47
|
+
let p = optimizedPartitions.entities[partitionId];
|
|
48
48
|
if (p !== undefined) {
|
|
49
49
|
return p;
|
|
50
50
|
} else {
|
|
51
|
-
return
|
|
51
|
+
return Stdlib_JsError.throwWithMessage(`Unexpected case: Couldn't find partition ` + partitionId);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAddrInPartition, nextPartitionIndexRef) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
let combinedAddresses = p1.addressesByContractName[contractName].concat(p2.addressesByContractName[contractName]);
|
|
57
|
+
let p1Below = p1.latestFetchedBlock.blockNumber < potentialMergeBlock;
|
|
58
|
+
let p2Below = p2.latestFetchedBlock.blockNumber < potentialMergeBlock;
|
|
59
|
+
let completed = [];
|
|
60
|
+
let continuingBase;
|
|
61
61
|
if (p1Below) {
|
|
62
|
-
completed.push({
|
|
63
|
-
id: p1.id,
|
|
64
|
-
latestFetchedBlock: p1.latestFetchedBlock,
|
|
65
|
-
selection: p1.selection,
|
|
66
|
-
addressesByContractName: p1.addressesByContractName,
|
|
67
|
-
mergeBlock: potentialMergeBlock,
|
|
68
|
-
dynamicContract: p1.dynamicContract,
|
|
69
|
-
mutPendingQueries: p1.mutPendingQueries,
|
|
70
|
-
prevQueryRange: p1.prevQueryRange,
|
|
71
|
-
prevPrevQueryRange: p1.prevPrevQueryRange,
|
|
72
|
-
latestBlockRangeUpdateBlock: p1.latestBlockRangeUpdateBlock
|
|
73
|
-
});
|
|
74
62
|
if (p2Below) {
|
|
75
63
|
completed.push({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
id: p1.id,
|
|
65
|
+
latestFetchedBlock: p1.latestFetchedBlock,
|
|
66
|
+
selection: p1.selection,
|
|
67
|
+
addressesByContractName: p1.addressesByContractName,
|
|
68
|
+
mergeBlock: potentialMergeBlock,
|
|
69
|
+
dynamicContract: p1.dynamicContract,
|
|
70
|
+
mutPendingQueries: p1.mutPendingQueries,
|
|
71
|
+
prevQueryRange: p1.prevQueryRange,
|
|
72
|
+
prevPrevQueryRange: p1.prevPrevQueryRange,
|
|
73
|
+
latestBlockRangeUpdateBlock: p1.latestBlockRangeUpdateBlock
|
|
74
|
+
});
|
|
75
|
+
completed.push({
|
|
76
|
+
id: p2.id,
|
|
77
|
+
latestFetchedBlock: p2.latestFetchedBlock,
|
|
78
|
+
selection: p2.selection,
|
|
79
|
+
addressesByContractName: p2.addressesByContractName,
|
|
80
|
+
mergeBlock: potentialMergeBlock,
|
|
81
|
+
dynamicContract: p2.dynamicContract,
|
|
82
|
+
mutPendingQueries: p2.mutPendingQueries,
|
|
83
|
+
prevQueryRange: p2.prevQueryRange,
|
|
84
|
+
prevPrevQueryRange: p2.prevPrevQueryRange,
|
|
85
|
+
latestBlockRangeUpdateBlock: p2.latestBlockRangeUpdateBlock
|
|
86
|
+
});
|
|
87
|
+
let newId = nextPartitionIndexRef.contents.toString();
|
|
88
88
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
let minRange = getMinQueryRange([
|
|
90
|
+
p1,
|
|
91
|
+
p2
|
|
92
|
+
]);
|
|
93
93
|
continuingBase = {
|
|
94
94
|
id: newId,
|
|
95
95
|
latestFetchedBlock: {
|
|
@@ -106,106 +106,119 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
106
106
|
latestBlockRangeUpdateBlock: 0
|
|
107
107
|
};
|
|
108
108
|
} else {
|
|
109
|
+
completed.push({
|
|
110
|
+
id: p1.id,
|
|
111
|
+
latestFetchedBlock: p1.latestFetchedBlock,
|
|
112
|
+
selection: p1.selection,
|
|
113
|
+
addressesByContractName: p1.addressesByContractName,
|
|
114
|
+
mergeBlock: potentialMergeBlock,
|
|
115
|
+
dynamicContract: p1.dynamicContract,
|
|
116
|
+
mutPendingQueries: p1.mutPendingQueries,
|
|
117
|
+
prevQueryRange: p1.prevQueryRange,
|
|
118
|
+
prevPrevQueryRange: p1.prevPrevQueryRange,
|
|
119
|
+
latestBlockRangeUpdateBlock: p1.latestBlockRangeUpdateBlock
|
|
120
|
+
});
|
|
109
121
|
continuingBase = p2;
|
|
110
122
|
}
|
|
111
123
|
} else if (p2Below) {
|
|
112
124
|
completed.push({
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
id: p2.id,
|
|
126
|
+
latestFetchedBlock: p2.latestFetchedBlock,
|
|
127
|
+
selection: p2.selection,
|
|
128
|
+
addressesByContractName: p2.addressesByContractName,
|
|
129
|
+
mergeBlock: potentialMergeBlock,
|
|
130
|
+
dynamicContract: p2.dynamicContract,
|
|
131
|
+
mutPendingQueries: p2.mutPendingQueries,
|
|
132
|
+
prevQueryRange: p2.prevQueryRange,
|
|
133
|
+
prevPrevQueryRange: p2.prevPrevQueryRange,
|
|
134
|
+
latestBlockRangeUpdateBlock: p2.latestBlockRangeUpdateBlock
|
|
135
|
+
});
|
|
124
136
|
continuingBase = p1;
|
|
125
137
|
} else {
|
|
126
138
|
continuingBase = p1;
|
|
127
139
|
}
|
|
128
140
|
if (combinedAddresses.length > maxAddrInPartition) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
let addressesFull = combinedAddresses.slice(0, maxAddrInPartition);
|
|
142
|
+
let addressesRest = combinedAddresses.slice(maxAddrInPartition);
|
|
143
|
+
let abcFull = {};
|
|
132
144
|
abcFull[contractName] = addressesFull;
|
|
133
|
-
|
|
145
|
+
let abcRest = {};
|
|
134
146
|
abcRest[contractName] = addressesRest;
|
|
135
147
|
completed.push({
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
id: continuingBase.id,
|
|
149
|
+
latestFetchedBlock: continuingBase.latestFetchedBlock,
|
|
150
|
+
selection: continuingBase.selection,
|
|
151
|
+
addressesByContractName: abcFull,
|
|
152
|
+
mergeBlock: continuingBase.mergeBlock,
|
|
153
|
+
dynamicContract: continuingBase.dynamicContract,
|
|
154
|
+
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
155
|
+
prevQueryRange: continuingBase.prevQueryRange,
|
|
156
|
+
prevPrevQueryRange: continuingBase.prevPrevQueryRange,
|
|
157
|
+
latestBlockRangeUpdateBlock: continuingBase.latestBlockRangeUpdateBlock
|
|
158
|
+
});
|
|
159
|
+
let restId = nextPartitionIndexRef.contents.toString();
|
|
148
160
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
149
161
|
completed.push({
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
id: restId,
|
|
163
|
+
latestFetchedBlock: continuingBase.latestFetchedBlock,
|
|
164
|
+
selection: continuingBase.selection,
|
|
165
|
+
addressesByContractName: abcRest,
|
|
166
|
+
mergeBlock: continuingBase.mergeBlock,
|
|
167
|
+
dynamicContract: continuingBase.dynamicContract,
|
|
168
|
+
mutPendingQueries: [],
|
|
169
|
+
prevQueryRange: continuingBase.prevQueryRange,
|
|
170
|
+
prevPrevQueryRange: continuingBase.prevPrevQueryRange,
|
|
171
|
+
latestBlockRangeUpdateBlock: continuingBase.latestBlockRangeUpdateBlock
|
|
172
|
+
});
|
|
161
173
|
return completed;
|
|
162
174
|
}
|
|
163
|
-
|
|
175
|
+
let abc = {};
|
|
164
176
|
abc[contractName] = combinedAddresses;
|
|
165
177
|
completed.push({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
id: continuingBase.id,
|
|
179
|
+
latestFetchedBlock: continuingBase.latestFetchedBlock,
|
|
180
|
+
selection: continuingBase.selection,
|
|
181
|
+
addressesByContractName: abc,
|
|
182
|
+
mergeBlock: continuingBase.mergeBlock,
|
|
183
|
+
dynamicContract: continuingBase.dynamicContract,
|
|
184
|
+
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
185
|
+
prevQueryRange: continuingBase.prevQueryRange,
|
|
186
|
+
prevPrevQueryRange: continuingBase.prevPrevQueryRange,
|
|
187
|
+
latestBlockRangeUpdateBlock: continuingBase.latestBlockRangeUpdateBlock
|
|
188
|
+
});
|
|
177
189
|
return completed;
|
|
178
190
|
}
|
|
179
191
|
|
|
180
192
|
function ascSortFn(a, b) {
|
|
181
|
-
return a.latestFetchedBlock.blockNumber
|
|
193
|
+
return Primitive_int.compare(a.latestFetchedBlock.blockNumber, b.latestFetchedBlock.blockNumber);
|
|
182
194
|
}
|
|
183
195
|
|
|
184
196
|
function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContracts) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
197
|
+
let newPartitions = [];
|
|
198
|
+
let mergingPartitions = {};
|
|
199
|
+
let nextPartitionIndexRef = {
|
|
188
200
|
contents: nextPartitionIndex
|
|
189
201
|
};
|
|
190
|
-
for(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
for (let idx = 0, idx_finish = partitions.length; idx < idx_finish; ++idx) {
|
|
203
|
+
let p = partitions[idx];
|
|
204
|
+
let exit = 0;
|
|
205
|
+
if (p.dynamicContract !== undefined && p.mergeBlock === undefined && p.selection.dependsOnAddresses) {
|
|
206
|
+
let contractName = p.dynamicContract;
|
|
207
|
+
let pAddressesCount = p.addressesByContractName[contractName].length;
|
|
208
|
+
let match = Utils.$$Array.last(p.mutPendingQueries);
|
|
209
|
+
let potentialMergeBlock;
|
|
197
210
|
if (match !== undefined) {
|
|
198
|
-
|
|
211
|
+
let toBlock = match.toBlock;
|
|
199
212
|
potentialMergeBlock = toBlock !== undefined && match.isChunk ? toBlock : undefined;
|
|
200
213
|
} else {
|
|
201
214
|
potentialMergeBlock = p.latestFetchedBlock.blockNumber;
|
|
202
215
|
}
|
|
203
216
|
if (potentialMergeBlock !== undefined && pAddressesCount < maxAddrInPartition) {
|
|
204
|
-
|
|
205
|
-
|
|
217
|
+
let partitionsByMergeBlock = Utils.Dict.getOrInsertEmptyDict(mergingPartitions, contractName);
|
|
218
|
+
let existingPartition = partitionsByMergeBlock[potentialMergeBlock];
|
|
206
219
|
if (existingPartition !== undefined) {
|
|
207
|
-
|
|
208
|
-
for(
|
|
220
|
+
let result = mergePartitionsAtBlock(existingPartition, p, potentialMergeBlock, contractName, maxAddrInPartition, nextPartitionIndexRef);
|
|
221
|
+
for (let i = 0, i_finish = result.length - 2 | 0; i <= i_finish; ++i) {
|
|
209
222
|
newPartitions.push(result[i]);
|
|
210
223
|
}
|
|
211
224
|
partitionsByMergeBlock[potentialMergeBlock] = Utils.$$Array.lastUnsafe(result);
|
|
@@ -216,34 +229,37 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
216
229
|
newPartitions.push(p);
|
|
217
230
|
}
|
|
218
231
|
} else {
|
|
232
|
+
exit = 1;
|
|
233
|
+
}
|
|
234
|
+
if (exit === 1) {
|
|
219
235
|
newPartitions.push(p);
|
|
220
236
|
}
|
|
221
237
|
}
|
|
222
|
-
|
|
223
|
-
for(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
238
|
+
let merginDynamicContracts = Object.keys(mergingPartitions);
|
|
239
|
+
for (let idx$1 = 0, idx_finish$1 = merginDynamicContracts.length; idx$1 < idx_finish$1; ++idx$1) {
|
|
240
|
+
let contractName$1 = merginDynamicContracts[idx$1];
|
|
241
|
+
let partitionsByMergeBlock$1 = mergingPartitions[contractName$1];
|
|
242
|
+
let ascPartitionKeys = Object.keys(partitionsByMergeBlock$1);
|
|
227
243
|
if (ascPartitionKeys[ascPartitionKeys.length - 1 | 0] === "-1") {
|
|
228
|
-
ascPartitionKeys.unshift(
|
|
244
|
+
ascPartitionKeys.unshift(ascPartitionKeys.pop());
|
|
229
245
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
while(nextJdx < ascPartitionKeys.length) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
246
|
+
let currentPRef = partitionsByMergeBlock$1[Utils.$$Array.firstUnsafe(ascPartitionKeys)];
|
|
247
|
+
let currentPMergeBlockRef = Stdlib_Int.fromString(Utils.$$Array.firstUnsafe(ascPartitionKeys), undefined);
|
|
248
|
+
let nextJdx = 1;
|
|
249
|
+
while (nextJdx < ascPartitionKeys.length) {
|
|
250
|
+
let nextKey = ascPartitionKeys[nextJdx];
|
|
251
|
+
let currentP = currentPRef;
|
|
252
|
+
let nextP = partitionsByMergeBlock$1[nextKey];
|
|
253
|
+
let nextPMergeBlock = Stdlib_Int.fromString(nextKey, undefined);
|
|
254
|
+
let currentPMergeBlock = currentPMergeBlockRef;
|
|
255
|
+
let isTooFar = (currentPMergeBlock + 20000 | 0) < nextPMergeBlock;
|
|
240
256
|
if (isTooFar) {
|
|
241
257
|
newPartitions.push(currentP);
|
|
242
258
|
currentPRef = nextP;
|
|
243
259
|
currentPMergeBlockRef = nextPMergeBlock;
|
|
244
260
|
} else {
|
|
245
|
-
|
|
246
|
-
for(
|
|
261
|
+
let result$1 = mergePartitionsAtBlock(nextP, currentP, nextPMergeBlock, contractName$1, maxAddrInPartition, nextPartitionIndexRef);
|
|
262
|
+
for (let i$1 = 0, i_finish$1 = result$1.length - 2 | 0; i$1 <= i_finish$1; ++i$1) {
|
|
247
263
|
newPartitions.push(result$1[i$1]);
|
|
248
264
|
}
|
|
249
265
|
currentPRef = Utils.$$Array.lastUnsafe(result$1);
|
|
@@ -254,74 +270,72 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
254
270
|
newPartitions.push(currentPRef);
|
|
255
271
|
}
|
|
256
272
|
newPartitions.sort(ascSortFn);
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
for(
|
|
261
|
-
|
|
273
|
+
let partitionsCount = newPartitions.length;
|
|
274
|
+
let idsInAscOrder = new Array(partitionsCount);
|
|
275
|
+
let entities = {};
|
|
276
|
+
for (let idx$2 = 0; idx$2 < partitionsCount; ++idx$2) {
|
|
277
|
+
let p$1 = newPartitions[idx$2];
|
|
262
278
|
idsInAscOrder[idx$2] = p$1.id;
|
|
263
279
|
entities[p$1.id] = p$1;
|
|
264
280
|
}
|
|
265
281
|
return {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
282
|
+
idsInAscOrder: idsInAscOrder,
|
|
283
|
+
entities: entities,
|
|
284
|
+
maxAddrInPartition: maxAddrInPartition,
|
|
285
|
+
nextPartitionIndex: nextPartitionIndexRef.contents,
|
|
286
|
+
dynamicContracts: dynamicContracts
|
|
287
|
+
};
|
|
272
288
|
}
|
|
273
289
|
|
|
274
290
|
function consumeFetchedQueries(mutPendingQueries, initialLatestFetchedBlock) {
|
|
275
|
-
|
|
276
|
-
while((
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
latestFetchedBlock =
|
|
286
|
-
removedQuery === undefined ? undefined : Caml_option.some(removedQuery)
|
|
287
|
-
).fetchedBlock;
|
|
291
|
+
let latestFetchedBlock = initialLatestFetchedBlock;
|
|
292
|
+
while ((() => {
|
|
293
|
+
let tmp = false;
|
|
294
|
+
if (mutPendingQueries.length !== 0) {
|
|
295
|
+
let pq = Utils.$$Array.firstUnsafe(mutPendingQueries);
|
|
296
|
+
tmp = pq.fetchedBlock !== undefined && pq.fromBlock <= (latestFetchedBlock.blockNumber + 1 | 0);
|
|
297
|
+
}
|
|
298
|
+
return tmp;
|
|
299
|
+
})()) {
|
|
300
|
+
let removedQuery = mutPendingQueries.shift();
|
|
301
|
+
latestFetchedBlock = removedQuery.fetchedBlock;
|
|
288
302
|
};
|
|
289
303
|
return latestFetchedBlock;
|
|
290
304
|
}
|
|
291
305
|
|
|
292
306
|
function getPendingQueryOrThrow(p, fromBlock) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
while(idxRef < p.mutPendingQueries.length && pendingQueryRef === undefined) {
|
|
296
|
-
|
|
307
|
+
let idxRef = 0;
|
|
308
|
+
let pendingQueryRef;
|
|
309
|
+
while (idxRef < p.mutPendingQueries.length && pendingQueryRef === undefined) {
|
|
310
|
+
let pq = p.mutPendingQueries[idxRef];
|
|
297
311
|
if (pq.fromBlock === fromBlock) {
|
|
298
312
|
pendingQueryRef = pq;
|
|
299
313
|
}
|
|
300
314
|
idxRef = idxRef + 1 | 0;
|
|
301
315
|
};
|
|
302
|
-
|
|
316
|
+
let pq$1 = pendingQueryRef;
|
|
303
317
|
if (pq$1 !== undefined) {
|
|
304
318
|
return pq$1;
|
|
305
319
|
} else {
|
|
306
|
-
return
|
|
320
|
+
return Stdlib_JsError.throwWithMessage(`Pending query not found for partition ` + p.id + ` fromBlock ` + fromBlock.toString());
|
|
307
321
|
}
|
|
308
322
|
}
|
|
309
323
|
|
|
310
324
|
function handleQueryResponse(optimizedPartitions, query, knownHeight, latestFetchedBlock) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
325
|
+
let partitionId = query.partitionId;
|
|
326
|
+
let p = optimizedPartitions.entities[partitionId];
|
|
327
|
+
let p$1 = p !== undefined ? p : Stdlib_JsError.throwWithMessage(`Unexpected case: Couldn't find partition ` + partitionId);
|
|
328
|
+
let mutEntities = Utils.Dict.shallowCopy(optimizedPartitions.entities);
|
|
329
|
+
let pendingQuery = getPendingQueryOrThrow(p$1, query.fromBlock);
|
|
316
330
|
pendingQuery.fetchedBlock = latestFetchedBlock;
|
|
317
|
-
|
|
318
|
-
|
|
331
|
+
let blockRange = (latestFetchedBlock.blockNumber - query.fromBlock | 0) + 1 | 0;
|
|
332
|
+
let shouldUpdateBlockRange = false;
|
|
319
333
|
if (latestFetchedBlock.blockNumber > p$1.latestBlockRangeUpdateBlock) {
|
|
320
|
-
|
|
321
|
-
|
|
334
|
+
let queryToBlock = query.toBlock;
|
|
335
|
+
let tmp;
|
|
322
336
|
if (queryToBlock !== undefined) {
|
|
323
337
|
if (latestFetchedBlock.blockNumber >= queryToBlock) {
|
|
324
|
-
|
|
338
|
+
let minHistoryRange = getMinHistoryRange(p$1);
|
|
325
339
|
tmp = minHistoryRange !== undefined ? ((queryToBlock - query.fromBlock | 0) + 1 | 0) >= minHistoryRange : false;
|
|
326
340
|
} else {
|
|
327
341
|
tmp = true;
|
|
@@ -331,37 +345,35 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, latestFetc
|
|
|
331
345
|
}
|
|
332
346
|
shouldUpdateBlockRange = tmp;
|
|
333
347
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
while((
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
latestFetchedBlock$1 =
|
|
348
|
-
removedQuery === undefined ? undefined : Caml_option.some(removedQuery)
|
|
349
|
-
).fetchedBlock;
|
|
348
|
+
let updatedPrevQueryRange = shouldUpdateBlockRange ? blockRange : p$1.prevQueryRange;
|
|
349
|
+
let updatedPrevPrevQueryRange = shouldUpdateBlockRange ? p$1.prevQueryRange : p$1.prevPrevQueryRange;
|
|
350
|
+
let mutPendingQueries = p$1.mutPendingQueries;
|
|
351
|
+
let latestFetchedBlock$1 = p$1.latestFetchedBlock;
|
|
352
|
+
while ((() => {
|
|
353
|
+
let tmp = false;
|
|
354
|
+
if (mutPendingQueries.length !== 0) {
|
|
355
|
+
let pq = Utils.$$Array.firstUnsafe(mutPendingQueries);
|
|
356
|
+
tmp = pq.fetchedBlock !== undefined && pq.fromBlock <= (latestFetchedBlock$1.blockNumber + 1 | 0);
|
|
357
|
+
}
|
|
358
|
+
return tmp;
|
|
359
|
+
})()) {
|
|
360
|
+
let removedQuery = mutPendingQueries.shift();
|
|
361
|
+
latestFetchedBlock$1 = removedQuery.fetchedBlock;
|
|
350
362
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
363
|
+
let updatedLatestFetchedBlock = latestFetchedBlock$1;
|
|
364
|
+
let mergeBlock = p$1.mergeBlock;
|
|
365
|
+
let partitionReachedMergeBlock = mergeBlock !== undefined ? updatedLatestFetchedBlock.blockNumber >= mergeBlock : false;
|
|
354
366
|
if (partitionReachedMergeBlock) {
|
|
355
367
|
Utils.Dict.deleteInPlace(mutEntities, p$1.id);
|
|
356
368
|
} else {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
369
|
+
let updatedMainPartition_id = p$1.id;
|
|
370
|
+
let updatedMainPartition_selection = p$1.selection;
|
|
371
|
+
let updatedMainPartition_addressesByContractName = p$1.addressesByContractName;
|
|
372
|
+
let updatedMainPartition_mergeBlock = p$1.mergeBlock;
|
|
373
|
+
let updatedMainPartition_dynamicContract = p$1.dynamicContract;
|
|
374
|
+
let updatedMainPartition_mutPendingQueries = p$1.mutPendingQueries;
|
|
375
|
+
let updatedMainPartition_latestBlockRangeUpdateBlock = shouldUpdateBlockRange ? latestFetchedBlock.blockNumber : p$1.latestBlockRangeUpdateBlock;
|
|
376
|
+
let updatedMainPartition = {
|
|
365
377
|
id: updatedMainPartition_id,
|
|
366
378
|
latestFetchedBlock: updatedLatestFetchedBlock,
|
|
367
379
|
selection: updatedMainPartition_selection,
|
|
@@ -375,18 +387,17 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, latestFetc
|
|
|
375
387
|
};
|
|
376
388
|
mutEntities[p$1.id] = updatedMainPartition;
|
|
377
389
|
}
|
|
378
|
-
return make(
|
|
390
|
+
return make(Object.values(mutEntities), optimizedPartitions.maxAddrInPartition, optimizedPartitions.nextPartitionIndex, optimizedPartitions.dynamicContracts);
|
|
379
391
|
}
|
|
380
392
|
|
|
381
393
|
function getLatestFullyFetchedBlock(optimizedPartitions) {
|
|
382
|
-
|
|
394
|
+
let id = optimizedPartitions.idsInAscOrder[0];
|
|
383
395
|
if (id !== undefined) {
|
|
384
396
|
return optimizedPartitions.entities[id].latestFetchedBlock;
|
|
385
397
|
}
|
|
386
|
-
|
|
387
398
|
}
|
|
388
399
|
|
|
389
|
-
|
|
400
|
+
let OptimizedPartitions = {
|
|
390
401
|
count: count,
|
|
391
402
|
getOrThrow: getOrThrow,
|
|
392
403
|
mergePartitionsAtBlock: mergePartitionsAtBlock,
|
|
@@ -400,10 +411,10 @@ var OptimizedPartitions = {
|
|
|
400
411
|
};
|
|
401
412
|
|
|
402
413
|
function bufferBlockNumber(param) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
414
|
+
let latestOnBlockBlockNumber = param.latestOnBlockBlockNumber;
|
|
415
|
+
let optimizedPartitions = param.optimizedPartitions;
|
|
416
|
+
let id = optimizedPartitions.idsInAscOrder[0];
|
|
417
|
+
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
407
418
|
if (latestFullyFetchedBlock !== undefined && latestOnBlockBlockNumber >= latestFullyFetchedBlock.blockNumber) {
|
|
408
419
|
return latestFullyFetchedBlock.blockNumber;
|
|
409
420
|
} else {
|
|
@@ -412,101 +423,100 @@ function bufferBlockNumber(param) {
|
|
|
412
423
|
}
|
|
413
424
|
|
|
414
425
|
function bufferBlock(param) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
426
|
+
let latestOnBlockBlockNumber = param.latestOnBlockBlockNumber;
|
|
427
|
+
let optimizedPartitions = param.optimizedPartitions;
|
|
428
|
+
let id = optimizedPartitions.idsInAscOrder[0];
|
|
429
|
+
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
419
430
|
if (latestFullyFetchedBlock !== undefined && latestOnBlockBlockNumber >= latestFullyFetchedBlock.blockNumber) {
|
|
420
431
|
return latestFullyFetchedBlock;
|
|
421
432
|
} else {
|
|
422
433
|
return {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
434
|
+
blockNumber: latestOnBlockBlockNumber,
|
|
435
|
+
blockTimestamp: 0
|
|
436
|
+
};
|
|
426
437
|
}
|
|
427
438
|
}
|
|
428
439
|
|
|
429
440
|
function compareBufferItem(a, b) {
|
|
430
|
-
|
|
431
|
-
if (
|
|
432
|
-
return a.logIndex
|
|
441
|
+
let blockOrdering = Primitive_int.compare(a.blockNumber, b.blockNumber);
|
|
442
|
+
if (blockOrdering === 0) {
|
|
443
|
+
return Primitive_int.compare(a.logIndex, b.logIndex);
|
|
433
444
|
} else {
|
|
434
|
-
return
|
|
445
|
+
return blockOrdering;
|
|
435
446
|
}
|
|
436
447
|
}
|
|
437
448
|
|
|
438
449
|
function numAddresses(fetchState) {
|
|
439
|
-
return
|
|
450
|
+
return Utils.Dict.size(fetchState.indexingAddresses);
|
|
440
451
|
}
|
|
441
452
|
|
|
442
|
-
function updateInternal(fetchState, optimizedPartitionsOpt,
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
453
|
+
function updateInternal(fetchState, optimizedPartitionsOpt, indexingAddressesOpt, mutItems, blockLagOpt, knownHeightOpt) {
|
|
454
|
+
let optimizedPartitions = optimizedPartitionsOpt !== undefined ? optimizedPartitionsOpt : fetchState.optimizedPartitions;
|
|
455
|
+
let indexingAddresses = indexingAddressesOpt !== undefined ? indexingAddressesOpt : fetchState.indexingAddresses;
|
|
456
|
+
let blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
|
|
457
|
+
let knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : fetchState.knownHeight;
|
|
458
|
+
let mutItemsRef = mutItems;
|
|
459
|
+
let onBlockConfigs = fetchState.onBlockConfigs;
|
|
460
|
+
let latestOnBlockBlockNumber;
|
|
450
461
|
if (onBlockConfigs.length !== 0) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
462
|
+
let mutItems$1 = mutItemsRef;
|
|
463
|
+
let item = Belt_Array.get(mutItems$1 !== undefined ? mutItems$1 : fetchState.buffer, fetchState.targetBufferSize - 1 | 0);
|
|
464
|
+
let maxBlockNumber;
|
|
454
465
|
if (item !== undefined) {
|
|
455
466
|
maxBlockNumber = item.blockNumber;
|
|
456
467
|
} else {
|
|
457
|
-
|
|
458
|
-
|
|
468
|
+
let id = optimizedPartitions.idsInAscOrder[0];
|
|
469
|
+
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
459
470
|
maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock.blockNumber : knownHeight;
|
|
460
471
|
}
|
|
461
|
-
|
|
462
|
-
|
|
472
|
+
let mutItems$2 = mutItemsRef;
|
|
473
|
+
let mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.buffer.slice();
|
|
463
474
|
mutItemsRef = mutItems$3;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
while(latestOnBlockBlockNumber$1 < maxBlockNumber && newItemsCounter <= fetchState.targetBufferSize) {
|
|
467
|
-
|
|
475
|
+
let newItemsCounter = 0;
|
|
476
|
+
let latestOnBlockBlockNumber$1 = fetchState.latestOnBlockBlockNumber;
|
|
477
|
+
while (latestOnBlockBlockNumber$1 < maxBlockNumber && newItemsCounter <= fetchState.targetBufferSize) {
|
|
478
|
+
let blockNumber = latestOnBlockBlockNumber$1 + 1 | 0;
|
|
468
479
|
latestOnBlockBlockNumber$1 = blockNumber;
|
|
469
|
-
for(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
480
|
+
for (let configIdx = 0, configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx) {
|
|
481
|
+
let onBlockConfig = onBlockConfigs[configIdx];
|
|
482
|
+
let startBlock = onBlockConfig.startBlock;
|
|
483
|
+
let handlerStartBlock = startBlock !== undefined ? startBlock : fetchState.startBlock;
|
|
484
|
+
let tmp = false;
|
|
474
485
|
if (blockNumber >= handlerStartBlock) {
|
|
475
|
-
|
|
486
|
+
let endBlock = onBlockConfig.endBlock;
|
|
476
487
|
tmp = endBlock !== undefined ? blockNumber <= endBlock : true;
|
|
477
488
|
}
|
|
478
|
-
if (tmp &&
|
|
489
|
+
if (tmp && Primitive_int.mod_(blockNumber - handlerStartBlock | 0, onBlockConfig.interval) === 0) {
|
|
479
490
|
mutItems$3.push({
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
491
|
+
kind: 1,
|
|
492
|
+
onBlockConfig: onBlockConfig,
|
|
493
|
+
blockNumber: blockNumber,
|
|
494
|
+
logIndex: 16777216 + onBlockConfig.index | 0
|
|
495
|
+
});
|
|
485
496
|
newItemsCounter = newItemsCounter + 1 | 0;
|
|
486
497
|
}
|
|
487
|
-
|
|
488
498
|
}
|
|
489
499
|
};
|
|
490
500
|
latestOnBlockBlockNumber = latestOnBlockBlockNumber$1;
|
|
491
501
|
} else {
|
|
492
502
|
latestOnBlockBlockNumber = knownHeight;
|
|
493
503
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
504
|
+
let mutItems$4 = mutItemsRef;
|
|
505
|
+
let updatedFetchState_startBlock = fetchState.startBlock;
|
|
506
|
+
let updatedFetchState_endBlock = fetchState.endBlock;
|
|
507
|
+
let updatedFetchState_normalSelection = fetchState.normalSelection;
|
|
508
|
+
let updatedFetchState_contractConfigs = fetchState.contractConfigs;
|
|
509
|
+
let updatedFetchState_chainId = fetchState.chainId;
|
|
510
|
+
let updatedFetchState_buffer = mutItems$4 !== undefined ? (mutItems$4.sort(compareBufferItem), mutItems$4) : fetchState.buffer;
|
|
511
|
+
let updatedFetchState_targetBufferSize = fetchState.targetBufferSize;
|
|
512
|
+
let updatedFetchState_onBlockConfigs = fetchState.onBlockConfigs;
|
|
513
|
+
let updatedFetchState_firstEventBlock = fetchState.firstEventBlock;
|
|
514
|
+
let updatedFetchState = {
|
|
505
515
|
optimizedPartitions: optimizedPartitions,
|
|
506
516
|
startBlock: updatedFetchState_startBlock,
|
|
507
517
|
endBlock: updatedFetchState_endBlock,
|
|
508
518
|
normalSelection: updatedFetchState_normalSelection,
|
|
509
|
-
|
|
519
|
+
indexingAddresses: indexingAddresses,
|
|
510
520
|
contractConfigs: updatedFetchState_contractConfigs,
|
|
511
521
|
chainId: updatedFetchState_chainId,
|
|
512
522
|
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
@@ -520,156 +530,154 @@ function updateInternal(fetchState, optimizedPartitionsOpt, indexingContractsOpt
|
|
|
520
530
|
Prometheus.IndexingPartitions.set(optimizedPartitions.idsInAscOrder.length, fetchState.chainId);
|
|
521
531
|
Prometheus.IndexingBufferSize.set(updatedFetchState_buffer.length, fetchState.chainId);
|
|
522
532
|
Prometheus.IndexingBufferBlockNumber.set(bufferBlockNumber(updatedFetchState), fetchState.chainId);
|
|
523
|
-
if (
|
|
524
|
-
Prometheus.IndexingAddresses.set(
|
|
533
|
+
if (indexingAddresses !== fetchState.indexingAddresses) {
|
|
534
|
+
Prometheus.IndexingAddresses.set(Utils.Dict.size(indexingAddresses), fetchState.chainId);
|
|
525
535
|
}
|
|
526
536
|
return updatedFetchState;
|
|
527
537
|
}
|
|
528
538
|
|
|
529
539
|
function warnDifferentContractType(fetchState, existingContract, dc) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
Logging.childWarn(logger,
|
|
540
|
+
let logger = Logging.createChild({
|
|
541
|
+
chainId: fetchState.chainId,
|
|
542
|
+
contractAddress: dc.address,
|
|
543
|
+
existingContractType: existingContract.contractName,
|
|
544
|
+
newContractType: dc.contractName
|
|
545
|
+
});
|
|
546
|
+
Logging.childWarn(logger, `Skipping contract registration: Contract address is already registered for one contract and cannot be registered for another contract.`);
|
|
537
547
|
}
|
|
538
548
|
|
|
539
549
|
function addressesByContractNameCount(addressesByContractName) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
numAddresses = numAddresses +
|
|
545
|
-
}
|
|
546
|
-
return numAddresses;
|
|
550
|
+
let numAddresses = {
|
|
551
|
+
contents: 0
|
|
552
|
+
};
|
|
553
|
+
Utils.Dict.forEach(addressesByContractName, addresses => {
|
|
554
|
+
numAddresses.contents = numAddresses.contents + addresses.length | 0;
|
|
555
|
+
});
|
|
556
|
+
return numAddresses.contents;
|
|
547
557
|
}
|
|
548
558
|
|
|
549
559
|
function addressesByContractNameGetAll(addressesByContractName) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
560
|
+
let all = [];
|
|
561
|
+
Utils.Dict.forEach(addressesByContractName, addresses => {
|
|
562
|
+
for (let idx = 0, idx_finish = addresses.length; idx < idx_finish; ++idx) {
|
|
563
|
+
all.push(addresses[idx]);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
556
566
|
return all;
|
|
557
567
|
}
|
|
558
568
|
|
|
559
569
|
function createPartitionsFromIndexingAddresses(registeringContractsByContract, contractConfigs, dynamicContracts, normalSelection, maxAddrInPartition, nextPartitionIndex, existingPartitions, progressBlockNumber) {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
for(
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
for(
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
Utils.Dict.push(byStartBlock,
|
|
570
|
+
let nextPartitionIndexRef = nextPartitionIndex;
|
|
571
|
+
let dynamicPartitions = [];
|
|
572
|
+
let nonDynamicPartitions = [];
|
|
573
|
+
let contractNames = Object.keys(registeringContractsByContract);
|
|
574
|
+
for (let cIdx = 0, cIdx_finish = contractNames.length; cIdx < cIdx_finish; ++cIdx) {
|
|
575
|
+
let contractName = contractNames[cIdx];
|
|
576
|
+
let registeringContracts = registeringContractsByContract[contractName];
|
|
577
|
+
let addresses = Object.keys(registeringContracts);
|
|
578
|
+
let contractConfig = contractConfigs[contractName];
|
|
579
|
+
let isDynamic = dynamicContracts.has(contractName);
|
|
580
|
+
let partitions = isDynamic ? dynamicPartitions : nonDynamicPartitions;
|
|
581
|
+
let byStartBlock = {};
|
|
582
|
+
for (let jdx = 0, jdx_finish = addresses.length; jdx < jdx_finish; ++jdx) {
|
|
583
|
+
let address = addresses[jdx];
|
|
584
|
+
let indexingContract = registeringContracts[address];
|
|
585
|
+
Utils.Dict.push(byStartBlock, indexingContract.effectiveStartBlock.toString(), address);
|
|
576
586
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
for(
|
|
582
|
-
|
|
583
|
-
|
|
587
|
+
let ascKeys = Object.keys(byStartBlock);
|
|
588
|
+
let initialKey = Utils.$$Array.firstUnsafe(ascKeys);
|
|
589
|
+
let startBlockRef = Stdlib_Int.fromString(initialKey, undefined);
|
|
590
|
+
let addressesRef = byStartBlock[initialKey];
|
|
591
|
+
for (let idx = 0, idx_finish = ascKeys.length; idx < idx_finish; ++idx) {
|
|
592
|
+
let maybeNextStartBlockKey = ascKeys[idx + 1 | 0];
|
|
593
|
+
let shouldAllocateNewPartition;
|
|
584
594
|
if (contractConfig.filterByAddresses || maybeNextStartBlockKey === undefined) {
|
|
585
595
|
shouldAllocateNewPartition = true;
|
|
586
596
|
} else {
|
|
587
|
-
|
|
588
|
-
|
|
597
|
+
let nextStartBlock = Stdlib_Int.fromString(maybeNextStartBlockKey, undefined);
|
|
598
|
+
let shouldJoinCurrentStartBlock = (nextStartBlock - startBlockRef | 0) < 20000;
|
|
589
599
|
if (shouldJoinCurrentStartBlock) {
|
|
590
|
-
addressesRef =
|
|
600
|
+
addressesRef = addressesRef.concat(byStartBlock[maybeNextStartBlockKey]);
|
|
591
601
|
shouldAllocateNewPartition = false;
|
|
592
602
|
} else {
|
|
593
603
|
shouldAllocateNewPartition = true;
|
|
594
604
|
}
|
|
595
605
|
}
|
|
596
606
|
if (shouldAllocateNewPartition) {
|
|
597
|
-
|
|
598
|
-
|
|
607
|
+
let latestFetchedBlock_blockNumber = Primitive_int.max(startBlockRef - 1 | 0, progressBlockNumber);
|
|
608
|
+
let latestFetchedBlock = {
|
|
599
609
|
blockNumber: latestFetchedBlock_blockNumber,
|
|
600
610
|
blockTimestamp: 0
|
|
601
611
|
};
|
|
602
|
-
while(addressesRef.length !== 0) {
|
|
603
|
-
|
|
612
|
+
while (addressesRef.length !== 0) {
|
|
613
|
+
let pAddresses = addressesRef.slice(0, maxAddrInPartition);
|
|
604
614
|
addressesRef = addressesRef.slice(maxAddrInPartition);
|
|
605
|
-
|
|
615
|
+
let addressesByContractName = {};
|
|
606
616
|
addressesByContractName[contractName] = pAddresses;
|
|
607
617
|
partitions.push({
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
618
|
+
id: nextPartitionIndexRef.toString(),
|
|
619
|
+
latestFetchedBlock: latestFetchedBlock,
|
|
620
|
+
selection: normalSelection,
|
|
621
|
+
addressesByContractName: addressesByContractName,
|
|
622
|
+
mergeBlock: undefined,
|
|
623
|
+
dynamicContract: isDynamic ? contractName : undefined,
|
|
624
|
+
mutPendingQueries: [],
|
|
625
|
+
prevQueryRange: 0,
|
|
626
|
+
prevPrevQueryRange: 0,
|
|
627
|
+
latestBlockRangeUpdateBlock: 0
|
|
628
|
+
});
|
|
619
629
|
nextPartitionIndexRef = nextPartitionIndexRef + 1 | 0;
|
|
620
630
|
};
|
|
621
631
|
if (maybeNextStartBlockKey !== undefined) {
|
|
622
|
-
startBlockRef =
|
|
632
|
+
startBlockRef = Stdlib_Int.fromString(maybeNextStartBlockKey, undefined);
|
|
623
633
|
addressesRef = byStartBlock[maybeNextStartBlockKey];
|
|
624
634
|
}
|
|
625
|
-
|
|
626
635
|
}
|
|
627
|
-
|
|
628
636
|
}
|
|
629
637
|
}
|
|
630
|
-
|
|
638
|
+
let mergedNonDynamic = [];
|
|
631
639
|
if (nonDynamicPartitions.length !== 0) {
|
|
632
640
|
nonDynamicPartitions.sort(ascSortFn);
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
while(nextIdx < nonDynamicPartitions.length) {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
+
let currentPRef = nonDynamicPartitions[0];
|
|
642
|
+
let nextIdx = 1;
|
|
643
|
+
while (nextIdx < nonDynamicPartitions.length) {
|
|
644
|
+
let nextP = nonDynamicPartitions[nextIdx];
|
|
645
|
+
let currentP = currentPRef;
|
|
646
|
+
let currentPBlock = currentP.latestFetchedBlock.blockNumber;
|
|
647
|
+
let nextPBlock = nextP.latestFetchedBlock.blockNumber;
|
|
648
|
+
let totalCount = addressesByContractNameCount(currentP.addressesByContractName) + addressesByContractNameCount(nextP.addressesByContractName) | 0;
|
|
641
649
|
if (totalCount > maxAddrInPartition) {
|
|
642
650
|
mergedNonDynamic.push(currentP);
|
|
643
651
|
currentPRef = nextP;
|
|
644
652
|
} else {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
for(
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
653
|
+
let mergedAddresses = Utils.Dict.shallowCopy(nextP.addressesByContractName);
|
|
654
|
+
let currentContractNames = Object.keys(currentP.addressesByContractName);
|
|
655
|
+
for (let jdx$1 = 0, jdx_finish$1 = currentContractNames.length; jdx$1 < jdx_finish$1; ++jdx$1) {
|
|
656
|
+
let cn = currentContractNames[jdx$1];
|
|
657
|
+
let currentAddrs = currentP.addressesByContractName[cn];
|
|
658
|
+
let existingAddrs = mergedAddresses[cn];
|
|
651
659
|
if (existingAddrs !== undefined) {
|
|
652
|
-
mergedAddresses[cn] =
|
|
660
|
+
mergedAddresses[cn] = existingAddrs.concat(currentAddrs);
|
|
653
661
|
} else {
|
|
654
662
|
mergedAddresses[cn] = currentAddrs;
|
|
655
663
|
}
|
|
656
664
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
665
|
+
let nextContractName = Utils.$$Array.firstUnsafe(Object.keys(nextP.addressesByContractName));
|
|
666
|
+
let hasFilterByAddresses = contractConfigs[nextContractName].filterByAddresses;
|
|
667
|
+
let isTooFar = (currentPBlock + 20000 | 0) < nextPBlock;
|
|
660
668
|
if (isTooFar || hasFilterByAddresses) {
|
|
661
669
|
mergedNonDynamic.push({
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
670
|
+
id: currentP.id,
|
|
671
|
+
latestFetchedBlock: currentP.latestFetchedBlock,
|
|
672
|
+
selection: currentP.selection,
|
|
673
|
+
addressesByContractName: currentP.addressesByContractName,
|
|
674
|
+
mergeBlock: currentPBlock < nextPBlock ? nextPBlock : undefined,
|
|
675
|
+
dynamicContract: currentP.dynamicContract,
|
|
676
|
+
mutPendingQueries: currentP.mutPendingQueries,
|
|
677
|
+
prevQueryRange: currentP.prevQueryRange,
|
|
678
|
+
prevPrevQueryRange: currentP.prevPrevQueryRange,
|
|
679
|
+
latestBlockRangeUpdateBlock: currentP.latestBlockRangeUpdateBlock
|
|
680
|
+
});
|
|
673
681
|
currentPRef = {
|
|
674
682
|
id: nextP.id,
|
|
675
683
|
latestFetchedBlock: nextP.latestFetchedBlock,
|
|
@@ -701,49 +709,60 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, c
|
|
|
701
709
|
};
|
|
702
710
|
mergedNonDynamic.push(currentPRef);
|
|
703
711
|
}
|
|
704
|
-
|
|
712
|
+
let mergedPartitions = mergedNonDynamic.concat(dynamicPartitions);
|
|
705
713
|
return make(existingPartitions.concat(mergedPartitions), maxAddrInPartition, nextPartitionIndexRef, dynamicContracts);
|
|
706
714
|
}
|
|
707
715
|
|
|
708
716
|
function registerDynamicContracts(fetchState, items) {
|
|
709
717
|
if (Utils.$$Array.isEmpty(fetchState.normalSelection.eventConfigs)) {
|
|
710
|
-
|
|
718
|
+
Stdlib_JsError.throwWithMessage("Invalid configuration. No events to fetch for the dynamic contract registration.");
|
|
711
719
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
720
|
+
let indexingAddresses = fetchState.indexingAddresses;
|
|
721
|
+
let registeringContractsByContract = {};
|
|
722
|
+
let earliestRegisteringEventBlockNumber = Infinity;
|
|
723
|
+
let hasDCWithFilterByAddresses = false;
|
|
724
|
+
let noEventsAddresses = {};
|
|
725
|
+
for (let itemIdx = 0, itemIdx_finish = items.length; itemIdx < itemIdx_finish; ++itemIdx) {
|
|
726
|
+
let item = items[itemIdx];
|
|
727
|
+
let dcs = item.dcs;
|
|
719
728
|
if (dcs !== undefined) {
|
|
720
|
-
|
|
721
|
-
while(idx < dcs.length) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
729
|
+
let idx = 0;
|
|
730
|
+
while (idx < dcs.length) {
|
|
731
|
+
let dc = dcs[idx];
|
|
732
|
+
let shouldRemove = false;
|
|
733
|
+
let match = fetchState.contractConfigs[dc.contractName];
|
|
725
734
|
if (match !== undefined) {
|
|
726
|
-
|
|
735
|
+
let dcWithStartBlock_address = dc.address;
|
|
736
|
+
let dcWithStartBlock_contractName = dc.contractName;
|
|
737
|
+
let dcWithStartBlock_registrationBlock = dc.registrationBlock;
|
|
738
|
+
let dcWithStartBlock_effectiveStartBlock = deriveEffectiveStartBlock(dc.registrationBlock, match.startBlock);
|
|
739
|
+
let dcWithStartBlock = {
|
|
740
|
+
address: dcWithStartBlock_address,
|
|
741
|
+
contractName: dcWithStartBlock_contractName,
|
|
742
|
+
registrationBlock: dcWithStartBlock_registrationBlock,
|
|
743
|
+
effectiveStartBlock: dcWithStartBlock_effectiveStartBlock
|
|
744
|
+
};
|
|
745
|
+
let existingContract = indexingAddresses[dc.address];
|
|
727
746
|
if (existingContract !== undefined) {
|
|
728
747
|
if (existingContract.contractName !== dc.contractName) {
|
|
729
|
-
warnDifferentContractType(fetchState, existingContract,
|
|
730
|
-
} else if (existingContract.
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
Logging.childWarn(logger,
|
|
748
|
+
warnDifferentContractType(fetchState, existingContract, dcWithStartBlock);
|
|
749
|
+
} else if (existingContract.effectiveStartBlock > dcWithStartBlock_effectiveStartBlock) {
|
|
750
|
+
let logger = Logging.createChild({
|
|
751
|
+
chainId: fetchState.chainId,
|
|
752
|
+
contractAddress: dc.address,
|
|
753
|
+
existingBlockNumber: existingContract.effectiveStartBlock,
|
|
754
|
+
newBlockNumber: dcWithStartBlock_effectiveStartBlock
|
|
755
|
+
});
|
|
756
|
+
Logging.childWarn(logger, `Skipping contract registration: Contract address is already registered at a later block number. Currently registration of the same contract address is not supported by Envio. Reach out to us if it's a problem for you.`);
|
|
738
757
|
}
|
|
739
758
|
shouldRemove = true;
|
|
740
759
|
} else {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
760
|
+
let registeringContracts = Utils.Dict.getOrInsertEmptyDict(registeringContractsByContract, dc.contractName);
|
|
761
|
+
let registeringContract = registeringContracts[dc.address];
|
|
762
|
+
let shouldUpdate;
|
|
744
763
|
if (registeringContract !== undefined) {
|
|
745
764
|
if (registeringContract.contractName !== dc.contractName) {
|
|
746
|
-
warnDifferentContractType(fetchState, registeringContract,
|
|
765
|
+
warnDifferentContractType(fetchState, registeringContract, dcWithStartBlock);
|
|
747
766
|
shouldUpdate = false;
|
|
748
767
|
} else {
|
|
749
768
|
shouldUpdate = false;
|
|
@@ -753,20 +772,43 @@ function registerDynamicContracts(fetchState, items) {
|
|
|
753
772
|
shouldUpdate = true;
|
|
754
773
|
}
|
|
755
774
|
if (shouldUpdate) {
|
|
756
|
-
earliestRegisteringEventBlockNumber =
|
|
757
|
-
registeringContracts[dc.address] =
|
|
775
|
+
earliestRegisteringEventBlockNumber = Primitive_int.min(earliestRegisteringEventBlockNumber, dcWithStartBlock_effectiveStartBlock);
|
|
776
|
+
registeringContracts[dc.address] = dcWithStartBlock;
|
|
758
777
|
} else {
|
|
759
778
|
shouldRemove = true;
|
|
760
779
|
}
|
|
761
780
|
}
|
|
762
781
|
} else {
|
|
763
|
-
|
|
782
|
+
let dcAsIndexingAddress_address = dc.address;
|
|
783
|
+
let dcAsIndexingAddress_contractName = dc.contractName;
|
|
784
|
+
let dcAsIndexingAddress_registrationBlock = dc.registrationBlock;
|
|
785
|
+
let dcAsIndexingAddress_effectiveStartBlock = deriveEffectiveStartBlock(dc.registrationBlock, undefined);
|
|
786
|
+
let dcAsIndexingAddress = {
|
|
787
|
+
address: dcAsIndexingAddress_address,
|
|
788
|
+
contractName: dcAsIndexingAddress_contractName,
|
|
789
|
+
registrationBlock: dcAsIndexingAddress_registrationBlock,
|
|
790
|
+
effectiveStartBlock: dcAsIndexingAddress_effectiveStartBlock
|
|
791
|
+
};
|
|
792
|
+
let existingContract$1 = indexingAddresses[dc.address];
|
|
793
|
+
if (existingContract$1 !== undefined) {
|
|
794
|
+
if (existingContract$1.contractName !== dc.contractName) {
|
|
795
|
+
warnDifferentContractType(fetchState, existingContract$1, dcAsIndexingAddress);
|
|
796
|
+
}
|
|
797
|
+
shouldRemove = true;
|
|
798
|
+
} else {
|
|
799
|
+
let match$1 = noEventsAddresses[dc.address];
|
|
800
|
+
if (match$1 !== undefined) {
|
|
801
|
+
shouldRemove = true;
|
|
802
|
+
} else {
|
|
803
|
+
let logger$1 = Logging.createChild({
|
|
764
804
|
chainId: fetchState.chainId,
|
|
765
805
|
contractAddress: dc.address,
|
|
766
806
|
contractName: dc.contractName
|
|
767
807
|
});
|
|
768
|
-
|
|
769
|
-
|
|
808
|
+
Logging.childWarn(logger$1, `Persisting contract registration without fetching: Contract doesn't have any events to fetch. It'll be picked up on restart if you add events for the contract.`);
|
|
809
|
+
noEventsAddresses[dc.address] = dcAsIndexingAddress;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
770
812
|
}
|
|
771
813
|
if (shouldRemove) {
|
|
772
814
|
dcs.splice(idx, 1);
|
|
@@ -775,104 +817,108 @@ function registerDynamicContracts(fetchState, items) {
|
|
|
775
817
|
}
|
|
776
818
|
};
|
|
777
819
|
}
|
|
778
|
-
|
|
779
|
-
}
|
|
780
|
-
var dcContractNamesToStore = Object.keys(registeringContractsByContract);
|
|
781
|
-
if (dcContractNamesToStore.length === 0) {
|
|
782
|
-
return fetchState;
|
|
783
820
|
}
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
821
|
+
let dcContractNamesToStore = Object.keys(registeringContractsByContract);
|
|
822
|
+
let hasNoEventsUpdates = !Utils.Dict.isEmpty(noEventsAddresses);
|
|
823
|
+
if (dcContractNamesToStore.length !== 0) {
|
|
824
|
+
let newPartitions = [];
|
|
825
|
+
let newIndexingAddresses = Utils.Dict.shallowCopy(indexingAddresses);
|
|
826
|
+
let dynamicContractsRef = fetchState.optimizedPartitions.dynamicContracts;
|
|
827
|
+
let mutExistingPartitions = Object.values(fetchState.optimizedPartitions.entities);
|
|
828
|
+
for (let idx$1 = 0, idx_finish = dcContractNamesToStore.length; idx$1 < idx_finish; ++idx$1) {
|
|
829
|
+
let contractName = dcContractNamesToStore[idx$1];
|
|
830
|
+
if (!dynamicContractsRef.has(contractName)) {
|
|
831
|
+
dynamicContractsRef = Utils.$$Set.immutableAdd(dynamicContractsRef, contractName);
|
|
832
|
+
for (let idx$2 = 0, idx_finish$1 = mutExistingPartitions.length; idx$2 < idx_finish$1; ++idx$2) {
|
|
833
|
+
let p = mutExistingPartitions[idx$2];
|
|
834
|
+
let addresses = p.addressesByContractName[contractName];
|
|
835
|
+
if (addresses !== undefined && p.selection.dependsOnAddresses && p.mergeBlock === undefined) {
|
|
836
|
+
let allPartitionContractNames = Object.keys(p.addressesByContractName);
|
|
837
|
+
if (allPartitionContractNames.length !== 1) {
|
|
838
|
+
let isFetching = p.mutPendingQueries.length !== 0;
|
|
839
|
+
if (!isFetching) {
|
|
840
|
+
let newPartitionId = (fetchState.optimizedPartitions.nextPartitionIndex + newPartitions.length | 0).toString();
|
|
841
|
+
let restAddressesByContractName = Utils.Dict.shallowCopy(p.addressesByContractName);
|
|
842
|
+
Utils.Dict.deleteInPlace(restAddressesByContractName, contractName);
|
|
843
|
+
mutExistingPartitions[idx$2] = {
|
|
844
|
+
id: p.id,
|
|
845
|
+
latestFetchedBlock: p.latestFetchedBlock,
|
|
846
|
+
selection: p.selection,
|
|
847
|
+
addressesByContractName: restAddressesByContractName,
|
|
848
|
+
mergeBlock: p.mergeBlock,
|
|
849
|
+
dynamicContract: p.dynamicContract,
|
|
850
|
+
mutPendingQueries: p.mutPendingQueries,
|
|
851
|
+
prevQueryRange: p.prevQueryRange,
|
|
852
|
+
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
853
|
+
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
854
|
+
};
|
|
855
|
+
let addressesByContractName = {};
|
|
856
|
+
addressesByContractName[contractName] = addresses;
|
|
857
|
+
newPartitions.push({
|
|
858
|
+
id: newPartitionId,
|
|
859
|
+
latestFetchedBlock: p.latestFetchedBlock,
|
|
860
|
+
selection: fetchState.normalSelection,
|
|
861
|
+
addressesByContractName: addressesByContractName,
|
|
862
|
+
mergeBlock: undefined,
|
|
863
|
+
dynamicContract: contractName,
|
|
864
|
+
mutPendingQueries: p.mutPendingQueries,
|
|
865
|
+
prevQueryRange: p.prevQueryRange,
|
|
866
|
+
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
867
|
+
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
} else {
|
|
803
871
|
mutExistingPartitions[idx$2] = {
|
|
804
872
|
id: p.id,
|
|
805
873
|
latestFetchedBlock: p.latestFetchedBlock,
|
|
806
874
|
selection: p.selection,
|
|
807
|
-
addressesByContractName:
|
|
875
|
+
addressesByContractName: p.addressesByContractName,
|
|
808
876
|
mergeBlock: p.mergeBlock,
|
|
809
|
-
dynamicContract:
|
|
877
|
+
dynamicContract: contractName,
|
|
810
878
|
mutPendingQueries: p.mutPendingQueries,
|
|
811
879
|
prevQueryRange: p.prevQueryRange,
|
|
812
880
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
813
881
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
814
882
|
};
|
|
815
|
-
var addressesByContractName = {};
|
|
816
|
-
addressesByContractName[contractName] = addresses;
|
|
817
|
-
newPartitions.push({
|
|
818
|
-
id: newPartitionId,
|
|
819
|
-
latestFetchedBlock: p.latestFetchedBlock,
|
|
820
|
-
selection: fetchState.normalSelection,
|
|
821
|
-
addressesByContractName: addressesByContractName,
|
|
822
|
-
mergeBlock: undefined,
|
|
823
|
-
dynamicContract: contractName,
|
|
824
|
-
mutPendingQueries: p.mutPendingQueries,
|
|
825
|
-
prevQueryRange: p.prevQueryRange,
|
|
826
|
-
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
827
|
-
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
828
|
-
});
|
|
829
883
|
}
|
|
830
|
-
|
|
831
|
-
} else {
|
|
832
|
-
mutExistingPartitions[idx$2] = {
|
|
833
|
-
id: p.id,
|
|
834
|
-
latestFetchedBlock: p.latestFetchedBlock,
|
|
835
|
-
selection: p.selection,
|
|
836
|
-
addressesByContractName: p.addressesByContractName,
|
|
837
|
-
mergeBlock: p.mergeBlock,
|
|
838
|
-
dynamicContract: contractName,
|
|
839
|
-
mutPendingQueries: p.mutPendingQueries,
|
|
840
|
-
prevQueryRange: p.prevQueryRange,
|
|
841
|
-
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
842
|
-
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
843
|
-
};
|
|
844
884
|
}
|
|
845
885
|
}
|
|
846
|
-
|
|
847
886
|
}
|
|
887
|
+
let registeringContracts$1 = registeringContractsByContract[contractName];
|
|
888
|
+
Object.assign(newIndexingAddresses, registeringContracts$1);
|
|
848
889
|
}
|
|
849
|
-
|
|
850
|
-
|
|
890
|
+
Object.assign(newIndexingAddresses, noEventsAddresses);
|
|
891
|
+
let optimizedPartitions = createPartitionsFromIndexingAddresses(registeringContractsByContract, fetchState.contractConfigs, dynamicContractsRef, fetchState.normalSelection, fetchState.optimizedPartitions.maxAddrInPartition, fetchState.optimizedPartitions.nextPartitionIndex + newPartitions.length | 0, mutExistingPartitions.concat(newPartitions), 0);
|
|
892
|
+
return updateInternal(fetchState, optimizedPartitions, newIndexingAddresses, undefined, undefined, undefined);
|
|
893
|
+
}
|
|
894
|
+
if (!hasNoEventsUpdates) {
|
|
895
|
+
return fetchState;
|
|
851
896
|
}
|
|
852
|
-
|
|
853
|
-
|
|
897
|
+
let newIndexingContracts = Utils.Dict.shallowCopy(indexingAddresses);
|
|
898
|
+
Object.assign(newIndexingContracts, noEventsAddresses);
|
|
899
|
+
return updateInternal(fetchState, undefined, newIndexingContracts, undefined, undefined, undefined);
|
|
854
900
|
}
|
|
855
901
|
|
|
856
902
|
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
857
|
-
return updateInternal(fetchState, handleQueryResponse(fetchState.optimizedPartitions, query, fetchState.knownHeight, latestFetchedBlock), undefined, newItems.length !== 0 ?
|
|
903
|
+
return updateInternal(fetchState, handleQueryResponse(fetchState.optimizedPartitions, query, fetchState.knownHeight, latestFetchedBlock), undefined, newItems.length !== 0 ? fetchState.buffer.concat(newItems) : undefined, undefined, undefined);
|
|
858
904
|
}
|
|
859
905
|
|
|
860
906
|
function startFetchingQueries(param, queries) {
|
|
861
|
-
|
|
862
|
-
for(
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
907
|
+
let optimizedPartitions = param.optimizedPartitions;
|
|
908
|
+
for (let qIdx = 0, qIdx_finish = queries.length; qIdx < qIdx_finish; ++qIdx) {
|
|
909
|
+
let q = queries[qIdx];
|
|
910
|
+
let partitionId = q.partitionId;
|
|
911
|
+
let p = optimizedPartitions.entities[partitionId];
|
|
912
|
+
let p$1 = p !== undefined ? p : Stdlib_JsError.throwWithMessage(`Unexpected case: Couldn't find partition ` + partitionId);
|
|
913
|
+
let pq = {
|
|
868
914
|
fromBlock: q.fromBlock,
|
|
869
915
|
toBlock: q.toBlock,
|
|
870
916
|
isChunk: q.isChunk,
|
|
871
917
|
fetchedBlock: undefined
|
|
872
918
|
};
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
while(i < p$1.mutPendingQueries.length && !inserted) {
|
|
919
|
+
let inserted = false;
|
|
920
|
+
let i = 0;
|
|
921
|
+
while (i < p$1.mutPendingQueries.length && !inserted) {
|
|
876
922
|
if (p$1.mutPendingQueries[i].fromBlock > q.fromBlock) {
|
|
877
923
|
p$1.mutPendingQueries.splice(i, 0, pq);
|
|
878
924
|
inserted = true;
|
|
@@ -882,175 +928,170 @@ function startFetchingQueries(param, queries) {
|
|
|
882
928
|
if (!inserted) {
|
|
883
929
|
p$1.mutPendingQueries.push(pq);
|
|
884
930
|
}
|
|
885
|
-
|
|
886
931
|
}
|
|
887
932
|
}
|
|
888
933
|
|
|
889
|
-
function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, selection, addressesByContractName,
|
|
934
|
+
function pushQueriesForRange(queries, partitionId, rangeFromBlock, rangeEndBlock, maxQueryBlockNumber, maybeChunkRange, selection, addressesByContractName, indexingAddresses) {
|
|
890
935
|
if (rangeFromBlock > maxQueryBlockNumber) {
|
|
891
|
-
return
|
|
936
|
+
return;
|
|
892
937
|
}
|
|
893
938
|
if (rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock) {
|
|
894
|
-
return
|
|
939
|
+
return;
|
|
895
940
|
}
|
|
896
941
|
if (maybeChunkRange !== undefined) {
|
|
897
|
-
|
|
898
|
-
|
|
942
|
+
let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
|
|
943
|
+
let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
899
944
|
if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
|
|
900
945
|
queries.push({
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
946
|
+
partitionId: partitionId,
|
|
947
|
+
fromBlock: rangeFromBlock,
|
|
948
|
+
toBlock: (rangeFromBlock + chunkSize | 0) - 1 | 0,
|
|
949
|
+
isChunk: true,
|
|
950
|
+
selection: selection,
|
|
951
|
+
addressesByContractName: addressesByContractName,
|
|
952
|
+
indexingAddresses: indexingAddresses
|
|
953
|
+
});
|
|
909
954
|
queries.push({
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
955
|
+
partitionId: partitionId,
|
|
956
|
+
fromBlock: rangeFromBlock + chunkSize | 0,
|
|
957
|
+
toBlock: (rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0,
|
|
958
|
+
isChunk: true,
|
|
959
|
+
selection: selection,
|
|
960
|
+
addressesByContractName: addressesByContractName,
|
|
961
|
+
indexingAddresses: indexingAddresses
|
|
962
|
+
});
|
|
918
963
|
} else {
|
|
919
964
|
queries.push({
|
|
920
|
-
partitionId: partitionId,
|
|
921
|
-
fromBlock: rangeFromBlock,
|
|
922
|
-
toBlock: rangeEndBlock,
|
|
923
|
-
isChunk: rangeEndBlock !== undefined,
|
|
924
|
-
selection: selection,
|
|
925
|
-
addressesByContractName: addressesByContractName,
|
|
926
|
-
indexingContracts: indexingContracts
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
return ;
|
|
930
|
-
}
|
|
931
|
-
queries.push({
|
|
932
965
|
partitionId: partitionId,
|
|
933
966
|
fromBlock: rangeFromBlock,
|
|
934
967
|
toBlock: rangeEndBlock,
|
|
935
|
-
isChunk:
|
|
968
|
+
isChunk: rangeEndBlock !== undefined,
|
|
936
969
|
selection: selection,
|
|
937
970
|
addressesByContractName: addressesByContractName,
|
|
938
|
-
|
|
971
|
+
indexingAddresses: indexingAddresses
|
|
939
972
|
});
|
|
973
|
+
}
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
queries.push({
|
|
977
|
+
partitionId: partitionId,
|
|
978
|
+
fromBlock: rangeFromBlock,
|
|
979
|
+
toBlock: rangeEndBlock,
|
|
980
|
+
isChunk: false,
|
|
981
|
+
selection: selection,
|
|
982
|
+
addressesByContractName: addressesByContractName,
|
|
983
|
+
indexingAddresses: indexingAddresses
|
|
984
|
+
});
|
|
940
985
|
}
|
|
941
986
|
|
|
942
987
|
function getNextQuery(fetchState, concurrencyLimit) {
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
988
|
+
let knownHeight = fetchState.knownHeight;
|
|
989
|
+
let blockLag = fetchState.blockLag;
|
|
990
|
+
let indexingAddresses = fetchState.indexingAddresses;
|
|
991
|
+
let optimizedPartitions = fetchState.optimizedPartitions;
|
|
992
|
+
let headBlockNumber = knownHeight - blockLag | 0;
|
|
948
993
|
if (headBlockNumber <= 0) {
|
|
949
994
|
return "WaitingForNewBlock";
|
|
950
995
|
}
|
|
951
996
|
if (concurrencyLimit === 0) {
|
|
952
997
|
return "ReachedMaxConcurrency";
|
|
953
998
|
}
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
999
|
+
let isOnBlockBehindTheHead = fetchState.latestOnBlockBlockNumber < headBlockNumber;
|
|
1000
|
+
let endBlock = fetchState.endBlock;
|
|
1001
|
+
let shouldWaitForNewBlock = (
|
|
957
1002
|
endBlock !== undefined ? headBlockNumber < endBlock : true
|
|
958
1003
|
) && !isOnBlockBehindTheHead;
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
while(idxRef < partitionsCount) {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1004
|
+
let item = fetchState.buffer[fetchState.targetBufferSize - 1 | 0];
|
|
1005
|
+
let maxQueryBlockNumber = item !== undefined ? Primitive_int.min(item.blockNumber, knownHeight) : knownHeight;
|
|
1006
|
+
let queries = [];
|
|
1007
|
+
let partitionsCount = optimizedPartitions.idsInAscOrder.length;
|
|
1008
|
+
let idxRef = 0;
|
|
1009
|
+
while (idxRef < partitionsCount) {
|
|
1010
|
+
let idx = idxRef;
|
|
1011
|
+
let partitionId = optimizedPartitions.idsInAscOrder[idx];
|
|
1012
|
+
let p = optimizedPartitions.entities[partitionId];
|
|
1013
|
+
let isBehindTheHead = p.latestFetchedBlock.blockNumber < headBlockNumber;
|
|
1014
|
+
let hasPendingQueries = Utils.$$Array.notEmpty(p.mutPendingQueries);
|
|
970
1015
|
if (hasPendingQueries || isBehindTheHead) {
|
|
971
1016
|
shouldWaitForNewBlock = false;
|
|
972
1017
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
match ? (
|
|
978
|
-
maxQueryBlockNumber < queryEndBlock$1 ? maxQueryBlockNumber : queryEndBlock$1
|
|
979
|
-
) : queryEndBlock$1
|
|
1018
|
+
let queryEndBlock = Utils.$$Math.minOptInt(fetchState.endBlock, p.mergeBlock);
|
|
1019
|
+
let queryEndBlock$1 = blockLag !== 0 ? Utils.$$Math.minOptInt(headBlockNumber, queryEndBlock) : queryEndBlock;
|
|
1020
|
+
let match = maxQueryBlockNumber < knownHeight;
|
|
1021
|
+
let queryEndBlock$2 = queryEndBlock$1 !== undefined ? (
|
|
1022
|
+
match ? Primitive_int.min(maxQueryBlockNumber, queryEndBlock$1) : queryEndBlock$1
|
|
980
1023
|
) : (
|
|
981
1024
|
match ? maxQueryBlockNumber : queryEndBlock$1
|
|
982
1025
|
);
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
while(pqIdx < p.mutPendingQueries.length && canContinue) {
|
|
988
|
-
|
|
1026
|
+
let maybeChunkRange = getMinHistoryRange(p);
|
|
1027
|
+
let cursor = p.latestFetchedBlock.blockNumber + 1 | 0;
|
|
1028
|
+
let canContinue = true;
|
|
1029
|
+
let pqIdx = 0;
|
|
1030
|
+
while (pqIdx < p.mutPendingQueries.length && canContinue) {
|
|
1031
|
+
let pq = p.mutPendingQueries[pqIdx];
|
|
989
1032
|
if (pq.fromBlock > cursor) {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1033
|
+
let addressesByContractName = p.addressesByContractName;
|
|
1034
|
+
let selection = p.selection;
|
|
1035
|
+
let rangeEndBlock = Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock$2);
|
|
1036
|
+
let rangeFromBlock = cursor;
|
|
994
1037
|
if (rangeFromBlock <= maxQueryBlockNumber) {
|
|
995
|
-
|
|
1038
|
+
let exit = 0;
|
|
996
1039
|
if (!(rangeEndBlock !== undefined && rangeFromBlock > rangeEndBlock)) {
|
|
997
1040
|
exit = 1;
|
|
998
1041
|
}
|
|
999
1042
|
if (exit === 1) {
|
|
1000
1043
|
if (maybeChunkRange !== undefined) {
|
|
1001
|
-
|
|
1002
|
-
|
|
1044
|
+
let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : maxQueryBlockNumber;
|
|
1045
|
+
let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
1003
1046
|
if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) <= maxBlock) {
|
|
1004
1047
|
queries.push({
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1048
|
+
partitionId: partitionId,
|
|
1049
|
+
fromBlock: rangeFromBlock,
|
|
1050
|
+
toBlock: (rangeFromBlock + chunkSize | 0) - 1 | 0,
|
|
1051
|
+
isChunk: true,
|
|
1052
|
+
selection: selection,
|
|
1053
|
+
addressesByContractName: addressesByContractName,
|
|
1054
|
+
indexingAddresses: indexingAddresses
|
|
1055
|
+
});
|
|
1013
1056
|
queries.push({
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1057
|
+
partitionId: partitionId,
|
|
1058
|
+
fromBlock: rangeFromBlock + chunkSize | 0,
|
|
1059
|
+
toBlock: (rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0,
|
|
1060
|
+
isChunk: true,
|
|
1061
|
+
selection: selection,
|
|
1062
|
+
addressesByContractName: addressesByContractName,
|
|
1063
|
+
indexingAddresses: indexingAddresses
|
|
1064
|
+
});
|
|
1022
1065
|
} else {
|
|
1023
1066
|
queries.push({
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1067
|
+
partitionId: partitionId,
|
|
1068
|
+
fromBlock: rangeFromBlock,
|
|
1069
|
+
toBlock: rangeEndBlock,
|
|
1070
|
+
isChunk: rangeEndBlock !== undefined,
|
|
1071
|
+
selection: selection,
|
|
1072
|
+
addressesByContractName: addressesByContractName,
|
|
1073
|
+
indexingAddresses: indexingAddresses
|
|
1074
|
+
});
|
|
1032
1075
|
}
|
|
1033
1076
|
} else {
|
|
1034
1077
|
queries.push({
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1078
|
+
partitionId: partitionId,
|
|
1079
|
+
fromBlock: rangeFromBlock,
|
|
1080
|
+
toBlock: rangeEndBlock,
|
|
1081
|
+
isChunk: false,
|
|
1082
|
+
selection: selection,
|
|
1083
|
+
addressesByContractName: addressesByContractName,
|
|
1084
|
+
indexingAddresses: indexingAddresses
|
|
1085
|
+
});
|
|
1043
1086
|
}
|
|
1044
1087
|
}
|
|
1045
|
-
|
|
1046
1088
|
}
|
|
1047
|
-
|
|
1048
1089
|
}
|
|
1049
|
-
|
|
1090
|
+
let toBlock = pq.toBlock;
|
|
1050
1091
|
if (toBlock !== undefined && pq.isChunk) {
|
|
1051
|
-
|
|
1092
|
+
let match$1 = pq.fetchedBlock;
|
|
1052
1093
|
if (match$1 !== undefined) {
|
|
1053
|
-
|
|
1094
|
+
let blockNumber = match$1.blockNumber;
|
|
1054
1095
|
cursor = blockNumber < toBlock ? blockNumber + 1 | 0 : toBlock + 1 | 0;
|
|
1055
1096
|
} else {
|
|
1056
1097
|
cursor = toBlock + 1 | 0;
|
|
@@ -1061,63 +1102,61 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1061
1102
|
pqIdx = pqIdx + 1 | 0;
|
|
1062
1103
|
};
|
|
1063
1104
|
if (canContinue) {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1105
|
+
let addressesByContractName$1 = p.addressesByContractName;
|
|
1106
|
+
let selection$1 = p.selection;
|
|
1107
|
+
let rangeFromBlock$1 = cursor;
|
|
1067
1108
|
if (rangeFromBlock$1 <= maxQueryBlockNumber) {
|
|
1068
|
-
|
|
1109
|
+
let exit$1 = 0;
|
|
1069
1110
|
if (!(queryEndBlock$2 !== undefined && rangeFromBlock$1 > queryEndBlock$2)) {
|
|
1070
1111
|
exit$1 = 1;
|
|
1071
1112
|
}
|
|
1072
1113
|
if (exit$1 === 1) {
|
|
1073
1114
|
if (maybeChunkRange !== undefined) {
|
|
1074
|
-
|
|
1075
|
-
|
|
1115
|
+
let maxBlock$1 = queryEndBlock$2 !== undefined ? queryEndBlock$2 : maxQueryBlockNumber;
|
|
1116
|
+
let chunkSize$1 = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
1076
1117
|
if (((rangeFromBlock$1 + (chunkSize$1 << 1) | 0) - 1 | 0) <= maxBlock$1) {
|
|
1077
1118
|
queries.push({
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1119
|
+
partitionId: partitionId,
|
|
1120
|
+
fromBlock: rangeFromBlock$1,
|
|
1121
|
+
toBlock: (rangeFromBlock$1 + chunkSize$1 | 0) - 1 | 0,
|
|
1122
|
+
isChunk: true,
|
|
1123
|
+
selection: selection$1,
|
|
1124
|
+
addressesByContractName: addressesByContractName$1,
|
|
1125
|
+
indexingAddresses: indexingAddresses
|
|
1126
|
+
});
|
|
1086
1127
|
queries.push({
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1128
|
+
partitionId: partitionId,
|
|
1129
|
+
fromBlock: rangeFromBlock$1 + chunkSize$1 | 0,
|
|
1130
|
+
toBlock: (rangeFromBlock$1 + (chunkSize$1 << 1) | 0) - 1 | 0,
|
|
1131
|
+
isChunk: true,
|
|
1132
|
+
selection: selection$1,
|
|
1133
|
+
addressesByContractName: addressesByContractName$1,
|
|
1134
|
+
indexingAddresses: indexingAddresses
|
|
1135
|
+
});
|
|
1095
1136
|
} else {
|
|
1096
1137
|
queries.push({
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1138
|
+
partitionId: partitionId,
|
|
1139
|
+
fromBlock: rangeFromBlock$1,
|
|
1140
|
+
toBlock: queryEndBlock$2,
|
|
1141
|
+
isChunk: queryEndBlock$2 !== undefined,
|
|
1142
|
+
selection: selection$1,
|
|
1143
|
+
addressesByContractName: addressesByContractName$1,
|
|
1144
|
+
indexingAddresses: indexingAddresses
|
|
1145
|
+
});
|
|
1105
1146
|
}
|
|
1106
1147
|
} else {
|
|
1107
1148
|
queries.push({
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1149
|
+
partitionId: partitionId,
|
|
1150
|
+
fromBlock: rangeFromBlock$1,
|
|
1151
|
+
toBlock: queryEndBlock$2,
|
|
1152
|
+
isChunk: false,
|
|
1153
|
+
selection: selection$1,
|
|
1154
|
+
addressesByContractName: addressesByContractName$1,
|
|
1155
|
+
indexingAddresses: indexingAddresses
|
|
1156
|
+
});
|
|
1116
1157
|
}
|
|
1117
1158
|
}
|
|
1118
|
-
|
|
1119
1159
|
}
|
|
1120
|
-
|
|
1121
1160
|
}
|
|
1122
1161
|
idxRef = idxRef + 1 | 0;
|
|
1123
1162
|
};
|
|
@@ -1128,22 +1167,20 @@ function getNextQuery(fetchState, concurrencyLimit) {
|
|
|
1128
1167
|
return "NothingToQuery";
|
|
1129
1168
|
}
|
|
1130
1169
|
}
|
|
1131
|
-
|
|
1132
|
-
return a.fromBlock - b.fromBlock | 0;
|
|
1133
|
-
}), queries.slice(0, concurrencyLimit)) : queries;
|
|
1170
|
+
let queries$1 = queries.length > concurrencyLimit ? (queries.sort((a, b) => Primitive_int.compare(a.fromBlock, b.fromBlock)), queries.slice(0, concurrencyLimit)) : queries;
|
|
1134
1171
|
return {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1172
|
+
TAG: "Ready",
|
|
1173
|
+
_0: queries$1
|
|
1174
|
+
};
|
|
1138
1175
|
}
|
|
1139
1176
|
|
|
1140
1177
|
function getTimestampAt(fetchState, index) {
|
|
1141
|
-
|
|
1178
|
+
let match = Belt_Array.get(fetchState.buffer, index);
|
|
1142
1179
|
if (match !== undefined) {
|
|
1143
1180
|
if (match.kind === 0) {
|
|
1144
1181
|
return match.timestamp;
|
|
1145
1182
|
} else {
|
|
1146
|
-
return
|
|
1183
|
+
return Stdlib_JsError.throwWithMessage("Block handlers are not supported for ordered multichain mode.");
|
|
1147
1184
|
}
|
|
1148
1185
|
} else {
|
|
1149
1186
|
return bufferBlock(fetchState).blockTimestamp;
|
|
@@ -1151,7 +1188,7 @@ function getTimestampAt(fetchState, index) {
|
|
|
1151
1188
|
}
|
|
1152
1189
|
|
|
1153
1190
|
function hasReadyItem(fetchState) {
|
|
1154
|
-
|
|
1191
|
+
let item = Belt_Array.get(fetchState.buffer, 0);
|
|
1155
1192
|
if (item !== undefined) {
|
|
1156
1193
|
return item.blockNumber <= bufferBlockNumber(fetchState);
|
|
1157
1194
|
} else {
|
|
@@ -1160,19 +1197,18 @@ function hasReadyItem(fetchState) {
|
|
|
1160
1197
|
}
|
|
1161
1198
|
|
|
1162
1199
|
function getReadyItemsCount(fetchState, targetSize, fromItem) {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
while(!isFinished) {
|
|
1167
|
-
|
|
1200
|
+
let readyBlockNumber = bufferBlockNumber(fetchState);
|
|
1201
|
+
let acc = 0;
|
|
1202
|
+
let isFinished = false;
|
|
1203
|
+
while (!isFinished) {
|
|
1204
|
+
let item = Belt_Array.get(fetchState.buffer, fromItem + acc | 0);
|
|
1168
1205
|
if (item !== undefined) {
|
|
1169
|
-
|
|
1206
|
+
let itemBlockNumber = item.blockNumber;
|
|
1170
1207
|
if (itemBlockNumber <= readyBlockNumber) {
|
|
1171
1208
|
acc = acc + 1 | 0;
|
|
1172
1209
|
if (acc === targetSize) {
|
|
1173
1210
|
readyBlockNumber = itemBlockNumber;
|
|
1174
1211
|
}
|
|
1175
|
-
|
|
1176
1212
|
} else {
|
|
1177
1213
|
isFinished = true;
|
|
1178
1214
|
}
|
|
@@ -1183,83 +1219,100 @@ function getReadyItemsCount(fetchState, targetSize, fromItem) {
|
|
|
1183
1219
|
return acc;
|
|
1184
1220
|
}
|
|
1185
1221
|
|
|
1186
|
-
function make$1(startBlock, endBlock, eventConfigs,
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1222
|
+
function make$1(startBlock, endBlock, eventConfigs, addresses, maxAddrInPartition, chainId, targetBufferSize, knownHeight, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt, firstEventBlockOpt) {
|
|
1223
|
+
let progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
1224
|
+
let onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
|
|
1225
|
+
let blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
1226
|
+
let firstEventBlock = firstEventBlockOpt !== undefined ? Primitive_option.valFromOption(firstEventBlockOpt) : undefined;
|
|
1227
|
+
let latestFetchedBlock = {
|
|
1192
1228
|
blockNumber: progressBlockNumber,
|
|
1193
1229
|
blockTimestamp: 0
|
|
1194
1230
|
};
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1231
|
+
let notDependingOnAddresses = [];
|
|
1232
|
+
let normalEventConfigs = [];
|
|
1233
|
+
let contractNamesWithNormalEvents = new Set();
|
|
1234
|
+
let indexingAddresses = {};
|
|
1235
|
+
let contractConfigs = {};
|
|
1236
|
+
eventConfigs.forEach(ec => {
|
|
1237
|
+
let match = contractConfigs[ec.contractName];
|
|
1238
|
+
if (match !== undefined) {
|
|
1239
|
+
let startBlock = match.startBlock;
|
|
1240
|
+
let match$1 = ec.startBlock;
|
|
1241
|
+
contractConfigs[ec.contractName] = {
|
|
1242
|
+
filterByAddresses: match.filterByAddresses || ec.filterByAddresses,
|
|
1243
|
+
startBlock: startBlock !== undefined ? (
|
|
1244
|
+
match$1 !== undefined ? Primitive_int.min(startBlock, match$1) : startBlock
|
|
1245
|
+
) : (
|
|
1246
|
+
match$1 !== undefined ? match$1 : undefined
|
|
1247
|
+
)
|
|
1248
|
+
};
|
|
1249
|
+
} else {
|
|
1250
|
+
contractConfigs[ec.contractName] = {
|
|
1251
|
+
filterByAddresses: ec.filterByAddresses,
|
|
1252
|
+
startBlock: ec.startBlock
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
if (ec.dependsOnAddresses) {
|
|
1256
|
+
normalEventConfigs.push(ec);
|
|
1257
|
+
contractNamesWithNormalEvents.add(ec.contractName);
|
|
1258
|
+
} else {
|
|
1259
|
+
notDependingOnAddresses.push(ec);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
let partitions = [];
|
|
1219
1263
|
if (notDependingOnAddresses.length !== 0) {
|
|
1220
1264
|
partitions.push({
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1265
|
+
id: partitions.length.toString(),
|
|
1266
|
+
latestFetchedBlock: latestFetchedBlock,
|
|
1267
|
+
selection: {
|
|
1268
|
+
eventConfigs: notDependingOnAddresses,
|
|
1269
|
+
dependsOnAddresses: false
|
|
1270
|
+
},
|
|
1271
|
+
addressesByContractName: {},
|
|
1272
|
+
mergeBlock: undefined,
|
|
1273
|
+
dynamicContract: undefined,
|
|
1274
|
+
mutPendingQueries: [],
|
|
1275
|
+
prevQueryRange: 0,
|
|
1276
|
+
prevPrevQueryRange: 0,
|
|
1277
|
+
latestBlockRangeUpdateBlock: 0
|
|
1278
|
+
});
|
|
1235
1279
|
}
|
|
1236
|
-
|
|
1280
|
+
let normalSelection = {
|
|
1237
1281
|
eventConfigs: normalEventConfigs,
|
|
1238
1282
|
dependsOnAddresses: true
|
|
1239
1283
|
};
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1284
|
+
let registeringContractsByContract = {};
|
|
1285
|
+
let dynamicContracts = new Set();
|
|
1286
|
+
addresses.forEach(contract => {
|
|
1287
|
+
let contractName = contract.contractName;
|
|
1288
|
+
let match = contractConfigs[contractName];
|
|
1289
|
+
let contractStartBlock = match !== undefined ? match.startBlock : undefined;
|
|
1290
|
+
let ia_address = contract.address;
|
|
1291
|
+
let ia_contractName = contract.contractName;
|
|
1292
|
+
let ia_registrationBlock = contract.registrationBlock;
|
|
1293
|
+
let ia_effectiveStartBlock = deriveEffectiveStartBlock(contract.registrationBlock, contractStartBlock);
|
|
1294
|
+
let ia = {
|
|
1295
|
+
address: ia_address,
|
|
1296
|
+
contractName: ia_contractName,
|
|
1297
|
+
registrationBlock: ia_registrationBlock,
|
|
1298
|
+
effectiveStartBlock: ia_effectiveStartBlock
|
|
1299
|
+
};
|
|
1300
|
+
indexingAddresses[contract.address] = ia;
|
|
1301
|
+
if (!contractNamesWithNormalEvents.has(contractName)) {
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
let registeringContracts = Utils.Dict.getOrInsertEmptyDict(registeringContractsByContract, contractName);
|
|
1305
|
+
registeringContracts[contract.address] = ia;
|
|
1306
|
+
if (contract.registrationBlock !== -1) {
|
|
1307
|
+
dynamicContracts.add(contractName);
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
let optimizedPartitions = createPartitionsFromIndexingAddresses(registeringContractsByContract, contractConfigs, dynamicContracts, normalSelection, maxAddrInPartition, partitions.length, partitions, progressBlockNumber);
|
|
1259
1312
|
if (optimizedPartitions.idsInAscOrder.length === 0 && Utils.$$Array.isEmpty(onBlockConfigs)) {
|
|
1260
|
-
|
|
1313
|
+
Stdlib_JsError.throwWithMessage(`Invalid configuration: Nothing to fetch on chain ` + chainId.toString() + `. ` + (`addresses=` + addresses.length.toString() + `, `) + (`eventConfigs=` + eventConfigs.length.toString() + `, `) + (`normalEventConfigs=` + normalEventConfigs.length.toString() + `. `) + `Make sure that you provided at least one contract address to index, or have events with Wildcard mode enabled, or have onBlock handlers.`);
|
|
1261
1314
|
}
|
|
1262
|
-
|
|
1315
|
+
let numAddresses = Utils.Dict.size(indexingAddresses);
|
|
1263
1316
|
Prometheus.IndexingAddresses.set(numAddresses, chainId);
|
|
1264
1317
|
Prometheus.IndexingPartitions.set(optimizedPartitions.idsInAscOrder.length, chainId);
|
|
1265
1318
|
Prometheus.IndexingBufferSize.set(0, chainId);
|
|
@@ -1268,21 +1321,21 @@ function make$1(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartitio
|
|
|
1268
1321
|
Prometheus.IndexingEndBlock.set(endBlock, chainId);
|
|
1269
1322
|
}
|
|
1270
1323
|
return {
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1324
|
+
optimizedPartitions: optimizedPartitions,
|
|
1325
|
+
startBlock: startBlock,
|
|
1326
|
+
endBlock: endBlock,
|
|
1327
|
+
normalSelection: normalSelection,
|
|
1328
|
+
indexingAddresses: indexingAddresses,
|
|
1329
|
+
contractConfigs: contractConfigs,
|
|
1330
|
+
chainId: chainId,
|
|
1331
|
+
latestOnBlockBlockNumber: progressBlockNumber,
|
|
1332
|
+
blockLag: blockLag,
|
|
1333
|
+
buffer: [],
|
|
1334
|
+
targetBufferSize: targetBufferSize,
|
|
1335
|
+
onBlockConfigs: onBlockConfigs,
|
|
1336
|
+
knownHeight: knownHeight,
|
|
1337
|
+
firstEventBlock: firstEventBlock
|
|
1338
|
+
};
|
|
1286
1339
|
}
|
|
1287
1340
|
|
|
1288
1341
|
function bufferSize(param) {
|
|
@@ -1290,149 +1343,139 @@ function bufferSize(param) {
|
|
|
1290
1343
|
}
|
|
1291
1344
|
|
|
1292
1345
|
function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
|
|
1293
|
-
|
|
1294
|
-
for(
|
|
1295
|
-
|
|
1346
|
+
let adjusted = [];
|
|
1347
|
+
for (let qIdx = 0, qIdx_finish = mutPendingQueries.length; qIdx < qIdx_finish; ++qIdx) {
|
|
1348
|
+
let pq = mutPendingQueries[qIdx];
|
|
1296
1349
|
if (pq.fromBlock <= targetBlockNumber) {
|
|
1297
|
-
|
|
1350
|
+
let match = pq.fetchedBlock;
|
|
1298
1351
|
if (match !== undefined) {
|
|
1299
1352
|
if (match.blockNumber > targetBlockNumber) {
|
|
1300
1353
|
adjusted.push({
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1354
|
+
fromBlock: pq.fromBlock,
|
|
1355
|
+
toBlock: pq.toBlock,
|
|
1356
|
+
isChunk: pq.isChunk,
|
|
1357
|
+
fetchedBlock: {
|
|
1358
|
+
blockNumber: targetBlockNumber,
|
|
1359
|
+
blockTimestamp: 0
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1309
1362
|
} else {
|
|
1310
1363
|
adjusted.push(pq);
|
|
1311
1364
|
}
|
|
1312
1365
|
} else {
|
|
1313
|
-
|
|
1366
|
+
Stdlib_JsError.throwWithMessage("Internal error: Must not have a fetching query during rollback");
|
|
1314
1367
|
}
|
|
1315
1368
|
}
|
|
1316
|
-
|
|
1317
1369
|
}
|
|
1318
1370
|
return adjusted;
|
|
1319
1371
|
}
|
|
1320
1372
|
|
|
1321
1373
|
function rollback(fetchState, targetBlockNumber) {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
var p = partitions[idx];
|
|
1374
|
+
let addressesToRemove = new Set();
|
|
1375
|
+
let indexingAddresses = {};
|
|
1376
|
+
Object.keys(fetchState.indexingAddresses).forEach(address => {
|
|
1377
|
+
let indexingContract = fetchState.indexingAddresses[address];
|
|
1378
|
+
if (indexingContract.registrationBlock > targetBlockNumber) {
|
|
1379
|
+
addressesToRemove.add(address);
|
|
1380
|
+
} else {
|
|
1381
|
+
indexingAddresses[address] = indexingContract;
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
let keptPartitions = [];
|
|
1385
|
+
let nextKeptIdRef = 0;
|
|
1386
|
+
let registeringContractsByContract = {};
|
|
1387
|
+
let partitions = Object.values(fetchState.optimizedPartitions.entities);
|
|
1388
|
+
for (let idx = 0, idx_finish = partitions.length; idx < idx_finish; ++idx) {
|
|
1389
|
+
let p = partitions[idx];
|
|
1339
1390
|
if (p.selection.dependsOnAddresses) {
|
|
1340
1391
|
if (p.latestFetchedBlock.blockNumber > targetBlockNumber) {
|
|
1341
|
-
Utils.Dict.forEachWithKey(p.addressesByContractName, (
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
}
|
|
1346
|
-
var registeringContracts = Utils.Dict.getOrInsertEmptyDict(registeringContractsByContract, contractName);
|
|
1347
|
-
registeringContracts[address] = indexingContracts[address];
|
|
1348
|
-
}));
|
|
1349
|
-
}));
|
|
1350
|
-
} else {
|
|
1351
|
-
var mergeBlock = p.mergeBlock;
|
|
1352
|
-
var mergeBlock$1 = mergeBlock !== undefined && mergeBlock > targetBlockNumber ? targetBlockNumber : mergeBlock;
|
|
1353
|
-
var rollbackedAddressesByContractName = {};
|
|
1354
|
-
Utils.Dict.forEachWithKey(p.addressesByContractName, (function(rollbackedAddressesByContractName){
|
|
1355
|
-
return function (addresses, contractName) {
|
|
1356
|
-
var keptAddresses = Belt_Array.keep(addresses, (function (address) {
|
|
1357
|
-
return !addressesToRemove.has(address);
|
|
1358
|
-
}));
|
|
1359
|
-
if (keptAddresses.length !== 0) {
|
|
1360
|
-
rollbackedAddressesByContractName[contractName] = keptAddresses;
|
|
1361
|
-
return ;
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1392
|
+
Utils.Dict.forEachWithKey(p.addressesByContractName, (addresses, contractName) => {
|
|
1393
|
+
addresses.forEach(address => {
|
|
1394
|
+
if (!(!addressesToRemove.has(address) && Stdlib_Option.isSome(indexingAddresses[address]))) {
|
|
1395
|
+
return;
|
|
1364
1396
|
}
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1397
|
+
let registeringContracts = Utils.Dict.getOrInsertEmptyDict(registeringContractsByContract, contractName);
|
|
1398
|
+
registeringContracts[address] = indexingAddresses[address];
|
|
1399
|
+
});
|
|
1400
|
+
});
|
|
1401
|
+
} else {
|
|
1402
|
+
let mergeBlock = p.mergeBlock;
|
|
1403
|
+
let mergeBlock$1 = mergeBlock !== undefined && mergeBlock > targetBlockNumber ? targetBlockNumber : mergeBlock;
|
|
1404
|
+
let rollbackedAddressesByContractName = {};
|
|
1405
|
+
Utils.Dict.forEachWithKey(p.addressesByContractName, (addresses, contractName) => {
|
|
1406
|
+
let keptAddresses = addresses.filter(address => !addressesToRemove.has(address));
|
|
1407
|
+
if (keptAddresses.length !== 0) {
|
|
1408
|
+
rollbackedAddressesByContractName[contractName] = keptAddresses;
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
if (!Utils.Dict.isEmpty(rollbackedAddressesByContractName)) {
|
|
1413
|
+
let id = nextKeptIdRef.toString();
|
|
1368
1414
|
nextKeptIdRef = nextKeptIdRef + 1 | 0;
|
|
1369
1415
|
keptPartitions.push({
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
selection: p.selection,
|
|
1373
|
-
addressesByContractName: rollbackedAddressesByContractName,
|
|
1374
|
-
mergeBlock: mergeBlock$1,
|
|
1375
|
-
dynamicContract: p.dynamicContract,
|
|
1376
|
-
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1377
|
-
prevQueryRange: p.prevQueryRange,
|
|
1378
|
-
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
1379
|
-
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
1380
|
-
});
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
}
|
|
1384
|
-
} else {
|
|
1385
|
-
var id$1 = String(nextKeptIdRef);
|
|
1386
|
-
nextKeptIdRef = nextKeptIdRef + 1 | 0;
|
|
1387
|
-
keptPartitions.push({
|
|
1388
|
-
id: id$1,
|
|
1389
|
-
latestFetchedBlock: p.latestFetchedBlock.blockNumber > targetBlockNumber ? ({
|
|
1390
|
-
blockNumber: targetBlockNumber,
|
|
1391
|
-
blockTimestamp: 0
|
|
1392
|
-
}) : p.latestFetchedBlock,
|
|
1416
|
+
id: id,
|
|
1417
|
+
latestFetchedBlock: p.latestFetchedBlock,
|
|
1393
1418
|
selection: p.selection,
|
|
1394
|
-
addressesByContractName:
|
|
1395
|
-
mergeBlock:
|
|
1419
|
+
addressesByContractName: rollbackedAddressesByContractName,
|
|
1420
|
+
mergeBlock: mergeBlock$1,
|
|
1396
1421
|
dynamicContract: p.dynamicContract,
|
|
1397
1422
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1398
1423
|
prevQueryRange: p.prevQueryRange,
|
|
1399
1424
|
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
1400
1425
|
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
1401
1426
|
});
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
} else {
|
|
1430
|
+
let id$1 = nextKeptIdRef.toString();
|
|
1431
|
+
nextKeptIdRef = nextKeptIdRef + 1 | 0;
|
|
1432
|
+
keptPartitions.push({
|
|
1433
|
+
id: id$1,
|
|
1434
|
+
latestFetchedBlock: p.latestFetchedBlock.blockNumber > targetBlockNumber ? ({
|
|
1435
|
+
blockNumber: targetBlockNumber,
|
|
1436
|
+
blockTimestamp: 0
|
|
1437
|
+
}) : p.latestFetchedBlock,
|
|
1438
|
+
selection: p.selection,
|
|
1439
|
+
addressesByContractName: p.addressesByContractName,
|
|
1440
|
+
mergeBlock: p.mergeBlock,
|
|
1441
|
+
dynamicContract: p.dynamicContract,
|
|
1442
|
+
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1443
|
+
prevQueryRange: p.prevQueryRange,
|
|
1444
|
+
prevPrevQueryRange: p.prevPrevQueryRange,
|
|
1445
|
+
latestBlockRangeUpdateBlock: p.latestBlockRangeUpdateBlock
|
|
1446
|
+
});
|
|
1402
1447
|
}
|
|
1403
1448
|
}
|
|
1404
|
-
|
|
1449
|
+
let optimizedPartitions = createPartitionsFromIndexingAddresses(registeringContractsByContract, fetchState.contractConfigs, fetchState.optimizedPartitions.dynamicContracts, fetchState.normalSelection, fetchState.optimizedPartitions.maxAddrInPartition, nextKeptIdRef, keptPartitions, targetBlockNumber);
|
|
1405
1450
|
return updateInternal({
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1451
|
+
optimizedPartitions: fetchState.optimizedPartitions,
|
|
1452
|
+
startBlock: fetchState.startBlock,
|
|
1453
|
+
endBlock: fetchState.endBlock,
|
|
1454
|
+
normalSelection: fetchState.normalSelection,
|
|
1455
|
+
indexingAddresses: fetchState.indexingAddresses,
|
|
1456
|
+
contractConfigs: fetchState.contractConfigs,
|
|
1457
|
+
chainId: fetchState.chainId,
|
|
1458
|
+
latestOnBlockBlockNumber: Primitive_int.min(fetchState.latestOnBlockBlockNumber, targetBlockNumber),
|
|
1459
|
+
blockLag: fetchState.blockLag,
|
|
1460
|
+
buffer: fetchState.buffer,
|
|
1461
|
+
targetBufferSize: fetchState.targetBufferSize,
|
|
1462
|
+
onBlockConfigs: fetchState.onBlockConfigs,
|
|
1463
|
+
knownHeight: fetchState.knownHeight,
|
|
1464
|
+
firstEventBlock: fetchState.firstEventBlock
|
|
1465
|
+
}, optimizedPartitions, indexingAddresses, fetchState.buffer.filter(item => {
|
|
1466
|
+
let tmp;
|
|
1467
|
+
tmp = item.kind === 0 ? item.blockNumber : item.blockNumber;
|
|
1468
|
+
return tmp <= targetBlockNumber;
|
|
1469
|
+
}), undefined, undefined);
|
|
1425
1470
|
}
|
|
1426
1471
|
|
|
1427
1472
|
function resetPendingQueries(fetchState) {
|
|
1428
|
-
|
|
1429
|
-
for(
|
|
1430
|
-
|
|
1431
|
-
|
|
1473
|
+
let newEntities = Utils.Dict.shallowCopy(fetchState.optimizedPartitions.entities);
|
|
1474
|
+
for (let idx = 0, idx_finish = fetchState.optimizedPartitions.idsInAscOrder.length; idx < idx_finish; ++idx) {
|
|
1475
|
+
let partitionId = fetchState.optimizedPartitions.idsInAscOrder[idx];
|
|
1476
|
+
let partition = fetchState.optimizedPartitions.entities[partitionId];
|
|
1432
1477
|
if (partition.mutPendingQueries.length !== 0) {
|
|
1433
|
-
|
|
1434
|
-
return pq.fetchedBlock !== undefined;
|
|
1435
|
-
}));
|
|
1478
|
+
let kept = partition.mutPendingQueries.filter(pq => pq.fetchedBlock !== undefined);
|
|
1436
1479
|
newEntities[partitionId] = {
|
|
1437
1480
|
id: partition.id,
|
|
1438
1481
|
latestFetchedBlock: partition.latestFetchedBlock,
|
|
@@ -1446,39 +1489,38 @@ function resetPendingQueries(fetchState) {
|
|
|
1446
1489
|
latestBlockRangeUpdateBlock: partition.latestBlockRangeUpdateBlock
|
|
1447
1490
|
};
|
|
1448
1491
|
}
|
|
1449
|
-
|
|
1450
1492
|
}
|
|
1451
|
-
|
|
1493
|
+
let init = fetchState.optimizedPartitions;
|
|
1452
1494
|
return {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1495
|
+
optimizedPartitions: {
|
|
1496
|
+
idsInAscOrder: init.idsInAscOrder,
|
|
1497
|
+
entities: newEntities,
|
|
1498
|
+
maxAddrInPartition: init.maxAddrInPartition,
|
|
1499
|
+
nextPartitionIndex: init.nextPartitionIndex,
|
|
1500
|
+
dynamicContracts: init.dynamicContracts
|
|
1501
|
+
},
|
|
1502
|
+
startBlock: fetchState.startBlock,
|
|
1503
|
+
endBlock: fetchState.endBlock,
|
|
1504
|
+
normalSelection: fetchState.normalSelection,
|
|
1505
|
+
indexingAddresses: fetchState.indexingAddresses,
|
|
1506
|
+
contractConfigs: fetchState.contractConfigs,
|
|
1507
|
+
chainId: fetchState.chainId,
|
|
1508
|
+
latestOnBlockBlockNumber: fetchState.latestOnBlockBlockNumber,
|
|
1509
|
+
blockLag: fetchState.blockLag,
|
|
1510
|
+
buffer: fetchState.buffer,
|
|
1511
|
+
targetBufferSize: fetchState.targetBufferSize,
|
|
1512
|
+
onBlockConfigs: fetchState.onBlockConfigs,
|
|
1513
|
+
knownHeight: fetchState.knownHeight,
|
|
1514
|
+
firstEventBlock: fetchState.firstEventBlock
|
|
1515
|
+
};
|
|
1474
1516
|
}
|
|
1475
1517
|
|
|
1476
1518
|
function isActivelyIndexing(fetchState) {
|
|
1477
|
-
|
|
1519
|
+
let endBlock = fetchState.endBlock;
|
|
1478
1520
|
if (endBlock === undefined) {
|
|
1479
1521
|
return true;
|
|
1480
1522
|
}
|
|
1481
|
-
|
|
1523
|
+
let isPastEndblock = bufferBlockNumber(fetchState) >= endBlock;
|
|
1482
1524
|
if (isPastEndblock) {
|
|
1483
1525
|
return bufferSize(fetchState) > 0;
|
|
1484
1526
|
} else {
|
|
@@ -1487,10 +1529,10 @@ function isActivelyIndexing(fetchState) {
|
|
|
1487
1529
|
}
|
|
1488
1530
|
|
|
1489
1531
|
function isReadyToEnterReorgThreshold(fetchState) {
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1532
|
+
let knownHeight = fetchState.knownHeight;
|
|
1533
|
+
let blockLag = fetchState.blockLag;
|
|
1534
|
+
let endBlock = fetchState.endBlock;
|
|
1535
|
+
let bufferBlockNumber$1 = bufferBlockNumber(fetchState);
|
|
1494
1536
|
if (knownHeight !== 0 && (
|
|
1495
1537
|
endBlock !== undefined && bufferBlockNumber$1 >= endBlock ? true : bufferBlockNumber$1 >= (knownHeight - blockLag | 0)
|
|
1496
1538
|
)) {
|
|
@@ -1501,7 +1543,7 @@ function isReadyToEnterReorgThreshold(fetchState) {
|
|
|
1501
1543
|
}
|
|
1502
1544
|
|
|
1503
1545
|
function hasFullBatch(fetchState, batchSizeTarget) {
|
|
1504
|
-
|
|
1546
|
+
let item = Belt_Array.get(fetchState.buffer, batchSizeTarget - 1 | 0);
|
|
1505
1547
|
if (item !== undefined) {
|
|
1506
1548
|
return item.blockNumber <= bufferBlockNumber(fetchState);
|
|
1507
1549
|
} else {
|
|
@@ -1510,46 +1552,47 @@ function hasFullBatch(fetchState, batchSizeTarget) {
|
|
|
1510
1552
|
}
|
|
1511
1553
|
|
|
1512
1554
|
function getProgressPercentage(fetchState) {
|
|
1513
|
-
|
|
1555
|
+
let firstEventBlock = fetchState.firstEventBlock;
|
|
1514
1556
|
if (firstEventBlock === undefined) {
|
|
1515
1557
|
return 0;
|
|
1516
1558
|
}
|
|
1517
|
-
|
|
1559
|
+
let totalRange = fetchState.knownHeight - firstEventBlock | 0;
|
|
1518
1560
|
if (totalRange <= 0) {
|
|
1519
1561
|
return 0;
|
|
1520
1562
|
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1563
|
+
let item = Belt_Array.get(fetchState.buffer, 0);
|
|
1564
|
+
let progress = item !== undefined ? item.blockNumber - firstEventBlock | 0 : bufferBlockNumber(fetchState) - firstEventBlock | 0;
|
|
1523
1565
|
return progress / totalRange;
|
|
1524
1566
|
}
|
|
1525
1567
|
|
|
1526
1568
|
function sortForUnorderedBatch(fetchStates, batchSizeTarget) {
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1569
|
+
let copied = fetchStates.slice();
|
|
1570
|
+
copied.sort((a, b) => {
|
|
1571
|
+
let match = hasFullBatch(a, batchSizeTarget);
|
|
1572
|
+
let match$1 = hasFullBatch(b, batchSizeTarget);
|
|
1573
|
+
if (match) {
|
|
1574
|
+
if (!match$1) {
|
|
1575
|
+
return -1;
|
|
1576
|
+
}
|
|
1577
|
+
} else if (match$1) {
|
|
1578
|
+
return 1;
|
|
1579
|
+
}
|
|
1580
|
+
let aProgress = getProgressPercentage(a);
|
|
1581
|
+
let bProgress = getProgressPercentage(b);
|
|
1582
|
+
if (aProgress < bProgress) {
|
|
1583
|
+
return -1;
|
|
1584
|
+
} else if (aProgress > bProgress) {
|
|
1585
|
+
return 1;
|
|
1586
|
+
} else {
|
|
1587
|
+
return 0;
|
|
1588
|
+
}
|
|
1589
|
+
});
|
|
1590
|
+
return copied;
|
|
1548
1591
|
}
|
|
1549
1592
|
|
|
1550
1593
|
function getUnorderedMultichainProgressBlockNumberAt(fetchState, index) {
|
|
1551
|
-
|
|
1552
|
-
|
|
1594
|
+
let bufferBlockNumber$1 = bufferBlockNumber(fetchState);
|
|
1595
|
+
let item = Belt_Array.get(fetchState.buffer, index);
|
|
1553
1596
|
if (item !== undefined && bufferBlockNumber$1 >= item.blockNumber) {
|
|
1554
1597
|
return item.blockNumber - 1 | 0;
|
|
1555
1598
|
} else {
|
|
@@ -1566,39 +1609,40 @@ function updateKnownHeight(fetchState, knownHeight) {
|
|
|
1566
1609
|
}
|
|
1567
1610
|
}
|
|
1568
1611
|
|
|
1569
|
-
|
|
1612
|
+
let blockItemLogIndex = 16777216;
|
|
1570
1613
|
|
|
1571
1614
|
export {
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1615
|
+
deriveEffectiveStartBlock,
|
|
1616
|
+
getMinHistoryRange,
|
|
1617
|
+
getMinQueryRange,
|
|
1618
|
+
OptimizedPartitions,
|
|
1619
|
+
bufferBlockNumber,
|
|
1620
|
+
bufferBlock,
|
|
1621
|
+
compareBufferItem,
|
|
1622
|
+
blockItemLogIndex,
|
|
1623
|
+
numAddresses,
|
|
1624
|
+
updateInternal,
|
|
1625
|
+
warnDifferentContractType,
|
|
1626
|
+
addressesByContractNameCount,
|
|
1627
|
+
addressesByContractNameGetAll,
|
|
1628
|
+
createPartitionsFromIndexingAddresses,
|
|
1629
|
+
registerDynamicContracts,
|
|
1630
|
+
handleQueryResult,
|
|
1631
|
+
startFetchingQueries,
|
|
1632
|
+
pushQueriesForRange,
|
|
1633
|
+
getNextQuery,
|
|
1634
|
+
getTimestampAt,
|
|
1635
|
+
hasReadyItem,
|
|
1636
|
+
getReadyItemsCount,
|
|
1593
1637
|
make$1 as make,
|
|
1594
|
-
bufferSize
|
|
1595
|
-
rollbackPendingQueries
|
|
1596
|
-
rollback
|
|
1597
|
-
resetPendingQueries
|
|
1598
|
-
isActivelyIndexing
|
|
1599
|
-
isReadyToEnterReorgThreshold
|
|
1600
|
-
sortForUnorderedBatch
|
|
1601
|
-
getUnorderedMultichainProgressBlockNumberAt
|
|
1602
|
-
updateKnownHeight
|
|
1638
|
+
bufferSize,
|
|
1639
|
+
rollbackPendingQueries,
|
|
1640
|
+
rollback,
|
|
1641
|
+
resetPendingQueries,
|
|
1642
|
+
isActivelyIndexing,
|
|
1643
|
+
isReadyToEnterReorgThreshold,
|
|
1644
|
+
sortForUnorderedBatch,
|
|
1645
|
+
getUnorderedMultichainProgressBlockNumberAt,
|
|
1646
|
+
updateKnownHeight,
|
|
1603
1647
|
}
|
|
1604
1648
|
/* Utils Not a pure module */
|