envio 3.3.0-alpha.11 → 3.3.0-alpha.13
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/package.json +6 -6
- package/src/ChainFetching.res +21 -12
- package/src/ChainFetching.res.mjs +20 -9
- package/src/ChainState.res +20 -8
- package/src/ChainState.res.mjs +13 -12
- package/src/ChainState.resi +1 -1
- package/src/CrossChainState.res +64 -41
- package/src/CrossChainState.res.mjs +18 -13
- 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/FetchState.res +115 -76
- package/src/FetchState.res.mjs +114 -104
- package/src/InMemoryStore.res +14 -26
- package/src/InMemoryStore.res.mjs +6 -19
- package/src/IndexerState.res +10 -19
- package/src/IndexerState.res.mjs +7 -6
- package/src/IndexerState.resi +1 -9
- package/src/Internal.res +87 -12
- 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/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/Rollback.res +32 -13
- package/src/Rollback.res.mjs +24 -11
- package/src/UserContext.res +62 -23
- package/src/UserContext.res.mjs +26 -6
- package/src/Writing.res +28 -12
- package/src/Writing.res.mjs +15 -7
- package/src/bindings/NodeJs.res +5 -0
- package/src/sources/SvmHyperSyncSource.res +10 -0
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
package/src/FetchState.res.mjs
CHANGED
|
@@ -28,27 +28,23 @@ function densityItemsTarget(density, fromBlock, toBlock, chainTargetBlock) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function getMinHistoryRange(p) {
|
|
31
|
-
let match = p.
|
|
32
|
-
let match$1 = p.
|
|
31
|
+
let match = p.sourceRangeCapacity;
|
|
32
|
+
let match$1 = p.prevSourceRangeCapacity;
|
|
33
33
|
if (match !== 0 && match$1 !== 0) {
|
|
34
34
|
return match < match$1 ? match : match$1;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function getTrustedDensity(p) {
|
|
39
|
-
|
|
40
|
-
let match$1 = p.prevPrevQueryRange;
|
|
41
|
-
if (match !== 0 && match$1 !== 0) {
|
|
42
|
-
return p.prevRangeSize / match;
|
|
43
|
-
}
|
|
39
|
+
return p.eventDensity;
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
function getMinQueryRange(partitions) {
|
|
47
43
|
let min = 0;
|
|
48
44
|
for (let i = 0, i_finish = partitions.length; i < i_finish; ++i) {
|
|
49
45
|
let p = partitions[i];
|
|
50
|
-
let a = p.
|
|
51
|
-
let b = p.
|
|
46
|
+
let a = p.sourceRangeCapacity;
|
|
47
|
+
let b = p.prevSourceRangeCapacity;
|
|
52
48
|
if (a > 0 && (min === 0 || a < min)) {
|
|
53
49
|
min = a;
|
|
54
50
|
}
|
|
@@ -88,10 +84,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
88
84
|
mergeBlock: potentialMergeBlock,
|
|
89
85
|
dynamicContract: p1.dynamicContract,
|
|
90
86
|
mutPendingQueries: p1.mutPendingQueries,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
sourceRangeCapacity: p1.sourceRangeCapacity,
|
|
88
|
+
prevSourceRangeCapacity: p1.prevSourceRangeCapacity,
|
|
89
|
+
eventDensity: p1.eventDensity,
|
|
90
|
+
latestSourceRangeCapacityUpdateBlock: p1.latestSourceRangeCapacityUpdateBlock
|
|
95
91
|
});
|
|
96
92
|
completed.push({
|
|
97
93
|
id: p2.id,
|
|
@@ -101,10 +97,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
101
97
|
mergeBlock: potentialMergeBlock,
|
|
102
98
|
dynamicContract: p2.dynamicContract,
|
|
103
99
|
mutPendingQueries: p2.mutPendingQueries,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
sourceRangeCapacity: p2.sourceRangeCapacity,
|
|
101
|
+
prevSourceRangeCapacity: p2.prevSourceRangeCapacity,
|
|
102
|
+
eventDensity: p2.eventDensity,
|
|
103
|
+
latestSourceRangeCapacityUpdateBlock: p2.latestSourceRangeCapacityUpdateBlock
|
|
108
104
|
});
|
|
109
105
|
let newId = nextPartitionIndexRef.contents.toString();
|
|
110
106
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
@@ -112,7 +108,13 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
112
108
|
p1,
|
|
113
109
|
p2
|
|
114
110
|
]);
|
|
115
|
-
let
|
|
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
|
+
);
|
|
116
118
|
continuingBase = {
|
|
117
119
|
id: newId,
|
|
118
120
|
latestFetchedBlock: {
|
|
@@ -124,10 +126,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
124
126
|
mergeBlock: undefined,
|
|
125
127
|
dynamicContract: contractName,
|
|
126
128
|
mutPendingQueries: [],
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
sourceRangeCapacity: minRange,
|
|
130
|
+
prevSourceRangeCapacity: minRange,
|
|
131
|
+
eventDensity: inheritedDensity,
|
|
132
|
+
latestSourceRangeCapacityUpdateBlock: 0
|
|
131
133
|
};
|
|
132
134
|
} else {
|
|
133
135
|
completed.push({
|
|
@@ -138,10 +140,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
138
140
|
mergeBlock: potentialMergeBlock,
|
|
139
141
|
dynamicContract: p1.dynamicContract,
|
|
140
142
|
mutPendingQueries: p1.mutPendingQueries,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
sourceRangeCapacity: p1.sourceRangeCapacity,
|
|
144
|
+
prevSourceRangeCapacity: p1.prevSourceRangeCapacity,
|
|
145
|
+
eventDensity: p1.eventDensity,
|
|
146
|
+
latestSourceRangeCapacityUpdateBlock: p1.latestSourceRangeCapacityUpdateBlock
|
|
145
147
|
});
|
|
146
148
|
continuingBase = p2;
|
|
147
149
|
}
|
|
@@ -154,10 +156,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
154
156
|
mergeBlock: potentialMergeBlock,
|
|
155
157
|
dynamicContract: p2.dynamicContract,
|
|
156
158
|
mutPendingQueries: p2.mutPendingQueries,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
sourceRangeCapacity: p2.sourceRangeCapacity,
|
|
160
|
+
prevSourceRangeCapacity: p2.prevSourceRangeCapacity,
|
|
161
|
+
eventDensity: p2.eventDensity,
|
|
162
|
+
latestSourceRangeCapacityUpdateBlock: p2.latestSourceRangeCapacityUpdateBlock
|
|
161
163
|
});
|
|
162
164
|
continuingBase = p1;
|
|
163
165
|
} else {
|
|
@@ -178,10 +180,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
178
180
|
mergeBlock: continuingBase.mergeBlock,
|
|
179
181
|
dynamicContract: continuingBase.dynamicContract,
|
|
180
182
|
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
sourceRangeCapacity: continuingBase.sourceRangeCapacity,
|
|
184
|
+
prevSourceRangeCapacity: continuingBase.prevSourceRangeCapacity,
|
|
185
|
+
eventDensity: continuingBase.eventDensity,
|
|
186
|
+
latestSourceRangeCapacityUpdateBlock: continuingBase.latestSourceRangeCapacityUpdateBlock
|
|
185
187
|
});
|
|
186
188
|
let restId = nextPartitionIndexRef.contents.toString();
|
|
187
189
|
nextPartitionIndexRef.contents = nextPartitionIndexRef.contents + 1 | 0;
|
|
@@ -193,10 +195,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
193
195
|
mergeBlock: continuingBase.mergeBlock,
|
|
194
196
|
dynamicContract: continuingBase.dynamicContract,
|
|
195
197
|
mutPendingQueries: [],
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
sourceRangeCapacity: continuingBase.sourceRangeCapacity,
|
|
199
|
+
prevSourceRangeCapacity: continuingBase.prevSourceRangeCapacity,
|
|
200
|
+
eventDensity: continuingBase.eventDensity,
|
|
201
|
+
latestSourceRangeCapacityUpdateBlock: continuingBase.latestSourceRangeCapacityUpdateBlock
|
|
200
202
|
});
|
|
201
203
|
return completed;
|
|
202
204
|
}
|
|
@@ -210,10 +212,10 @@ function mergePartitionsAtBlock(p1, p2, potentialMergeBlock, contractName, maxAd
|
|
|
210
212
|
mergeBlock: continuingBase.mergeBlock,
|
|
211
213
|
dynamicContract: continuingBase.dynamicContract,
|
|
212
214
|
mutPendingQueries: continuingBase.mutPendingQueries,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
sourceRangeCapacity: continuingBase.sourceRangeCapacity,
|
|
216
|
+
prevSourceRangeCapacity: continuingBase.prevSourceRangeCapacity,
|
|
217
|
+
eventDensity: continuingBase.eventDensity,
|
|
218
|
+
latestSourceRangeCapacityUpdateBlock: continuingBase.latestSourceRangeCapacityUpdateBlock
|
|
217
219
|
});
|
|
218
220
|
return completed;
|
|
219
221
|
}
|
|
@@ -358,8 +360,11 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
|
|
|
358
360
|
let pendingQuery = getPendingQueryOrThrow(p$1, query.fromBlock);
|
|
359
361
|
pendingQuery.fetchedBlock = latestFetchedBlock;
|
|
360
362
|
let blockRange = (latestFetchedBlock.blockNumber - query.fromBlock | 0) + 1 | 0;
|
|
361
|
-
let
|
|
362
|
-
|
|
363
|
+
let observedEventDensity = itemsCount / blockRange;
|
|
364
|
+
let eventDensity = p$1.eventDensity;
|
|
365
|
+
let updatedEventDensity = eventDensity !== undefined ? (eventDensity + observedEventDensity) / 2 : observedEventDensity;
|
|
366
|
+
let shouldUpdateSourceRangeCapacity = false;
|
|
367
|
+
if (latestFetchedBlock.blockNumber > p$1.latestSourceRangeCapacityUpdateBlock) {
|
|
363
368
|
let queryToBlock = query.toBlock;
|
|
364
369
|
let tmp;
|
|
365
370
|
if (queryToBlock !== undefined) {
|
|
@@ -372,11 +377,10 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
|
|
|
372
377
|
} else {
|
|
373
378
|
tmp = latestFetchedBlock.blockNumber < (knownHeight - 10 | 0);
|
|
374
379
|
}
|
|
375
|
-
|
|
380
|
+
shouldUpdateSourceRangeCapacity = tmp;
|
|
376
381
|
}
|
|
377
|
-
let
|
|
378
|
-
let
|
|
379
|
-
let updatedPrevRangeSize = shouldUpdateBlockRange ? itemsCount : p$1.prevRangeSize;
|
|
382
|
+
let updatedSourceRangeCapacity = shouldUpdateSourceRangeCapacity ? blockRange : p$1.sourceRangeCapacity;
|
|
383
|
+
let updatedPrevSourceRangeCapacity = shouldUpdateSourceRangeCapacity ? p$1.sourceRangeCapacity : p$1.prevSourceRangeCapacity;
|
|
380
384
|
let mutPendingQueries = p$1.mutPendingQueries;
|
|
381
385
|
let latestFetchedBlock$1 = p$1.latestFetchedBlock;
|
|
382
386
|
while ((() => {
|
|
@@ -402,7 +406,7 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
|
|
|
402
406
|
let updatedMainPartition_mergeBlock = p$1.mergeBlock;
|
|
403
407
|
let updatedMainPartition_dynamicContract = p$1.dynamicContract;
|
|
404
408
|
let updatedMainPartition_mutPendingQueries = p$1.mutPendingQueries;
|
|
405
|
-
let
|
|
409
|
+
let updatedMainPartition_latestSourceRangeCapacityUpdateBlock = shouldUpdateSourceRangeCapacity ? latestFetchedBlock.blockNumber : p$1.latestSourceRangeCapacityUpdateBlock;
|
|
406
410
|
let updatedMainPartition = {
|
|
407
411
|
id: updatedMainPartition_id,
|
|
408
412
|
latestFetchedBlock: updatedLatestFetchedBlock,
|
|
@@ -411,10 +415,10 @@ function handleQueryResponse(optimizedPartitions, query, knownHeight, itemsCount
|
|
|
411
415
|
mergeBlock: updatedMainPartition_mergeBlock,
|
|
412
416
|
dynamicContract: updatedMainPartition_dynamicContract,
|
|
413
417
|
mutPendingQueries: updatedMainPartition_mutPendingQueries,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
+
sourceRangeCapacity: updatedSourceRangeCapacity,
|
|
419
|
+
prevSourceRangeCapacity: updatedPrevSourceRangeCapacity,
|
|
420
|
+
eventDensity: updatedEventDensity,
|
|
421
|
+
latestSourceRangeCapacityUpdateBlock: updatedMainPartition_latestSourceRangeCapacityUpdateBlock
|
|
418
422
|
};
|
|
419
423
|
mutEntities[p$1.id] = updatedMainPartition;
|
|
420
424
|
}
|
|
@@ -739,10 +743,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
739
743
|
mergeBlock: undefined,
|
|
740
744
|
dynamicContract: isDynamic ? contractName : undefined,
|
|
741
745
|
mutPendingQueries: [],
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
+
sourceRangeCapacity: 0,
|
|
747
|
+
prevSourceRangeCapacity: 0,
|
|
748
|
+
eventDensity: undefined,
|
|
749
|
+
latestSourceRangeCapacityUpdateBlock: 0
|
|
746
750
|
});
|
|
747
751
|
nextPartitionIndexRef = nextPartitionIndexRef + 1 | 0;
|
|
748
752
|
};
|
|
@@ -790,10 +794,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
790
794
|
mergeBlock: currentPBlock < nextPBlock ? nextPBlock : undefined,
|
|
791
795
|
dynamicContract: currentP.dynamicContract,
|
|
792
796
|
mutPendingQueries: currentP.mutPendingQueries,
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
+
sourceRangeCapacity: currentP.sourceRangeCapacity,
|
|
798
|
+
prevSourceRangeCapacity: currentP.prevSourceRangeCapacity,
|
|
799
|
+
eventDensity: currentP.eventDensity,
|
|
800
|
+
latestSourceRangeCapacityUpdateBlock: currentP.latestSourceRangeCapacityUpdateBlock
|
|
797
801
|
});
|
|
798
802
|
currentPRef = {
|
|
799
803
|
id: nextP.id,
|
|
@@ -803,10 +807,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
803
807
|
mergeBlock: nextP.mergeBlock,
|
|
804
808
|
dynamicContract: nextP.dynamicContract,
|
|
805
809
|
mutPendingQueries: nextP.mutPendingQueries,
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
+
sourceRangeCapacity: nextP.sourceRangeCapacity,
|
|
811
|
+
prevSourceRangeCapacity: nextP.prevSourceRangeCapacity,
|
|
812
|
+
eventDensity: nextP.eventDensity,
|
|
813
|
+
latestSourceRangeCapacityUpdateBlock: nextP.latestSourceRangeCapacityUpdateBlock
|
|
810
814
|
};
|
|
811
815
|
} else {
|
|
812
816
|
currentPRef = {
|
|
@@ -817,10 +821,10 @@ function createPartitionsFromIndexingAddresses(registeringContractsByContract, d
|
|
|
817
821
|
mergeBlock: currentP.mergeBlock,
|
|
818
822
|
dynamicContract: currentP.dynamicContract,
|
|
819
823
|
mutPendingQueries: currentP.mutPendingQueries,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
+
sourceRangeCapacity: currentP.sourceRangeCapacity,
|
|
825
|
+
prevSourceRangeCapacity: currentP.prevSourceRangeCapacity,
|
|
826
|
+
eventDensity: currentP.eventDensity,
|
|
827
|
+
latestSourceRangeCapacityUpdateBlock: currentP.latestSourceRangeCapacityUpdateBlock
|
|
824
828
|
};
|
|
825
829
|
}
|
|
826
830
|
}
|
|
@@ -967,10 +971,10 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
967
971
|
mergeBlock: p.mergeBlock,
|
|
968
972
|
dynamicContract: p.dynamicContract,
|
|
969
973
|
mutPendingQueries: p.mutPendingQueries,
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
975
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
976
|
+
eventDensity: p.eventDensity,
|
|
977
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
974
978
|
};
|
|
975
979
|
let addressesByContractName = {};
|
|
976
980
|
addressesByContractName[contractName] = addresses;
|
|
@@ -982,10 +986,10 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
982
986
|
mergeBlock: undefined,
|
|
983
987
|
dynamicContract: contractName,
|
|
984
988
|
mutPendingQueries: p.mutPendingQueries,
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
990
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
991
|
+
eventDensity: p.eventDensity,
|
|
992
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
989
993
|
});
|
|
990
994
|
}
|
|
991
995
|
} else {
|
|
@@ -997,10 +1001,10 @@ function registerDynamicContracts(fetchState, indexingAddresses, items) {
|
|
|
997
1001
|
mergeBlock: p.mergeBlock,
|
|
998
1002
|
dynamicContract: contractName,
|
|
999
1003
|
mutPendingQueries: p.mutPendingQueries,
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1005
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1006
|
+
eventDensity: p.eventDensity,
|
|
1007
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
1004
1008
|
};
|
|
1005
1009
|
}
|
|
1006
1010
|
}
|
|
@@ -1072,7 +1076,7 @@ function pushGapFillQueries(queries, partitionId, rangeFromBlock, rangeEndBlock,
|
|
|
1072
1076
|
exit = 1;
|
|
1073
1077
|
}
|
|
1074
1078
|
if (exit === 1) {
|
|
1075
|
-
let trustedDensity =
|
|
1079
|
+
let trustedDensity = partition.eventDensity;
|
|
1076
1080
|
let maxBlock = rangeEndBlock !== undefined ? rangeEndBlock : chainTargetBlock;
|
|
1077
1081
|
let pushSingleQuery = (density, isChunk) => {
|
|
1078
1082
|
let itemsTarget = densityItemsTarget(density * chunkItemsMultiplier, rangeFromBlock, rangeEndBlock, chainTargetBlock);
|
|
@@ -1150,7 +1154,8 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems, $staropt$star)
|
|
|
1150
1154
|
shouldWaitForNewBlock = false;
|
|
1151
1155
|
}
|
|
1152
1156
|
}
|
|
1153
|
-
let
|
|
1157
|
+
let partitionsCount$1 = chainTargetItems <= 0 || shouldWaitForNewBlock ? 0 : partitionsCount;
|
|
1158
|
+
let queriesByPartitionIndex = Stdlib_Array.fromInitializer(partitionsCount$1, param => []);
|
|
1154
1159
|
let computeQueryEndBlock = p => {
|
|
1155
1160
|
let queryEndBlock = Utils.$$Math.minOptInt(endBlock, p.mergeBlock);
|
|
1156
1161
|
if (blockLag !== 0) {
|
|
@@ -1164,7 +1169,7 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems, $staropt$star)
|
|
|
1164
1169
|
let partitionIndexById = {};
|
|
1165
1170
|
let candidates = [];
|
|
1166
1171
|
let fillStates = [];
|
|
1167
|
-
for (let idx$1 = 0; idx$1 < partitionsCount; ++idx$1) {
|
|
1172
|
+
for (let idx$1 = 0; idx$1 < partitionsCount$1; ++idx$1) {
|
|
1168
1173
|
let partitionId$1 = optimizedPartitions.idsInAscOrder[idx$1];
|
|
1169
1174
|
let p$1 = optimizedPartitions.entities[partitionId$1];
|
|
1170
1175
|
partitionIndexById[partitionId$1] = idx$1;
|
|
@@ -1189,7 +1194,7 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems, $staropt$star)
|
|
|
1189
1194
|
let pq$1 = p$1.mutPendingQueries[pqIdx$1];
|
|
1190
1195
|
if (pq$1.fromBlock > cursor) {
|
|
1191
1196
|
let beforeLen = candidates.length;
|
|
1192
|
-
pushGapFillQueries(candidates, partitionId$1, cursor, Utils.$$Math.minOptInt(pq$1.fromBlock - 1 | 0, queryEndBlock), knownHeight, chainTargetBlock, maybeChunkRange, (12 - pendingCount | 0) - chunksUsedThisCall | 0, p$1, chainTargetItems / partitionsCount, chunkItemsMultiplier, p$1.selection, p$1.addressesByContractName);
|
|
1197
|
+
pushGapFillQueries(candidates, partitionId$1, cursor, Utils.$$Math.minOptInt(pq$1.fromBlock - 1 | 0, queryEndBlock), knownHeight, chainTargetBlock, maybeChunkRange, (12 - pendingCount | 0) - chunksUsedThisCall | 0, p$1, chainTargetItems / partitionsCount$1, chunkItemsMultiplier, p$1.selection, p$1.addressesByContractName);
|
|
1193
1198
|
chunksUsedThisCall = chunksUsedThisCall + (candidates.length - beforeLen | 0) | 0;
|
|
1194
1199
|
}
|
|
1195
1200
|
let toBlock = pq$1.toBlock;
|
|
@@ -1248,7 +1253,7 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems, $staropt$star)
|
|
|
1248
1253
|
let eb = fs.queryEndBlock;
|
|
1249
1254
|
let maxBlock = eb !== undefined ? eb : chainTargetBlock;
|
|
1250
1255
|
let match = fs.maybeChunkRange;
|
|
1251
|
-
let match$1 =
|
|
1256
|
+
let match$1 = p.eventDensity;
|
|
1252
1257
|
if (match !== undefined && match$1 !== undefined && match$1 > 0) {
|
|
1253
1258
|
let chunkSize = Js_math.ceil_int(match * 1.8);
|
|
1254
1259
|
let maxChunksRemaining = (12 - fs.pendingCount | 0) - fs.chunksUsedThisCall | 0;
|
|
@@ -1326,12 +1331,14 @@ function getNextQuery(param, chainTargetBlock, chainTargetItems, $staropt$star)
|
|
|
1326
1331
|
let streamCount = acceptanceStream.length;
|
|
1327
1332
|
let remainingBudget = chainTargetItems;
|
|
1328
1333
|
let acceptIdx = 0;
|
|
1329
|
-
|
|
1334
|
+
let usedConcurrency = reservations.length;
|
|
1335
|
+
while (remainingBudget > 0 && acceptIdx < streamCount && usedConcurrency < 100) {
|
|
1330
1336
|
let match$1 = acceptanceStream[acceptIdx];
|
|
1331
1337
|
let maybeQuery = match$1[2];
|
|
1332
1338
|
if (maybeQuery !== undefined) {
|
|
1333
1339
|
let partitionIdx = partitionIndexById[maybeQuery.partitionId];
|
|
1334
1340
|
queriesByPartitionIndex[partitionIdx].push(maybeQuery);
|
|
1341
|
+
usedConcurrency = usedConcurrency + 1 | 0;
|
|
1335
1342
|
}
|
|
1336
1343
|
remainingBudget = remainingBudget - match$1[1];
|
|
1337
1344
|
acceptIdx = acceptIdx + 1 | 0;
|
|
@@ -1416,10 +1423,10 @@ function make$1(startBlock, endBlock, onEventRegistrations, contractConfigs, add
|
|
|
1416
1423
|
mergeBlock: undefined,
|
|
1417
1424
|
dynamicContract: undefined,
|
|
1418
1425
|
mutPendingQueries: [],
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1426
|
+
sourceRangeCapacity: 0,
|
|
1427
|
+
prevSourceRangeCapacity: 0,
|
|
1428
|
+
eventDensity: undefined,
|
|
1429
|
+
latestSourceRangeCapacityUpdateBlock: 0
|
|
1423
1430
|
});
|
|
1424
1431
|
}
|
|
1425
1432
|
let normalSelection = {
|
|
@@ -1554,10 +1561,10 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
|
|
|
1554
1561
|
mergeBlock: mergeBlock$1,
|
|
1555
1562
|
dynamicContract: p.dynamicContract,
|
|
1556
1563
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1564
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1565
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1566
|
+
eventDensity: p.eventDensity,
|
|
1567
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
1561
1568
|
});
|
|
1562
1569
|
}
|
|
1563
1570
|
}
|
|
@@ -1575,10 +1582,10 @@ function rollback(fetchState, indexingAddresses, targetBlockNumber) {
|
|
|
1575
1582
|
mergeBlock: p.mergeBlock,
|
|
1576
1583
|
dynamicContract: p.dynamicContract,
|
|
1577
1584
|
mutPendingQueries: rollbackPendingQueries(p.mutPendingQueries, targetBlockNumber),
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1585
|
+
sourceRangeCapacity: p.sourceRangeCapacity,
|
|
1586
|
+
prevSourceRangeCapacity: p.prevSourceRangeCapacity,
|
|
1587
|
+
eventDensity: p.eventDensity,
|
|
1588
|
+
latestSourceRangeCapacityUpdateBlock: p.latestSourceRangeCapacityUpdateBlock
|
|
1582
1589
|
});
|
|
1583
1590
|
}
|
|
1584
1591
|
}
|
|
@@ -1619,10 +1626,10 @@ function resetPendingQueries(fetchState) {
|
|
|
1619
1626
|
mergeBlock: partition.mergeBlock,
|
|
1620
1627
|
dynamicContract: partition.dynamicContract,
|
|
1621
1628
|
mutPendingQueries: kept,
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1629
|
+
sourceRangeCapacity: partition.sourceRangeCapacity,
|
|
1630
|
+
prevSourceRangeCapacity: partition.prevSourceRangeCapacity,
|
|
1631
|
+
eventDensity: partition.eventDensity,
|
|
1632
|
+
latestSourceRangeCapacityUpdateBlock: partition.latestSourceRangeCapacityUpdateBlock
|
|
1626
1633
|
};
|
|
1627
1634
|
}
|
|
1628
1635
|
}
|
|
@@ -1698,7 +1705,7 @@ function getProgressPercentage(fetchState) {
|
|
|
1698
1705
|
if (firstEventBlock === undefined) {
|
|
1699
1706
|
return 0;
|
|
1700
1707
|
}
|
|
1701
|
-
let totalRange = fetchState.knownHeight - firstEventBlock | 0;
|
|
1708
|
+
let totalRange = (fetchState.knownHeight - fetchState.blockLag | 0) - firstEventBlock | 0;
|
|
1702
1709
|
if (totalRange <= 0) {
|
|
1703
1710
|
return 0;
|
|
1704
1711
|
}
|
|
@@ -1764,6 +1771,8 @@ let blockItemLogIndex = 16777216;
|
|
|
1764
1771
|
|
|
1765
1772
|
let maxPendingChunksPerPartition = 12;
|
|
1766
1773
|
|
|
1774
|
+
let maxChainConcurrency = 100;
|
|
1775
|
+
|
|
1767
1776
|
export {
|
|
1768
1777
|
deriveContractNameByAddress,
|
|
1769
1778
|
densityItemsTarget,
|
|
@@ -1789,6 +1798,7 @@ export {
|
|
|
1789
1798
|
handleQueryResult,
|
|
1790
1799
|
startFetchingQueries,
|
|
1791
1800
|
maxPendingChunksPerPartition,
|
|
1801
|
+
maxChainConcurrency,
|
|
1792
1802
|
pushGapFillQueries,
|
|
1793
1803
|
getNextQuery,
|
|
1794
1804
|
hasReadyItem,
|
package/src/InMemoryStore.res
CHANGED
|
@@ -8,25 +8,13 @@ let getInMemTable = (
|
|
|
8
8
|
): InMemoryTable.Entity.t =>
|
|
9
9
|
state->IndexerState.entities->IndexerState.EntityTables.get(~entityName=entityConfig.name)
|
|
10
10
|
|
|
11
|
-
let getEffectInMemTable = (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
| None =>
|
|
17
|
-
let table: IndexerState.effectCacheInMemTable = {
|
|
18
|
-
idsToStore: [],
|
|
19
|
-
dict: Dict.make(),
|
|
20
|
-
changesCount: 0.,
|
|
21
|
-
invalidationsCount: 0,
|
|
22
|
-
effect,
|
|
23
|
-
}
|
|
24
|
-
effects->Dict.set(key, table)
|
|
25
|
-
table
|
|
26
|
-
}
|
|
27
|
-
}
|
|
11
|
+
let getEffectInMemTable = (
|
|
12
|
+
state: IndexerState.t,
|
|
13
|
+
~effect: Internal.effect,
|
|
14
|
+
~scope: Internal.chainScope,
|
|
15
|
+
) => state->IndexerState.effectState->EffectState.getTable(~effect, ~scope)
|
|
28
16
|
|
|
29
|
-
let hasEffectOutput = (inMemTable:
|
|
17
|
+
let hasEffectOutput = (inMemTable: EffectState.effectCacheInMemTable, key) =>
|
|
30
18
|
switch inMemTable.dict->Utils.Dict.dangerouslyGetNonOption(key) {
|
|
31
19
|
| Some(Set(_)) => true
|
|
32
20
|
| Some(Delete(_)) | None => false
|
|
@@ -36,7 +24,7 @@ let hasEffectOutput = (inMemTable: IndexerState.effectCacheInMemTable, key) =>
|
|
|
36
24
|
// optional output, so it must never be wrapped in another option here: Some(None)
|
|
37
25
|
// is encoded as the nested-option sentinel and would leak to the handler.
|
|
38
26
|
let getEffectOutputUnsafe = (
|
|
39
|
-
inMemTable:
|
|
27
|
+
inMemTable: EffectState.effectCacheInMemTable,
|
|
40
28
|
key,
|
|
41
29
|
): Internal.effectOutput =>
|
|
42
30
|
switch inMemTable.dict->Utils.Dict.dangerouslyGetNonOption(key) {
|
|
@@ -47,7 +35,7 @@ let getEffectOutputUnsafe = (
|
|
|
47
35
|
// Records a handler output. Persisted on the next write only when shouldCache;
|
|
48
36
|
// otherwise kept in memory (re-run on a later miss) but never written to the db.
|
|
49
37
|
let setEffectOutput = (
|
|
50
|
-
inMemTable:
|
|
38
|
+
inMemTable: EffectState.effectCacheInMemTable,
|
|
51
39
|
~checkpointId,
|
|
52
40
|
~cacheKey,
|
|
53
41
|
~output,
|
|
@@ -65,7 +53,7 @@ let setEffectOutput = (
|
|
|
65
53
|
|
|
66
54
|
// Seeds an entry from a db read. Stamped with loadedFromDbCheckpointId so it's
|
|
67
55
|
// always droppable (re-readable from the db) and never re-persisted.
|
|
68
|
-
let initEffectOutputFromDb = (inMemTable:
|
|
56
|
+
let initEffectOutputFromDb = (inMemTable: EffectState.effectCacheInMemTable, ~cacheKey, ~output) =>
|
|
69
57
|
if inMemTable.dict->Utils.Dict.dangerouslyGetNonOption(cacheKey)->Option.isNone {
|
|
70
58
|
inMemTable.changesCount = inMemTable.changesCount +. 1.
|
|
71
59
|
inMemTable.dict->Dict.set(
|
|
@@ -78,7 +66,7 @@ let initEffectOutputFromDb = (inMemTable: IndexerState.effectCacheInMemTable, ~c
|
|
|
78
66
|
// cache:false). Uncommitted entries stay warm. With keepLoadedFromDb, entries
|
|
79
67
|
// seeded from a db read are spared. Mirrors entity dropCommittedChanges.
|
|
80
68
|
let dropCommittedEffects = (
|
|
81
|
-
inMemTable:
|
|
69
|
+
inMemTable: EffectState.effectCacheInMemTable,
|
|
82
70
|
~committedCheckpointId,
|
|
83
71
|
~keepLoadedFromDb,
|
|
84
72
|
) => {
|
|
@@ -117,17 +105,17 @@ let prepareRollbackDiff = async (
|
|
|
117
105
|
->Array.map(async entityConfig => {
|
|
118
106
|
let entityTable = state->getInMemTable(~entityConfig)
|
|
119
107
|
|
|
120
|
-
let (
|
|
108
|
+
let (removedIds, restoredEntitiesResult) = await persistence.storage.getRollbackData(
|
|
121
109
|
~entityConfig,
|
|
122
110
|
~rollbackTargetCheckpointId,
|
|
123
111
|
)
|
|
124
112
|
|
|
125
|
-
|
|
126
|
-
deletedEntities->Utils.Dict.push(entityConfig.name,
|
|
113
|
+
removedIds->Array.forEach(entityId => {
|
|
114
|
+
deletedEntities->Utils.Dict.push(entityConfig.name, entityId)
|
|
127
115
|
entityTable->InMemoryTable.Entity.set(
|
|
128
116
|
~committedCheckpointId,
|
|
129
117
|
Delete({
|
|
130
|
-
entityId
|
|
118
|
+
entityId,
|
|
131
119
|
checkpointId: rollbackDiffCheckpointId,
|
|
132
120
|
}),
|
|
133
121
|
)
|
|
@@ -4,6 +4,7 @@ import * as Table from "./db/Table.res.mjs";
|
|
|
4
4
|
import * as Utils from "./Utils.res.mjs";
|
|
5
5
|
import * as Config from "./Config.res.mjs";
|
|
6
6
|
import * as Internal from "./Internal.res.mjs";
|
|
7
|
+
import * as EffectState from "./EffectState.res.mjs";
|
|
7
8
|
import * as IndexerState from "./IndexerState.res.mjs";
|
|
8
9
|
import * as InMemoryTable from "./InMemoryTable.res.mjs";
|
|
9
10
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
@@ -13,22 +14,8 @@ function getInMemTable(state, entityConfig) {
|
|
|
13
14
|
return IndexerState.EntityTables.get(IndexerState.entities(state), entityConfig.name);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
function getEffectInMemTable(state, effect) {
|
|
17
|
-
|
|
18
|
-
let effects = IndexerState.effects(state);
|
|
19
|
-
let table = effects[key];
|
|
20
|
-
if (table !== undefined) {
|
|
21
|
-
return table;
|
|
22
|
-
}
|
|
23
|
-
let table$1 = {
|
|
24
|
-
idsToStore: [],
|
|
25
|
-
invalidationsCount: 0,
|
|
26
|
-
dict: {},
|
|
27
|
-
changesCount: 0,
|
|
28
|
-
effect: effect
|
|
29
|
-
};
|
|
30
|
-
effects[key] = table$1;
|
|
31
|
-
return table$1;
|
|
17
|
+
function getEffectInMemTable(state, effect, scope) {
|
|
18
|
+
return EffectState.getTable(IndexerState.effectState(state), effect, scope);
|
|
32
19
|
}
|
|
33
20
|
|
|
34
21
|
function hasEffectOutput(inMemTable, key) {
|
|
@@ -102,11 +89,11 @@ async function prepareRollbackDiff(state, rollbackTargetCheckpointId, rollbackDi
|
|
|
102
89
|
await Promise.all(persistence.allEntities.map(async entityConfig => {
|
|
103
90
|
let entityTable = getInMemTable(state, entityConfig);
|
|
104
91
|
let match = await persistence.storage.getRollbackData(entityConfig, rollbackTargetCheckpointId);
|
|
105
|
-
match[0].forEach(
|
|
106
|
-
Utils.Dict.push(deletedEntities, entityConfig.name,
|
|
92
|
+
match[0].forEach(entityId => {
|
|
93
|
+
Utils.Dict.push(deletedEntities, entityConfig.name, entityId);
|
|
107
94
|
InMemoryTable.Entity.set(entityTable, committedCheckpointId, {
|
|
108
95
|
type: "DELETE",
|
|
109
|
-
entityId:
|
|
96
|
+
entityId: entityId,
|
|
110
97
|
checkpointId: rollbackDiffCheckpointId
|
|
111
98
|
});
|
|
112
99
|
});
|