@secondlayer/subgraphs 0.11.7 → 1.0.0-alpha.0
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/dist/src/index.js +63 -60
- package/dist/src/index.js.map +6 -6
- package/dist/src/runtime/block-processor.js +17 -11
- package/dist/src/runtime/block-processor.js.map +4 -4
- package/dist/src/runtime/catchup.js +31 -28
- package/dist/src/runtime/catchup.js.map +6 -6
- package/dist/src/runtime/processor.js +49 -43
- package/dist/src/runtime/processor.js.map +8 -8
- package/dist/src/runtime/reindex.js +63 -60
- package/dist/src/runtime/reindex.js.map +6 -6
- package/dist/src/runtime/reorg.js +21 -15
- package/dist/src/runtime/reorg.js.map +5 -5
- package/dist/src/runtime/source-matcher.js.map +2 -2
- package/dist/src/runtime/stats.d.ts +1 -2
- package/dist/src/runtime/stats.js +2 -6
- package/dist/src/runtime/stats.js.map +3 -3
- package/dist/src/service.js +49 -43
- package/dist/src/service.js.map +8 -8
- package/package.json +3 -3
|
@@ -849,7 +849,10 @@ function matchSources(sources, transactions, events) {
|
|
|
849
849
|
}
|
|
850
850
|
|
|
851
851
|
// src/runtime/block-processor.ts
|
|
852
|
-
import {
|
|
852
|
+
import {
|
|
853
|
+
getSourceDb,
|
|
854
|
+
getTargetDb
|
|
855
|
+
} from "@secondlayer/shared/db";
|
|
853
856
|
import {
|
|
854
857
|
recordSubgraphProcessed,
|
|
855
858
|
updateSubgraphStatus
|
|
@@ -863,7 +866,8 @@ import { pgSchemaName } from "@secondlayer/shared/db/queries/subgraphs";
|
|
|
863
866
|
// src/runtime/block-processor.ts
|
|
864
867
|
var schemaNameCache = new Map;
|
|
865
868
|
async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
866
|
-
const
|
|
869
|
+
const sourceDb = getSourceDb();
|
|
870
|
+
const targetDb = getTargetDb();
|
|
867
871
|
const blockStart = performance.now();
|
|
868
872
|
const result = {
|
|
869
873
|
blockHeight,
|
|
@@ -872,13 +876,15 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
872
876
|
errors: 0,
|
|
873
877
|
skipped: false
|
|
874
878
|
};
|
|
875
|
-
let block
|
|
879
|
+
let block;
|
|
880
|
+
let txs;
|
|
881
|
+
let evts;
|
|
876
882
|
if (opts?.preloaded) {
|
|
877
883
|
block = opts.preloaded.block;
|
|
878
884
|
txs = opts.preloaded.txs;
|
|
879
885
|
evts = opts.preloaded.events;
|
|
880
886
|
} else {
|
|
881
|
-
block = await
|
|
887
|
+
block = await sourceDb.selectFrom("blocks").selectAll().where("height", "=", blockHeight).executeTakeFirst();
|
|
882
888
|
if (!block) {
|
|
883
889
|
logger3.warn("Block not found for subgraph processing", {
|
|
884
890
|
subgraph: subgraphName,
|
|
@@ -895,20 +901,20 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
895
901
|
result.skipped = true;
|
|
896
902
|
return result;
|
|
897
903
|
}
|
|
898
|
-
txs = await
|
|
899
|
-
evts = await
|
|
904
|
+
txs = await sourceDb.selectFrom("transactions").selectAll().where("block_height", "=", blockHeight).execute();
|
|
905
|
+
evts = await sourceDb.selectFrom("events").selectAll().where("block_height", "=", blockHeight).execute();
|
|
900
906
|
}
|
|
901
907
|
const matched = matchSources(subgraph.sources, txs, evts);
|
|
902
908
|
result.matched = matched.length;
|
|
903
909
|
if (matched.length === 0) {
|
|
904
910
|
if (!opts?.skipProgressUpdate) {
|
|
905
|
-
await updateSubgraphStatus(
|
|
911
|
+
await updateSubgraphStatus(targetDb, subgraphName, "active", blockHeight);
|
|
906
912
|
}
|
|
907
913
|
return result;
|
|
908
914
|
}
|
|
909
915
|
let schemaName = schemaNameCache.get(subgraphName);
|
|
910
916
|
if (!schemaName) {
|
|
911
|
-
const subgraphRecord = await
|
|
917
|
+
const subgraphRecord = await targetDb.selectFrom("subgraphs").select("schema_name").where("name", "=", subgraphName).executeTakeFirst();
|
|
912
918
|
schemaName = subgraphRecord?.schema_name ?? pgSchemaName(subgraphName);
|
|
913
919
|
schemaNameCache.set(subgraphName, schemaName);
|
|
914
920
|
}
|
|
@@ -926,7 +932,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
926
932
|
};
|
|
927
933
|
let handlerMs = 0;
|
|
928
934
|
let flushMs = 0;
|
|
929
|
-
await
|
|
935
|
+
await targetDb.transaction().execute(async (tx) => {
|
|
930
936
|
const ctx = new SubgraphContext(tx, schemaName, subgraph.schema, blockMeta, initialTx);
|
|
931
937
|
const handlerStart = performance.now();
|
|
932
938
|
const runResult = await runHandlers(subgraph, matched, ctx);
|
|
@@ -957,7 +963,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
957
963
|
try {
|
|
958
964
|
const tables = Object.keys(subgraph.schema);
|
|
959
965
|
for (const table of tables) {
|
|
960
|
-
const { rows } = await sql2.raw(`SELECT n_live_tup AS count FROM pg_stat_user_tables WHERE schemaname = '${schemaName}' AND relname = '${table}'`).execute(
|
|
966
|
+
const { rows } = await sql2.raw(`SELECT n_live_tup AS count FROM pg_stat_user_tables WHERE schemaname = '${schemaName}' AND relname = '${table}'`).execute(targetDb);
|
|
961
967
|
const count = Number(rows[0]?.count ?? 0);
|
|
962
968
|
if (count >= 1e7) {
|
|
963
969
|
logger3.warn("Subgraph table exceeds 10M rows (estimate)", {
|
|
@@ -978,13 +984,11 @@ var FLUSH_INTERVAL_MS = 60000;
|
|
|
978
984
|
|
|
979
985
|
class StatsAccumulator {
|
|
980
986
|
subgraphName;
|
|
981
|
-
apiKeyId;
|
|
982
987
|
isCatchup;
|
|
983
988
|
current;
|
|
984
989
|
lastFlush = Date.now();
|
|
985
|
-
constructor(subgraphName,
|
|
990
|
+
constructor(subgraphName, isCatchup) {
|
|
986
991
|
this.subgraphName = subgraphName;
|
|
987
|
-
this.apiKeyId = apiKeyId;
|
|
988
992
|
this.isCatchup = isCatchup;
|
|
989
993
|
this.current = this.newEntry();
|
|
990
994
|
}
|
|
@@ -1009,7 +1013,6 @@ class StatsAccumulator {
|
|
|
1009
1013
|
const avgOpsPerBlock = entry.blocksProcessed > 0 ? entry.totalOps / entry.blocksProcessed : 0;
|
|
1010
1014
|
await db.insertInto("subgraph_processing_stats").values({
|
|
1011
1015
|
subgraph_name: entry.subgraphName,
|
|
1012
|
-
api_key_id: entry.apiKeyId,
|
|
1013
1016
|
bucket_start: entry.bucketStart,
|
|
1014
1017
|
bucket_end: new Date,
|
|
1015
1018
|
blocks_processed: entry.blocksProcessed,
|
|
@@ -1025,7 +1028,6 @@ class StatsAccumulator {
|
|
|
1025
1028
|
newEntry() {
|
|
1026
1029
|
return {
|
|
1027
1030
|
subgraphName: this.subgraphName,
|
|
1028
|
-
apiKeyId: this.apiKeyId,
|
|
1029
1031
|
bucketStart: new Date,
|
|
1030
1032
|
blocksProcessed: 0,
|
|
1031
1033
|
totalTimeMs: 0,
|
|
@@ -1041,7 +1043,7 @@ class StatsAccumulator {
|
|
|
1041
1043
|
|
|
1042
1044
|
// src/runtime/reindex.ts
|
|
1043
1045
|
import { getErrorMessage as getErrorMessage2 } from "@secondlayer/shared";
|
|
1044
|
-
import {
|
|
1046
|
+
import { getRawClient, getSourceDb as getSourceDb2, getTargetDb as getTargetDb2 } from "@secondlayer/shared/db";
|
|
1045
1047
|
import {
|
|
1046
1048
|
recordGapBatch,
|
|
1047
1049
|
resolveGaps
|
|
@@ -1206,11 +1208,12 @@ function coalesceFailedBlocks(blocks) {
|
|
|
1206
1208
|
return ranges;
|
|
1207
1209
|
}
|
|
1208
1210
|
async function processBlockRange(def, opts) {
|
|
1209
|
-
const
|
|
1211
|
+
const sourceDb = getSourceDb2();
|
|
1212
|
+
const targetDb = getTargetDb2();
|
|
1210
1213
|
const subgraphName = def.name;
|
|
1211
1214
|
const { fromBlock, toBlock, status } = opts;
|
|
1212
1215
|
const totalBlocks = toBlock - fromBlock + 1;
|
|
1213
|
-
const stats = new StatsAccumulator(subgraphName, opts.
|
|
1216
|
+
const stats = new StatsAccumulator(subgraphName, opts.isCatchup);
|
|
1214
1217
|
let blocksProcessed = 0;
|
|
1215
1218
|
let totalEventsProcessed = 0;
|
|
1216
1219
|
let totalErrors = 0;
|
|
@@ -1218,7 +1221,7 @@ async function processBlockRange(def, opts) {
|
|
|
1218
1221
|
let currentHeight = fromBlock;
|
|
1219
1222
|
let aborted = false;
|
|
1220
1223
|
let nextBatchEnd = Math.min(currentHeight + batchSize - 1, toBlock);
|
|
1221
|
-
let nextBatchPromise = loadBlockRange(
|
|
1224
|
+
let nextBatchPromise = loadBlockRange(sourceDb, currentHeight, nextBatchEnd);
|
|
1222
1225
|
while (currentHeight <= toBlock) {
|
|
1223
1226
|
if (opts.signal?.aborted) {
|
|
1224
1227
|
aborted = true;
|
|
@@ -1234,7 +1237,7 @@ async function processBlockRange(def, opts) {
|
|
|
1234
1237
|
const nextStart = batchEnd + 1;
|
|
1235
1238
|
if (nextStart <= toBlock) {
|
|
1236
1239
|
nextBatchEnd = Math.min(nextStart + batchSize - 1, toBlock);
|
|
1237
|
-
nextBatchPromise = loadBlockRange(
|
|
1240
|
+
nextBatchPromise = loadBlockRange(sourceDb, nextStart, nextBatchEnd);
|
|
1238
1241
|
}
|
|
1239
1242
|
const batchFailedBlocks = [];
|
|
1240
1243
|
for (let height = currentHeight;height <= batchEnd; height++) {
|
|
@@ -1258,8 +1261,8 @@ async function processBlockRange(def, opts) {
|
|
|
1258
1261
|
error: errorMsg
|
|
1259
1262
|
});
|
|
1260
1263
|
batchFailedBlocks.push({ height, reason: "processing_error" });
|
|
1261
|
-
await updateSubgraphStatus2(
|
|
1262
|
-
await recordSubgraphProcessed2(
|
|
1264
|
+
await updateSubgraphStatus2(targetDb, subgraphName, status, height).catch(() => {});
|
|
1265
|
+
await recordSubgraphProcessed2(targetDb, subgraphName, 0, 1, errorMsg).catch(() => {});
|
|
1263
1266
|
blocksProcessed++;
|
|
1264
1267
|
totalErrors++;
|
|
1265
1268
|
continue;
|
|
@@ -1270,11 +1273,11 @@ async function processBlockRange(def, opts) {
|
|
|
1270
1273
|
if (result.timing) {
|
|
1271
1274
|
stats.record(result.timing, result.processed);
|
|
1272
1275
|
if (stats.shouldFlush()) {
|
|
1273
|
-
await stats.flush(
|
|
1276
|
+
await stats.flush(targetDb);
|
|
1274
1277
|
}
|
|
1275
1278
|
}
|
|
1276
1279
|
if (blocksProcessed % 100 === 0) {
|
|
1277
|
-
await updateSubgraphStatus2(
|
|
1280
|
+
await updateSubgraphStatus2(targetDb, subgraphName, status, height);
|
|
1278
1281
|
}
|
|
1279
1282
|
if (blocksProcessed % LOG_INTERVAL === 0) {
|
|
1280
1283
|
logger4.info(`${status === "reindexing" ? "Reindex" : "Backfill"} progress`, {
|
|
@@ -1288,7 +1291,7 @@ async function processBlockRange(def, opts) {
|
|
|
1288
1291
|
}
|
|
1289
1292
|
if (batchFailedBlocks.length > 0 && opts.subgraphId) {
|
|
1290
1293
|
const gaps = coalesceFailedBlocks(batchFailedBlocks);
|
|
1291
|
-
await recordGapBatch(
|
|
1294
|
+
await recordGapBatch(targetDb, opts.subgraphId, subgraphName, gaps).catch((err) => {
|
|
1292
1295
|
logger4.warn("Failed to record subgraph gaps", {
|
|
1293
1296
|
subgraph: subgraphName,
|
|
1294
1297
|
error: err instanceof Error ? err.message : String(err)
|
|
@@ -1302,16 +1305,16 @@ async function processBlockRange(def, opts) {
|
|
|
1302
1305
|
batchSize = Math.min(Math.round(batchSize * 1.5), MAX_BATCH_SIZE);
|
|
1303
1306
|
currentHeight = batchEnd + 1;
|
|
1304
1307
|
}
|
|
1305
|
-
await stats.flush(
|
|
1308
|
+
await stats.flush(targetDb);
|
|
1306
1309
|
return { blocksProcessed, totalEventsProcessed, totalErrors, aborted };
|
|
1307
1310
|
}
|
|
1308
|
-
async function resolveBlockRange(
|
|
1311
|
+
async function resolveBlockRange(sourceDb, def, opts) {
|
|
1309
1312
|
const fromBlock = opts?.fromBlock ?? def.startBlock ?? 1;
|
|
1310
1313
|
let toBlock;
|
|
1311
1314
|
if (opts?.toBlock != null) {
|
|
1312
1315
|
toBlock = opts.toBlock;
|
|
1313
1316
|
} else {
|
|
1314
|
-
const progress = await
|
|
1317
|
+
const progress = await sourceDb.selectFrom("index_progress").selectAll().where("network", "=", process.env.NETWORK ?? "mainnet").executeTakeFirst();
|
|
1315
1318
|
toBlock = progress?.highest_seen_block ?? 0;
|
|
1316
1319
|
}
|
|
1317
1320
|
return { fromBlock, toBlock };
|
|
@@ -1320,24 +1323,25 @@ async function clearReindexMetadata(db, subgraphName) {
|
|
|
1320
1323
|
await db.updateTable("subgraphs").set({ reindex_from_block: null, reindex_to_block: null }).where("name", "=", subgraphName).execute();
|
|
1321
1324
|
}
|
|
1322
1325
|
async function reindexSubgraph(def, opts) {
|
|
1323
|
-
const
|
|
1324
|
-
const
|
|
1326
|
+
const sourceDb = getSourceDb2();
|
|
1327
|
+
const targetDb = getTargetDb2();
|
|
1328
|
+
const client = getRawClient("target");
|
|
1325
1329
|
const subgraphName = def.name;
|
|
1326
1330
|
const schemaName = opts?.schemaName ?? pgSchemaName(subgraphName);
|
|
1327
|
-
await updateSubgraphStatus2(
|
|
1331
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "reindexing");
|
|
1328
1332
|
logger4.info("Reindex starting", { subgraph: subgraphName });
|
|
1329
1333
|
try {
|
|
1330
|
-
const { fromBlock, toBlock } = await resolveBlockRange(
|
|
1334
|
+
const { fromBlock, toBlock } = await resolveBlockRange(sourceDb, def, opts);
|
|
1331
1335
|
if (fromBlock > toBlock) {
|
|
1332
1336
|
logger4.info("No blocks to reindex", {
|
|
1333
1337
|
subgraph: subgraphName,
|
|
1334
1338
|
fromBlock,
|
|
1335
1339
|
toBlock
|
|
1336
1340
|
});
|
|
1337
|
-
await updateSubgraphStatus2(
|
|
1341
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", 0);
|
|
1338
1342
|
return { processed: 0 };
|
|
1339
1343
|
}
|
|
1340
|
-
await
|
|
1344
|
+
await targetDb.updateTable("subgraphs").set({ reindex_from_block: fromBlock, reindex_to_block: toBlock }).where("name", "=", subgraphName).execute();
|
|
1341
1345
|
await client.unsafe(`DROP SCHEMA IF EXISTS "${schemaName}" CASCADE`);
|
|
1342
1346
|
const { statements } = generateSubgraphSQL(def, schemaName);
|
|
1343
1347
|
for (const stmt of statements) {
|
|
@@ -1350,21 +1354,21 @@ async function reindexSubgraph(def, opts) {
|
|
|
1350
1354
|
toBlock,
|
|
1351
1355
|
totalBlocks: toBlock - fromBlock + 1
|
|
1352
1356
|
});
|
|
1353
|
-
const subgraphRow = await
|
|
1357
|
+
const subgraphRow = await targetDb.selectFrom("subgraphs").select(["id"]).where("name", "=", subgraphName).executeTakeFirst();
|
|
1354
1358
|
const result = await processBlockRange(def, {
|
|
1355
1359
|
fromBlock,
|
|
1356
1360
|
toBlock,
|
|
1357
1361
|
status: "reindexing",
|
|
1358
1362
|
isCatchup: false,
|
|
1359
|
-
apiKeyId:
|
|
1363
|
+
apiKeyId: null,
|
|
1360
1364
|
subgraphId: subgraphRow?.id,
|
|
1361
1365
|
signal: opts?.signal
|
|
1362
1366
|
});
|
|
1363
1367
|
if (result.aborted) {
|
|
1364
1368
|
const reason = String(opts?.signal?.reason ?? "unknown");
|
|
1365
1369
|
if (reason === "user-cancelled") {
|
|
1366
|
-
await updateSubgraphStatus2(
|
|
1367
|
-
await clearReindexMetadata(
|
|
1370
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active");
|
|
1371
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1368
1372
|
logger4.info("Reindex cancelled by user", { subgraph: subgraphName });
|
|
1369
1373
|
} else {
|
|
1370
1374
|
logger4.info("Reindex interrupted by shutdown, will resume", {
|
|
@@ -1375,10 +1379,10 @@ async function reindexSubgraph(def, opts) {
|
|
|
1375
1379
|
}
|
|
1376
1380
|
const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
|
|
1377
1381
|
if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
|
|
1378
|
-
await recordSubgraphProcessed3(
|
|
1382
|
+
await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during reindex` : undefined);
|
|
1379
1383
|
}
|
|
1380
|
-
await updateSubgraphStatus2(
|
|
1381
|
-
await clearReindexMetadata(
|
|
1384
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
1385
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1382
1386
|
logger4.info("Reindex complete", {
|
|
1383
1387
|
subgraph: subgraphName,
|
|
1384
1388
|
blocks: result.blocksProcessed,
|
|
@@ -1391,16 +1395,15 @@ async function reindexSubgraph(def, opts) {
|
|
|
1391
1395
|
subgraph: subgraphName,
|
|
1392
1396
|
error: getErrorMessage2(err)
|
|
1393
1397
|
});
|
|
1394
|
-
await updateSubgraphStatus2(
|
|
1398
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "error");
|
|
1395
1399
|
throw err;
|
|
1396
1400
|
}
|
|
1397
1401
|
}
|
|
1398
1402
|
async function resumeReindex(def, opts) {
|
|
1399
|
-
const
|
|
1403
|
+
const targetDb = getTargetDb2();
|
|
1400
1404
|
const subgraphName = def.name;
|
|
1401
|
-
const row = await
|
|
1405
|
+
const row = await targetDb.selectFrom("subgraphs").select([
|
|
1402
1406
|
"id",
|
|
1403
|
-
"api_key_id",
|
|
1404
1407
|
"last_processed_block",
|
|
1405
1408
|
"reindex_from_block",
|
|
1406
1409
|
"reindex_to_block"
|
|
@@ -1420,8 +1423,8 @@ async function resumeReindex(def, opts) {
|
|
|
1420
1423
|
const toBlock = row.reindex_to_block;
|
|
1421
1424
|
if (fromBlock > toBlock) {
|
|
1422
1425
|
logger4.info("Resume: no remaining blocks", { subgraph: subgraphName });
|
|
1423
|
-
await updateSubgraphStatus2(
|
|
1424
|
-
await clearReindexMetadata(
|
|
1426
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
1427
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1425
1428
|
return { processed: 0 };
|
|
1426
1429
|
}
|
|
1427
1430
|
logger4.info("Resuming reindex", {
|
|
@@ -1436,15 +1439,15 @@ async function resumeReindex(def, opts) {
|
|
|
1436
1439
|
toBlock,
|
|
1437
1440
|
status: "reindexing",
|
|
1438
1441
|
isCatchup: false,
|
|
1439
|
-
apiKeyId:
|
|
1442
|
+
apiKeyId: null,
|
|
1440
1443
|
subgraphId: row.id,
|
|
1441
1444
|
signal: opts.signal
|
|
1442
1445
|
});
|
|
1443
1446
|
if (result.aborted) {
|
|
1444
1447
|
const reason = String(opts.signal?.reason ?? "unknown");
|
|
1445
1448
|
if (reason === "user-cancelled") {
|
|
1446
|
-
await updateSubgraphStatus2(
|
|
1447
|
-
await clearReindexMetadata(
|
|
1449
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active");
|
|
1450
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1448
1451
|
logger4.info("Resume cancelled by user", { subgraph: subgraphName });
|
|
1449
1452
|
} else {
|
|
1450
1453
|
logger4.info("Resume interrupted by shutdown, will resume again", {
|
|
@@ -1455,10 +1458,10 @@ async function resumeReindex(def, opts) {
|
|
|
1455
1458
|
}
|
|
1456
1459
|
const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
|
|
1457
1460
|
if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
|
|
1458
|
-
await recordSubgraphProcessed3(
|
|
1461
|
+
await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during resumed reindex` : undefined);
|
|
1459
1462
|
}
|
|
1460
|
-
await updateSubgraphStatus2(
|
|
1461
|
-
await clearReindexMetadata(
|
|
1463
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
1464
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1462
1465
|
logger4.info("Resumed reindex complete", {
|
|
1463
1466
|
subgraph: subgraphName,
|
|
1464
1467
|
blocks: result.blocksProcessed
|
|
@@ -1469,12 +1472,12 @@ async function resumeReindex(def, opts) {
|
|
|
1469
1472
|
subgraph: subgraphName,
|
|
1470
1473
|
error: getErrorMessage2(err)
|
|
1471
1474
|
});
|
|
1472
|
-
await updateSubgraphStatus2(
|
|
1475
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "error");
|
|
1473
1476
|
throw err;
|
|
1474
1477
|
}
|
|
1475
1478
|
}
|
|
1476
1479
|
async function backfillSubgraph(def, opts) {
|
|
1477
|
-
const
|
|
1480
|
+
const targetDb = getTargetDb2();
|
|
1478
1481
|
const subgraphName = def.name;
|
|
1479
1482
|
logger4.info("Backfill starting", {
|
|
1480
1483
|
subgraph: subgraphName,
|
|
@@ -1482,13 +1485,13 @@ async function backfillSubgraph(def, opts) {
|
|
|
1482
1485
|
to: opts.toBlock
|
|
1483
1486
|
});
|
|
1484
1487
|
try {
|
|
1485
|
-
const subgraphRow = await
|
|
1488
|
+
const subgraphRow = await targetDb.selectFrom("subgraphs").select(["id"]).where("name", "=", subgraphName).executeTakeFirst();
|
|
1486
1489
|
const result = await processBlockRange(def, {
|
|
1487
1490
|
fromBlock: opts.fromBlock,
|
|
1488
1491
|
toBlock: opts.toBlock,
|
|
1489
1492
|
status: "active",
|
|
1490
1493
|
isCatchup: false,
|
|
1491
|
-
apiKeyId:
|
|
1494
|
+
apiKeyId: null,
|
|
1492
1495
|
subgraphId: subgraphRow?.id,
|
|
1493
1496
|
signal: opts.signal
|
|
1494
1497
|
});
|
|
@@ -1496,7 +1499,7 @@ async function backfillSubgraph(def, opts) {
|
|
|
1496
1499
|
logger4.info("Backfill aborted", { subgraph: subgraphName });
|
|
1497
1500
|
return { processed: result.blocksProcessed };
|
|
1498
1501
|
}
|
|
1499
|
-
const resolved = await resolveGaps(
|
|
1502
|
+
const resolved = await resolveGaps(targetDb, subgraphName, opts.fromBlock, opts.toBlock).catch(() => 0);
|
|
1500
1503
|
if (resolved > 0) {
|
|
1501
1504
|
logger4.info("Resolved subgraph gaps via backfill", {
|
|
1502
1505
|
subgraph: subgraphName,
|
|
@@ -1505,7 +1508,7 @@ async function backfillSubgraph(def, opts) {
|
|
|
1505
1508
|
}
|
|
1506
1509
|
const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
|
|
1507
1510
|
if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
|
|
1508
|
-
await recordSubgraphProcessed3(
|
|
1511
|
+
await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during backfill` : undefined);
|
|
1509
1512
|
}
|
|
1510
1513
|
logger4.info("Backfill complete", {
|
|
1511
1514
|
subgraph: subgraphName,
|
|
@@ -1528,5 +1531,5 @@ export {
|
|
|
1528
1531
|
backfillSubgraph
|
|
1529
1532
|
};
|
|
1530
1533
|
|
|
1531
|
-
//# debugId=
|
|
1534
|
+
//# debugId=CA98B860698EE36C64756E2164756E21
|
|
1532
1535
|
//# sourceMappingURL=reindex.js.map
|