envio 3.3.0-alpha.8 → 3.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +19 -0
- package/licenses/CLA.md +35 -0
- package/licenses/EULA.md +67 -0
- package/licenses/LICENSE.md +45 -0
- package/licenses/README.md +35 -0
- package/package.json +9 -8
- package/src/Batch.res.mjs +1 -1
- package/src/BatchProcessing.res +0 -7
- package/src/BatchProcessing.res.mjs +1 -8
- package/src/ChainFetching.res +30 -18
- package/src/ChainFetching.res.mjs +23 -13
- package/src/ChainState.res +205 -59
- package/src/ChainState.res.mjs +130 -27
- package/src/ChainState.resi +16 -1
- package/src/Config.res +9 -5
- package/src/Config.res.mjs +2 -2
- package/src/Core.res +20 -0
- package/src/Core.res.mjs +12 -0
- package/src/CrossChainState.res +147 -39
- package/src/CrossChainState.res.mjs +42 -10
- package/src/EffectState.res +100 -0
- package/src/EffectState.res.mjs +74 -0
- package/src/EffectState.resi +32 -0
- package/src/Envio.res +25 -7
- package/src/Envio.res.mjs +15 -19
- package/src/EnvioGlobal.res +53 -0
- package/src/EnvioGlobal.res.mjs +31 -0
- package/src/EventConfigBuilder.res +30 -56
- package/src/EventConfigBuilder.res.mjs +24 -30
- package/src/EventProcessing.res +8 -5
- package/src/EventProcessing.res.mjs +2 -1
- package/src/FetchState.res +842 -474
- package/src/FetchState.res.mjs +545 -356
- package/src/HandlerLoader.res +1 -1
- package/src/HandlerLoader.res.mjs +1 -1
- package/src/HandlerRegister.res +478 -305
- package/src/HandlerRegister.res.mjs +277 -209
- package/src/HandlerRegister.resi +11 -6
- package/src/InMemoryStore.res +14 -26
- package/src/InMemoryStore.res.mjs +6 -19
- package/src/IndexerState.res +15 -39
- package/src/IndexerState.res.mjs +18 -29
- package/src/IndexerState.resi +2 -10
- package/src/Internal.res +121 -18
- package/src/Internal.res.mjs +96 -2
- package/src/LoadLayer.res +44 -24
- package/src/LoadLayer.res.mjs +43 -20
- package/src/LoadLayer.resi +1 -0
- package/src/LogSelection.res +92 -217
- package/src/LogSelection.res.mjs +95 -184
- package/src/Main.res +29 -143
- package/src/Main.res.mjs +25 -88
- package/src/Metrics.res +1 -1
- package/src/Metrics.res.mjs +1 -1
- package/src/Persistence.res +12 -3
- package/src/PgStorage.res +155 -82
- package/src/PgStorage.res.mjs +130 -77
- package/src/Prometheus.res +20 -10
- package/src/Prometheus.res.mjs +22 -10
- package/src/PruneStaleHistory.res +146 -35
- package/src/PruneStaleHistory.res.mjs +114 -20
- package/src/RawEvent.res +2 -2
- package/src/Rollback.res +32 -13
- package/src/Rollback.res.mjs +24 -11
- package/src/RollbackCommit.res +4 -1
- package/src/RollbackCommit.res.mjs +3 -2
- package/src/SimulateDeadInputTracker.res +1 -1
- package/src/SimulateItems.res +39 -7
- package/src/SimulateItems.res.mjs +28 -9
- package/src/TestIndexer.res +2 -2
- package/src/TestIndexer.res.mjs +2 -2
- package/src/TopicFilter.res +1 -25
- package/src/TopicFilter.res.mjs +0 -74
- package/src/UserContext.res +62 -23
- package/src/UserContext.res.mjs +26 -6
- package/src/Writing.res +60 -21
- package/src/Writing.res.mjs +27 -9
- package/src/bindings/NodeJs.res +5 -0
- package/src/bindings/Viem.res +0 -5
- package/src/sources/EventRouter.res +0 -21
- package/src/sources/EventRouter.res.mjs +0 -12
- package/src/sources/Evm.res +4 -1
- package/src/sources/Evm.res.mjs +1 -1
- package/src/sources/EvmChain.res +2 -27
- package/src/sources/EvmChain.res.mjs +2 -23
- package/src/sources/EvmRpcClient.res +58 -23
- package/src/sources/EvmRpcClient.res.mjs +11 -5
- package/src/sources/Fuel.res +3 -1
- package/src/sources/Fuel.res.mjs +1 -1
- package/src/sources/HyperSync.res +9 -38
- package/src/sources/HyperSync.res.mjs +16 -28
- package/src/sources/HyperSync.resi +2 -2
- package/src/sources/HyperSyncClient.res +88 -11
- package/src/sources/HyperSyncClient.res.mjs +39 -6
- package/src/sources/HyperSyncSource.res +18 -210
- package/src/sources/HyperSyncSource.res.mjs +9 -137
- package/src/sources/Rpc.res +0 -32
- package/src/sources/Rpc.res.mjs +1 -46
- package/src/sources/RpcSource.res +129 -533
- package/src/sources/RpcSource.res.mjs +161 -379
- package/src/sources/SimulateSource.res +37 -19
- package/src/sources/SimulateSource.res.mjs +27 -10
- package/src/sources/SourceManager.res +4 -14
- package/src/sources/SourceManager.res.mjs +3 -9
- package/src/sources/SourceManager.resi +0 -2
- package/src/sources/SvmHyperSyncSource.res +13 -3
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
package/src/FetchState.res.mjs
CHANGED
|
@@ -23,25 +23,28 @@ let deriveContractNameByAddress = Utils.$$WeakMap.memoize(addressesByContractNam
|
|
|
23
23
|
return result;
|
|
24
24
|
});
|
|
25
25
|
|
|
26
|
-
function densityItemsTarget(
|
|
27
|
-
|
|
28
|
-
return ((Stdlib_Option.getOr(toBlock, chainTargetBlock) - fromBlock | 0) + 1 | 0) * density;
|
|
26
|
+
function densityItemsTarget(density, fromBlock, toBlock, chainTargetBlock) {
|
|
27
|
+
return Primitive_int.max(1, Math.ceil(((Stdlib_Option.getOr(toBlock, chainTargetBlock) - fromBlock | 0) + 1 | 0) * density) | 0);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
function getMinHistoryRange(p) {
|
|
32
|
-
let match = p.
|
|
33
|
-
let match$1 = p.
|
|
31
|
+
let match = p.sourceRangeCapacity;
|
|
32
|
+
let match$1 = p.prevSourceRangeCapacity;
|
|
34
33
|
if (match !== 0 && match$1 !== 0) {
|
|
35
34
|
return match < match$1 ? match : match$1;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
function getTrustedDensity(p) {
|
|
39
|
+
return p.eventDensity;
|
|
40
|
+
}
|
|
41
|
+
|
|
39
42
|
function getMinQueryRange(partitions) {
|
|
40
43
|
let min = 0;
|
|
41
44
|
for (let i = 0, i_finish = partitions.length; i < i_finish; ++i) {
|
|
42
45
|
let p = partitions[i];
|
|
43
|
-
let a = p.
|
|
44
|
-
let b = p.
|
|
46
|
+
let a = p.sourceRangeCapacity;
|
|
47
|
+
let b = p.prevSourceRangeCapacity;
|
|
45
48
|
if (a > 0 && (min === 0 || a < min)) {
|
|
46
49
|
min = a;
|
|
47
50
|
}
|
|
@@ -81,10 +84,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
81
84
|
mergeBlock: potentialMergeBlock,
|
|
82
85
|
dynamicContract: p1.dynamicContract,
|
|
83
86
|
mutPendingQueries: p1.mutPendingQueries,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
sourceRangeCapacity: p1.sourceRangeCapacity,
|
|
88
|
+
prevSourceRangeCapacity: p1.prevSourceRangeCapacity,
|
|
89
|
+
eventDensity: p1.eventDensity,
|
|
90
|
+
latestSourceRangeCapacityUpdateBlock: p1.latestSourceRangeCapacityUpdateBlock
|
|
88
91
|
});
|
|
89
92
|
completed.push({
|
|
90
93
|
id: p2.id,
|
|
@@ -94,10 +97,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
94
97
|
mergeBlock: potentialMergeBlock,
|
|
95
98
|
dynamicContract: p2.dynamicContract,
|
|
96
99
|
mutPendingQueries: p2.mutPendingQueries,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
sourceRangeCapacity: p2.sourceRangeCapacity,
|
|
101
|
+
prevSourceRangeCapacity: p2.prevSourceRangeCapacity,
|
|
102
|
+
eventDensity: p2.eventDensity,
|
|
103
|
+
latestSourceRangeCapacityUpdateBlock: p2.latestSourceRangeCapacityUpdateBlock
|
|
101
104
|
});
|
|
102
105
|
let newId = nextPartitionIndexRef.contents.toString();
|
|
103
106
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
@@ -105,6 +108,13 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
105
108
|
p1,
|
|
106
109
|
p2
|
|
107
110
|
]);
|
|
111
|
+
let match = p1.eventDensity;
|
|
112
|
+
let match$1 = p2.eventDensity;
|
|
113
|
+
let inheritedDensity = match !== undefined ? (
|
|
114
|
+
match$1 !== undefined ? match + match$1 : match
|
|
115
|
+
) : (
|
|
116
|
+
match$1 !== undefined ? match$1 : undefined
|
|
117
|
+
);
|
|
108
118
|
continuingBase = {
|
|
109
119
|
id: newId,
|
|
110
120
|
latestFetchedBlock: {
|
|
@@ -116,10 +126,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
116
126
|
mergeBlock: undefined,
|
|
117
127
|
dynamicContract: contractName,
|
|
118
128
|
mutPendingQueries: [],
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
129
|
+
sourceRangeCapacity: minRange,
|
|
130
|
+
prevSourceRangeCapacity: minRange,
|
|
131
|
+
eventDensity: inheritedDensity,
|
|
132
|
+
latestSourceRangeCapacityUpdateBlock: 0
|
|
123
133
|
};
|
|
124
134
|
} else {
|
|
125
135
|
completed.push({
|
|
@@ -130,10 +140,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
130
140
|
mergeBlock: potentialMergeBlock,
|
|
131
141
|
dynamicContract: p1.dynamicContract,
|
|
132
142
|
mutPendingQueries: p1.mutPendingQueries,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
sourceRangeCapacity: p1.sourceRangeCapacity,
|
|
144
|
+
prevSourceRangeCapacity: p1.prevSourceRangeCapacity,
|
|
145
|
+
eventDensity: p1.eventDensity,
|
|
146
|
+
latestSourceRangeCapacityUpdateBlock: p1.latestSourceRangeCapacityUpdateBlock
|
|
137
147
|
});
|
|
138
148
|
continuingBase = p2;
|
|
139
149
|
}
|
|
@@ -146,10 +156,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
146
156
|
mergeBlock: potentialMergeBlock,
|
|
147
157
|
dynamicContract: p2.dynamicContract,
|
|
148
158
|
mutPendingQueries: p2.mutPendingQueries,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
sourceRangeCapacity: p2.sourceRangeCapacity,
|
|
160
|
+
prevSourceRangeCapacity: p2.prevSourceRangeCapacity,
|
|
161
|
+
eventDensity: p2.eventDensity,
|
|
162
|
+
latestSourceRangeCapacityUpdateBlock: p2.latestSourceRangeCapacityUpdateBlock
|
|
153
163
|
});
|
|
154
164
|
continuingBase = p1;
|
|
155
165
|
} else {
|
|
@@ -170,10 +180,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
170
180
|
mergeBlock: continuingBase.mergeBlock,
|
|
171
181
|
dynamicContract: continuingBase.dynamicContract,
|
|
172
182
|
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
183
|
+
sourceRangeCapacity: continuingBase.sourceRangeCapacity,
|
|
184
|
+
prevSourceRangeCapacity: continuingBase.prevSourceRangeCapacity,
|
|
185
|
+
eventDensity: continuingBase.eventDensity,
|
|
186
|
+
latestSourceRangeCapacityUpdateBlock: continuingBase.latestSourceRangeCapacityUpdateBlock
|
|
177
187
|
});
|
|
178
188
|
let restId = nextPartitionIndexRef.contents.toString();
|
|
179
189
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
@@ -185,10 +195,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
185
195
|
mergeBlock: continuingBase.mergeBlock,
|
|
186
196
|
dynamicContract: continuingBase.dynamicContract,
|
|
187
197
|
mutPendingQueries: [],
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
198
|
+
sourceRangeCapacity: continuingBase.sourceRangeCapacity,
|
|
199
|
+
prevSourceRangeCapacity: continuingBase.prevSourceRangeCapacity,
|
|
200
|
+
eventDensity: continuingBase.eventDensity,
|
|
201
|
+
latestSourceRangeCapacityUpdateBlock: continuingBase.latestSourceRangeCapacityUpdateBlock
|
|
192
202
|
});
|
|
193
203
|
return completed;
|
|
194
204
|
}
|
|
@@ -202,10 +212,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
202
212
|
mergeBlock: continuingBase.mergeBlock,
|
|
203
213
|
dynamicContract: continuingBase.dynamicContract,
|
|
204
214
|
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
sourceRangeCapacity: continuingBase.sourceRangeCapacity,
|
|
216
|
+
prevSourceRangeCapacity: continuingBase.prevSourceRangeCapacity,
|
|
217
|
+
eventDensity: continuingBase.eventDensity,
|
|
218
|
+
latestSourceRangeCapacityUpdateBlock: continuingBase.latestSourceRangeCapacityUpdateBlock
|
|
209
219
|
});
|
|
210
220
|
return completed;
|
|
211
221
|
}
|
|
@@ -310,17 +320,25 @@ function make(partitions, maxAddrInPartition, nextPartitionIndex, dynamicContrac
|
|
|
310
320
|
|
|
311
321
|
function consumeFetchedQueries(mutPendingQueries, initialLatestFetchedBlock) {
|
|
312
322
|
let latestFetchedBlock = initialLatestFetchedBlock;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
323
|
+
let consumedCount = 0;
|
|
324
|
+
let canContinue = true;
|
|
325
|
+
while (canContinue) {
|
|
326
|
+
let match = mutPendingQueries[consumedCount];
|
|
327
|
+
if (match !== undefined) {
|
|
328
|
+
let fetchedBlock = match.fetchedBlock;
|
|
329
|
+
if (fetchedBlock !== undefined && match.fromBlock <= (latestFetchedBlock.blockNumber + 1 | 0)) {
|
|
330
|
+
latestFetchedBlock = fetchedBlock;
|
|
331
|
+
consumedCount = consumedCount + 1 | 0;
|
|
332
|
+
} else {
|
|
333
|
+
canContinue = false;
|
|
318
334
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
latestFetchedBlock = removedQuery.fetchedBlock;
|
|
335
|
+
} else {
|
|
336
|
+
canContinue = false;
|
|
337
|
+
}
|
|
323
338
|
};
|
|
339
|
+
if (consumedCount > 0) {
|
|
340
|
+
mutPendingQueries.splice(0, consumedCount);
|
|
341
|
+
}
|
|
324
342
|
return latestFetchedBlock;
|
|
325
343
|
}
|
|
326
344
|
|
|
@@ -350,67 +368,112 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
|
|
|
350
368
|
let pendingQuery = getPendingQueryOrThrow(p$1, query.fromBlock);
|
|
351
369
|
pendingQuery.fetchedBlock = latestFetchedBlock;
|
|
352
370
|
let blockRange = (latestFetchedBlock.blockNumber - query.fromBlock | 0) + 1 | 0;
|
|
353
|
-
let
|
|
354
|
-
|
|
371
|
+
let observedEventDensity = itemsCount / blockRange;
|
|
372
|
+
let eventDensity = p$1.eventDensity;
|
|
373
|
+
let updatedEventDensity = eventDensity !== undefined ? (eventDensity + observedEventDensity) / 2 : observedEventDensity;
|
|
374
|
+
let shouldUpdateSourceRangeCapacity = false;
|
|
375
|
+
if (latestFetchedBlock.blockNumber > p$1.latestSourceRangeCapacityUpdateBlock) {
|
|
355
376
|
let queryToBlock = query.toBlock;
|
|
356
377
|
let tmp;
|
|
357
378
|
if (queryToBlock !== undefined) {
|
|
358
|
-
if (latestFetchedBlock.blockNumber
|
|
379
|
+
if (latestFetchedBlock.blockNumber < queryToBlock) {
|
|
380
|
+
tmp = itemsCount < query.itemsTarget;
|
|
381
|
+
} else {
|
|
359
382
|
let minHistoryRange = getMinHistoryRange(p$1);
|
|
360
383
|
tmp = minHistoryRange !== undefined ? ((queryToBlock - query.fromBlock | 0) + 1 | 0) >= minHistoryRange : false;
|
|
361
|
-
} else {
|
|
362
|
-
tmp = true;
|
|
363
384
|
}
|
|
364
385
|
} else {
|
|
365
386
|
tmp = latestFetchedBlock.blockNumber < (knownHeight - 10 | 0);
|
|
366
387
|
}
|
|
367
|
-
|
|
388
|
+
shouldUpdateSourceRangeCapacity = tmp;
|
|
368
389
|
}
|
|
369
|
-
let
|
|
370
|
-
let
|
|
371
|
-
let updatedPrevRangeSize = shouldUpdateBlockRange ? itemsCount : p$1.prevRangeSize;
|
|
390
|
+
let updatedSourceRangeCapacity = shouldUpdateSourceRangeCapacity ? blockRange : p$1.sourceRangeCapacity;
|
|
391
|
+
let updatedPrevSourceRangeCapacity = shouldUpdateSourceRangeCapacity ? p$1.sourceRangeCapacity : p$1.prevSourceRangeCapacity;
|
|
372
392
|
let mutPendingQueries = p$1.mutPendingQueries;
|
|
373
393
|
let latestFetchedBlock$1 = p$1.latestFetchedBlock;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
394
|
+
let consumedCount = 0;
|
|
395
|
+
let canContinue = true;
|
|
396
|
+
while (canContinue) {
|
|
397
|
+
let match = mutPendingQueries[consumedCount];
|
|
398
|
+
if (match !== undefined) {
|
|
399
|
+
let fetchedBlock = match.fetchedBlock;
|
|
400
|
+
if (fetchedBlock !== undefined && match.fromBlock <= (latestFetchedBlock$1.blockNumber + 1 | 0)) {
|
|
401
|
+
latestFetchedBlock$1 = fetchedBlock;
|
|
402
|
+
consumedCount = consumedCount + 1 | 0;
|
|
403
|
+
} else {
|
|
404
|
+
canContinue = false;
|
|
379
405
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
latestFetchedBlock$1 = removedQuery.fetchedBlock;
|
|
406
|
+
} else {
|
|
407
|
+
canContinue = false;
|
|
408
|
+
}
|
|
384
409
|
};
|
|
410
|
+
if (consumedCount > 0) {
|
|
411
|
+
mutPendingQueries.splice(0, consumedCount);
|
|
412
|
+
}
|
|
385
413
|
let updatedLatestFetchedBlock = latestFetchedBlock$1;
|
|
386
414
|
let mergeBlock = p$1.mergeBlock;
|
|
387
415
|
let partitionReachedMergeBlock = mergeBlock !== undefined ? updatedLatestFetchedBlock.blockNumber >= mergeBlock : false;
|
|
388
416
|
if (partitionReachedMergeBlock) {
|
|
389
417
|
Utils.Dict.deleteInPlace(mutEntities, p$1.id);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
418
|
+
return make(Object.values(mutEntities), optimizedPartitions.maxAddrInPartition, optimizedPartitions.nextPartitionIndex, optimizedPartitions.dynamicContracts);
|
|
419
|
+
}
|
|
420
|
+
let updatedMainPartition_id = p$1.id;
|
|
421
|
+
let updatedMainPartition_selection = p$1.selection;
|
|
422
|
+
let updatedMainPartition_addressesByContractName = p$1.addressesByContractName;
|
|
423
|
+
let updatedMainPartition_mergeBlock = p$1.mergeBlock;
|
|
424
|
+
let updatedMainPartition_dynamicContract = p$1.dynamicContract;
|
|
425
|
+
let updatedMainPartition_mutPendingQueries = p$1.mutPendingQueries;
|
|
426
|
+
let updatedMainPartition_latestSourceRangeCapacityUpdateBlock = shouldUpdateSourceRangeCapacity ? latestFetchedBlock.blockNumber : p$1.latestSourceRangeCapacityUpdateBlock;
|
|
427
|
+
let updatedMainPartition = {
|
|
428
|
+
id: updatedMainPartition_id,
|
|
429
|
+
latestFetchedBlock: updatedLatestFetchedBlock,
|
|
430
|
+
selection: updatedMainPartition_selection,
|
|
431
|
+
addressesByContractName: updatedMainPartition_addressesByContractName,
|
|
432
|
+
mergeBlock: updatedMainPartition_mergeBlock,
|
|
433
|
+
dynamicContract: updatedMainPartition_dynamicContract,
|
|
434
|
+
mutPendingQueries: updatedMainPartition_mutPendingQueries,
|
|
435
|
+
sourceRangeCapacity: updatedSourceRangeCapacity,
|
|
436
|
+
prevSourceRangeCapacity: updatedPrevSourceRangeCapacity,
|
|
437
|
+
eventDensity: updatedEventDensity,
|
|
438
|
+
latestSourceRangeCapacityUpdateBlock: updatedMainPartition_latestSourceRangeCapacityUpdateBlock
|
|
439
|
+
};
|
|
440
|
+
mutEntities[p$1.id] = updatedMainPartition;
|
|
441
|
+
if (optimizedPartitions.dynamicContracts.size !== 0) {
|
|
442
|
+
return make(Object.values(mutEntities), optimizedPartitions.maxAddrInPartition, optimizedPartitions.nextPartitionIndex, optimizedPartitions.dynamicContracts);
|
|
443
|
+
}
|
|
444
|
+
let ids = optimizedPartitions.idsInAscOrder;
|
|
445
|
+
let count = ids.length;
|
|
446
|
+
let idx = ids.indexOf(p$1.id);
|
|
447
|
+
let isAfter = jdx => {
|
|
448
|
+
if (jdx < count) {
|
|
449
|
+
return mutEntities[ids[jdx]].latestFetchedBlock.blockNumber < updatedLatestFetchedBlock.blockNumber;
|
|
450
|
+
} else {
|
|
451
|
+
return false;
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
if (!isAfter(idx + 1 | 0)) {
|
|
455
|
+
return {
|
|
456
|
+
idsInAscOrder: optimizedPartitions.idsInAscOrder,
|
|
457
|
+
entities: mutEntities,
|
|
458
|
+
maxAddrInPartition: optimizedPartitions.maxAddrInPartition,
|
|
459
|
+
nextPartitionIndex: optimizedPartitions.nextPartitionIndex,
|
|
460
|
+
dynamicContracts: optimizedPartitions.dynamicContracts
|
|
410
461
|
};
|
|
411
|
-
mutEntities[p$1.id] = updatedMainPartition;
|
|
412
462
|
}
|
|
413
|
-
|
|
463
|
+
let reordered = ids.slice();
|
|
464
|
+
let jdx = idx;
|
|
465
|
+
while (isAfter(jdx + 1 | 0)) {
|
|
466
|
+
reordered[jdx] = ids[jdx + 1 | 0];
|
|
467
|
+
jdx = jdx + 1 | 0;
|
|
468
|
+
};
|
|
469
|
+
reordered[jdx] = p$1.id;
|
|
470
|
+
return {
|
|
471
|
+
idsInAscOrder: reordered,
|
|
472
|
+
entities: mutEntities,
|
|
473
|
+
maxAddrInPartition: optimizedPartitions.maxAddrInPartition,
|
|
474
|
+
nextPartitionIndex: optimizedPartitions.nextPartitionIndex,
|
|
475
|
+
dynamicContracts: optimizedPartitions.dynamicContracts
|
|
476
|
+
};
|
|
414
477
|
}
|
|
415
478
|
|
|
416
479
|
function getLatestFullyFetchedBlock(optimizedPartitions) {
|
|
@@ -476,13 +539,90 @@ function bufferReadyCount(fetchState) {
|
|
|
476
539
|
return lo;
|
|
477
540
|
}
|
|
478
541
|
|
|
542
|
+
function getRegistrationIndex(item) {
|
|
543
|
+
if (item.kind === 0) {
|
|
544
|
+
return item.onEventRegistration.index;
|
|
545
|
+
} else {
|
|
546
|
+
return item.onBlockRegistration.index;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
479
550
|
function compareBufferItem(a, b) {
|
|
480
|
-
let
|
|
481
|
-
|
|
482
|
-
|
|
551
|
+
let ba = a.blockNumber;
|
|
552
|
+
let bb = b.blockNumber;
|
|
553
|
+
if (ba !== bb) {
|
|
554
|
+
if (ba < bb) {
|
|
555
|
+
return -1;
|
|
556
|
+
} else {
|
|
557
|
+
return 1;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
let la = a.logIndex;
|
|
561
|
+
let lb = b.logIndex;
|
|
562
|
+
if (la !== lb) {
|
|
563
|
+
if (la < lb) {
|
|
564
|
+
return -1;
|
|
565
|
+
} else {
|
|
566
|
+
return 1;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
let ia = getRegistrationIndex(a);
|
|
570
|
+
let ib = getRegistrationIndex(b);
|
|
571
|
+
if (ia < ib) {
|
|
572
|
+
return -1;
|
|
573
|
+
} else if (ia > ib) {
|
|
574
|
+
return 1;
|
|
483
575
|
} else {
|
|
484
|
-
return
|
|
576
|
+
return 0;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function mergeIntoBuffer(buffer, newItems) {
|
|
581
|
+
let n = newItems.length;
|
|
582
|
+
for (let i = 1; i < n; ++i) {
|
|
583
|
+
let x = newItems[i];
|
|
584
|
+
let j = i - 1 | 0;
|
|
585
|
+
while (j >= 0 && compareBufferItem(newItems[j], x) > 0) {
|
|
586
|
+
newItems[j + 1 | 0] = newItems[j];
|
|
587
|
+
j = j - 1 | 0;
|
|
588
|
+
};
|
|
589
|
+
newItems[j + 1 | 0] = x;
|
|
485
590
|
}
|
|
591
|
+
let m = buffer.length;
|
|
592
|
+
let merged = [];
|
|
593
|
+
let last = {
|
|
594
|
+
contents: undefined
|
|
595
|
+
};
|
|
596
|
+
let push = item => {
|
|
597
|
+
let l = last.contents;
|
|
598
|
+
if (l !== undefined && compareBufferItem(l, item) === 0) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
merged.push(item);
|
|
602
|
+
last.contents = item;
|
|
603
|
+
};
|
|
604
|
+
let i$1 = 0;
|
|
605
|
+
let j$1 = 0;
|
|
606
|
+
while (i$1 < m && j$1 < n) {
|
|
607
|
+
let a = buffer[i$1];
|
|
608
|
+
let b = newItems[j$1];
|
|
609
|
+
if (compareBufferItem(a, b) <= 0) {
|
|
610
|
+
push(a);
|
|
611
|
+
i$1 = i$1 + 1 | 0;
|
|
612
|
+
} else {
|
|
613
|
+
push(b);
|
|
614
|
+
j$1 = j$1 + 1 | 0;
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
while (i$1 < m) {
|
|
618
|
+
push(buffer[i$1]);
|
|
619
|
+
i$1 = i$1 + 1 | 0;
|
|
620
|
+
};
|
|
621
|
+
while (j$1 < n) {
|
|
622
|
+
push(newItems[j$1]);
|
|
623
|
+
j$1 = j$1 + 1 | 0;
|
|
624
|
+
};
|
|
625
|
+
return merged;
|
|
486
626
|
}
|
|
487
627
|
|
|
488
628
|
function appendOnBlockItems(mutItems, onBlockRegistrations, indexerStartBlock, fromBlock, maxBlockNumber, maxOnBlockBufferSize) {
|
|
@@ -514,18 +654,19 @@ function appendOnBlockItems(mutItems, onBlockRegistrations, indexerStartBlock, f
|
|
|
514
654
|
return latestOnBlockBlockNumber;
|
|
515
655
|
}
|
|
516
656
|
|
|
517
|
-
function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOpt, knownHeightOpt) {
|
|
657
|
+
function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, mutItemsSortedOpt, blockLagOpt, knownHeightOpt) {
|
|
518
658
|
let optimizedPartitions = optimizedPartitionsOpt !== undefined ? optimizedPartitionsOpt : fetchState.optimizedPartitions;
|
|
659
|
+
let mutItemsSorted = mutItemsSortedOpt !== undefined ? mutItemsSortedOpt : false;
|
|
519
660
|
let blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
|
|
520
661
|
let knownHeight = knownHeightOpt !== undefined ? knownHeightOpt : fetchState.knownHeight;
|
|
521
|
-
let
|
|
662
|
+
let base = mutItems !== undefined ? (
|
|
663
|
+
mutItemsSorted ? mutItems : mergeIntoBuffer([], mutItems)
|
|
664
|
+
) : fetchState.buffer;
|
|
665
|
+
let blockItems = [];
|
|
522
666
|
let onBlockRegistrations = fetchState.onBlockRegistrations;
|
|
523
667
|
let latestOnBlockBlockNumber;
|
|
524
668
|
if (onBlockRegistrations.length !== 0) {
|
|
525
|
-
let
|
|
526
|
-
let item = (
|
|
527
|
-
mutItems$1 !== undefined ? mutItems$1 : fetchState.buffer
|
|
528
|
-
)[fetchState.maxOnBlockBufferSize - 1 | 0];
|
|
669
|
+
let item = base[fetchState.maxOnBlockBufferSize - 1 | 0];
|
|
529
670
|
let maxBlockNumber;
|
|
530
671
|
if (item !== undefined) {
|
|
531
672
|
maxBlockNumber = item.blockNumber;
|
|
@@ -534,20 +675,16 @@ function updateInternal(fetchState, optimizedPartitionsOpt, mutItems, blockLagOp
|
|
|
534
675
|
let latestFullyFetchedBlock = id !== undefined ? optimizedPartitions.entities[id].latestFetchedBlock : undefined;
|
|
535
676
|
maxBlockNumber = latestFullyFetchedBlock !== undefined ? latestFullyFetchedBlock.blockNumber : knownHeight;
|
|
536
677
|
}
|
|
537
|
-
|
|
538
|
-
let mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.buffer.slice();
|
|
539
|
-
mutItemsRef = mutItems$3;
|
|
540
|
-
latestOnBlockBlockNumber = appendOnBlockItems(mutItems$3, onBlockRegistrations, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
|
|
678
|
+
latestOnBlockBlockNumber = appendOnBlockItems(blockItems, onBlockRegistrations, fetchState.startBlock, fetchState.latestOnBlockBlockNumber, maxBlockNumber, fetchState.maxOnBlockBufferSize);
|
|
541
679
|
} else {
|
|
542
680
|
latestOnBlockBlockNumber = knownHeight;
|
|
543
681
|
}
|
|
544
|
-
let mutItems$4 = mutItemsRef;
|
|
545
682
|
let updatedFetchState_startBlock = fetchState.startBlock;
|
|
546
683
|
let updatedFetchState_endBlock = fetchState.endBlock;
|
|
547
684
|
let updatedFetchState_normalSelection = fetchState.normalSelection;
|
|
548
685
|
let updatedFetchState_contractConfigs = fetchState.contractConfigs;
|
|
549
686
|
let updatedFetchState_chainId = fetchState.chainId;
|
|
550
|
-
let updatedFetchState_buffer =
|
|
687
|
+
let updatedFetchState_buffer = blockItems.length !== 0 ? mergeIntoBuffer(base, blockItems) : base;
|
|
551
688
|
let updatedFetchState_maxOnBlockBufferSize = fetchState.maxOnBlockBufferSize;
|
|
552
689
|
let updatedFetchState_onBlockRegistrations = fetchState.onBlockRegistrations;
|
|
553
690
|
let updatedFetchState_firstEventBlock = fetchState.firstEventBlock;
|
|
@@ -657,10 +794,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
657
794
|
mergeBlock: undefined,
|
|
658
795
|
dynamicContract: isDynamic ? contractName : undefined,
|
|
659
796
|
mutPendingQueries: [],
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
797
|
+
sourceRangeCapacity: 0,
|
|
798
|
+
prevSourceRangeCapacity: 0,
|
|
799
|
+
eventDensity: undefined,
|
|
800
|
+
latestSourceRangeCapacityUpdateBlock: 0
|
|
664
801
|
});
|
|
665
802
|
nextPartitionIndexRef = nextPartitionIndexRef + 1 | 0;
|
|
666
803
|
};
|
|
@@ -708,10 +845,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
708
845
|
mergeBlock: currentPBlock < nextPBlock ? nextPBlock : undefined,
|
|
709
846
|
dynamicContract: currentP.dynamicContract,
|
|
710
847
|
mutPendingQueries: currentP.mutPendingQueries,
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
848
|
+
sourceRangeCapacity: currentP.sourceRangeCapacity,
|
|
849
|
+
prevSourceRangeCapacity: currentP.prevSourceRangeCapacity,
|
|
850
|
+
eventDensity: currentP.eventDensity,
|
|
851
|
+
latestSourceRangeCapacityUpdateBlock: currentP.latestSourceRangeCapacityUpdateBlock
|
|
715
852
|
});
|
|
716
853
|
currentPRef = {
|
|
717
854
|
id: nextP.id,
|
|
@@ -721,10 +858,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
721
858
|
mergeBlock: nextP.mergeBlock,
|
|
722
859
|
dynamicContract: nextP.dynamicContract,
|
|
723
860
|
mutPendingQueries: nextP.mutPendingQueries,
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
861
|
+
sourceRangeCapacity: nextP.sourceRangeCapacity,
|
|
862
|
+
prevSourceRangeCapacity: nextP.prevSourceRangeCapacity,
|
|
863
|
+
eventDensity: nextP.eventDensity,
|
|
864
|
+
latestSourceRangeCapacityUpdateBlock: nextP.latestSourceRangeCapacityUpdateBlock
|
|
728
865
|
};
|
|
729
866
|
} else {
|
|
730
867
|
currentPRef = {
|
|
@@ -735,10 +872,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
735
872
|
mergeBlock: currentP.mergeBlock,
|
|
736
873
|
dynamicContract: currentP.dynamicContract,
|
|
737
874
|
mutPendingQueries: currentP.mutPendingQueries,
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
875
|
+
sourceRangeCapacity: currentP.sourceRangeCapacity,
|
|
876
|
+
prevSourceRangeCapacity: currentP.prevSourceRangeCapacity,
|
|
877
|
+
eventDensity: currentP.eventDensity,
|
|
878
|
+
latestSourceRangeCapacityUpdateBlock: currentP.latestSourceRangeCapacityUpdateBlock
|
|
742
879
|
};
|
|
743
880
|
}
|
|
744
881
|
}
|
|
@@ -885,10 +1022,10 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
885
1022
|
mergeBlock: p.mergeBlock,
|
|
886
1023
|
dynamicContract: p.dynamicContract,
|
|
887
1024
|
mutPendingQueries: p.mutPendingQueries,
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1025
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1026
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1027
|
+
eventDensity: p.eventDensity,
|
|
1028
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
892
1029
|
};
|
|
893
1030
|
let addressesByContractName = {};
|
|
894
1031
|
addressesByContractName[contractName] = addresses;
|
|
@@ -900,10 +1037,10 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
900
1037
|
mergeBlock: undefined,
|
|
901
1038
|
dynamicContract: contractName,
|
|
902
1039
|
mutPendingQueries: p.mutPendingQueries,
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1040
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1041
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1042
|
+
eventDensity: p.eventDensity,
|
|
1043
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
907
1044
|
});
|
|
908
1045
|
}
|
|
909
1046
|
} else {
|
|
@@ -915,10 +1052,10 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
915
1052
|
mergeBlock: p.mergeBlock,
|
|
916
1053
|
dynamicContract: contractName,
|
|
917
1054
|
mutPendingQueries: p.mutPendingQueries,
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1055
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1056
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1057
|
+
eventDensity: p.eventDensity,
|
|
1058
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
922
1059
|
};
|
|
923
1060
|
}
|
|
924
1061
|
}
|
|
@@ -929,11 +1066,11 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
929
1066
|
}
|
|
930
1067
|
IndexingAddresses.register(indexingAddresses, noEventsAddresses);
|
|
931
1068
|
let optimizedPartitions = createPartitionsFromIndexingAddresses(registeringContractsByContract, dynamicContractsRef, fetchState.normalSelection, fetchState.optimizedPartitions.maxAddrInPartition, fetchState.optimizedPartitions.nextPartitionIndex + newPartitions.length | 0, mutExistingPartitions.concat(newPartitions), 0);
|
|
932
|
-
return updateInternal(fetchState, optimizedPartitions, undefined, undefined, undefined);
|
|
1069
|
+
return updateInternal(fetchState, optimizedPartitions, undefined, undefined, undefined, undefined);
|
|
933
1070
|
}
|
|
934
1071
|
|
|
935
|
-
function
|
|
936
|
-
|
|
1072
|
+
function filterByClientAddress(items, indexingAddresses) {
|
|
1073
|
+
return items.filter(item => {
|
|
937
1074
|
if (item.kind !== 0) {
|
|
938
1075
|
return true;
|
|
939
1076
|
}
|
|
@@ -944,7 +1081,10 @@ function handleQueryResult(fetchState, indexingAddresses, query, latestFetchedBl
|
|
|
944
1081
|
return true;
|
|
945
1082
|
}
|
|
946
1083
|
});
|
|
947
|
-
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
1087
|
+
return updateInternal(fetchState, handleQueryResponse(fetchState.optimizedPartitions, query, fetchState.knownHeight, newItems.length, latestFetchedBlock), newItems.length !== 0 ? mergeIntoBuffer(fetchState.buffer, newItems) : undefined, true, undefined, undefined);
|
|
948
1088
|
}
|
|
949
1089
|
|
|
950
1090
|
function startFetchingQueries(param, queries) {
|
|
@@ -959,6 +1099,7 @@ function startFetchingQueries(param, queries) {
|
|
|
959
1099
|
toBlock: q.toBlock,
|
|
960
1100
|
isChunk: q.isChunk,
|
|
961
1101
|
itemsTarget: q.itemsTarget,
|
|
1102
|
+
itemsEst: q.itemsEst,
|
|
962
1103
|
fetchedBlock: undefined
|
|
963
1104
|
};
|
|
964
1105
|
let inserted = false;
|
|
@@ -976,73 +1117,223 @@ function startFetchingQueries(param, queries) {
|
|
|
976
1117
|
}
|
|
977
1118
|
}
|
|
978
1119
|
|
|
979
|
-
function
|
|
980
|
-
let
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1120
|
+
function pushDensityPricedQuery(queries, partitionId, fromBlock, toBlock, isChunk, density, chunkItemsMultiplier, chainTargetBlock, itemsTargetFloor, selection, addressesByContractName) {
|
|
1121
|
+
let itemsEst = densityItemsTarget(density, fromBlock, toBlock, chainTargetBlock);
|
|
1122
|
+
let itemsTarget = densityItemsTarget(density * chunkItemsMultiplier, fromBlock, toBlock, chainTargetBlock);
|
|
1123
|
+
queries.push({
|
|
1124
|
+
partitionId: partitionId,
|
|
1125
|
+
fromBlock: fromBlock,
|
|
1126
|
+
toBlock: toBlock,
|
|
1127
|
+
isChunk: isChunk,
|
|
1128
|
+
itemsTarget: toBlock !== undefined ? Primitive_int.max(itemsTarget, itemsTargetFloor) : itemsTarget,
|
|
1129
|
+
itemsEst: itemsEst,
|
|
1130
|
+
selection: selection,
|
|
1131
|
+
addressesByContractName: addressesByContractName
|
|
1132
|
+
});
|
|
1133
|
+
return itemsEst;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
function pushGapFillQueries(queries, partitionId, rangeFromBlock, rangeEndBlock, headBlockNumber, chainTargetBlock, maybeChunkRange, maxChunks, partition, partitionBudget, chunkItemsMultiplier, itemsTargetFloor, selection, addressesByContractName) {
|
|
1137
|
+
if (!(rangeFromBlock <= Primitive_int.min(headBlockNumber, chainTargetBlock) && maxChunks > 0)) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
let exit = 0;
|
|
1141
|
+
if (rangeEndBlock !== undefined) {
|
|
1142
|
+
if (rangeFromBlock > rangeEndBlock) {
|
|
1143
|
+
return;
|
|
985
1144
|
}
|
|
986
|
-
|
|
1145
|
+
exit = 1;
|
|
1146
|
+
} else {
|
|
1147
|
+
exit = 1;
|
|
1148
|
+
}
|
|
1149
|
+
if (exit === 1) {
|
|
1150
|
+
let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : chainTargetBlock;
|
|
1151
|
+
let pushSingleQuery = (density, isChunk) => {
|
|
1152
|
+
pushDensityPricedQuery(queries, partitionId, rangeFromBlock, rangeEndBlock, isChunk, density, chunkItemsMultiplier, chainTargetBlock, itemsTargetFloor, selection, addressesByContractName);
|
|
1153
|
+
};
|
|
1154
|
+
let match = partition.eventDensity;
|
|
1155
|
+
let exit$1 = 0;
|
|
1156
|
+
if (match !== undefined) {
|
|
987
1157
|
if (maybeChunkRange !== undefined) {
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1158
|
+
if (match > 0) {
|
|
1159
|
+
let chunkSize = Js_math.ceil_int(maybeChunkRange * 1.8);
|
|
1160
|
+
if (((rangeFromBlock + (chunkSize << 1) | 0) - 1 | 0) > maxBlock) {
|
|
1161
|
+
return pushSingleQuery(match, rangeEndBlock !== undefined);
|
|
1162
|
+
}
|
|
991
1163
|
let chunkFromBlock = rangeFromBlock;
|
|
992
1164
|
let chunkIdx = 0;
|
|
993
1165
|
while (chunkIdx < maxChunks && ((chunkFromBlock + chunkSize | 0) - 1 | 0) <= maxBlock) {
|
|
994
1166
|
let chunkToBlock = (chunkFromBlock + chunkSize | 0) - 1 | 0;
|
|
995
|
-
|
|
996
|
-
queries.push({
|
|
997
|
-
partitionId: partitionId,
|
|
998
|
-
fromBlock: chunkFromBlock,
|
|
999
|
-
toBlock: chunkToBlock,
|
|
1000
|
-
isChunk: true,
|
|
1001
|
-
itemsTarget: itemsTarget,
|
|
1002
|
-
selection: selection,
|
|
1003
|
-
addressesByContractName: addressesByContractName
|
|
1004
|
-
});
|
|
1005
|
-
cost = cost + itemsTarget;
|
|
1167
|
+
pushDensityPricedQuery(queries, partitionId, chunkFromBlock, chunkToBlock, true, match, chunkItemsMultiplier, chainTargetBlock, itemsTargetFloor, selection, addressesByContractName);
|
|
1006
1168
|
chunkFromBlock = chunkToBlock + 1 | 0;
|
|
1007
1169
|
chunkIdx = chunkIdx + 1 | 0;
|
|
1008
1170
|
};
|
|
1009
|
-
|
|
1010
|
-
let itemsTarget$1 = densityItemsTarget(partition, rangeFromBlock, rangeEndBlock, chainTargetBlock);
|
|
1011
|
-
queries.push({
|
|
1012
|
-
partitionId: partitionId,
|
|
1013
|
-
fromBlock: rangeFromBlock,
|
|
1014
|
-
toBlock: rangeEndBlock,
|
|
1015
|
-
isChunk: rangeEndBlock !== undefined,
|
|
1016
|
-
itemsTarget: itemsTarget$1,
|
|
1017
|
-
selection: selection,
|
|
1018
|
-
addressesByContractName: addressesByContractName
|
|
1019
|
-
});
|
|
1020
|
-
cost = cost + itemsTarget$1;
|
|
1171
|
+
return;
|
|
1021
1172
|
}
|
|
1173
|
+
exit$1 = 2;
|
|
1022
1174
|
} else {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1175
|
+
if (match > 0) {
|
|
1176
|
+
return pushSingleQuery(match, false);
|
|
1177
|
+
}
|
|
1178
|
+
exit$1 = 2;
|
|
1179
|
+
}
|
|
1180
|
+
} else {
|
|
1181
|
+
exit$1 = 2;
|
|
1182
|
+
}
|
|
1183
|
+
if (exit$1 === 2) {
|
|
1184
|
+
let remainingRange = Primitive_int.max(1, (chainTargetBlock - rangeFromBlock | 0) + 1 | 0);
|
|
1185
|
+
return pushSingleQuery(partitionBudget / remainingRange, false);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
function walkPartitionPending(p, partitionId, inFlightCount, candidates, headBlockNumber, chainTargetBlock, chunkItemsMultiplier, itemsTargetFloor, partitionBudget, queryEndBlock) {
|
|
1191
|
+
let maybeChunkRange = getMinHistoryRange(p);
|
|
1192
|
+
let pendingCount = p.mutPendingQueries.length;
|
|
1193
|
+
let cursor = p.latestFetchedBlock.blockNumber + 1 | 0;
|
|
1194
|
+
let canContinue = true;
|
|
1195
|
+
let chunksUsedThisCall = 0;
|
|
1196
|
+
let pqIdx = 0;
|
|
1197
|
+
while (pqIdx < pendingCount && canContinue) {
|
|
1198
|
+
let pq = p.mutPendingQueries[pqIdx];
|
|
1199
|
+
if (pq.fromBlock > cursor) {
|
|
1200
|
+
let beforeLen = candidates.length;
|
|
1201
|
+
pushGapFillQueries(candidates, partitionId, cursor, Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock), headBlockNumber, chainTargetBlock, maybeChunkRange, (12 - inFlightCount | 0) - chunksUsedThisCall | 0, p, partitionBudget, chunkItemsMultiplier, itemsTargetFloor, p.selection, p.addressesByContractName);
|
|
1202
|
+
chunksUsedThisCall = chunksUsedThisCall + (candidates.length - beforeLen | 0) | 0;
|
|
1203
|
+
}
|
|
1204
|
+
let toBlock = pq.toBlock;
|
|
1205
|
+
if (toBlock !== undefined && pq.isChunk) {
|
|
1206
|
+
let match = pq.fetchedBlock;
|
|
1207
|
+
if (match !== undefined) {
|
|
1208
|
+
let blockNumber = match.blockNumber;
|
|
1209
|
+
cursor = blockNumber < toBlock ? blockNumber + 1 | 0 : toBlock + 1 | 0;
|
|
1210
|
+
} else {
|
|
1211
|
+
cursor = toBlock + 1 | 0;
|
|
1034
1212
|
}
|
|
1213
|
+
} else {
|
|
1214
|
+
canContinue = false;
|
|
1035
1215
|
}
|
|
1216
|
+
pqIdx = pqIdx + 1 | 0;
|
|
1217
|
+
};
|
|
1218
|
+
if (canContinue) {
|
|
1219
|
+
return {
|
|
1220
|
+
partitionId: partitionId,
|
|
1221
|
+
p: p,
|
|
1222
|
+
cursor: cursor,
|
|
1223
|
+
chunksUsedThisCall: chunksUsedThisCall,
|
|
1224
|
+
inFlightCount: inFlightCount,
|
|
1225
|
+
queryEndBlock: queryEndBlock,
|
|
1226
|
+
maybeChunkRange: maybeChunkRange
|
|
1227
|
+
};
|
|
1036
1228
|
}
|
|
1037
|
-
return cost;
|
|
1038
1229
|
}
|
|
1039
1230
|
|
|
1040
|
-
function
|
|
1041
|
-
let
|
|
1231
|
+
function pushForwardCandidates(candidates, inRangeStates, inRangeCount, chainTargetBlock, freshBudget, chunkItemsMultiplier, itemsTargetFloor) {
|
|
1232
|
+
let probeShare = inRangeCount === 0 ? 0 : freshBudget / inRangeCount;
|
|
1233
|
+
let frontierCursor = Stdlib_Array.reduce(inRangeStates, chainTargetBlock, (min, fs) => {
|
|
1234
|
+
if (fs.cursor < min) {
|
|
1235
|
+
return fs.cursor;
|
|
1236
|
+
} else {
|
|
1237
|
+
return min;
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
let rangeToTarget = (chainTargetBlock - frontierCursor | 0) + 1 | 0;
|
|
1241
|
+
let rangeTargetDensity = inRangeCount > 0 && rangeToTarget > 0 ? freshBudget / rangeToTarget : 0;
|
|
1242
|
+
inRangeStates.forEach(fs => {
|
|
1243
|
+
let p = fs.p;
|
|
1244
|
+
let eb = fs.queryEndBlock;
|
|
1245
|
+
let maxBlock = eb !== undefined ? eb : chainTargetBlock;
|
|
1246
|
+
let match = fs.maybeChunkRange;
|
|
1247
|
+
let match$1 = p.eventDensity;
|
|
1248
|
+
if (match !== undefined && match$1 !== undefined && match$1 > 0) {
|
|
1249
|
+
let chunkSize = Js_math.ceil_int(match * 1.8);
|
|
1250
|
+
let maxChunksRemaining = (12 - fs.inFlightCount | 0) - fs.chunksUsedThisCall | 0;
|
|
1251
|
+
let chunkStartCeiling = Primitive_int.min(maxBlock, chainTargetBlock);
|
|
1252
|
+
let created = 0;
|
|
1253
|
+
let chunkFromBlock = fs.cursor;
|
|
1254
|
+
let generatedItems = 0;
|
|
1255
|
+
while (created < maxChunksRemaining && chunkFromBlock <= chunkStartCeiling && generatedItems <= freshBudget) {
|
|
1256
|
+
let chunkToBlock = Primitive_int.min((chunkFromBlock + chunkSize | 0) - 1 | 0, maxBlock);
|
|
1257
|
+
let itemsEst = pushDensityPricedQuery(candidates, fs.partitionId, chunkFromBlock, chunkToBlock, true, match$1, chunkItemsMultiplier, chainTargetBlock, itemsTargetFloor, p.selection, p.addressesByContractName);
|
|
1258
|
+
generatedItems = generatedItems + itemsEst;
|
|
1259
|
+
chunkFromBlock = chunkToBlock + 1 | 0;
|
|
1260
|
+
created = created + 1 | 0;
|
|
1261
|
+
};
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
let itemsTarget = rangeToTarget > 0 ? Primitive_int.max(1, Math.round(rangeTargetDensity * ((chainTargetBlock - fs.cursor | 0) + 1 | 0) / inRangeCount) | 0) : Primitive_int.max(1, Math.round(probeShare) | 0);
|
|
1265
|
+
candidates.push({
|
|
1266
|
+
partitionId: fs.partitionId,
|
|
1267
|
+
fromBlock: fs.cursor,
|
|
1268
|
+
toBlock: fs.queryEndBlock,
|
|
1269
|
+
isChunk: false,
|
|
1270
|
+
itemsTarget: itemsTarget,
|
|
1271
|
+
itemsEst: itemsTarget,
|
|
1272
|
+
selection: p.selection,
|
|
1273
|
+
addressesByContractName: p.addressesByContractName
|
|
1274
|
+
});
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function acceptCandidates(candidates, reservations, chainTargetItems, partitionIndexById, queriesByPartitionIndex) {
|
|
1279
|
+
let acceptanceStream = [];
|
|
1280
|
+
candidates.forEach(query => {
|
|
1281
|
+
acceptanceStream.push([
|
|
1282
|
+
query.fromBlock,
|
|
1283
|
+
query.itemsEst,
|
|
1284
|
+
query
|
|
1285
|
+
]);
|
|
1286
|
+
});
|
|
1287
|
+
reservations.forEach(param => {
|
|
1288
|
+
acceptanceStream.push([
|
|
1289
|
+
param[0],
|
|
1290
|
+
param[1],
|
|
1291
|
+
undefined
|
|
1292
|
+
]);
|
|
1293
|
+
});
|
|
1294
|
+
acceptanceStream.sort((param, param$1) => {
|
|
1295
|
+
let bFrom = param$1[0];
|
|
1296
|
+
let aFrom = param[0];
|
|
1297
|
+
if (aFrom !== bFrom) {
|
|
1298
|
+
return Primitive_int.compare(aFrom, bFrom);
|
|
1299
|
+
}
|
|
1300
|
+
let bQuery = param$1[2];
|
|
1301
|
+
if (param[2] !== undefined) {
|
|
1302
|
+
if (bQuery !== undefined) {
|
|
1303
|
+
return 0;
|
|
1304
|
+
} else {
|
|
1305
|
+
return 1;
|
|
1306
|
+
}
|
|
1307
|
+
} else if (bQuery !== undefined) {
|
|
1308
|
+
return -1;
|
|
1309
|
+
} else {
|
|
1310
|
+
return 0;
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
let streamCount = acceptanceStream.length;
|
|
1314
|
+
let remainingBudget = chainTargetItems;
|
|
1315
|
+
let acceptIdx = 0;
|
|
1316
|
+
let usedConcurrency = reservations.length;
|
|
1317
|
+
while (remainingBudget > 0 && acceptIdx < streamCount && usedConcurrency < 100) {
|
|
1318
|
+
let match = acceptanceStream[acceptIdx];
|
|
1319
|
+
let maybeQuery = match[2];
|
|
1320
|
+
if (maybeQuery !== undefined) {
|
|
1321
|
+
let partitionIdx = partitionIndexById[maybeQuery.partitionId];
|
|
1322
|
+
queriesByPartitionIndex[partitionIdx].push(maybeQuery);
|
|
1323
|
+
usedConcurrency = usedConcurrency + 1 | 0;
|
|
1324
|
+
}
|
|
1325
|
+
remainingBudget = remainingBudget - match[1];
|
|
1326
|
+
acceptIdx = acceptIdx + 1 | 0;
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function getNextQuery(param, chainTargetBlock, chainTargetItems, $staropt$star, $staropt$star$1) {
|
|
1042
1331
|
let blockLag = param.blockLag;
|
|
1043
1332
|
let endBlock = param.endBlock;
|
|
1044
1333
|
let optimizedPartitions = param.optimizedPartitions;
|
|
1045
|
-
let
|
|
1334
|
+
let chunkItemsMultiplier = $staropt$star !== undefined ? $staropt$star : 1;
|
|
1335
|
+
let itemsTargetFloor = $staropt$star$1 !== undefined ? $staropt$star$1 : 0;
|
|
1336
|
+
let headBlockNumber = param.knownHeight - blockLag | 0;
|
|
1046
1337
|
if (headBlockNumber <= 0) {
|
|
1047
1338
|
return "WaitingForNewBlock";
|
|
1048
1339
|
}
|
|
@@ -1051,14 +1342,34 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
|
|
|
1051
1342
|
endBlock !== undefined ? headBlockNumber < endBlock : true
|
|
1052
1343
|
) && !isOnBlockBehindTheHead;
|
|
1053
1344
|
let partitionsCount = optimizedPartitions.idsInAscOrder.length;
|
|
1345
|
+
let inFlightCounts = Array(partitionsCount);
|
|
1346
|
+
let reservations = [];
|
|
1347
|
+
let chainReserved = 0;
|
|
1348
|
+
let partitionIndexById = {};
|
|
1054
1349
|
for (let idx = 0; idx < partitionsCount; ++idx) {
|
|
1055
1350
|
let partitionId = optimizedPartitions.idsInAscOrder[idx];
|
|
1056
1351
|
let p = optimizedPartitions.entities[partitionId];
|
|
1352
|
+
partitionIndexById[partitionId] = idx;
|
|
1353
|
+
let inFlightCount = 0;
|
|
1354
|
+
for (let pqIdx = 0, pqIdx_finish = p.mutPendingQueries.length; pqIdx < pqIdx_finish; ++pqIdx) {
|
|
1355
|
+
let pq = p.mutPendingQueries[pqIdx];
|
|
1356
|
+
if (pq.fetchedBlock === undefined) {
|
|
1357
|
+
inFlightCount = inFlightCount + 1 | 0;
|
|
1358
|
+
chainReserved = chainReserved + pq.itemsEst;
|
|
1359
|
+
reservations.push([
|
|
1360
|
+
pq.fromBlock,
|
|
1361
|
+
pq.itemsEst
|
|
1362
|
+
]);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
inFlightCounts[idx] = inFlightCount;
|
|
1057
1366
|
if (p.mutPendingQueries.length !== 0 || p.latestFetchedBlock.blockNumber < headBlockNumber) {
|
|
1058
1367
|
shouldWaitForNewBlock = false;
|
|
1059
1368
|
}
|
|
1060
1369
|
}
|
|
1061
|
-
let
|
|
1370
|
+
let availableConcurrency = 100 - reservations.length | 0;
|
|
1371
|
+
let partitionsCount$1 = chainTargetItems <= 0 || shouldWaitForNewBlock || availableConcurrency <= 0 ? 0 : partitionsCount;
|
|
1372
|
+
let queriesByPartitionIndex = Stdlib_Array.fromInitializer(partitionsCount$1, param => []);
|
|
1062
1373
|
let computeQueryEndBlock = p => {
|
|
1063
1374
|
let queryEndBlock = Utils.$$Math.minOptInt(endBlock, p.mergeBlock);
|
|
1064
1375
|
if (blockLag !== 0) {
|
|
@@ -1067,124 +1378,18 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
|
|
|
1067
1378
|
return queryEndBlock;
|
|
1068
1379
|
}
|
|
1069
1380
|
};
|
|
1070
|
-
let
|
|
1071
|
-
let
|
|
1072
|
-
|
|
1381
|
+
let candidates = [];
|
|
1382
|
+
let partitionBudget = partitionsCount$1 === 0 ? 0 : chainTargetItems / partitionsCount$1;
|
|
1383
|
+
let fillStates = [];
|
|
1384
|
+
for (let idx$1 = 0; idx$1 < partitionsCount$1; ++idx$1) {
|
|
1073
1385
|
let partitionId$1 = optimizedPartitions.idsInAscOrder[idx$1];
|
|
1074
1386
|
let p$1 = optimizedPartitions.entities[partitionId$1];
|
|
1075
|
-
let
|
|
1076
|
-
|
|
1077
|
-
|
|
1387
|
+
let fillState = walkPartitionPending(p$1, partitionId$1, inFlightCounts[idx$1], candidates, headBlockNumber, chainTargetBlock, chunkItemsMultiplier, itemsTargetFloor, partitionBudget, computeQueryEndBlock(p$1));
|
|
1388
|
+
if (fillState !== undefined) {
|
|
1389
|
+
fillStates.push(fillState);
|
|
1078
1390
|
}
|
|
1079
|
-
existingReservedByPartition[partitionId$1] = cost;
|
|
1080
|
-
chainReserved = chainReserved + cost;
|
|
1081
1391
|
}
|
|
1082
|
-
let
|
|
1083
|
-
let gapFillCost = 0;
|
|
1084
|
-
for (let idx$2 = 0; idx$2 < partitionsCount; ++idx$2) {
|
|
1085
|
-
let partitionId$2 = optimizedPartitions.idsInAscOrder[idx$2];
|
|
1086
|
-
let p$2 = optimizedPartitions.entities[partitionId$2];
|
|
1087
|
-
let bucket = queriesByPartitionIndex[idx$2];
|
|
1088
|
-
let pendingCount = p$2.mutPendingQueries.length;
|
|
1089
|
-
let queryEndBlock = computeQueryEndBlock(p$2);
|
|
1090
|
-
let maybeChunkRange = getMinHistoryRange(p$2);
|
|
1091
|
-
let cursor = p$2.latestFetchedBlock.blockNumber + 1 | 0;
|
|
1092
|
-
let canContinue = true;
|
|
1093
|
-
let chunksUsedThisCall = 0;
|
|
1094
|
-
let pqIdx$1 = 0;
|
|
1095
|
-
while (pqIdx$1 < pendingCount && canContinue) {
|
|
1096
|
-
let pq = p$2.mutPendingQueries[pqIdx$1];
|
|
1097
|
-
if (pq.fromBlock > cursor) {
|
|
1098
|
-
let beforeLen = bucket.length;
|
|
1099
|
-
let cost$1 = pushGapFillQueries(bucket, partitionId$2, cursor, Utils.$$Math.minOptInt(pq.fromBlock - 1 | 0, queryEndBlock), knownHeight, chainTargetBlock, maybeChunkRange, (10 - pendingCount | 0) - chunksUsedThisCall | 0, p$2, p$2.selection, p$2.addressesByContractName);
|
|
1100
|
-
chunksUsedThisCall = chunksUsedThisCall + (bucket.length - beforeLen | 0) | 0;
|
|
1101
|
-
gapFillCost = gapFillCost + cost$1;
|
|
1102
|
-
}
|
|
1103
|
-
let toBlock = pq.toBlock;
|
|
1104
|
-
if (toBlock !== undefined && pq.isChunk) {
|
|
1105
|
-
let match = pq.fetchedBlock;
|
|
1106
|
-
if (match !== undefined) {
|
|
1107
|
-
let blockNumber = match.blockNumber;
|
|
1108
|
-
cursor = blockNumber < toBlock ? blockNumber + 1 | 0 : toBlock + 1 | 0;
|
|
1109
|
-
} else {
|
|
1110
|
-
cursor = toBlock + 1 | 0;
|
|
1111
|
-
}
|
|
1112
|
-
} else {
|
|
1113
|
-
canContinue = false;
|
|
1114
|
-
}
|
|
1115
|
-
pqIdx$1 = pqIdx$1 + 1 | 0;
|
|
1116
|
-
};
|
|
1117
|
-
if (canContinue) {
|
|
1118
|
-
fillStates.push({
|
|
1119
|
-
partitionId: partitionId$2,
|
|
1120
|
-
p: p$2,
|
|
1121
|
-
cursor: cursor,
|
|
1122
|
-
chunksUsedThisCall: chunksUsedThisCall,
|
|
1123
|
-
pendingCount: pendingCount,
|
|
1124
|
-
queryEndBlock: queryEndBlock,
|
|
1125
|
-
maybeChunkRange: maybeChunkRange,
|
|
1126
|
-
bucket: bucket
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
let rangeItemsTarget = Primitive_float.max(0, chainTargetItems - chainReserved - gapFillCost);
|
|
1131
|
-
let reservedByPartition = {};
|
|
1132
|
-
fillStates.forEach(fs => {
|
|
1133
|
-
let cost = existingReservedByPartition[fs.partitionId];
|
|
1134
|
-
for (let i = 0, i_finish = fs.bucket.length; i < i_finish; ++i) {
|
|
1135
|
-
cost = cost + fs.bucket[i].itemsTarget;
|
|
1136
|
-
}
|
|
1137
|
-
reservedByPartition[fs.partitionId] = cost;
|
|
1138
|
-
});
|
|
1139
|
-
let emitQueries = (fs, budget) => {
|
|
1140
|
-
let p = fs.p;
|
|
1141
|
-
let eb = fs.queryEndBlock;
|
|
1142
|
-
let maxBlock = eb !== undefined ? eb : chainTargetBlock;
|
|
1143
|
-
let minHistoryRange = fs.maybeChunkRange;
|
|
1144
|
-
if (minHistoryRange !== undefined) {
|
|
1145
|
-
let density = p.prevRangeSize / p.prevQueryRange;
|
|
1146
|
-
let chunkSize = Js_math.ceil_int(minHistoryRange * 1.8);
|
|
1147
|
-
let chunkCost = density * chunkSize;
|
|
1148
|
-
let maxChunksRemaining = (10 - fs.pendingCount | 0) - fs.chunksUsedThisCall | 0;
|
|
1149
|
-
let affordable = chunkCost > 0 ? Math.floor(budget / chunkCost) | 0 : maxChunksRemaining;
|
|
1150
|
-
let numChunks = Primitive_int.max(1, Primitive_int.min(affordable, maxChunksRemaining));
|
|
1151
|
-
let consumed = 0;
|
|
1152
|
-
let created = 0;
|
|
1153
|
-
let chunkFromBlock = fs.cursor;
|
|
1154
|
-
while (created < numChunks && chunkFromBlock <= maxBlock) {
|
|
1155
|
-
let chunkToBlock = Primitive_int.min((chunkFromBlock + chunkSize | 0) - 1 | 0, maxBlock);
|
|
1156
|
-
let itemsTarget = density * ((chunkToBlock - chunkFromBlock | 0) + 1 | 0);
|
|
1157
|
-
fs.bucket.push({
|
|
1158
|
-
partitionId: fs.partitionId,
|
|
1159
|
-
fromBlock: chunkFromBlock,
|
|
1160
|
-
toBlock: chunkToBlock,
|
|
1161
|
-
isChunk: true,
|
|
1162
|
-
itemsTarget: itemsTarget,
|
|
1163
|
-
selection: p.selection,
|
|
1164
|
-
addressesByContractName: p.addressesByContractName
|
|
1165
|
-
});
|
|
1166
|
-
consumed = consumed + itemsTarget;
|
|
1167
|
-
chunkFromBlock = chunkToBlock + 1 | 0;
|
|
1168
|
-
created = created + 1 | 0;
|
|
1169
|
-
};
|
|
1170
|
-
fs.cursor = chunkFromBlock;
|
|
1171
|
-
fs.chunksUsedThisCall = fs.chunksUsedThisCall + created | 0;
|
|
1172
|
-
return consumed;
|
|
1173
|
-
}
|
|
1174
|
-
let itemsTarget$1 = Primitive_float.min(Math.round(budget), 10000);
|
|
1175
|
-
fs.bucket.push({
|
|
1176
|
-
partitionId: fs.partitionId,
|
|
1177
|
-
fromBlock: fs.cursor,
|
|
1178
|
-
toBlock: fs.queryEndBlock,
|
|
1179
|
-
isChunk: false,
|
|
1180
|
-
itemsTarget: itemsTarget$1,
|
|
1181
|
-
selection: p.selection,
|
|
1182
|
-
addressesByContractName: p.addressesByContractName
|
|
1183
|
-
});
|
|
1184
|
-
fs.cursor = maxBlock + 1 | 0;
|
|
1185
|
-
fs.chunksUsedThisCall = fs.chunksUsedThisCall + 1 | 0;
|
|
1186
|
-
return itemsTarget$1;
|
|
1187
|
-
};
|
|
1392
|
+
let freshBudget = Primitive_float.max(0, chainTargetItems - chainReserved);
|
|
1188
1393
|
let isInRange = fs => {
|
|
1189
1394
|
let tmp = false;
|
|
1190
1395
|
if (fs.cursor <= chainTargetBlock) {
|
|
@@ -1192,41 +1397,16 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems) {
|
|
|
1192
1397
|
tmp = eb !== undefined ? fs.cursor <= eb : true;
|
|
1193
1398
|
}
|
|
1194
1399
|
if (tmp) {
|
|
1195
|
-
return (fs.
|
|
1400
|
+
return (fs.inFlightCount + fs.chunksUsedThisCall | 0) < 12;
|
|
1196
1401
|
} else {
|
|
1197
1402
|
return false;
|
|
1198
1403
|
}
|
|
1199
1404
|
};
|
|
1200
|
-
let
|
|
1201
|
-
let
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
let n = notFilledPartitions.length;
|
|
1206
|
-
let footprintSum = {
|
|
1207
|
-
contents: 0
|
|
1208
|
-
};
|
|
1209
|
-
notFilledPartitions.forEach(fs => {
|
|
1210
|
-
footprintSum.contents = footprintSum.contents + reservedByPartition[fs.partitionId];
|
|
1211
|
-
});
|
|
1212
|
-
let line = (rangeItemsTarget - reservedFromRange.contents + footprintSum.contents) / n;
|
|
1213
|
-
let next = [];
|
|
1214
|
-
notFilledPartitions.forEach(fs => {
|
|
1215
|
-
let reserved = reservedByPartition[fs.partitionId];
|
|
1216
|
-
let budget = line - reserved;
|
|
1217
|
-
if (budget <= 0) {
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
|
-
let consumed = emitQueries(fs, budget);
|
|
1221
|
-
reservedByPartition[fs.partitionId] = reserved + consumed;
|
|
1222
|
-
reservedFromRange.contents = reservedFromRange.contents + consumed;
|
|
1223
|
-
if (isInRange(fs)) {
|
|
1224
|
-
next.push(fs);
|
|
1225
|
-
return;
|
|
1226
|
-
}
|
|
1227
|
-
});
|
|
1228
|
-
notFilledPartitions = next;
|
|
1229
|
-
};
|
|
1405
|
+
let inRangeStates = fillStates.filter(isInRange);
|
|
1406
|
+
let inRangeCount = inRangeStates.length;
|
|
1407
|
+
let inRangeStates$1 = inRangeCount > availableConcurrency ? (inRangeStates.sort((a, b) => Primitive_int.compare(a.cursor, b.cursor)), inRangeStates.slice(0, availableConcurrency)) : inRangeStates;
|
|
1408
|
+
pushForwardCandidates(candidates, inRangeStates$1, inRangeCount, chainTargetBlock, freshBudget, chunkItemsMultiplier, itemsTargetFloor);
|
|
1409
|
+
acceptCandidates(candidates, reservations, chainTargetItems, partitionIndexById, queriesByPartitionIndex);
|
|
1230
1410
|
let queries = queriesByPartitionIndex.flat();
|
|
1231
1411
|
if (Utils.$$Array.isEmpty(queries)) {
|
|
1232
1412
|
if (shouldWaitForNewBlock) {
|
|
@@ -1307,10 +1487,10 @@ function make$1(startBlock, endBlock, onEventRegistrations, contractConfigs, add
|
|
|
1307
1487
|
mergeBlock: undefined,
|
|
1308
1488
|
dynamicContract: undefined,
|
|
1309
1489
|
mutPendingQueries: [],
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1490
|
+
sourceRangeCapacity: 0,
|
|
1491
|
+
prevSourceRangeCapacity: 0,
|
|
1492
|
+
eventDensity: undefined,
|
|
1493
|
+
latestSourceRangeCapacityUpdateBlock: 0
|
|
1314
1494
|
});
|
|
1315
1495
|
}
|
|
1316
1496
|
let normalSelection = {
|
|
@@ -1386,6 +1566,7 @@ function rollbackPendingQueries(mutPendingQueries, targetBlockNumber) {
|
|
|
1386
1566
|
toBlock: pq.toBlock,
|
|
1387
1567
|
isChunk: pq.isChunk,
|
|
1388
1568
|
itemsTarget: pq.itemsTarget,
|
|
1569
|
+
itemsEst: pq.itemsEst,
|
|
1389
1570
|
fetchedBlock: {
|
|
1390
1571
|
blockNumber: targetBlockNumber,
|
|
1391
1572
|
blockTimestamp: 0
|
|
@@ -1444,10 +1625,10 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
|
|
|
1444
1625
|
mergeBlock: mergeBlock$1,
|
|
1445
1626
|
dynamicContract: p.dynamicContract,
|
|
1446
1627
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1628
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1629
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1630
|
+
eventDensity: p.eventDensity,
|
|
1631
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
1451
1632
|
});
|
|
1452
1633
|
}
|
|
1453
1634
|
}
|
|
@@ -1465,10 +1646,10 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
|
|
|
1465
1646
|
mergeBlock: p.mergeBlock,
|
|
1466
1647
|
dynamicContract: p.dynamicContract,
|
|
1467
1648
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1649
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1650
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1651
|
+
eventDensity: p.eventDensity,
|
|
1652
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
1472
1653
|
});
|
|
1473
1654
|
}
|
|
1474
1655
|
}
|
|
@@ -1491,7 +1672,7 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
|
|
|
1491
1672
|
let tmp;
|
|
1492
1673
|
tmp = item.kind === 0 ? item.blockNumber : item.blockNumber;
|
|
1493
1674
|
return tmp <= targetBlockNumber;
|
|
1494
|
-
}), undefined, undefined);
|
|
1675
|
+
}), true, undefined, undefined);
|
|
1495
1676
|
}
|
|
1496
1677
|
|
|
1497
1678
|
function resetPendingQueries(fetchState) {
|
|
@@ -1509,10 +1690,10 @@ function resetPendingQueries(fetchState) {
|
|
|
1509
1690
|
mergeBlock: partition.mergeBlock,
|
|
1510
1691
|
dynamicContract: partition.dynamicContract,
|
|
1511
1692
|
mutPendingQueries: kept,
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1693
|
+
sourceRangeCapacity: partition.sourceRangeCapacity,
|
|
1694
|
+
prevSourceRangeCapacity: partition.prevSourceRangeCapacity,
|
|
1695
|
+
eventDensity: partition.eventDensity,
|
|
1696
|
+
latestSourceRangeCapacityUpdateBlock: partition.latestSourceRangeCapacityUpdateBlock
|
|
1516
1697
|
};
|
|
1517
1698
|
}
|
|
1518
1699
|
}
|
|
@@ -1588,7 +1769,7 @@ function getProgressPercentage(fetchState) {
|
|
|
1588
1769
|
if (firstEventBlock === undefined) {
|
|
1589
1770
|
return 0;
|
|
1590
1771
|
}
|
|
1591
|
-
let totalRange = fetchState.knownHeight - firstEventBlock | 0;
|
|
1772
|
+
let totalRange = (fetchState.knownHeight - fetchState.blockLag | 0) - firstEventBlock | 0;
|
|
1592
1773
|
if (totalRange <= 0) {
|
|
1593
1774
|
return 0;
|
|
1594
1775
|
}
|
|
@@ -1644,32 +1825,33 @@ function getProgressBlockNumberAt(fetchState, index) {
|
|
|
1644
1825
|
function updateKnownHeight(fetchState, knownHeight) {
|
|
1645
1826
|
if (knownHeight > fetchState.knownHeight) {
|
|
1646
1827
|
Prometheus.IndexingKnownHeight.set(knownHeight, fetchState.chainId);
|
|
1647
|
-
return updateInternal(fetchState, undefined, undefined, undefined, knownHeight);
|
|
1828
|
+
return updateInternal(fetchState, undefined, undefined, undefined, undefined, knownHeight);
|
|
1648
1829
|
} else {
|
|
1649
1830
|
return fetchState;
|
|
1650
1831
|
}
|
|
1651
1832
|
}
|
|
1652
1833
|
|
|
1653
|
-
let
|
|
1834
|
+
let blockItemLogIndex = 16777216;
|
|
1654
1835
|
|
|
1655
|
-
let
|
|
1836
|
+
let maxInFlightChunksPerPartition = 12;
|
|
1656
1837
|
|
|
1657
|
-
let
|
|
1838
|
+
let maxChainConcurrency = 100;
|
|
1658
1839
|
|
|
1659
|
-
let
|
|
1840
|
+
let chunkRangeGrowthFactor = 1.8;
|
|
1660
1841
|
|
|
1661
1842
|
export {
|
|
1662
1843
|
deriveContractNameByAddress,
|
|
1663
|
-
minItemsTarget,
|
|
1664
|
-
maxItemsTarget,
|
|
1665
1844
|
densityItemsTarget,
|
|
1666
1845
|
getMinHistoryRange,
|
|
1846
|
+
getTrustedDensity,
|
|
1667
1847
|
getMinQueryRange,
|
|
1668
1848
|
OptimizedPartitions,
|
|
1669
1849
|
bufferBlockNumber,
|
|
1670
1850
|
bufferBlock,
|
|
1671
1851
|
bufferReadyCount,
|
|
1852
|
+
getRegistrationIndex,
|
|
1672
1853
|
compareBufferItem,
|
|
1854
|
+
mergeIntoBuffer,
|
|
1673
1855
|
blockItemLogIndex,
|
|
1674
1856
|
appendOnBlockItems,
|
|
1675
1857
|
updateInternal,
|
|
@@ -1678,10 +1860,17 @@ export {
|
|
|
1678
1860
|
addressesByContractNameGetAll,
|
|
1679
1861
|
createPartitionsFromIndexingAddresses,
|
|
1680
1862
|
registerDynamicContracts,
|
|
1863
|
+
filterByClientAddress,
|
|
1681
1864
|
handleQueryResult,
|
|
1682
1865
|
startFetchingQueries,
|
|
1683
|
-
|
|
1866
|
+
maxInFlightChunksPerPartition,
|
|
1867
|
+
maxChainConcurrency,
|
|
1868
|
+
chunkRangeGrowthFactor,
|
|
1869
|
+
pushDensityPricedQuery,
|
|
1684
1870
|
pushGapFillQueries,
|
|
1871
|
+
walkPartitionPending,
|
|
1872
|
+
pushForwardCandidates,
|
|
1873
|
+
acceptCandidates,
|
|
1685
1874
|
getNextQuery,
|
|
1686
1875
|
hasReadyItem,
|
|
1687
1876
|
getReadyItemsCount,
|