envio 2.29.0-alpha.2 → 2.29.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/package.json +7 -5
- package/src/Batch.res +12 -0
- package/src/Batch.res.js +15 -0
- package/src/EventRegister.res +14 -1
- package/src/EventRegister.res.js +11 -4
- package/src/EventUtils.res +4 -0
- package/src/EventUtils.res.js +3 -0
- package/src/FetchState.res +189 -160
- package/src/FetchState.res.js +212 -130
- package/src/Logging.res.js +3 -4
- package/src/Utils.res +2 -0
- package/src/bindings/Pino.res +1 -0
- package/src/bindings/Pino.res.js +10 -3
- package/src/db/EntityHistory.res +0 -3
- package/src/db/EntityHistory.res.js +30 -33
- package/src/db/InternalTable.res +0 -6
- package/src/db/InternalTable.res.js +0 -1
- package/src/sources/SourceManager.res +0 -2
- package/src/sources/SourceManager.res.js +2 -2
- package/src/sources/SourceManager.resi +0 -1
package/src/FetchState.res.js
CHANGED
|
@@ -21,7 +21,6 @@ function copy(fetchState) {
|
|
|
21
21
|
return {
|
|
22
22
|
partitions: fetchState.partitions,
|
|
23
23
|
nextPartitionIndex: fetchState.nextPartitionIndex,
|
|
24
|
-
isFetchingAtHead: fetchState.isFetchingAtHead,
|
|
25
24
|
startBlock: fetchState.startBlock,
|
|
26
25
|
endBlock: fetchState.endBlock,
|
|
27
26
|
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
@@ -31,8 +30,10 @@ function copy(fetchState) {
|
|
|
31
30
|
dcsToStore: fetchState.dcsToStore,
|
|
32
31
|
chainId: fetchState.chainId,
|
|
33
32
|
latestFullyFetchedBlock: fetchState.latestFullyFetchedBlock,
|
|
33
|
+
latestOnBlockBlockNumber: fetchState.latestOnBlockBlockNumber,
|
|
34
34
|
blockLag: fetchState.blockLag,
|
|
35
35
|
queue: fetchState.queue.slice(0),
|
|
36
|
+
targetBufferSize: fetchState.targetBufferSize,
|
|
36
37
|
onBlockConfigs: fetchState.onBlockConfigs
|
|
37
38
|
};
|
|
38
39
|
}
|
|
@@ -112,16 +113,43 @@ function mergeIntoPartition(p, target, maxAddrInPartition) {
|
|
|
112
113
|
];
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
function
|
|
116
|
-
|
|
116
|
+
function bufferBlockNumber(param) {
|
|
117
|
+
var latestOnBlockBlockNumber = param.latestOnBlockBlockNumber;
|
|
118
|
+
var latestFullyFetchedBlock = param.latestFullyFetchedBlock;
|
|
119
|
+
if (latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber) {
|
|
120
|
+
return latestOnBlockBlockNumber;
|
|
121
|
+
} else {
|
|
122
|
+
return latestFullyFetchedBlock.blockNumber;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function bufferBlock(param) {
|
|
127
|
+
var latestOnBlockBlockNumber = param.latestOnBlockBlockNumber;
|
|
128
|
+
var latestFullyFetchedBlock = param.latestFullyFetchedBlock;
|
|
129
|
+
if (latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber) {
|
|
130
|
+
return {
|
|
131
|
+
blockNumber: latestOnBlockBlockNumber,
|
|
132
|
+
blockTimestamp: 0
|
|
133
|
+
};
|
|
134
|
+
} else {
|
|
135
|
+
return latestFullyFetchedBlock;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function compareBufferItem(a, b) {
|
|
140
|
+
var blockDiff = b.blockNumber - a.blockNumber | 0;
|
|
141
|
+
if (blockDiff === 0) {
|
|
142
|
+
return b.logIndex - a.logIndex | 0;
|
|
143
|
+
} else {
|
|
144
|
+
return blockDiff;
|
|
145
|
+
}
|
|
117
146
|
}
|
|
118
147
|
|
|
119
|
-
function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexingContractsOpt, dcsToStoreOpt,
|
|
148
|
+
function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexingContractsOpt, dcsToStoreOpt, mutItems, blockLagOpt) {
|
|
120
149
|
var partitions = partitionsOpt !== undefined ? partitionsOpt : fetchState.partitions;
|
|
121
150
|
var nextPartitionIndex = nextPartitionIndexOpt !== undefined ? nextPartitionIndexOpt : fetchState.nextPartitionIndex;
|
|
122
151
|
var indexingContracts = indexingContractsOpt !== undefined ? indexingContractsOpt : fetchState.indexingContracts;
|
|
123
152
|
var dcsToStore = dcsToStoreOpt !== undefined ? Caml_option.valFromOption(dcsToStoreOpt) : fetchState.dcsToStore;
|
|
124
|
-
var queue = queueOpt !== undefined ? queueOpt : fetchState.queue;
|
|
125
153
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
|
|
126
154
|
var firstPartition = partitions[0];
|
|
127
155
|
var latestFullyFetchedBlock = firstPartition.latestFetchedBlock;
|
|
@@ -133,30 +161,80 @@ function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexi
|
|
|
133
161
|
|
|
134
162
|
}
|
|
135
163
|
var latestFullyFetchedBlock$1 = latestFullyFetchedBlock;
|
|
136
|
-
var
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
164
|
+
var mutItemsRef = mutItems;
|
|
165
|
+
var onBlockConfigs = fetchState.onBlockConfigs;
|
|
166
|
+
var latestOnBlockBlockNumber;
|
|
167
|
+
if (onBlockConfigs.length !== 0) {
|
|
168
|
+
var mutItems$1 = mutItemsRef;
|
|
169
|
+
var item = (
|
|
170
|
+
mutItems$1 !== undefined ? mutItems$1 : fetchState.queue
|
|
171
|
+
).at(-fetchState.targetBufferSize | 0);
|
|
172
|
+
var maxBlockNumber = item !== undefined ? item.blockNumber : latestFullyFetchedBlock$1.blockNumber;
|
|
173
|
+
var mutItems$2 = mutItemsRef;
|
|
174
|
+
var mutItems$3 = mutItems$2 !== undefined ? mutItems$2 : fetchState.queue.slice(0);
|
|
175
|
+
mutItemsRef = mutItems$3;
|
|
176
|
+
var newItemsCounter = 0;
|
|
177
|
+
var latestOnBlockBlockNumber$1 = fetchState.latestOnBlockBlockNumber;
|
|
178
|
+
while(latestOnBlockBlockNumber$1 < maxBlockNumber && newItemsCounter <= fetchState.targetBufferSize) {
|
|
179
|
+
var blockNumber = latestOnBlockBlockNumber$1 + 1 | 0;
|
|
180
|
+
latestOnBlockBlockNumber$1 = blockNumber;
|
|
181
|
+
for(var configIdx = 0 ,configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx){
|
|
182
|
+
var onBlockConfig = onBlockConfigs[configIdx];
|
|
183
|
+
var startBlock = onBlockConfig.startBlock;
|
|
184
|
+
var handlerStartBlock = startBlock !== undefined ? startBlock : fetchState.startBlock;
|
|
185
|
+
var tmp = false;
|
|
186
|
+
if (blockNumber >= handlerStartBlock) {
|
|
187
|
+
var endBlock = onBlockConfig.endBlock;
|
|
188
|
+
tmp = endBlock !== undefined ? blockNumber <= endBlock : true;
|
|
189
|
+
}
|
|
190
|
+
if (tmp && Caml_int32.mod_(blockNumber - handlerStartBlock | 0, onBlockConfig.interval) === 0) {
|
|
191
|
+
mutItems$3.push({
|
|
192
|
+
kind: 1,
|
|
193
|
+
onBlockConfig: onBlockConfig,
|
|
194
|
+
blockNumber: blockNumber,
|
|
195
|
+
logIndex: 16777216 + onBlockConfig.index | 0
|
|
196
|
+
});
|
|
197
|
+
newItemsCounter = newItemsCounter + 1 | 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
latestOnBlockBlockNumber = latestOnBlockBlockNumber$1;
|
|
203
|
+
} else {
|
|
204
|
+
latestOnBlockBlockNumber = latestFullyFetchedBlock$1.blockNumber;
|
|
205
|
+
}
|
|
206
|
+
var mutItems$4 = mutItemsRef;
|
|
207
|
+
var updatedFetchState_startBlock = fetchState.startBlock;
|
|
208
|
+
var updatedFetchState_endBlock = fetchState.endBlock;
|
|
209
|
+
var updatedFetchState_maxAddrInPartition = fetchState.maxAddrInPartition;
|
|
210
|
+
var updatedFetchState_normalSelection = fetchState.normalSelection;
|
|
211
|
+
var updatedFetchState_contractConfigs = fetchState.contractConfigs;
|
|
212
|
+
var updatedFetchState_chainId = fetchState.chainId;
|
|
213
|
+
var updatedFetchState_queue = mutItems$4 !== undefined ? mutItems$4.sort(compareBufferItem) : fetchState.queue;
|
|
214
|
+
var updatedFetchState_targetBufferSize = fetchState.targetBufferSize;
|
|
215
|
+
var updatedFetchState_onBlockConfigs = fetchState.onBlockConfigs;
|
|
216
|
+
var updatedFetchState = {
|
|
217
|
+
partitions: partitions,
|
|
218
|
+
nextPartitionIndex: nextPartitionIndex,
|
|
219
|
+
startBlock: updatedFetchState_startBlock,
|
|
220
|
+
endBlock: updatedFetchState_endBlock,
|
|
221
|
+
maxAddrInPartition: updatedFetchState_maxAddrInPartition,
|
|
222
|
+
normalSelection: updatedFetchState_normalSelection,
|
|
223
|
+
indexingContracts: indexingContracts,
|
|
224
|
+
contractConfigs: updatedFetchState_contractConfigs,
|
|
225
|
+
dcsToStore: dcsToStore,
|
|
226
|
+
chainId: updatedFetchState_chainId,
|
|
227
|
+
latestFullyFetchedBlock: latestFullyFetchedBlock$1,
|
|
228
|
+
latestOnBlockBlockNumber: latestOnBlockBlockNumber,
|
|
229
|
+
blockLag: blockLag,
|
|
230
|
+
queue: updatedFetchState_queue,
|
|
231
|
+
targetBufferSize: updatedFetchState_targetBufferSize,
|
|
232
|
+
onBlockConfigs: updatedFetchState_onBlockConfigs
|
|
233
|
+
};
|
|
140
234
|
Prometheus.IndexingPartitions.set(partitions.length, fetchState.chainId);
|
|
141
|
-
Prometheus.IndexingBufferSize.set(
|
|
142
|
-
Prometheus.IndexingBufferBlockNumber.set(latestFullyFetchedBlock$1.blockNumber, fetchState.chainId);
|
|
143
|
-
return
|
|
144
|
-
partitions: partitions,
|
|
145
|
-
nextPartitionIndex: nextPartitionIndex,
|
|
146
|
-
isFetchingAtHead: isFetchingAtHead,
|
|
147
|
-
startBlock: fetchState.startBlock,
|
|
148
|
-
endBlock: fetchState.endBlock,
|
|
149
|
-
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
150
|
-
normalSelection: fetchState.normalSelection,
|
|
151
|
-
indexingContracts: indexingContracts,
|
|
152
|
-
contractConfigs: fetchState.contractConfigs,
|
|
153
|
-
dcsToStore: dcsToStore,
|
|
154
|
-
chainId: fetchState.chainId,
|
|
155
|
-
latestFullyFetchedBlock: latestFullyFetchedBlock$1,
|
|
156
|
-
blockLag: blockLag,
|
|
157
|
-
queue: queue,
|
|
158
|
-
onBlockConfigs: fetchState.onBlockConfigs
|
|
159
|
-
};
|
|
235
|
+
Prometheus.IndexingBufferSize.set(updatedFetchState_queue.length, fetchState.chainId);
|
|
236
|
+
Prometheus.IndexingBufferBlockNumber.set(latestOnBlockBlockNumber < latestFullyFetchedBlock$1.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock$1.blockNumber, fetchState.chainId);
|
|
237
|
+
return updatedFetchState;
|
|
160
238
|
}
|
|
161
239
|
|
|
162
240
|
function numAddresses(fetchState) {
|
|
@@ -173,7 +251,7 @@ function warnDifferentContractType(fetchState, existingContract, dc) {
|
|
|
173
251
|
Logging.childWarn(logger, "Skipping contract registration: Contract address is already registered for one contract and cannot be registered for another contract.");
|
|
174
252
|
}
|
|
175
253
|
|
|
176
|
-
function registerDynamicContracts(fetchState, dynamicContracts
|
|
254
|
+
function registerDynamicContracts(fetchState, dynamicContracts) {
|
|
177
255
|
if (Utils.$$Array.isEmpty(fetchState.normalSelection.eventConfigs)) {
|
|
178
256
|
Js_exn.raiseError("Invalid configuration. No events to fetch for the dynamic contract registration.");
|
|
179
257
|
}
|
|
@@ -326,23 +404,14 @@ function registerDynamicContracts(fetchState, dynamicContracts, currentBlockHeig
|
|
|
326
404
|
}
|
|
327
405
|
Prometheus.IndexingAddresses.set(Object.keys(fetchState.indexingContracts).length + dcsToStore.length | 0, fetchState.chainId);
|
|
328
406
|
var existingDcs = fetchState.dcsToStore;
|
|
329
|
-
return updateInternal(fetchState, fetchState.partitions.concat(newPartitions), fetchState.nextPartitionIndex + newPartitions.length | 0, Object.assign(registeringContracts, indexingContracts), Caml_option.some(existingDcs !== undefined ? Belt_Array.concat(existingDcs, dcsToStore) : dcsToStore),
|
|
407
|
+
return updateInternal(fetchState, fetchState.partitions.concat(newPartitions), fetchState.nextPartitionIndex + newPartitions.length | 0, Object.assign(registeringContracts, indexingContracts), Caml_option.some(existingDcs !== undefined ? Belt_Array.concat(existingDcs, dcsToStore) : dcsToStore), undefined, undefined);
|
|
330
408
|
}
|
|
331
409
|
|
|
332
410
|
var UnexpectedPartitionNotFound = /* @__PURE__ */Caml_exceptions.create("FetchState.UnexpectedPartitionNotFound");
|
|
333
411
|
|
|
334
412
|
var UnexpectedMergeQueryResponse = /* @__PURE__ */Caml_exceptions.create("FetchState.UnexpectedMergeQueryResponse");
|
|
335
413
|
|
|
336
|
-
function
|
|
337
|
-
var blockDiff = b.blockNumber - a.blockNumber | 0;
|
|
338
|
-
if (blockDiff === 0) {
|
|
339
|
-
return b.logIndex - a.logIndex | 0;
|
|
340
|
-
} else {
|
|
341
|
-
return blockDiff;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems, currentBlockHeight) {
|
|
414
|
+
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
346
415
|
var partitions = fetchState.partitions;
|
|
347
416
|
var partitionId = query.partitionId;
|
|
348
417
|
var pIndex = Belt_Array.getIndexBy(partitions, (function (p) {
|
|
@@ -412,46 +481,7 @@ function handleQueryResult(fetchState, query, latestFetchedBlock, newItems, curr
|
|
|
412
481
|
};
|
|
413
482
|
}
|
|
414
483
|
return Belt_Result.map(tmp, (function (partitions) {
|
|
415
|
-
|
|
416
|
-
var onBlockConfigs = fetchState.onBlockConfigs;
|
|
417
|
-
if (onBlockConfigs !== undefined) {
|
|
418
|
-
var prevLatestFetchedBlockNumber = fetchState.latestFullyFetchedBlock.blockNumber;
|
|
419
|
-
var nextLatestFullyFetchedBlockNumber = latestFetchedBlock.blockNumber;
|
|
420
|
-
for(var idx = 0 ,idx_finish = partitions.length; idx < idx_finish; ++idx){
|
|
421
|
-
var p = partitions[idx];
|
|
422
|
-
if (nextLatestFullyFetchedBlockNumber > p.latestFetchedBlock.blockNumber) {
|
|
423
|
-
nextLatestFullyFetchedBlockNumber = p.latestFetchedBlock.blockNumber;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
var nextLatestFullyFetchedBlockNumber$1 = nextLatestFullyFetchedBlockNumber;
|
|
428
|
-
if (nextLatestFullyFetchedBlockNumber$1 > prevLatestFetchedBlockNumber) {
|
|
429
|
-
for(var configIdx = 0 ,configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx){
|
|
430
|
-
var onBlockConfig = onBlockConfigs[configIdx];
|
|
431
|
-
var startBlock = onBlockConfig.startBlock;
|
|
432
|
-
var handlerStartBlock = startBlock !== undefined ? startBlock : fetchState.startBlock;
|
|
433
|
-
var rangeStart = Caml.int_max(handlerStartBlock, prevLatestFetchedBlockNumber + 1 | 0);
|
|
434
|
-
var endBlock = onBlockConfig.endBlock;
|
|
435
|
-
var rangeEnd = endBlock !== undefined && endBlock < nextLatestFullyFetchedBlockNumber$1 ? endBlock : nextLatestFullyFetchedBlockNumber$1;
|
|
436
|
-
if (rangeStart <= rangeEnd) {
|
|
437
|
-
for(var blockNumber = rangeStart; blockNumber <= rangeEnd; ++blockNumber){
|
|
438
|
-
if (Caml_int32.mod_(blockNumber - handlerStartBlock | 0, onBlockConfig.interval) === 0) {
|
|
439
|
-
newQueue.push({
|
|
440
|
-
kind: 1,
|
|
441
|
-
onBlockConfig: onBlockConfig,
|
|
442
|
-
blockNumber: blockNumber,
|
|
443
|
-
logIndex: 16777216
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
return updateInternal(fetchState, partitions, undefined, undefined, undefined, currentBlockHeight, newQueue.sort(compareBufferItem), undefined);
|
|
484
|
+
return updateInternal(fetchState, partitions, undefined, undefined, undefined, newItems.length !== 0 ? Belt_Array.concat(fetchState.queue, newItems) : undefined, undefined);
|
|
455
485
|
}));
|
|
456
486
|
}
|
|
457
487
|
|
|
@@ -538,7 +568,7 @@ function isFullPartition(p, maxAddrInPartition) {
|
|
|
538
568
|
}
|
|
539
569
|
}
|
|
540
570
|
|
|
541
|
-
function getNextQuery(param, concurrencyLimit,
|
|
571
|
+
function getNextQuery(param, concurrencyLimit, currentBlockHeight, stateId) {
|
|
542
572
|
var queue = param.queue;
|
|
543
573
|
var blockLag = param.blockLag;
|
|
544
574
|
var indexingContracts = param.indexingContracts;
|
|
@@ -600,7 +630,7 @@ function getNextQuery(param, concurrencyLimit, targetBufferSize, currentBlockHei
|
|
|
600
630
|
|
|
601
631
|
}
|
|
602
632
|
}
|
|
603
|
-
var targetBlockIdx = queue.length - targetBufferSize | 0;
|
|
633
|
+
var targetBlockIdx = queue.length - param.targetBufferSize | 0;
|
|
604
634
|
var maxQueryBlockNumber;
|
|
605
635
|
if (targetBlockIdx < 0) {
|
|
606
636
|
maxQueryBlockNumber = currentBlockHeight;
|
|
@@ -681,30 +711,50 @@ function makeNoItem(param) {
|
|
|
681
711
|
};
|
|
682
712
|
}
|
|
683
713
|
|
|
684
|
-
function getEarliestEvent(
|
|
685
|
-
var queue =
|
|
686
|
-
var
|
|
687
|
-
|
|
688
|
-
|
|
714
|
+
function getEarliestEvent(fetchState) {
|
|
715
|
+
var queue = fetchState.queue;
|
|
716
|
+
var item = Utils.$$Array.last(fetchState.queue);
|
|
717
|
+
if (item !== undefined) {
|
|
718
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
719
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
720
|
+
if (item.blockNumber <= (
|
|
721
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
722
|
+
)) {
|
|
723
|
+
return {
|
|
724
|
+
TAG: "Item",
|
|
725
|
+
_0: {
|
|
726
|
+
item: item,
|
|
727
|
+
popItemOffQueue: (function () {
|
|
728
|
+
queue.pop();
|
|
729
|
+
})
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
var latestOnBlockBlockNumber$1 = fetchState.latestOnBlockBlockNumber;
|
|
734
|
+
var latestFullyFetchedBlock$1 = fetchState.latestFullyFetchedBlock;
|
|
689
735
|
return {
|
|
690
|
-
TAG: "
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
})
|
|
696
|
-
}
|
|
736
|
+
TAG: "NoItem",
|
|
737
|
+
latestFetchedBlock: latestOnBlockBlockNumber$1 < latestFullyFetchedBlock$1.blockNumber ? ({
|
|
738
|
+
blockNumber: latestOnBlockBlockNumber$1,
|
|
739
|
+
blockTimestamp: 0
|
|
740
|
+
}) : latestFullyFetchedBlock$1
|
|
697
741
|
};
|
|
698
742
|
} else {
|
|
743
|
+
var latestOnBlockBlockNumber$2 = fetchState.latestOnBlockBlockNumber;
|
|
744
|
+
var latestFullyFetchedBlock$2 = fetchState.latestFullyFetchedBlock;
|
|
699
745
|
return {
|
|
700
746
|
TAG: "NoItem",
|
|
701
|
-
latestFetchedBlock: latestFullyFetchedBlock
|
|
747
|
+
latestFetchedBlock: latestOnBlockBlockNumber$2 < latestFullyFetchedBlock$2.blockNumber ? ({
|
|
748
|
+
blockNumber: latestOnBlockBlockNumber$2,
|
|
749
|
+
blockTimestamp: 0
|
|
750
|
+
}) : latestFullyFetchedBlock$2
|
|
702
751
|
};
|
|
703
752
|
}
|
|
704
753
|
}
|
|
705
754
|
|
|
706
|
-
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, progressBlockNumberOpt,
|
|
755
|
+
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, targetBufferSize, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt) {
|
|
707
756
|
var progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
757
|
+
var onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
|
|
708
758
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
709
759
|
var latestFetchedBlock = {
|
|
710
760
|
blockNumber: progressBlockNumber,
|
|
@@ -801,7 +851,6 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
801
851
|
return {
|
|
802
852
|
partitions: partitions,
|
|
803
853
|
nextPartitionIndex: partitions.length,
|
|
804
|
-
isFetchingAtHead: false,
|
|
805
854
|
startBlock: startBlock,
|
|
806
855
|
endBlock: endBlock,
|
|
807
856
|
maxAddrInPartition: maxAddrInPartition,
|
|
@@ -811,8 +860,10 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
811
860
|
dcsToStore: undefined,
|
|
812
861
|
chainId: chainId,
|
|
813
862
|
latestFullyFetchedBlock: latestFetchedBlock,
|
|
863
|
+
latestOnBlockBlockNumber: progressBlockNumber,
|
|
814
864
|
blockLag: blockLag,
|
|
815
865
|
queue: [],
|
|
866
|
+
targetBufferSize: targetBufferSize,
|
|
816
867
|
onBlockConfigs: onBlockConfigs
|
|
817
868
|
};
|
|
818
869
|
}
|
|
@@ -821,10 +872,6 @@ function bufferSize(param) {
|
|
|
821
872
|
return param.queue.length;
|
|
822
873
|
}
|
|
823
874
|
|
|
824
|
-
function getLatestFullyFetchedBlock(param) {
|
|
825
|
-
return param.latestFullyFetchedBlock;
|
|
826
|
-
}
|
|
827
|
-
|
|
828
875
|
function pruneQueueFromFirstChangeEvent(queue, firstChangeEvent) {
|
|
829
876
|
return Belt_Array.keep(queue, (function (item) {
|
|
830
877
|
var tmp;
|
|
@@ -910,7 +957,24 @@ function rollback(fetchState, firstChangeEvent) {
|
|
|
910
957
|
} else {
|
|
911
958
|
tmp = undefined;
|
|
912
959
|
}
|
|
913
|
-
return updateInternal(
|
|
960
|
+
return updateInternal({
|
|
961
|
+
partitions: fetchState.partitions,
|
|
962
|
+
nextPartitionIndex: fetchState.nextPartitionIndex,
|
|
963
|
+
startBlock: fetchState.startBlock,
|
|
964
|
+
endBlock: fetchState.endBlock,
|
|
965
|
+
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
966
|
+
normalSelection: fetchState.normalSelection,
|
|
967
|
+
indexingContracts: fetchState.indexingContracts,
|
|
968
|
+
contractConfigs: fetchState.contractConfigs,
|
|
969
|
+
dcsToStore: fetchState.dcsToStore,
|
|
970
|
+
chainId: fetchState.chainId,
|
|
971
|
+
latestFullyFetchedBlock: fetchState.latestFullyFetchedBlock,
|
|
972
|
+
latestOnBlockBlockNumber: firstChangeEvent.blockNumber - 1 | 0,
|
|
973
|
+
blockLag: fetchState.blockLag,
|
|
974
|
+
queue: fetchState.queue,
|
|
975
|
+
targetBufferSize: fetchState.targetBufferSize,
|
|
976
|
+
onBlockConfigs: fetchState.onBlockConfigs
|
|
977
|
+
}, partitions, undefined, indexingContracts, Caml_option.some(tmp), pruneQueueFromFirstChangeEvent(fetchState.queue, firstChangeEvent), undefined);
|
|
914
978
|
}
|
|
915
979
|
|
|
916
980
|
function isActivelyIndexing(fetchState) {
|
|
@@ -918,7 +982,11 @@ function isActivelyIndexing(fetchState) {
|
|
|
918
982
|
if (endBlock === undefined) {
|
|
919
983
|
return true;
|
|
920
984
|
}
|
|
921
|
-
var
|
|
985
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
986
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
987
|
+
var isPastEndblock = (
|
|
988
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
989
|
+
) >= endBlock;
|
|
922
990
|
if (isPastEndblock) {
|
|
923
991
|
return bufferSize(fetchState) > 0;
|
|
924
992
|
} else {
|
|
@@ -926,36 +994,44 @@ function isActivelyIndexing(fetchState) {
|
|
|
926
994
|
}
|
|
927
995
|
}
|
|
928
996
|
|
|
929
|
-
function isReadyToEnterReorgThreshold(
|
|
930
|
-
var blockLag =
|
|
931
|
-
var
|
|
932
|
-
var
|
|
997
|
+
function isReadyToEnterReorgThreshold(fetchState, currentBlockHeight) {
|
|
998
|
+
var blockLag = fetchState.blockLag;
|
|
999
|
+
var endBlock = fetchState.endBlock;
|
|
1000
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1001
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1002
|
+
var bufferBlockNumber = latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber;
|
|
933
1003
|
if (currentBlockHeight !== 0 && (
|
|
934
|
-
endBlock !== undefined &&
|
|
1004
|
+
endBlock !== undefined && bufferBlockNumber >= endBlock ? true : bufferBlockNumber >= (currentBlockHeight - blockLag | 0)
|
|
935
1005
|
)) {
|
|
936
|
-
return Utils.$$Array.isEmpty(
|
|
1006
|
+
return Utils.$$Array.isEmpty(fetchState.queue);
|
|
937
1007
|
} else {
|
|
938
1008
|
return false;
|
|
939
1009
|
}
|
|
940
1010
|
}
|
|
941
1011
|
|
|
942
|
-
function hasBatchItem(
|
|
943
|
-
var item = Utils.$$Array.last(
|
|
944
|
-
if (item
|
|
945
|
-
return item.blockNumber <= param.latestFullyFetchedBlock.blockNumber;
|
|
946
|
-
} else {
|
|
1012
|
+
function hasBatchItem(fetchState) {
|
|
1013
|
+
var item = Utils.$$Array.last(fetchState.queue);
|
|
1014
|
+
if (item === undefined) {
|
|
947
1015
|
return false;
|
|
948
1016
|
}
|
|
1017
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1018
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1019
|
+
return item.blockNumber <= (
|
|
1020
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
1021
|
+
);
|
|
949
1022
|
}
|
|
950
1023
|
|
|
951
|
-
function hasFullBatch(
|
|
952
|
-
var queue =
|
|
1024
|
+
function hasFullBatch(fetchState, maxBatchSize) {
|
|
1025
|
+
var queue = fetchState.queue;
|
|
953
1026
|
var targetBlockIdx = queue.length - maxBatchSize | 0;
|
|
954
1027
|
if (targetBlockIdx < 0) {
|
|
955
1028
|
return false;
|
|
956
|
-
} else {
|
|
957
|
-
return queue[targetBlockIdx].blockNumber <= param.latestFullyFetchedBlock.blockNumber;
|
|
958
1029
|
}
|
|
1030
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1031
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1032
|
+
return queue[targetBlockIdx].blockNumber <= (
|
|
1033
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
1034
|
+
);
|
|
959
1035
|
}
|
|
960
1036
|
|
|
961
1037
|
function filterAndSortForUnorderedBatch(fetchStates, maxBatchSize) {
|
|
@@ -980,18 +1056,20 @@ function filterAndSortForUnorderedBatch(fetchStates, maxBatchSize) {
|
|
|
980
1056
|
});
|
|
981
1057
|
}
|
|
982
1058
|
|
|
983
|
-
function getProgressBlockNumber(
|
|
984
|
-
var
|
|
985
|
-
var
|
|
986
|
-
|
|
1059
|
+
function getProgressBlockNumber(fetchState) {
|
|
1060
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1061
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1062
|
+
var bufferBlockNumber = latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber;
|
|
1063
|
+
var item = Utils.$$Array.last(fetchState.queue);
|
|
1064
|
+
if (item !== undefined && bufferBlockNumber >= item.blockNumber) {
|
|
987
1065
|
return item.blockNumber - 1 | 0;
|
|
988
1066
|
} else {
|
|
989
|
-
return
|
|
1067
|
+
return bufferBlockNumber;
|
|
990
1068
|
}
|
|
991
1069
|
}
|
|
992
1070
|
|
|
993
|
-
function getProgressNextBlockLogIndex(
|
|
994
|
-
var match = Utils.$$Array.last(
|
|
1071
|
+
function getProgressNextBlockLogIndex(fetchState) {
|
|
1072
|
+
var match = Utils.$$Array.last(fetchState.queue);
|
|
995
1073
|
if (match === undefined) {
|
|
996
1074
|
return ;
|
|
997
1075
|
}
|
|
@@ -999,7 +1077,11 @@ function getProgressNextBlockLogIndex(param) {
|
|
|
999
1077
|
return ;
|
|
1000
1078
|
}
|
|
1001
1079
|
var logIndex = match.logIndex;
|
|
1002
|
-
|
|
1080
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1081
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1082
|
+
if ((
|
|
1083
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
1084
|
+
) >= match.blockNumber && logIndex > 0) {
|
|
1003
1085
|
return logIndex - 1 | 0;
|
|
1004
1086
|
}
|
|
1005
1087
|
|
|
@@ -1009,15 +1091,16 @@ var blockItemLogIndex = 16777216;
|
|
|
1009
1091
|
|
|
1010
1092
|
exports.copy = copy;
|
|
1011
1093
|
exports.mergeIntoPartition = mergeIntoPartition;
|
|
1012
|
-
exports.
|
|
1094
|
+
exports.bufferBlockNumber = bufferBlockNumber;
|
|
1095
|
+
exports.bufferBlock = bufferBlock;
|
|
1096
|
+
exports.compareBufferItem = compareBufferItem;
|
|
1097
|
+
exports.blockItemLogIndex = blockItemLogIndex;
|
|
1013
1098
|
exports.updateInternal = updateInternal;
|
|
1014
1099
|
exports.numAddresses = numAddresses;
|
|
1015
1100
|
exports.warnDifferentContractType = warnDifferentContractType;
|
|
1016
1101
|
exports.registerDynamicContracts = registerDynamicContracts;
|
|
1017
1102
|
exports.UnexpectedPartitionNotFound = UnexpectedPartitionNotFound;
|
|
1018
1103
|
exports.UnexpectedMergeQueryResponse = UnexpectedMergeQueryResponse;
|
|
1019
|
-
exports.compareBufferItem = compareBufferItem;
|
|
1020
|
-
exports.blockItemLogIndex = blockItemLogIndex;
|
|
1021
1104
|
exports.handleQueryResult = handleQueryResult;
|
|
1022
1105
|
exports.makePartitionQuery = makePartitionQuery;
|
|
1023
1106
|
exports.startFetchingQueries = startFetchingQueries;
|
|
@@ -1029,7 +1112,6 @@ exports.makeNoItem = makeNoItem;
|
|
|
1029
1112
|
exports.getEarliestEvent = getEarliestEvent;
|
|
1030
1113
|
exports.make = make;
|
|
1031
1114
|
exports.bufferSize = bufferSize;
|
|
1032
|
-
exports.getLatestFullyFetchedBlock = getLatestFullyFetchedBlock;
|
|
1033
1115
|
exports.pruneQueueFromFirstChangeEvent = pruneQueueFromFirstChangeEvent;
|
|
1034
1116
|
exports.rollbackPartition = rollbackPartition;
|
|
1035
1117
|
exports.rollback = rollback;
|
package/src/Logging.res.js
CHANGED
|
@@ -8,7 +8,6 @@ var Js_exn = require("rescript/lib/js/js_exn.js");
|
|
|
8
8
|
var Js_dict = require("rescript/lib/js/js_dict.js");
|
|
9
9
|
var Caml_obj = require("rescript/lib/js/caml_obj.js");
|
|
10
10
|
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
11
|
-
var EcsPinoFormat = require("@elastic/ecs-pino-format");
|
|
12
11
|
|
|
13
12
|
var logLevels = Js_dict.fromArray([
|
|
14
13
|
[
|
|
@@ -75,13 +74,13 @@ function makeLogger(logStrategy, logFilePath, defaultFileLogLevel, userLogLevel)
|
|
|
75
74
|
};
|
|
76
75
|
switch (logStrategy) {
|
|
77
76
|
case "ecs-file" :
|
|
78
|
-
var newrecord = Caml_obj.obj_dup(
|
|
77
|
+
var newrecord = Caml_obj.obj_dup(Pino.ECS.make());
|
|
79
78
|
return Pino$1((newrecord.customLevels = logLevels, newrecord), Pino$1.transport(pinoFile));
|
|
80
79
|
case "ecs-console" :
|
|
81
|
-
var newrecord$1 = Caml_obj.obj_dup(
|
|
80
|
+
var newrecord$1 = Caml_obj.obj_dup(Pino.ECS.make());
|
|
82
81
|
return Pino$1((newrecord$1.customLevels = logLevels, newrecord$1.level = userLogLevel, newrecord$1));
|
|
83
82
|
case "ecs-console-multistream" :
|
|
84
|
-
return makeMultiStreamLogger(undefined,
|
|
83
|
+
return makeMultiStreamLogger(undefined, Pino.ECS.make());
|
|
85
84
|
case "file-only" :
|
|
86
85
|
return Pino$1({
|
|
87
86
|
level: defaultFileLogLevel,
|
package/src/Utils.res
CHANGED
package/src/bindings/Pino.res
CHANGED
package/src/bindings/Pino.res.js
CHANGED
|
@@ -7,6 +7,7 @@ var Caml_obj = require("rescript/lib/js/caml_obj.js");
|
|
|
7
7
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
8
8
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
9
9
|
var PinoPretty = require("pino-pretty");
|
|
10
|
+
var EcsPinoFormat = require("@elastic/ecs-pino-format");
|
|
10
11
|
|
|
11
12
|
function createPinoMessage(message) {
|
|
12
13
|
return message;
|
|
@@ -31,7 +32,13 @@ function createChildParams(prim) {
|
|
|
31
32
|
return prim;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
function make(prim) {
|
|
36
|
+
return EcsPinoFormat(prim);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var ECS = {
|
|
40
|
+
make: make
|
|
41
|
+
};
|
|
35
42
|
|
|
36
43
|
function makeFormatter(logLevels) {
|
|
37
44
|
return PinoPretty.prettyFactory({
|
|
@@ -63,7 +70,7 @@ function makeStreams(userLogLevel, formatter, logFile, defaultFileLogLevel) {
|
|
|
63
70
|
return Belt_Array.concat([stream], maybeFileStream);
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
function make(userLogLevel, customLevels, logFile, options, defaultFileLogLevel) {
|
|
73
|
+
function make$1(userLogLevel, customLevels, logFile, options, defaultFileLogLevel) {
|
|
67
74
|
var options$1;
|
|
68
75
|
if (options !== undefined) {
|
|
69
76
|
var newrecord = Caml_obj.obj_dup(options);
|
|
@@ -84,7 +91,7 @@ function make(userLogLevel, customLevels, logFile, options, defaultFileLogLevel)
|
|
|
84
91
|
var MultiStreamLogger = {
|
|
85
92
|
makeFormatter: makeFormatter,
|
|
86
93
|
makeStreams: makeStreams,
|
|
87
|
-
make: make
|
|
94
|
+
make: make$1
|
|
88
95
|
};
|
|
89
96
|
|
|
90
97
|
exports.createPinoMessage = createPinoMessage;
|
package/src/db/EntityHistory.res
CHANGED
|
@@ -188,9 +188,6 @@ let fromTable = (table: table, ~schema: S.t<'entity>): t<'entity> => {
|
|
|
188
188
|
switch field.fieldName {
|
|
189
189
|
//id is not nullable and should be part of the pk
|
|
190
190
|
| "id" => {...field, fieldName: id, isPrimaryKey: true}->Field->Some
|
|
191
|
-
//db_write_timestamp can be removed for this. TODO: remove this when we depracate
|
|
192
|
-
//automatic db_write_timestamp creation
|
|
193
|
-
| "db_write_timestamp" => None
|
|
194
191
|
| _ =>
|
|
195
192
|
{
|
|
196
193
|
...field,
|