envio 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +164 -30
- package/bin.mjs +49 -0
- package/evm.schema.json +79 -169
- package/fuel.schema.json +50 -21
- package/index.d.ts +497 -1
- package/index.js +4 -0
- package/package.json +42 -31
- package/rescript.json +4 -1
- package/src/Batch.res +11 -8
- package/src/Batch.res.mjs +11 -9
- package/src/ChainFetcher.res +531 -0
- package/src/ChainFetcher.res.mjs +339 -0
- package/src/ChainManager.res +190 -0
- package/src/ChainManager.res.mjs +166 -0
- package/src/Change.res +3 -3
- package/src/Config.gen.ts +19 -0
- package/src/Config.res +737 -22
- package/src/Config.res.mjs +703 -26
- package/src/{Indexer.res → Ctx.res} +1 -1
- package/src/Ecosystem.res +9 -124
- package/src/Ecosystem.res.mjs +19 -160
- package/src/Env.res +30 -74
- package/src/Env.res.mjs +25 -87
- package/src/Envio.gen.ts +3 -1
- package/src/Envio.res +20 -9
- package/src/EventProcessing.res +469 -0
- package/src/EventProcessing.res.mjs +337 -0
- package/src/EvmTypes.gen.ts +6 -0
- package/src/EvmTypes.res +1 -0
- package/src/FetchState.res +1256 -639
- package/src/FetchState.res.mjs +1135 -612
- package/src/GlobalState.res +1190 -0
- package/src/GlobalState.res.mjs +1183 -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/HandlerRegister.res +357 -0
- package/src/HandlerRegister.res.mjs +299 -0
- package/src/{EventRegister.resi → HandlerRegister.resi} +13 -13
- package/src/Hasura.res +111 -175
- package/src/Hasura.res.mjs +88 -150
- package/src/InMemoryStore.res +1 -1
- package/src/InMemoryStore.res.mjs +3 -3
- package/src/InMemoryTable.res +1 -1
- package/src/InMemoryTable.res.mjs +1 -1
- package/src/Internal.gen.ts +4 -0
- package/src/Internal.res +230 -12
- package/src/Internal.res.mjs +115 -1
- 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 +21 -7
- package/src/Logging.res.mjs +16 -8
- package/src/Main.res +377 -0
- package/src/Main.res.mjs +339 -0
- package/src/Persistence.res +7 -21
- package/src/Persistence.res.mjs +3 -3
- package/src/PgStorage.gen.ts +10 -0
- package/src/PgStorage.res +116 -69
- package/src/PgStorage.res.d.mts +5 -0
- package/src/PgStorage.res.mjs +93 -50
- package/src/Prometheus.res +294 -224
- package/src/Prometheus.res.mjs +353 -340
- package/src/ReorgDetection.res +6 -10
- package/src/ReorgDetection.res.mjs +6 -6
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +2 -2
- package/src/Sink.res +4 -2
- package/src/Sink.res.mjs +2 -1
- package/src/TableIndices.res +0 -1
- package/src/TestIndexer.res +692 -0
- package/src/TestIndexer.res.mjs +527 -0
- package/src/TestIndexerProxyStorage.res +205 -0
- package/src/TestIndexerProxyStorage.res.mjs +151 -0
- package/src/TopicFilter.res +1 -1
- package/src/Types.ts +1 -1
- package/src/UserContext.res +424 -0
- package/src/UserContext.res.mjs +279 -0
- package/src/Utils.res +97 -26
- package/src/Utils.res.mjs +91 -44
- package/src/bindings/BigInt.res +10 -0
- package/src/bindings/BigInt.res.mjs +15 -0
- package/src/bindings/ClickHouse.res +120 -23
- package/src/bindings/ClickHouse.res.mjs +118 -28
- package/src/bindings/DateFns.res +74 -0
- package/src/bindings/DateFns.res.mjs +22 -0
- package/src/bindings/EventSource.res +8 -1
- package/src/bindings/EventSource.res.mjs +8 -1
- package/src/bindings/Express.res +1 -0
- package/src/bindings/Hrtime.res +14 -1
- package/src/bindings/Hrtime.res.mjs +22 -2
- package/src/bindings/Hrtime.resi +4 -0
- package/src/bindings/Lodash.res +0 -1
- package/src/bindings/NodeJs.res +49 -3
- package/src/bindings/NodeJs.res.mjs +11 -3
- package/src/bindings/Pino.res +24 -10
- package/src/bindings/Pino.res.mjs +14 -8
- package/src/bindings/Postgres.gen.ts +8 -0
- package/src/bindings/Postgres.res +5 -1
- package/src/bindings/Postgres.res.d.mts +5 -0
- package/src/bindings/PromClient.res +0 -10
- package/src/bindings/PromClient.res.mjs +0 -3
- package/src/bindings/Vitest.res +142 -0
- package/src/bindings/Vitest.res.mjs +9 -0
- package/src/bindings/WebSocket.res +27 -0
- package/src/bindings/WebSocket.res.mjs +2 -0
- package/src/bindings/Yargs.res +8 -0
- package/src/bindings/Yargs.res.mjs +2 -0
- package/src/db/EntityHistory.res +7 -7
- package/src/db/EntityHistory.res.mjs +9 -9
- package/src/db/InternalTable.res +59 -111
- package/src/db/InternalTable.res.mjs +73 -104
- package/src/db/Table.res +27 -8
- package/src/db/Table.res.mjs +25 -14
- package/src/sources/Evm.res +84 -0
- package/src/sources/Evm.res.mjs +105 -0
- package/src/sources/EvmChain.res +94 -0
- package/src/sources/EvmChain.res.mjs +60 -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 +33 -13
- package/src/sources/HyperFuelSource.res.mjs +24 -16
- package/src/sources/HyperSync.res +36 -6
- package/src/sources/HyperSync.res.mjs +9 -7
- package/src/sources/HyperSync.resi +4 -0
- package/src/sources/HyperSyncClient.res +1 -1
- package/src/sources/HyperSyncHeightStream.res +47 -116
- package/src/sources/HyperSyncHeightStream.res.mjs +46 -73
- package/src/sources/HyperSyncSource.res +118 -139
- package/src/sources/HyperSyncSource.res.mjs +104 -121
- package/src/sources/Rpc.res +86 -14
- package/src/sources/Rpc.res.mjs +101 -9
- package/src/sources/RpcSource.res +621 -364
- package/src/sources/RpcSource.res.mjs +843 -410
- package/src/sources/RpcWebSocketHeightStream.res +181 -0
- package/src/sources/RpcWebSocketHeightStream.res.mjs +196 -0
- package/src/sources/Source.res +7 -5
- package/src/sources/SourceManager.res +325 -225
- package/src/sources/SourceManager.res.mjs +314 -171
- package/src/sources/SourceManager.resi +17 -6
- package/src/sources/Svm.res +81 -0
- package/src/sources/Svm.res.mjs +90 -0
- package/src/tui/Tui.res +247 -0
- package/src/tui/Tui.res.mjs +337 -0
- package/src/tui/bindings/Ink.res +371 -0
- package/src/tui/bindings/Ink.res.mjs +72 -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 +174 -0
- package/src/tui/components/SyncETA.res.mjs +263 -0
- package/src/tui/components/TuiData.res +47 -0
- package/src/tui/components/TuiData.res.mjs +34 -0
- package/svm.schema.json +112 -0
- package/bin.js +0 -48
- package/src/EventRegister.res +0 -241
- package/src/EventRegister.res.mjs +0 -240
- package/src/bindings/Ethers.gen.ts +0 -14
- package/src/bindings/Ethers.res +0 -204
- package/src/bindings/Ethers.res.mjs +0 -130
- /package/src/{Indexer.res.mjs → Ctx.res.mjs} +0 -0
package/src/PgStorage.res
CHANGED
|
@@ -1,18 +1,73 @@
|
|
|
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: Env.Db.maxConnections,
|
|
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(", ")
|
|
6
31
|
`CREATE INDEX IF NOT EXISTS "${indexName}" ON "${pgSchema}"."${tableName}"(${index});`
|
|
7
32
|
}
|
|
8
33
|
|
|
34
|
+
let directionToSql = (direction: Table.indexFieldDirection) =>
|
|
35
|
+
switch direction {
|
|
36
|
+
| Asc => ""
|
|
37
|
+
| Desc => " DESC"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let directionToIndexName = (direction: Table.indexFieldDirection) =>
|
|
41
|
+
switch direction {
|
|
42
|
+
| Asc => ""
|
|
43
|
+
| Desc => "_desc"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let makeCreateCompositeIndexQuery = (
|
|
47
|
+
~tableName,
|
|
48
|
+
~indexFields: array<Table.compositeIndexField>,
|
|
49
|
+
~pgSchema,
|
|
50
|
+
) => {
|
|
51
|
+
let indexName =
|
|
52
|
+
tableName ++
|
|
53
|
+
"_" ++
|
|
54
|
+
indexFields
|
|
55
|
+
->Js.Array2.map(f => f.fieldName ++ directionToIndexName(f.direction))
|
|
56
|
+
->Js.Array2.joinWith("_")
|
|
57
|
+
let index =
|
|
58
|
+
indexFields
|
|
59
|
+
->Belt.Array.map(f => `"${f.fieldName}"${directionToSql(f.direction)}`)
|
|
60
|
+
->Js.Array2.joinWith(", ")
|
|
61
|
+
`CREATE INDEX IF NOT EXISTS "${indexName}" ON "${pgSchema}"."${tableName}"(${index});`
|
|
62
|
+
}
|
|
63
|
+
|
|
9
64
|
let makeCreateTableIndicesQuery = (table: Table.table, ~pgSchema) => {
|
|
10
65
|
open Belt
|
|
11
66
|
let tableName = table.tableName
|
|
12
67
|
let createIndex = indexField =>
|
|
13
68
|
makeCreateIndexQuery(~tableName, ~indexFields=[indexField], ~pgSchema)
|
|
14
69
|
let createCompositeIndex = indexFields => {
|
|
15
|
-
|
|
70
|
+
makeCreateCompositeIndexQuery(~tableName, ~indexFields, ~pgSchema)
|
|
16
71
|
}
|
|
17
72
|
|
|
18
73
|
let singleIndices = table->Table.getSingleIndices
|
|
@@ -57,10 +112,11 @@ let makeCreateTableQuery = (table: Table.table, ~pgSchema, ~isNumericArrayAsText
|
|
|
57
112
|
: ""});`
|
|
58
113
|
}
|
|
59
114
|
|
|
115
|
+
let entityHistoryCache = Utils.WeakMap.make()
|
|
60
116
|
let getEntityHistory = (~entityConfig: Internal.entityConfig): EntityHistory.pgEntityHistory<
|
|
61
117
|
'entity,
|
|
62
118
|
> => {
|
|
63
|
-
switch entityConfig
|
|
119
|
+
switch entityHistoryCache->Utils.WeakMap.get(entityConfig) {
|
|
64
120
|
| Some(cache) => cache
|
|
65
121
|
| None =>
|
|
66
122
|
let cache = {
|
|
@@ -119,7 +175,7 @@ let getEntityHistory = (~entityConfig: Internal.entityConfig): EntityHistory.pgE
|
|
|
119
175
|
}
|
|
120
176
|
}
|
|
121
177
|
|
|
122
|
-
entityConfig
|
|
178
|
+
entityHistoryCache->Utils.WeakMap.set(entityConfig, cache)->ignore
|
|
123
179
|
cache
|
|
124
180
|
}
|
|
125
181
|
}
|
|
@@ -154,9 +210,9 @@ let makeInitializeTransaction = (
|
|
|
154
210
|
isEmptyPgSchema && pgSchema === "public"
|
|
155
211
|
// Hosted Service already have a DB with the created public schema
|
|
156
212
|
// It also doesn't allow to simply drop it,
|
|
157
|
-
// so we reuse the existing schema when it's empty
|
|
158
|
-
//
|
|
159
|
-
? ""
|
|
213
|
+
// so we reuse the existing schema when it's empty.
|
|
214
|
+
// IF NOT EXISTS handles the case where public was previously dropped.
|
|
215
|
+
? `CREATE SCHEMA IF NOT EXISTS "${pgSchema}";\n`
|
|
160
216
|
: `DROP SCHEMA IF EXISTS "${pgSchema}" CASCADE;
|
|
161
217
|
CREATE SCHEMA "${pgSchema}";\n`
|
|
162
218
|
) ++
|
|
@@ -376,7 +432,9 @@ let makeTableBatchSetQuery = (~pgSchema, ~table: Table.table, ~itemSchema: S.t<'
|
|
|
376
432
|
),
|
|
377
433
|
"convertOrThrow": S.compile(
|
|
378
434
|
S.unnest(itemSchema)->S.preprocess(_ => {
|
|
379
|
-
serializer: Utils.Array.flatten->
|
|
435
|
+
serializer: Utils.Array.flatten->(
|
|
436
|
+
Utils.magic: (array<array<'a>> => array<'a>) => unknown => unknown
|
|
437
|
+
),
|
|
380
438
|
}),
|
|
381
439
|
~input=Value,
|
|
382
440
|
~output=Unknown,
|
|
@@ -454,14 +512,17 @@ let setOrThrow = async (sql, ~items, ~table: Table.table, ~itemSchema, ~pgSchema
|
|
|
454
512
|
let chunkSize = chunk->Array.length
|
|
455
513
|
let isFullChunk = chunkSize === maxItemsPerQuery
|
|
456
514
|
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
// or create a new one for partial chunks on the fly.
|
|
460
|
-
isFullChunk
|
|
461
|
-
? data["query"]
|
|
462
|
-
: makeInsertValuesSetQuery(~pgSchema, ~table, ~itemSchema, ~itemsCount=chunkSize),
|
|
463
|
-
data["convertOrThrow"](chunk->(Utils.magic: array<'item> => array<unknown>)),
|
|
515
|
+
let params = data["convertOrThrow"](
|
|
516
|
+
chunk->(Utils.magic: array<'item> => array<unknown>),
|
|
464
517
|
)
|
|
518
|
+
// Use prepared query only for full batches where the cached query is reused.
|
|
519
|
+
// Partial chunks generate unique SQL each time, so preparation has no benefit.
|
|
520
|
+
let response = isFullChunk
|
|
521
|
+
? sql->Postgres.preparedUnsafe(data["query"], params)
|
|
522
|
+
: sql->Postgres.unpreparedUnsafe(
|
|
523
|
+
makeInsertValuesSetQuery(~pgSchema, ~table, ~itemSchema, ~itemsCount=chunkSize),
|
|
524
|
+
params,
|
|
525
|
+
)
|
|
465
526
|
responses->Js.Array2.push(response)->ignore
|
|
466
527
|
})
|
|
467
528
|
let _ = await Promise.all(responses)
|
|
@@ -522,18 +583,17 @@ type psqlExecState =
|
|
|
522
583
|
Unknown | Pending(promise<result<string, string>>) | Resolved(result<string, string>)
|
|
523
584
|
|
|
524
585
|
let getConnectedPsqlExec = {
|
|
525
|
-
let pgDockerServiceName = "envio-postgres"
|
|
526
586
|
// Should use the default port, since we're executing the command
|
|
527
587
|
// from the postgres container's network.
|
|
528
588
|
let pgDockerServicePort = 5432
|
|
529
589
|
|
|
530
590
|
// For development: We run the indexer process locally,
|
|
531
591
|
// and there might not be psql installed on the user's machine.
|
|
532
|
-
// So we use docker
|
|
592
|
+
// So we use docker exec to run psql inside the postgres container.
|
|
533
593
|
// For production: We expect indexer to be running in a container,
|
|
534
594
|
// with psql installed. So we can call it directly.
|
|
535
595
|
let psqlExecState = ref(Unknown)
|
|
536
|
-
async (~pgUser, ~pgHost, ~pgDatabase, ~pgPort) => {
|
|
596
|
+
async (~pgUser, ~pgHost, ~pgDatabase, ~pgPort, ~containerName) => {
|
|
537
597
|
switch psqlExecState.contents {
|
|
538
598
|
| Unknown => {
|
|
539
599
|
let promise = Promise.make((resolve, _reject) => {
|
|
@@ -541,14 +601,16 @@ let getConnectedPsqlExec = {
|
|
|
541
601
|
NodeJs.ChildProcess.exec(`${binary} --version`, (~error, ~stdout as _, ~stderr as _) => {
|
|
542
602
|
switch error {
|
|
543
603
|
| Value(_) => {
|
|
544
|
-
let binary = `docker
|
|
604
|
+
let binary = `docker exec -i -u ${pgUser} ${containerName} psql`
|
|
545
605
|
NodeJs.ChildProcess.exec(
|
|
546
606
|
`${binary} --version`,
|
|
547
607
|
(~error, ~stdout as _, ~stderr as _) => {
|
|
548
608
|
switch error {
|
|
549
609
|
| Value(_) =>
|
|
550
610
|
resolve(
|
|
551
|
-
Error(
|
|
611
|
+
Error(
|
|
612
|
+
`Please check if "psql" binary is installed or Docker container "${containerName}" is running.`,
|
|
613
|
+
),
|
|
552
614
|
)
|
|
553
615
|
| Null =>
|
|
554
616
|
resolve(
|
|
@@ -766,7 +828,7 @@ let rec writeBatch = async (
|
|
|
766
828
|
sql
|
|
767
829
|
->Postgres.preparedUnsafe(
|
|
768
830
|
makeInsertDeleteUpdatesQuery(~entityConfig, ~pgSchema),
|
|
769
|
-
(batchDeleteEntityIds, batchDeleteCheckpointIds)->Obj.magic,
|
|
831
|
+
(batchDeleteEntityIds, batchDeleteCheckpointIds->BigInt.arrayToStringArray)->Obj.magic,
|
|
770
832
|
)
|
|
771
833
|
->Promise.ignoreValue,
|
|
772
834
|
)
|
|
@@ -908,6 +970,7 @@ let rec writeBatch = async (
|
|
|
908
970
|
): InternalTable.Chains.progressedChain => {
|
|
909
971
|
chainId: chainAfterBatch.fetchState.chainId,
|
|
910
972
|
progressBlockNumber: chainAfterBatch.progressBlockNumber,
|
|
973
|
+
sourceBlockNumber: chainAfterBatch.sourceBlockNumber,
|
|
911
974
|
totalEventsProcessed: chainAfterBatch.totalEventsProcessed,
|
|
912
975
|
}),
|
|
913
976
|
),
|
|
@@ -1051,13 +1114,14 @@ let make = (
|
|
|
1051
1114
|
~onInitialize=?,
|
|
1052
1115
|
~onNewTables=?,
|
|
1053
1116
|
): Persistence.storage => {
|
|
1117
|
+
// Must match PG_CONTAINER in packages/cli/src/docker_env.rs
|
|
1118
|
+
let containerName = "envio-postgres"
|
|
1054
1119
|
let psqlExecOptions: NodeJs.ChildProcess.execOptions = {
|
|
1055
1120
|
env: Js.Dict.fromArray([("PGPASSWORD", pgPassword), ("PATH", %raw(`process.env.PATH`))]),
|
|
1056
1121
|
}
|
|
1057
1122
|
|
|
1058
1123
|
let cacheDirPath = NodeJs.Path.resolve([
|
|
1059
|
-
// Right
|
|
1060
|
-
"..",
|
|
1124
|
+
// Right at the project root
|
|
1061
1125
|
".envio",
|
|
1062
1126
|
"cache",
|
|
1063
1127
|
])
|
|
@@ -1079,7 +1143,7 @@ let make = (
|
|
|
1079
1143
|
NodeJs.Fs.Promises.readdir(cacheDirPath)
|
|
1080
1144
|
->Promise.thenResolve(e => Ok(e))
|
|
1081
1145
|
->Promise.catch(_ => Promise.resolve(Error(nothingToUploadErrorMessage))),
|
|
1082
|
-
getConnectedPsqlExec(~pgUser, ~pgHost, ~pgDatabase, ~pgPort),
|
|
1146
|
+
getConnectedPsqlExec(~pgUser, ~pgHost, ~pgDatabase, ~pgPort, ~containerName),
|
|
1083
1147
|
)) {
|
|
1084
1148
|
| (Ok(entries), Ok(psqlExec)) => {
|
|
1085
1149
|
let cacheFiles = entries->Js.Array2.filter(entry => {
|
|
@@ -1175,7 +1239,7 @@ let make = (
|
|
|
1175
1239
|
)
|
|
1176
1240
|
) {
|
|
1177
1241
|
Js.Exn.raiseError(
|
|
1178
|
-
`Cannot run Envio migrations on PostgreSQL schema "${pgSchema}" because it contains non-Envio tables. Running migrations would delete all data in this schema.\n\nTo resolve this:\n1. If you want to use this schema, first backup any important data, then drop it with: "pnpm envio local db-migrate down"\n2. Or specify a different schema name by setting the "
|
|
1242
|
+
`Cannot run Envio migrations on PostgreSQL schema "${pgSchema}" because it contains non-Envio tables. Running migrations would delete all data in this schema.\n\nTo resolve this:\n1. If you want to use this schema, first backup any important data, then drop it with: "pnpm envio local db-migrate down"\n2. Or specify a different schema name by setting the "ENVIO_PG_SCHEMA" environment variable\n3. Or manually drop the schema in your database if you're certain the data is not needed.`,
|
|
1179
1243
|
)
|
|
1180
1244
|
}
|
|
1181
1245
|
|
|
@@ -1219,10 +1283,11 @@ let make = (
|
|
|
1219
1283
|
endBlock: chainConfig.endBlock,
|
|
1220
1284
|
maxReorgDepth: chainConfig.maxReorgDepth,
|
|
1221
1285
|
progressBlockNumber: -1,
|
|
1222
|
-
numEventsProcessed: 0
|
|
1286
|
+
numEventsProcessed: 0.,
|
|
1223
1287
|
firstEventBlockNumber: None,
|
|
1224
1288
|
timestampCaughtUpToHeadOrEndblock: None,
|
|
1225
1289
|
dynamicContracts: [],
|
|
1290
|
+
sourceBlockNumber: 0,
|
|
1226
1291
|
}),
|
|
1227
1292
|
checkpointId: InternalTable.Checkpoints.initialCheckpointId,
|
|
1228
1293
|
}
|
|
@@ -1363,10 +1428,10 @@ let make = (
|
|
|
1363
1428
|
await NodeJs.Fs.Promises.mkdir(~path=cacheDirPath, ~options={recursive: true})
|
|
1364
1429
|
}
|
|
1365
1430
|
|
|
1366
|
-
// Command for testing. Run from
|
|
1367
|
-
// docker
|
|
1431
|
+
// Command for testing. Run from project root:
|
|
1432
|
+
// docker exec -i -u postgres envio-{indexerName}-postgres psql -d envio-dev -c 'COPY "public"."envio_effect_getTokenMetadata" TO STDOUT (FORMAT text, HEADER);' > ../.envio/cache/getTokenMetadata.tsv
|
|
1368
1433
|
|
|
1369
|
-
switch await getConnectedPsqlExec(~pgUser, ~pgHost, ~pgDatabase, ~pgPort) {
|
|
1434
|
+
switch await getConnectedPsqlExec(~pgUser, ~pgHost, ~pgDatabase, ~pgPort, ~containerName) {
|
|
1370
1435
|
| Ok(psqlExec) => {
|
|
1371
1436
|
Logging.info(
|
|
1372
1437
|
`Dumping cache: ${cacheTableInfo
|
|
@@ -1425,17 +1490,30 @@ let make = (
|
|
|
1425
1490
|
numEventsProcessed: rawInitialState.numEventsProcessed,
|
|
1426
1491
|
progressBlockNumber: rawInitialState.progressBlockNumber,
|
|
1427
1492
|
dynamicContracts: rawInitialState.dynamicContracts,
|
|
1493
|
+
sourceBlockNumber: rawInitialState.sourceBlockNumber,
|
|
1428
1494
|
})
|
|
1429
1495
|
}),
|
|
1430
1496
|
sql
|
|
1431
1497
|
->Postgres.unsafe(InternalTable.Checkpoints.makeCommitedCheckpointIdQuery(~pgSchema))
|
|
1432
|
-
->(Utils.magic: promise<array<unknown>> => promise<array<{"id":
|
|
1498
|
+
->(Utils.magic: promise<array<unknown>> => promise<array<{"id": string}>>),
|
|
1433
1499
|
sql
|
|
1434
1500
|
->Postgres.unsafe(InternalTable.Checkpoints.makeGetReorgCheckpointsQuery(~pgSchema))
|
|
1435
|
-
->(
|
|
1501
|
+
->(
|
|
1502
|
+
Utils.magic: promise<array<unknown>> => promise<
|
|
1503
|
+
array<{"id": string, "chain_id": int, "block_number": int, "block_hash": string}>,
|
|
1504
|
+
>
|
|
1505
|
+
),
|
|
1436
1506
|
))
|
|
1437
1507
|
|
|
1438
|
-
let checkpointId = (checkpointIdResult->Belt.Array.getUnsafe(0))["id"]
|
|
1508
|
+
let checkpointId = (checkpointIdResult->Belt.Array.getUnsafe(0))["id"]->BigInt.fromStringUnsafe
|
|
1509
|
+
|
|
1510
|
+
// Convert string checkpoint IDs from DB to bigint
|
|
1511
|
+
let reorgCheckpoints = Belt.Array.map(reorgCheckpoints, (raw): Internal.reorgCheckpoint => {
|
|
1512
|
+
checkpointId: raw["id"]->BigInt.fromStringUnsafe,
|
|
1513
|
+
chainId: raw["chain_id"],
|
|
1514
|
+
blockNumber: raw["block_number"],
|
|
1515
|
+
blockHash: raw["block_hash"],
|
|
1516
|
+
})
|
|
1439
1517
|
|
|
1440
1518
|
// Resume sink if present - needed to rollback any reorg changes
|
|
1441
1519
|
switch sink {
|
|
@@ -1452,37 +1530,9 @@ let make = (
|
|
|
1452
1530
|
}
|
|
1453
1531
|
}
|
|
1454
1532
|
|
|
1455
|
-
let
|
|
1456
|
-
|
|
1457
|
-
|
|
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
|
-
}
|
|
1533
|
+
let reset = async () => {
|
|
1534
|
+
let query = `DROP SCHEMA IF EXISTS "${pgSchema}" CASCADE;`
|
|
1535
|
+
await sql->Postgres.unsafe(query)->Promise.ignoreValue
|
|
1486
1536
|
}
|
|
1487
1537
|
|
|
1488
1538
|
let setChainMeta = chainsData =>
|
|
@@ -1522,14 +1572,14 @@ let make = (
|
|
|
1522
1572
|
sql
|
|
1523
1573
|
->Postgres.preparedUnsafe(
|
|
1524
1574
|
makeGetRollbackRemovedIdsQuery(~entityConfig, ~pgSchema),
|
|
1525
|
-
[rollbackTargetCheckpointId]->Utils.magic,
|
|
1575
|
+
[rollbackTargetCheckpointId->BigInt.toString]->(Utils.magic: array<string> => unknown),
|
|
1526
1576
|
)
|
|
1527
1577
|
->(Utils.magic: promise<unknown> => promise<array<{"id": string}>>),
|
|
1528
1578
|
// Get entities that should be restored to their state at or before rollback target
|
|
1529
1579
|
sql
|
|
1530
1580
|
->Postgres.preparedUnsafe(
|
|
1531
1581
|
makeGetRollbackRestoredEntitiesQuery(~entityConfig, ~pgSchema),
|
|
1532
|
-
[rollbackTargetCheckpointId]->Utils.magic,
|
|
1582
|
+
[rollbackTargetCheckpointId->BigInt.toString]->(Utils.magic: array<string> => unknown),
|
|
1533
1583
|
)
|
|
1534
1584
|
->(Utils.magic: promise<unknown> => promise<array<unknown>>),
|
|
1535
1585
|
))
|
|
@@ -1554,7 +1604,7 @@ let make = (
|
|
|
1554
1604
|
->Promise.thenResolve(_ => {
|
|
1555
1605
|
Prometheus.SinkWrite.increment(
|
|
1556
1606
|
~sinkName=sink.name,
|
|
1557
|
-
~
|
|
1607
|
+
~timeSeconds=timerRef->Hrtime.timeSince->Hrtime.toSecondsFloat,
|
|
1558
1608
|
)
|
|
1559
1609
|
None
|
|
1560
1610
|
})
|
|
@@ -1587,11 +1637,8 @@ let make = (
|
|
|
1587
1637
|
resumeInitialState,
|
|
1588
1638
|
loadByFieldOrThrow,
|
|
1589
1639
|
loadByIdsOrThrow,
|
|
1590
|
-
setOrThrow,
|
|
1591
|
-
setEffectCacheOrThrow,
|
|
1592
1640
|
dumpEffectCache,
|
|
1593
|
-
|
|
1594
|
-
hasEntityHistoryRows,
|
|
1641
|
+
reset,
|
|
1595
1642
|
setChainMeta,
|
|
1596
1643
|
pruneStaleCheckpoints,
|
|
1597
1644
|
pruneStaleEntityHistory,
|