envio 2.29.0-alpha.1 → 2.29.0-alpha.3
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/Envio.gen.ts +7 -3
- package/src/Envio.res +5 -8
- package/src/EventRegister.res +51 -15
- package/src/EventRegister.res.js +34 -9
- package/src/EventRegister.resi +1 -1
- package/src/EventUtils.res +4 -0
- package/src/EventUtils.res.js +3 -0
- package/src/FetchState.res +195 -145
- package/src/FetchState.res.js +218 -121
- package/src/Internal.res +3 -0
- 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
|
@@ -10,6 +10,7 @@ var Logging = require("./Logging.res.js");
|
|
|
10
10
|
var Belt_Int = require("rescript/lib/js/belt_Int.js");
|
|
11
11
|
var Caml_obj = require("rescript/lib/js/caml_obj.js");
|
|
12
12
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
13
|
+
var Caml_int32 = require("rescript/lib/js/caml_int32.js");
|
|
13
14
|
var Prometheus = require("./Prometheus.res.js");
|
|
14
15
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
|
15
16
|
var Belt_Result = require("rescript/lib/js/belt_Result.js");
|
|
@@ -20,7 +21,7 @@ function copy(fetchState) {
|
|
|
20
21
|
return {
|
|
21
22
|
partitions: fetchState.partitions,
|
|
22
23
|
nextPartitionIndex: fetchState.nextPartitionIndex,
|
|
23
|
-
|
|
24
|
+
startBlock: fetchState.startBlock,
|
|
24
25
|
endBlock: fetchState.endBlock,
|
|
25
26
|
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
26
27
|
normalSelection: fetchState.normalSelection,
|
|
@@ -29,8 +30,10 @@ function copy(fetchState) {
|
|
|
29
30
|
dcsToStore: fetchState.dcsToStore,
|
|
30
31
|
chainId: fetchState.chainId,
|
|
31
32
|
latestFullyFetchedBlock: fetchState.latestFullyFetchedBlock,
|
|
33
|
+
latestOnBlockBlockNumber: fetchState.latestOnBlockBlockNumber,
|
|
32
34
|
blockLag: fetchState.blockLag,
|
|
33
35
|
queue: fetchState.queue.slice(0),
|
|
36
|
+
targetBufferSize: fetchState.targetBufferSize,
|
|
34
37
|
onBlockConfigs: fetchState.onBlockConfigs
|
|
35
38
|
};
|
|
36
39
|
}
|
|
@@ -110,16 +113,43 @@ function mergeIntoPartition(p, target, maxAddrInPartition) {
|
|
|
110
113
|
];
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
function
|
|
114
|
-
|
|
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
|
+
}
|
|
115
146
|
}
|
|
116
147
|
|
|
117
|
-
function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexingContractsOpt, dcsToStoreOpt,
|
|
148
|
+
function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexingContractsOpt, dcsToStoreOpt, mutItems, blockLagOpt) {
|
|
118
149
|
var partitions = partitionsOpt !== undefined ? partitionsOpt : fetchState.partitions;
|
|
119
150
|
var nextPartitionIndex = nextPartitionIndexOpt !== undefined ? nextPartitionIndexOpt : fetchState.nextPartitionIndex;
|
|
120
151
|
var indexingContracts = indexingContractsOpt !== undefined ? indexingContractsOpt : fetchState.indexingContracts;
|
|
121
152
|
var dcsToStore = dcsToStoreOpt !== undefined ? Caml_option.valFromOption(dcsToStoreOpt) : fetchState.dcsToStore;
|
|
122
|
-
var queue = queueOpt !== undefined ? queueOpt : fetchState.queue;
|
|
123
153
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : fetchState.blockLag;
|
|
124
154
|
var firstPartition = partitions[0];
|
|
125
155
|
var latestFullyFetchedBlock = firstPartition.latestFetchedBlock;
|
|
@@ -131,29 +161,80 @@ function updateInternal(fetchState, partitionsOpt, nextPartitionIndexOpt, indexi
|
|
|
131
161
|
|
|
132
162
|
}
|
|
133
163
|
var latestFullyFetchedBlock$1 = latestFullyFetchedBlock;
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
+
};
|
|
138
234
|
Prometheus.IndexingPartitions.set(partitions.length, fetchState.chainId);
|
|
139
|
-
Prometheus.IndexingBufferSize.set(
|
|
140
|
-
Prometheus.IndexingBufferBlockNumber.set(latestFullyFetchedBlock$1.blockNumber, fetchState.chainId);
|
|
141
|
-
return
|
|
142
|
-
partitions: partitions,
|
|
143
|
-
nextPartitionIndex: nextPartitionIndex,
|
|
144
|
-
isFetchingAtHead: isFetchingAtHead,
|
|
145
|
-
endBlock: fetchState.endBlock,
|
|
146
|
-
maxAddrInPartition: fetchState.maxAddrInPartition,
|
|
147
|
-
normalSelection: fetchState.normalSelection,
|
|
148
|
-
indexingContracts: indexingContracts,
|
|
149
|
-
contractConfigs: fetchState.contractConfigs,
|
|
150
|
-
dcsToStore: dcsToStore,
|
|
151
|
-
chainId: fetchState.chainId,
|
|
152
|
-
latestFullyFetchedBlock: latestFullyFetchedBlock$1,
|
|
153
|
-
blockLag: blockLag,
|
|
154
|
-
queue: queue,
|
|
155
|
-
onBlockConfigs: fetchState.onBlockConfigs
|
|
156
|
-
};
|
|
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;
|
|
157
238
|
}
|
|
158
239
|
|
|
159
240
|
function numAddresses(fetchState) {
|
|
@@ -170,7 +251,7 @@ function warnDifferentContractType(fetchState, existingContract, dc) {
|
|
|
170
251
|
Logging.childWarn(logger, "Skipping contract registration: Contract address is already registered for one contract and cannot be registered for another contract.");
|
|
171
252
|
}
|
|
172
253
|
|
|
173
|
-
function registerDynamicContracts(fetchState, dynamicContracts
|
|
254
|
+
function registerDynamicContracts(fetchState, dynamicContracts) {
|
|
174
255
|
if (Utils.$$Array.isEmpty(fetchState.normalSelection.eventConfigs)) {
|
|
175
256
|
Js_exn.raiseError("Invalid configuration. No events to fetch for the dynamic contract registration.");
|
|
176
257
|
}
|
|
@@ -323,23 +404,14 @@ function registerDynamicContracts(fetchState, dynamicContracts, currentBlockHeig
|
|
|
323
404
|
}
|
|
324
405
|
Prometheus.IndexingAddresses.set(Object.keys(fetchState.indexingContracts).length + dcsToStore.length | 0, fetchState.chainId);
|
|
325
406
|
var existingDcs = fetchState.dcsToStore;
|
|
326
|
-
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);
|
|
327
408
|
}
|
|
328
409
|
|
|
329
410
|
var UnexpectedPartitionNotFound = /* @__PURE__ */Caml_exceptions.create("FetchState.UnexpectedPartitionNotFound");
|
|
330
411
|
|
|
331
412
|
var UnexpectedMergeQueryResponse = /* @__PURE__ */Caml_exceptions.create("FetchState.UnexpectedMergeQueryResponse");
|
|
332
413
|
|
|
333
|
-
function
|
|
334
|
-
var blockDiff = b.blockNumber - a.blockNumber | 0;
|
|
335
|
-
if (blockDiff === 0) {
|
|
336
|
-
return b.logIndex - a.logIndex | 0;
|
|
337
|
-
} else {
|
|
338
|
-
return blockDiff;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems, currentBlockHeight) {
|
|
414
|
+
function handleQueryResult(fetchState, query, latestFetchedBlock, newItems) {
|
|
343
415
|
var partitions = fetchState.partitions;
|
|
344
416
|
var partitionId = query.partitionId;
|
|
345
417
|
var pIndex = Belt_Array.getIndexBy(partitions, (function (p) {
|
|
@@ -409,35 +481,7 @@ function handleQueryResult(fetchState, query, latestFetchedBlock, newItems, curr
|
|
|
409
481
|
};
|
|
410
482
|
}
|
|
411
483
|
return Belt_Result.map(tmp, (function (partitions) {
|
|
412
|
-
|
|
413
|
-
var onBlockConfigs = fetchState.onBlockConfigs;
|
|
414
|
-
if (onBlockConfigs !== undefined) {
|
|
415
|
-
var prevLatestFetchedBlockNumber = fetchState.latestFullyFetchedBlock.blockNumber;
|
|
416
|
-
var nextLatestFullyFetchedBlockNumber = latestFetchedBlock.blockNumber;
|
|
417
|
-
for(var idx = 0 ,idx_finish = partitions.length; idx < idx_finish; ++idx){
|
|
418
|
-
var p = partitions[idx];
|
|
419
|
-
if (nextLatestFullyFetchedBlockNumber > p.latestFetchedBlock.blockNumber) {
|
|
420
|
-
nextLatestFullyFetchedBlockNumber = p.latestFetchedBlock.blockNumber;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
var nextLatestFullyFetchedBlockNumber$1 = nextLatestFullyFetchedBlockNumber;
|
|
425
|
-
if (nextLatestFullyFetchedBlockNumber$1 > prevLatestFetchedBlockNumber) {
|
|
426
|
-
for(var blockNumber = prevLatestFetchedBlockNumber + 1 | 0; blockNumber <= nextLatestFullyFetchedBlockNumber$1; ++blockNumber){
|
|
427
|
-
for(var configIdx = 0 ,configIdx_finish = onBlockConfigs.length; configIdx < configIdx_finish; ++configIdx){
|
|
428
|
-
var onBlockConfig = onBlockConfigs[configIdx];
|
|
429
|
-
newQueue.push({
|
|
430
|
-
kind: 1,
|
|
431
|
-
onBlockConfig: onBlockConfig,
|
|
432
|
-
blockNumber: blockNumber,
|
|
433
|
-
logIndex: 16777216
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
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);
|
|
441
485
|
}));
|
|
442
486
|
}
|
|
443
487
|
|
|
@@ -524,7 +568,7 @@ function isFullPartition(p, maxAddrInPartition) {
|
|
|
524
568
|
}
|
|
525
569
|
}
|
|
526
570
|
|
|
527
|
-
function getNextQuery(param, concurrencyLimit,
|
|
571
|
+
function getNextQuery(param, concurrencyLimit, currentBlockHeight, stateId) {
|
|
528
572
|
var queue = param.queue;
|
|
529
573
|
var blockLag = param.blockLag;
|
|
530
574
|
var indexingContracts = param.indexingContracts;
|
|
@@ -586,7 +630,7 @@ function getNextQuery(param, concurrencyLimit, targetBufferSize, currentBlockHei
|
|
|
586
630
|
|
|
587
631
|
}
|
|
588
632
|
}
|
|
589
|
-
var targetBlockIdx = queue.length - targetBufferSize | 0;
|
|
633
|
+
var targetBlockIdx = queue.length - param.targetBufferSize | 0;
|
|
590
634
|
var maxQueryBlockNumber;
|
|
591
635
|
if (targetBlockIdx < 0) {
|
|
592
636
|
maxQueryBlockNumber = currentBlockHeight;
|
|
@@ -667,33 +711,53 @@ function makeNoItem(param) {
|
|
|
667
711
|
};
|
|
668
712
|
}
|
|
669
713
|
|
|
670
|
-
function getEarliestEvent(
|
|
671
|
-
var queue =
|
|
672
|
-
var
|
|
673
|
-
|
|
674
|
-
|
|
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;
|
|
675
735
|
return {
|
|
676
|
-
TAG: "
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
})
|
|
682
|
-
}
|
|
736
|
+
TAG: "NoItem",
|
|
737
|
+
latestFetchedBlock: latestOnBlockBlockNumber$1 < latestFullyFetchedBlock$1.blockNumber ? ({
|
|
738
|
+
blockNumber: latestOnBlockBlockNumber$1,
|
|
739
|
+
blockTimestamp: 0
|
|
740
|
+
}) : latestFullyFetchedBlock$1
|
|
683
741
|
};
|
|
684
742
|
} else {
|
|
743
|
+
var latestOnBlockBlockNumber$2 = fetchState.latestOnBlockBlockNumber;
|
|
744
|
+
var latestFullyFetchedBlock$2 = fetchState.latestFullyFetchedBlock;
|
|
685
745
|
return {
|
|
686
746
|
TAG: "NoItem",
|
|
687
|
-
latestFetchedBlock: latestFullyFetchedBlock
|
|
747
|
+
latestFetchedBlock: latestOnBlockBlockNumber$2 < latestFullyFetchedBlock$2.blockNumber ? ({
|
|
748
|
+
blockNumber: latestOnBlockBlockNumber$2,
|
|
749
|
+
blockTimestamp: 0
|
|
750
|
+
}) : latestFullyFetchedBlock$2
|
|
688
751
|
};
|
|
689
752
|
}
|
|
690
753
|
}
|
|
691
754
|
|
|
692
|
-
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId,
|
|
755
|
+
function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition, chainId, targetBufferSize, progressBlockNumberOpt, onBlockConfigsOpt, blockLagOpt) {
|
|
756
|
+
var progressBlockNumber = progressBlockNumberOpt !== undefined ? progressBlockNumberOpt : startBlock - 1 | 0;
|
|
757
|
+
var onBlockConfigs = onBlockConfigsOpt !== undefined ? onBlockConfigsOpt : [];
|
|
693
758
|
var blockLag = blockLagOpt !== undefined ? blockLagOpt : 0;
|
|
694
|
-
var latestFetchedBlock_blockNumber = startBlock - 1 | 0;
|
|
695
759
|
var latestFetchedBlock = {
|
|
696
|
-
blockNumber:
|
|
760
|
+
blockNumber: progressBlockNumber,
|
|
697
761
|
blockTimestamp: 0
|
|
698
762
|
};
|
|
699
763
|
var notDependingOnAddresses = [];
|
|
@@ -780,14 +844,14 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
780
844
|
Prometheus.IndexingAddresses.set(numAddresses, chainId);
|
|
781
845
|
Prometheus.IndexingPartitions.set(partitions.length, chainId);
|
|
782
846
|
Prometheus.IndexingBufferSize.set(0, chainId);
|
|
783
|
-
Prometheus.IndexingBufferBlockNumber.set(
|
|
847
|
+
Prometheus.IndexingBufferBlockNumber.set(progressBlockNumber, chainId);
|
|
784
848
|
if (endBlock !== undefined) {
|
|
785
849
|
Prometheus.IndexingEndBlock.set(endBlock, chainId);
|
|
786
850
|
}
|
|
787
851
|
return {
|
|
788
852
|
partitions: partitions,
|
|
789
853
|
nextPartitionIndex: partitions.length,
|
|
790
|
-
|
|
854
|
+
startBlock: startBlock,
|
|
791
855
|
endBlock: endBlock,
|
|
792
856
|
maxAddrInPartition: maxAddrInPartition,
|
|
793
857
|
normalSelection: normalSelection,
|
|
@@ -796,8 +860,10 @@ function make(startBlock, endBlock, eventConfigs, contracts, maxAddrInPartition,
|
|
|
796
860
|
dcsToStore: undefined,
|
|
797
861
|
chainId: chainId,
|
|
798
862
|
latestFullyFetchedBlock: latestFetchedBlock,
|
|
863
|
+
latestOnBlockBlockNumber: progressBlockNumber,
|
|
799
864
|
blockLag: blockLag,
|
|
800
865
|
queue: [],
|
|
866
|
+
targetBufferSize: targetBufferSize,
|
|
801
867
|
onBlockConfigs: onBlockConfigs
|
|
802
868
|
};
|
|
803
869
|
}
|
|
@@ -806,10 +872,6 @@ function bufferSize(param) {
|
|
|
806
872
|
return param.queue.length;
|
|
807
873
|
}
|
|
808
874
|
|
|
809
|
-
function getLatestFullyFetchedBlock(param) {
|
|
810
|
-
return param.latestFullyFetchedBlock;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
875
|
function pruneQueueFromFirstChangeEvent(queue, firstChangeEvent) {
|
|
814
876
|
return Belt_Array.keep(queue, (function (item) {
|
|
815
877
|
var tmp;
|
|
@@ -895,7 +957,24 @@ function rollback(fetchState, firstChangeEvent) {
|
|
|
895
957
|
} else {
|
|
896
958
|
tmp = undefined;
|
|
897
959
|
}
|
|
898
|
-
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);
|
|
899
978
|
}
|
|
900
979
|
|
|
901
980
|
function isActivelyIndexing(fetchState) {
|
|
@@ -903,7 +982,11 @@ function isActivelyIndexing(fetchState) {
|
|
|
903
982
|
if (endBlock === undefined) {
|
|
904
983
|
return true;
|
|
905
984
|
}
|
|
906
|
-
var
|
|
985
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
986
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
987
|
+
var isPastEndblock = (
|
|
988
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
989
|
+
) >= endBlock;
|
|
907
990
|
if (isPastEndblock) {
|
|
908
991
|
return bufferSize(fetchState) > 0;
|
|
909
992
|
} else {
|
|
@@ -911,36 +994,44 @@ function isActivelyIndexing(fetchState) {
|
|
|
911
994
|
}
|
|
912
995
|
}
|
|
913
996
|
|
|
914
|
-
function isReadyToEnterReorgThreshold(
|
|
915
|
-
var blockLag =
|
|
916
|
-
var
|
|
917
|
-
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;
|
|
918
1003
|
if (currentBlockHeight !== 0 && (
|
|
919
|
-
endBlock !== undefined &&
|
|
1004
|
+
endBlock !== undefined && bufferBlockNumber >= endBlock ? true : bufferBlockNumber >= (currentBlockHeight - blockLag | 0)
|
|
920
1005
|
)) {
|
|
921
|
-
return Utils.$$Array.isEmpty(
|
|
1006
|
+
return Utils.$$Array.isEmpty(fetchState.queue);
|
|
922
1007
|
} else {
|
|
923
1008
|
return false;
|
|
924
1009
|
}
|
|
925
1010
|
}
|
|
926
1011
|
|
|
927
|
-
function hasBatchItem(
|
|
928
|
-
var item = Utils.$$Array.last(
|
|
929
|
-
if (item
|
|
930
|
-
return item.blockNumber <= param.latestFullyFetchedBlock.blockNumber;
|
|
931
|
-
} else {
|
|
1012
|
+
function hasBatchItem(fetchState) {
|
|
1013
|
+
var item = Utils.$$Array.last(fetchState.queue);
|
|
1014
|
+
if (item === undefined) {
|
|
932
1015
|
return false;
|
|
933
1016
|
}
|
|
1017
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1018
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1019
|
+
return item.blockNumber <= (
|
|
1020
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
1021
|
+
);
|
|
934
1022
|
}
|
|
935
1023
|
|
|
936
|
-
function hasFullBatch(
|
|
937
|
-
var queue =
|
|
1024
|
+
function hasFullBatch(fetchState, maxBatchSize) {
|
|
1025
|
+
var queue = fetchState.queue;
|
|
938
1026
|
var targetBlockIdx = queue.length - maxBatchSize | 0;
|
|
939
1027
|
if (targetBlockIdx < 0) {
|
|
940
1028
|
return false;
|
|
941
|
-
} else {
|
|
942
|
-
return queue[targetBlockIdx].blockNumber <= param.latestFullyFetchedBlock.blockNumber;
|
|
943
1029
|
}
|
|
1030
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1031
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1032
|
+
return queue[targetBlockIdx].blockNumber <= (
|
|
1033
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
1034
|
+
);
|
|
944
1035
|
}
|
|
945
1036
|
|
|
946
1037
|
function filterAndSortForUnorderedBatch(fetchStates, maxBatchSize) {
|
|
@@ -965,18 +1056,20 @@ function filterAndSortForUnorderedBatch(fetchStates, maxBatchSize) {
|
|
|
965
1056
|
});
|
|
966
1057
|
}
|
|
967
1058
|
|
|
968
|
-
function getProgressBlockNumber(
|
|
969
|
-
var
|
|
970
|
-
var
|
|
971
|
-
|
|
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) {
|
|
972
1065
|
return item.blockNumber - 1 | 0;
|
|
973
1066
|
} else {
|
|
974
|
-
return
|
|
1067
|
+
return bufferBlockNumber;
|
|
975
1068
|
}
|
|
976
1069
|
}
|
|
977
1070
|
|
|
978
|
-
function getProgressNextBlockLogIndex(
|
|
979
|
-
var match = Utils.$$Array.last(
|
|
1071
|
+
function getProgressNextBlockLogIndex(fetchState) {
|
|
1072
|
+
var match = Utils.$$Array.last(fetchState.queue);
|
|
980
1073
|
if (match === undefined) {
|
|
981
1074
|
return ;
|
|
982
1075
|
}
|
|
@@ -984,7 +1077,11 @@ function getProgressNextBlockLogIndex(param) {
|
|
|
984
1077
|
return ;
|
|
985
1078
|
}
|
|
986
1079
|
var logIndex = match.logIndex;
|
|
987
|
-
|
|
1080
|
+
var latestOnBlockBlockNumber = fetchState.latestOnBlockBlockNumber;
|
|
1081
|
+
var latestFullyFetchedBlock = fetchState.latestFullyFetchedBlock;
|
|
1082
|
+
if ((
|
|
1083
|
+
latestOnBlockBlockNumber < latestFullyFetchedBlock.blockNumber ? latestOnBlockBlockNumber : latestFullyFetchedBlock.blockNumber
|
|
1084
|
+
) >= match.blockNumber && logIndex > 0) {
|
|
988
1085
|
return logIndex - 1 | 0;
|
|
989
1086
|
}
|
|
990
1087
|
|
|
@@ -994,15 +1091,16 @@ var blockItemLogIndex = 16777216;
|
|
|
994
1091
|
|
|
995
1092
|
exports.copy = copy;
|
|
996
1093
|
exports.mergeIntoPartition = mergeIntoPartition;
|
|
997
|
-
exports.
|
|
1094
|
+
exports.bufferBlockNumber = bufferBlockNumber;
|
|
1095
|
+
exports.bufferBlock = bufferBlock;
|
|
1096
|
+
exports.compareBufferItem = compareBufferItem;
|
|
1097
|
+
exports.blockItemLogIndex = blockItemLogIndex;
|
|
998
1098
|
exports.updateInternal = updateInternal;
|
|
999
1099
|
exports.numAddresses = numAddresses;
|
|
1000
1100
|
exports.warnDifferentContractType = warnDifferentContractType;
|
|
1001
1101
|
exports.registerDynamicContracts = registerDynamicContracts;
|
|
1002
1102
|
exports.UnexpectedPartitionNotFound = UnexpectedPartitionNotFound;
|
|
1003
1103
|
exports.UnexpectedMergeQueryResponse = UnexpectedMergeQueryResponse;
|
|
1004
|
-
exports.compareBufferItem = compareBufferItem;
|
|
1005
|
-
exports.blockItemLogIndex = blockItemLogIndex;
|
|
1006
1104
|
exports.handleQueryResult = handleQueryResult;
|
|
1007
1105
|
exports.makePartitionQuery = makePartitionQuery;
|
|
1008
1106
|
exports.startFetchingQueries = startFetchingQueries;
|
|
@@ -1014,7 +1112,6 @@ exports.makeNoItem = makeNoItem;
|
|
|
1014
1112
|
exports.getEarliestEvent = getEarliestEvent;
|
|
1015
1113
|
exports.make = make;
|
|
1016
1114
|
exports.bufferSize = bufferSize;
|
|
1017
|
-
exports.getLatestFullyFetchedBlock = getLatestFullyFetchedBlock;
|
|
1018
1115
|
exports.pruneQueueFromFirstChangeEvent = pruneQueueFromFirstChangeEvent;
|
|
1019
1116
|
exports.rollbackPartition = rollbackPartition;
|
|
1020
1117
|
exports.rollback = rollback;
|
package/src/Internal.res
CHANGED
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,
|