envio 2.21.4 → 2.21.5
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 +5 -5
- package/src/ReorgDetection.res +27 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "v2.21.
|
|
3
|
+
"version": "v2.21.5",
|
|
4
4
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
5
5
|
"bin": "./bin.js",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://envio.dev",
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"envio-linux-x64": "v2.21.
|
|
29
|
-
"envio-linux-arm64": "v2.21.
|
|
30
|
-
"envio-darwin-x64": "v2.21.
|
|
31
|
-
"envio-darwin-arm64": "v2.21.
|
|
28
|
+
"envio-linux-x64": "v2.21.5",
|
|
29
|
+
"envio-linux-arm64": "v2.21.5",
|
|
30
|
+
"envio-darwin-x64": "v2.21.5",
|
|
31
|
+
"envio-darwin-arm64": "v2.21.5"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@envio-dev/hypersync-client": "0.6.5",
|
package/src/ReorgDetection.res
CHANGED
|
@@ -70,6 +70,7 @@ module LastBlockScannedHashes: {
|
|
|
70
70
|
t,
|
|
71
71
|
~blockNumbersAndHashes: array<blockDataWithTimestamp>,
|
|
72
72
|
~currentBlockHeight: int,
|
|
73
|
+
~skipReorgDuplicationCheck: bool=?,
|
|
73
74
|
) => validBlockResult
|
|
74
75
|
|
|
75
76
|
let getThresholdBlockNumbers: (t, ~currentBlockHeight: int) => array<int>
|
|
@@ -212,6 +213,7 @@ module LastBlockScannedHashes: {
|
|
|
212
213
|
self: t,
|
|
213
214
|
~blockNumbersAndHashes: array<blockDataWithTimestamp>,
|
|
214
215
|
~currentBlockHeight,
|
|
216
|
+
~skipReorgDuplicationCheck=false,
|
|
215
217
|
) => {
|
|
216
218
|
let verifiedDataByBlockNumber = Js.Dict.empty()
|
|
217
219
|
for idx in 0 to blockNumbersAndHashes->Array.length - 1 {
|
|
@@ -219,16 +221,31 @@ module LastBlockScannedHashes: {
|
|
|
219
221
|
verifiedDataByBlockNumber->Js.Dict.set(blockData.blockNumber->Int.toString, blockData)
|
|
220
222
|
}
|
|
221
223
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
224
|
+
/*
|
|
225
|
+
Let's say we indexed block X with hash A.
|
|
226
|
+
The next query we got the block X with hash B.
|
|
227
|
+
We assume that the hash A is reorged since we received it earlier than B.
|
|
228
|
+
So when we try to detect the reorg depth, we consider hash A as already invalid,
|
|
229
|
+
and retry the block hashes query if we receive one. (since it could come from a different instance and cause a double reorg)
|
|
230
|
+
But the assumption that A is reorged might be wrong sometimes,
|
|
231
|
+
for example if we got B from instance which didn't handle a reorg A.
|
|
232
|
+
Theoretically, it's possible with high partition concurrency.
|
|
233
|
+
So to handle this and prevent entering an infinite loop,
|
|
234
|
+
we can skip the reorg duplication check if we're sure that the block hashes query
|
|
235
|
+
is not coming from a different instance. (let's say we tried several times)
|
|
236
|
+
*/
|
|
237
|
+
let isAlreadyReorgedResponse = skipReorgDuplicationCheck
|
|
238
|
+
? false
|
|
239
|
+
: switch self.detectedReorgBlock {
|
|
240
|
+
| Some(detectedReorgBlock) =>
|
|
241
|
+
switch verifiedDataByBlockNumber->Utils.Dict.dangerouslyGetNonOption(
|
|
242
|
+
detectedReorgBlock.blockNumber->Int.toString,
|
|
243
|
+
) {
|
|
244
|
+
| Some(verifiedBlockData) => verifiedBlockData.blockHash === detectedReorgBlock.blockHash
|
|
245
|
+
| None => false
|
|
246
|
+
}
|
|
247
|
+
| None => false
|
|
248
|
+
}
|
|
232
249
|
|
|
233
250
|
if isAlreadyReorgedResponse {
|
|
234
251
|
Error(AlreadyReorgedHashes)
|