envio 3.0.0-alpha.0 → 3.0.0-alpha.10
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/README.md +2 -2
- package/evm.schema.json +53 -57
- package/fuel.schema.json +35 -31
- package/index.d.ts +446 -1
- package/index.js +4 -0
- package/package.json +23 -11
- package/rescript.json +4 -1
- package/src/Batch.res.mjs +1 -1
- package/src/Benchmark.res +394 -0
- package/src/Benchmark.res.mjs +398 -0
- package/src/ChainFetcher.res +526 -0
- package/src/ChainFetcher.res.mjs +343 -0
- package/src/ChainManager.res +182 -0
- package/src/ChainManager.res.mjs +150 -0
- package/src/Config.res +367 -27
- package/src/Config.res.mjs +338 -28
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +25 -0
- package/src/Ecosystem.res.mjs +29 -0
- package/src/Env.res +252 -0
- package/src/Env.res.mjs +271 -0
- package/src/Envio.gen.ts +9 -1
- package/src/Envio.res +12 -9
- package/src/EventProcessing.res +476 -0
- package/src/EventProcessing.res.mjs +341 -0
- package/src/EventRegister.res +4 -15
- package/src/EventRegister.res.mjs +3 -9
- package/src/EventRegister.resi +2 -8
- package/src/FetchState.res +54 -29
- package/src/FetchState.res.mjs +62 -35
- package/src/GlobalState.res +1163 -0
- package/src/GlobalState.res.mjs +1196 -0
- package/src/GlobalStateManager.res +68 -0
- package/src/GlobalStateManager.res.mjs +75 -0
- package/src/GlobalStateManager.resi +7 -0
- package/src/HandlerLoader.res +89 -0
- package/src/HandlerLoader.res.mjs +79 -0
- package/src/Internal.gen.ts +3 -14
- package/src/Internal.res +45 -13
- package/src/LoadLayer.res +444 -0
- package/src/LoadLayer.res.mjs +296 -0
- package/src/LoadLayer.resi +32 -0
- package/src/LogSelection.res +33 -27
- package/src/LogSelection.res.mjs +6 -0
- package/src/Logging.res +11 -4
- package/src/Logging.res.mjs +14 -6
- package/src/Main.res +351 -0
- package/src/Main.res.mjs +312 -0
- package/src/Persistence.res +1 -2
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +28 -34
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +27 -27
- package/src/Prometheus.res +8 -8
- package/src/Prometheus.res.mjs +10 -10
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/TestIndexer.res +536 -0
- package/src/TestIndexer.res.mjs +412 -0
- package/src/TestIndexerProxyStorage.res +210 -0
- package/src/TestIndexerProxyStorage.res.mjs +157 -0
- package/src/Types.ts +1 -1
- package/src/UserContext.res +355 -0
- package/src/UserContext.res.mjs +236 -0
- package/src/Utils.res +28 -0
- package/src/Utils.res.mjs +18 -0
- package/src/bindings/ClickHouse.res +31 -1
- package/src/bindings/ClickHouse.res.mjs +27 -1
- package/src/bindings/DateFns.res +71 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/Ethers.res +27 -67
- package/src/bindings/Ethers.res.mjs +18 -70
- package/src/bindings/EventSource.res +13 -0
- package/src/bindings/EventSource.res.mjs +2 -0
- package/src/bindings/NodeJs.res +44 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +21 -7
- package/src/bindings/Pino.res.mjs +11 -5
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +3 -0
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/RescriptMocha.res +123 -0
- package/src/bindings/RescriptMocha.res.mjs +18 -0
- package/src/bindings/Vitest.res +134 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/InternalTable.res +2 -0
- package/src/db/InternalTable.res.mjs +1 -1
- package/src/sources/Evm.res +87 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +90 -0
- package/src/sources/EvmChain.res.mjs +57 -0
- package/src/sources/Fuel.res +19 -34
- package/src/sources/Fuel.res.mjs +34 -16
- package/src/sources/FuelSDK.res +38 -0
- package/src/sources/FuelSDK.res.mjs +29 -0
- package/src/sources/HyperFuel.res +2 -2
- package/src/sources/HyperFuel.resi +1 -1
- package/src/sources/HyperFuelClient.res +2 -2
- package/src/sources/HyperFuelSource.res +8 -8
- package/src/sources/HyperFuelSource.res.mjs +5 -5
- package/src/sources/HyperSyncHeightStream.res +97 -0
- package/src/sources/HyperSyncHeightStream.res.mjs +94 -0
- package/src/sources/HyperSyncSource.res +64 -172
- package/src/sources/HyperSyncSource.res.mjs +73 -155
- package/src/sources/Rpc.res +43 -0
- package/src/sources/Rpc.res.mjs +31 -0
- package/src/sources/RpcSource.res +32 -130
- package/src/sources/RpcSource.res.mjs +47 -121
- package/src/sources/Source.res +3 -2
- package/src/sources/SourceManager.res +183 -108
- package/src/sources/SourceManager.res.mjs +162 -99
- package/src/sources/SourceManager.resi +4 -5
- package/src/sources/Svm.res +59 -0
- package/src/sources/Svm.res.mjs +79 -0
- package/src/tui/Tui.res +266 -0
- package/src/tui/Tui.res.mjs +342 -0
- package/src/tui/bindings/Ink.res +376 -0
- package/src/tui/bindings/Ink.res.mjs +75 -0
- package/src/tui/bindings/Style.res +123 -0
- package/src/tui/bindings/Style.res.mjs +2 -0
- package/src/tui/components/BufferedProgressBar.res +40 -0
- package/src/tui/components/BufferedProgressBar.res.mjs +57 -0
- package/src/tui/components/CustomHooks.res +122 -0
- package/src/tui/components/CustomHooks.res.mjs +179 -0
- package/src/tui/components/Messages.res +41 -0
- package/src/tui/components/Messages.res.mjs +75 -0
- package/src/tui/components/SyncETA.res +193 -0
- package/src/tui/components/SyncETA.res.mjs +269 -0
- package/src/tui/components/TuiData.res +46 -0
- package/src/tui/components/TuiData.res.mjs +29 -0
- package/src/Platform.res +0 -140
- package/src/Platform.res.mjs +0 -170
- package/src/bindings/Ethers.gen.ts +0 -14
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/src/PgStorage.res
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
let getCacheRowCountFnName = "get_cache_row_count"
|
|
2
2
|
|
|
3
|
+
// Only needed for some old tests
|
|
4
|
+
// Remove @genType in the future
|
|
5
|
+
@genType
|
|
6
|
+
let makeClient = () => {
|
|
7
|
+
Postgres.makeSql(
|
|
8
|
+
~config={
|
|
9
|
+
host: Env.Db.host,
|
|
10
|
+
port: Env.Db.port,
|
|
11
|
+
username: Env.Db.user,
|
|
12
|
+
password: Env.Db.password,
|
|
13
|
+
database: Env.Db.database,
|
|
14
|
+
ssl: Env.Db.ssl,
|
|
15
|
+
// TODO: think how we want to pipe these logs to pino.
|
|
16
|
+
onnotice: ?(
|
|
17
|
+
Env.userLogLevel == Some(#warn) || Env.userLogLevel == Some(#error)
|
|
18
|
+
? None
|
|
19
|
+
: Some(_str => ())
|
|
20
|
+
),
|
|
21
|
+
transform: {undefined: Null},
|
|
22
|
+
max: 2,
|
|
23
|
+
// debug: (~connection, ~query, ~params as _, ~types as _) => Js.log2(connection, query),
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
3
28
|
let makeCreateIndexQuery = (~tableName, ~indexFields, ~pgSchema) => {
|
|
4
29
|
let indexName = tableName ++ "_" ++ indexFields->Js.Array2.joinWith("_")
|
|
5
30
|
let index = indexFields->Belt.Array.map(idx => `"${idx}"`)->Js.Array2.joinWith(", ")
|
|
@@ -1056,8 +1081,7 @@ let make = (
|
|
|
1056
1081
|
}
|
|
1057
1082
|
|
|
1058
1083
|
let cacheDirPath = NodeJs.Path.resolve([
|
|
1059
|
-
// Right
|
|
1060
|
-
"..",
|
|
1084
|
+
// Right at the project root
|
|
1061
1085
|
".envio",
|
|
1062
1086
|
"cache",
|
|
1063
1087
|
])
|
|
@@ -1223,6 +1247,7 @@ let make = (
|
|
|
1223
1247
|
firstEventBlockNumber: None,
|
|
1224
1248
|
timestampCaughtUpToHeadOrEndblock: None,
|
|
1225
1249
|
dynamicContracts: [],
|
|
1250
|
+
sourceBlockNumber: 0,
|
|
1226
1251
|
}),
|
|
1227
1252
|
checkpointId: InternalTable.Checkpoints.initialCheckpointId,
|
|
1228
1253
|
}
|
|
@@ -1425,6 +1450,7 @@ let make = (
|
|
|
1425
1450
|
numEventsProcessed: rawInitialState.numEventsProcessed,
|
|
1426
1451
|
progressBlockNumber: rawInitialState.progressBlockNumber,
|
|
1427
1452
|
dynamicContracts: rawInitialState.dynamicContracts,
|
|
1453
|
+
sourceBlockNumber: rawInitialState.sourceBlockNumber,
|
|
1428
1454
|
})
|
|
1429
1455
|
}),
|
|
1430
1456
|
sql
|
|
@@ -1454,37 +1480,6 @@ let make = (
|
|
|
1454
1480
|
|
|
1455
1481
|
let executeUnsafe = query => sql->Postgres.unsafe(query)
|
|
1456
1482
|
|
|
1457
|
-
let hasEntityHistoryRows = async () => {
|
|
1458
|
-
// Query for all entity history tables (they have the prefix "envio_history_")
|
|
1459
|
-
let historyTables = await sql->Postgres.unsafe(
|
|
1460
|
-
`SELECT table_name FROM information_schema.tables
|
|
1461
|
-
WHERE table_schema = '${pgSchema}'
|
|
1462
|
-
AND table_name LIKE 'envio_history_%';`,
|
|
1463
|
-
)
|
|
1464
|
-
|
|
1465
|
-
if historyTables->Utils.Array.isEmpty {
|
|
1466
|
-
false
|
|
1467
|
-
} else {
|
|
1468
|
-
// Check if any of these tables have rows
|
|
1469
|
-
let checks =
|
|
1470
|
-
await historyTables
|
|
1471
|
-
->Belt.Array.map(async (table: {"table_name": string}) => {
|
|
1472
|
-
try {
|
|
1473
|
-
let query = `SELECT EXISTS(SELECT 1 FROM "${pgSchema}"."${table["table_name"]}" LIMIT 1);`
|
|
1474
|
-
let result: array<{"exists": bool}> = (await sql->Postgres.unsafe(query))->Utils.magic
|
|
1475
|
-
switch result {
|
|
1476
|
-
| [row] => row["exists"]
|
|
1477
|
-
| _ => false
|
|
1478
|
-
}
|
|
1479
|
-
} catch {
|
|
1480
|
-
| _ => false
|
|
1481
|
-
}
|
|
1482
|
-
})
|
|
1483
|
-
->Promise.all
|
|
1484
|
-
checks->Belt.Array.some(v => v)
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
1483
|
let setChainMeta = chainsData =>
|
|
1489
1484
|
InternalTable.Chains.setMeta(sql, ~pgSchema, ~chainsData)->Promise.thenResolve(_ =>
|
|
1490
1485
|
%raw(`undefined`)
|
|
@@ -1591,7 +1586,6 @@ let make = (
|
|
|
1591
1586
|
setEffectCacheOrThrow,
|
|
1592
1587
|
dumpEffectCache,
|
|
1593
1588
|
executeUnsafe,
|
|
1594
|
-
hasEntityHistoryRows,
|
|
1595
1589
|
setChainMeta,
|
|
1596
1590
|
pruneStaleCheckpoints,
|
|
1597
1591
|
pruneStaleEntityHistory,
|
package/src/PgStorage.res.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Fs from "fs";
|
|
4
|
+
import * as Env from "./Env.res.mjs";
|
|
4
5
|
import * as Path from "path";
|
|
5
6
|
import * as $$Array from "rescript/lib/es6/array.js";
|
|
6
7
|
import * as Table from "./db/Table.res.mjs";
|
|
@@ -12,7 +13,9 @@ import * as Schema from "./db/Schema.res.mjs";
|
|
|
12
13
|
import * as Js_dict from "rescript/lib/es6/js_dict.js";
|
|
13
14
|
import * as Logging from "./Logging.res.mjs";
|
|
14
15
|
import * as $$Promise from "./bindings/Promise.res.mjs";
|
|
16
|
+
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
|
|
15
17
|
import * as Internal from "./Internal.res.mjs";
|
|
18
|
+
import Postgres from "postgres";
|
|
16
19
|
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
|
|
17
20
|
import * as Prometheus from "./Prometheus.res.mjs";
|
|
18
21
|
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
@@ -26,6 +29,24 @@ import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
|
|
|
26
29
|
|
|
27
30
|
var getCacheRowCountFnName = "get_cache_row_count";
|
|
28
31
|
|
|
32
|
+
function makeClient() {
|
|
33
|
+
return Postgres({
|
|
34
|
+
host: Env.Db.host,
|
|
35
|
+
port: Env.Db.port,
|
|
36
|
+
database: Env.Db.database,
|
|
37
|
+
username: Env.Db.user,
|
|
38
|
+
password: Env.Db.password,
|
|
39
|
+
ssl: Env.Db.ssl,
|
|
40
|
+
max: 2,
|
|
41
|
+
onnotice: Caml_obj.equal(Env.userLogLevel, "warn") || Caml_obj.equal(Env.userLogLevel, "error") ? undefined : (function (_str) {
|
|
42
|
+
|
|
43
|
+
}),
|
|
44
|
+
transform: {
|
|
45
|
+
undefined: null
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
function makeCreateIndexQuery(tableName, indexFields, pgSchema) {
|
|
30
51
|
var indexName = tableName + "_" + indexFields.join("_");
|
|
31
52
|
var index = Belt_Array.map(indexFields, (function (idx) {
|
|
@@ -697,7 +718,7 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
|
|
|
697
718
|
var psqlExecOptions = {
|
|
698
719
|
env: psqlExecOptions_env
|
|
699
720
|
};
|
|
700
|
-
var cacheDirPath = Path.resolve("
|
|
721
|
+
var cacheDirPath = Path.resolve(".envio", "cache");
|
|
701
722
|
var isInitialized = async function () {
|
|
702
723
|
var envioTables = await sql.unsafe("SELECT table_schema FROM information_schema.tables WHERE table_schema = '" + pgSchema + "' AND (table_name = 'event_sync_state' OR table_name = '" + InternalTable.Chains.table.tableName + "');");
|
|
703
724
|
return Utils.$$Array.notEmpty(envioTables);
|
|
@@ -816,7 +837,8 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
|
|
|
816
837
|
numEventsProcessed: 0,
|
|
817
838
|
firstEventBlockNumber: undefined,
|
|
818
839
|
timestampCaughtUpToHeadOrEndblock: undefined,
|
|
819
|
-
dynamicContracts: []
|
|
840
|
+
dynamicContracts: [],
|
|
841
|
+
sourceBlockNumber: 0
|
|
820
842
|
};
|
|
821
843
|
}),
|
|
822
844
|
checkpointId: InternalTable.Checkpoints.initialCheckpointId,
|
|
@@ -968,7 +990,8 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
|
|
|
968
990
|
numEventsProcessed: rawInitialState.numEventsProcessed,
|
|
969
991
|
firstEventBlockNumber: Caml_option.null_to_opt(rawInitialState.firstEventBlockNumber),
|
|
970
992
|
timestampCaughtUpToHeadOrEndblock: Caml_option.null_to_opt(rawInitialState.timestampCaughtUpToHeadOrEndblock),
|
|
971
|
-
dynamicContracts: rawInitialState.dynamicContracts
|
|
993
|
+
dynamicContracts: rawInitialState.dynamicContracts,
|
|
994
|
+
sourceBlockNumber: rawInitialState.sourceBlockNumber
|
|
972
995
|
};
|
|
973
996
|
}));
|
|
974
997
|
}),
|
|
@@ -990,29 +1013,6 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
|
|
|
990
1013
|
var executeUnsafe = function (query) {
|
|
991
1014
|
return sql.unsafe(query);
|
|
992
1015
|
};
|
|
993
|
-
var hasEntityHistoryRows = async function () {
|
|
994
|
-
var historyTables = await sql.unsafe("SELECT table_name FROM information_schema.tables \n WHERE table_schema = '" + pgSchema + "' \n AND table_name LIKE 'envio_history_%';");
|
|
995
|
-
if (Utils.$$Array.isEmpty(historyTables)) {
|
|
996
|
-
return false;
|
|
997
|
-
}
|
|
998
|
-
var checks = await Promise.all(Belt_Array.map(historyTables, (async function (table) {
|
|
999
|
-
try {
|
|
1000
|
-
var query = "SELECT EXISTS(SELECT 1 FROM \"" + pgSchema + "\".\"" + table.table_name + "\" LIMIT 1);";
|
|
1001
|
-
var result = await sql.unsafe(query);
|
|
1002
|
-
if (result.length !== 1) {
|
|
1003
|
-
return false;
|
|
1004
|
-
} else {
|
|
1005
|
-
return result[0].exists;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
catch (exn){
|
|
1009
|
-
return false;
|
|
1010
|
-
}
|
|
1011
|
-
})));
|
|
1012
|
-
return Belt_Array.some(checks, (function (v) {
|
|
1013
|
-
return v;
|
|
1014
|
-
}));
|
|
1015
|
-
};
|
|
1016
1016
|
var setChainMeta = function (chainsData) {
|
|
1017
1017
|
return InternalTable.Chains.setMeta(sql, pgSchema, chainsData).then(function (param) {
|
|
1018
1018
|
return undefined;
|
|
@@ -1060,7 +1060,6 @@ function make(sql, pgHost, pgSchema, pgPort, pgUser, pgDatabase, pgPassword, isH
|
|
|
1060
1060
|
setEffectCacheOrThrow: setEffectCacheOrThrow,
|
|
1061
1061
|
dumpEffectCache: dumpEffectCache,
|
|
1062
1062
|
executeUnsafe: executeUnsafe,
|
|
1063
|
-
hasEntityHistoryRows: hasEntityHistoryRows,
|
|
1064
1063
|
setChainMeta: setChainMeta,
|
|
1065
1064
|
pruneStaleCheckpoints: pruneStaleCheckpoints,
|
|
1066
1065
|
pruneStaleEntityHistory: pruneStaleEntityHistory,
|
|
@@ -1075,6 +1074,7 @@ var maxItemsPerQuery = 500;
|
|
|
1075
1074
|
|
|
1076
1075
|
export {
|
|
1077
1076
|
getCacheRowCountFnName ,
|
|
1077
|
+
makeClient ,
|
|
1078
1078
|
makeCreateIndexQuery ,
|
|
1079
1079
|
makeCreateTableIndicesQuery ,
|
|
1080
1080
|
makeCreateTableQuery ,
|
package/src/Prometheus.res
CHANGED
|
@@ -34,12 +34,6 @@ let allChainsSyncedToHead = PromClient.Gauge.makeGauge({
|
|
|
34
34
|
"labelNames": [],
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
let sourceChainHeight = PromClient.Gauge.makeGauge({
|
|
38
|
-
"name": "chain_block_height",
|
|
39
|
-
"help": "Chain Height of Source Chain",
|
|
40
|
-
"labelNames": ["chainId"],
|
|
41
|
-
})
|
|
42
|
-
|
|
43
37
|
module Labels = {
|
|
44
38
|
let rec schemaIsString = (schema: S.t<'a>) =>
|
|
45
39
|
switch schema->S.classify {
|
|
@@ -233,8 +227,14 @@ let incrementStorageWriteCounter = () => {
|
|
|
233
227
|
storageWriteCounter->PromClient.Counter.inc
|
|
234
228
|
}
|
|
235
229
|
|
|
236
|
-
let
|
|
237
|
-
|
|
230
|
+
let knownHeightGauge = PromClient.Gauge.makeGauge({
|
|
231
|
+
"name": "envio_indexing_known_height",
|
|
232
|
+
"help": "The latest known block number reported by the active indexing source. This value may lag behind the actual chain height, as it is updated only when needed.",
|
|
233
|
+
"labelNames": ["chainId"],
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
let setKnownHeight = (~blockNumber, ~chainId) => {
|
|
237
|
+
knownHeightGauge
|
|
238
238
|
->PromClient.Gauge.labels({"chainId": chainId})
|
|
239
239
|
->PromClient.Gauge.set(blockNumber)
|
|
240
240
|
}
|
package/src/Prometheus.res.mjs
CHANGED
|
@@ -44,12 +44,6 @@ var allChainsSyncedToHead = new PromClient.Gauge({
|
|
|
44
44
|
labelNames: []
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
var sourceChainHeight = new PromClient.Gauge({
|
|
48
|
-
name: "chain_block_height",
|
|
49
|
-
help: "Chain Height of Source Chain",
|
|
50
|
-
labelNames: ["chainId"]
|
|
51
|
-
});
|
|
52
|
-
|
|
53
47
|
function schemaIsString(_schema) {
|
|
54
48
|
while(true) {
|
|
55
49
|
var schema = _schema;
|
|
@@ -333,8 +327,14 @@ function incrementStorageWriteCounter() {
|
|
|
333
327
|
storageWriteCounter.inc();
|
|
334
328
|
}
|
|
335
329
|
|
|
336
|
-
|
|
337
|
-
|
|
330
|
+
var knownHeightGauge = new PromClient.Gauge({
|
|
331
|
+
name: "envio_indexing_known_height",
|
|
332
|
+
help: "The latest known block number reported by the active indexing source. This value may lag behind the actual chain height, as it is updated only when needed.",
|
|
333
|
+
labelNames: ["chainId"]
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
function setKnownHeight(blockNumber, chainId) {
|
|
337
|
+
knownHeightGauge.labels({
|
|
338
338
|
chainId: chainId
|
|
339
339
|
}).set(blockNumber);
|
|
340
340
|
}
|
|
@@ -854,7 +854,6 @@ export {
|
|
|
854
854
|
storageWriteTimeCounter ,
|
|
855
855
|
storageWriteCounter ,
|
|
856
856
|
allChainsSyncedToHead ,
|
|
857
|
-
sourceChainHeight ,
|
|
858
857
|
Labels ,
|
|
859
858
|
metricNames ,
|
|
860
859
|
MakeSafePromMetric ,
|
|
@@ -867,7 +866,8 @@ export {
|
|
|
867
866
|
incrementExecuteBatchDurationCounter ,
|
|
868
867
|
incrementStorageWriteTimeCounter ,
|
|
869
868
|
incrementStorageWriteCounter ,
|
|
870
|
-
|
|
869
|
+
knownHeightGauge ,
|
|
870
|
+
setKnownHeight ,
|
|
871
871
|
setAllChainsSyncedToHead ,
|
|
872
872
|
BenchmarkCounters ,
|
|
873
873
|
chainIdLabelsSchema ,
|
package/src/ReorgDetection.res
CHANGED
|
@@ -77,13 +77,10 @@ let make = (
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
let getDataByBlockNumberCopyInThreshold = (
|
|
81
|
-
{dataByBlockNumber, maxReorgDepth}: t,
|
|
82
|
-
~currentBlockHeight,
|
|
83
|
-
) => {
|
|
80
|
+
let getDataByBlockNumberCopyInThreshold = ({dataByBlockNumber, maxReorgDepth}: t, ~knownHeight) => {
|
|
84
81
|
// Js engine automatically orders numeric object keys
|
|
85
82
|
let ascBlockNumberKeys = dataByBlockNumber->Js.Dict.keys
|
|
86
|
-
let thresholdBlockNumber =
|
|
83
|
+
let thresholdBlockNumber = knownHeight - maxReorgDepth
|
|
87
84
|
|
|
88
85
|
let copy = Js.Dict.empty()
|
|
89
86
|
|
|
@@ -105,10 +102,9 @@ let getDataByBlockNumberCopyInThreshold = (
|
|
|
105
102
|
let registerReorgGuard = (
|
|
106
103
|
{maxReorgDepth, shouldRollbackOnReorg} as self: t,
|
|
107
104
|
~reorgGuard: reorgGuard,
|
|
108
|
-
~
|
|
105
|
+
~knownHeight,
|
|
109
106
|
) => {
|
|
110
|
-
let dataByBlockNumberCopyInThreshold =
|
|
111
|
-
self->getDataByBlockNumberCopyInThreshold(~currentBlockHeight)
|
|
107
|
+
let dataByBlockNumberCopyInThreshold = self->getDataByBlockNumberCopyInThreshold(~knownHeight)
|
|
112
108
|
|
|
113
109
|
let {rangeLastBlock, prevRangeLastBlock} = reorgGuard
|
|
114
110
|
|
|
@@ -248,12 +244,12 @@ let rollbackToValidBlockNumber = (
|
|
|
248
244
|
}
|
|
249
245
|
}
|
|
250
246
|
|
|
251
|
-
let getThresholdBlockNumbersBelowBlock = (self: t, ~blockNumber: int, ~
|
|
247
|
+
let getThresholdBlockNumbersBelowBlock = (self: t, ~blockNumber: int, ~knownHeight) => {
|
|
252
248
|
let arr = []
|
|
253
249
|
|
|
254
250
|
// Js engine automatically orders numeric object keys
|
|
255
251
|
let ascBlockNumberKeys = self.dataByBlockNumber->Js.Dict.keys
|
|
256
|
-
let thresholdBlockNumber =
|
|
252
|
+
let thresholdBlockNumber = knownHeight - self.maxReorgDepth
|
|
257
253
|
|
|
258
254
|
for idx in 0 to ascBlockNumberKeys->Array.length - 1 {
|
|
259
255
|
let blockNumberKey = ascBlockNumberKeys->Js.Array2.unsafe_get(idx)
|
|
@@ -30,10 +30,10 @@ function make(chainReorgCheckpoints, maxReorgDepth, shouldRollbackOnReorg) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function getDataByBlockNumberCopyInThreshold(param,
|
|
33
|
+
function getDataByBlockNumberCopyInThreshold(param, knownHeight) {
|
|
34
34
|
var dataByBlockNumber = param.dataByBlockNumber;
|
|
35
35
|
var ascBlockNumberKeys = Object.keys(dataByBlockNumber);
|
|
36
|
-
var thresholdBlockNumber =
|
|
36
|
+
var thresholdBlockNumber = knownHeight - param.maxReorgDepth | 0;
|
|
37
37
|
var copy = {};
|
|
38
38
|
for(var idx = 0 ,idx_finish = ascBlockNumberKeys.length; idx < idx_finish; ++idx){
|
|
39
39
|
var blockNumberKey = ascBlockNumberKeys[idx];
|
|
@@ -47,10 +47,10 @@ function getDataByBlockNumberCopyInThreshold(param, currentBlockHeight) {
|
|
|
47
47
|
return copy;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
function registerReorgGuard(self, reorgGuard,
|
|
50
|
+
function registerReorgGuard(self, reorgGuard, knownHeight) {
|
|
51
51
|
var maxReorgDepth = self.maxReorgDepth;
|
|
52
52
|
var shouldRollbackOnReorg = self.shouldRollbackOnReorg;
|
|
53
|
-
var dataByBlockNumberCopyInThreshold = getDataByBlockNumberCopyInThreshold(self,
|
|
53
|
+
var dataByBlockNumberCopyInThreshold = getDataByBlockNumberCopyInThreshold(self, knownHeight);
|
|
54
54
|
var prevRangeLastBlock = reorgGuard.prevRangeLastBlock;
|
|
55
55
|
var rangeLastBlock = reorgGuard.rangeLastBlock;
|
|
56
56
|
var scannedBlock = dataByBlockNumberCopyInThreshold[String(rangeLastBlock.blockNumber)];
|
|
@@ -159,10 +159,10 @@ function rollbackToValidBlockNumber(param, blockNumber) {
|
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
function getThresholdBlockNumbersBelowBlock(self, blockNumber,
|
|
162
|
+
function getThresholdBlockNumbersBelowBlock(self, blockNumber, knownHeight) {
|
|
163
163
|
var arr = [];
|
|
164
164
|
var ascBlockNumberKeys = Object.keys(self.dataByBlockNumber);
|
|
165
|
-
var thresholdBlockNumber =
|
|
165
|
+
var thresholdBlockNumber = knownHeight - self.maxReorgDepth | 0;
|
|
166
166
|
for(var idx = 0 ,idx_finish = ascBlockNumberKeys.length; idx < idx_finish; ++idx){
|
|
167
167
|
var blockNumberKey = ascBlockNumberKeys[idx];
|
|
168
168
|
var scannedBlock = self.dataByBlockNumber[blockNumberKey];
|