@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
package/dist/src/index.js
CHANGED
|
@@ -918,7 +918,10 @@ function matchSources(sources, transactions, events) {
|
|
|
918
918
|
}
|
|
919
919
|
|
|
920
920
|
// src/runtime/block-processor.ts
|
|
921
|
-
import {
|
|
921
|
+
import {
|
|
922
|
+
getSourceDb,
|
|
923
|
+
getTargetDb
|
|
924
|
+
} from "@secondlayer/shared/db";
|
|
922
925
|
import {
|
|
923
926
|
recordSubgraphProcessed,
|
|
924
927
|
updateSubgraphStatus
|
|
@@ -932,7 +935,8 @@ import { pgSchemaName } from "@secondlayer/shared/db/queries/subgraphs";
|
|
|
932
935
|
// src/runtime/block-processor.ts
|
|
933
936
|
var schemaNameCache = new Map;
|
|
934
937
|
async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
935
|
-
const
|
|
938
|
+
const sourceDb = getSourceDb();
|
|
939
|
+
const targetDb = getTargetDb();
|
|
936
940
|
const blockStart = performance.now();
|
|
937
941
|
const result = {
|
|
938
942
|
blockHeight,
|
|
@@ -941,13 +945,15 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
941
945
|
errors: 0,
|
|
942
946
|
skipped: false
|
|
943
947
|
};
|
|
944
|
-
let block
|
|
948
|
+
let block;
|
|
949
|
+
let txs;
|
|
950
|
+
let evts;
|
|
945
951
|
if (opts?.preloaded) {
|
|
946
952
|
block = opts.preloaded.block;
|
|
947
953
|
txs = opts.preloaded.txs;
|
|
948
954
|
evts = opts.preloaded.events;
|
|
949
955
|
} else {
|
|
950
|
-
block = await
|
|
956
|
+
block = await sourceDb.selectFrom("blocks").selectAll().where("height", "=", blockHeight).executeTakeFirst();
|
|
951
957
|
if (!block) {
|
|
952
958
|
logger3.warn("Block not found for subgraph processing", {
|
|
953
959
|
subgraph: subgraphName,
|
|
@@ -964,20 +970,20 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
964
970
|
result.skipped = true;
|
|
965
971
|
return result;
|
|
966
972
|
}
|
|
967
|
-
txs = await
|
|
968
|
-
evts = await
|
|
973
|
+
txs = await sourceDb.selectFrom("transactions").selectAll().where("block_height", "=", blockHeight).execute();
|
|
974
|
+
evts = await sourceDb.selectFrom("events").selectAll().where("block_height", "=", blockHeight).execute();
|
|
969
975
|
}
|
|
970
976
|
const matched = matchSources(subgraph.sources, txs, evts);
|
|
971
977
|
result.matched = matched.length;
|
|
972
978
|
if (matched.length === 0) {
|
|
973
979
|
if (!opts?.skipProgressUpdate) {
|
|
974
|
-
await updateSubgraphStatus(
|
|
980
|
+
await updateSubgraphStatus(targetDb, subgraphName, "active", blockHeight);
|
|
975
981
|
}
|
|
976
982
|
return result;
|
|
977
983
|
}
|
|
978
984
|
let schemaName = schemaNameCache.get(subgraphName);
|
|
979
985
|
if (!schemaName) {
|
|
980
|
-
const subgraphRecord = await
|
|
986
|
+
const subgraphRecord = await targetDb.selectFrom("subgraphs").select("schema_name").where("name", "=", subgraphName).executeTakeFirst();
|
|
981
987
|
schemaName = subgraphRecord?.schema_name ?? pgSchemaName(subgraphName);
|
|
982
988
|
schemaNameCache.set(subgraphName, schemaName);
|
|
983
989
|
}
|
|
@@ -995,7 +1001,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
995
1001
|
};
|
|
996
1002
|
let handlerMs = 0;
|
|
997
1003
|
let flushMs = 0;
|
|
998
|
-
await
|
|
1004
|
+
await targetDb.transaction().execute(async (tx) => {
|
|
999
1005
|
const ctx = new SubgraphContext(tx, schemaName, subgraph.schema, blockMeta, initialTx);
|
|
1000
1006
|
const handlerStart = performance.now();
|
|
1001
1007
|
const runResult = await runHandlers(subgraph, matched, ctx);
|
|
@@ -1026,7 +1032,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
1026
1032
|
try {
|
|
1027
1033
|
const tables = Object.keys(subgraph.schema);
|
|
1028
1034
|
for (const table of tables) {
|
|
1029
|
-
const { rows } = await sql2.raw(`SELECT n_live_tup AS count FROM pg_stat_user_tables WHERE schemaname = '${schemaName}' AND relname = '${table}'`).execute(
|
|
1035
|
+
const { rows } = await sql2.raw(`SELECT n_live_tup AS count FROM pg_stat_user_tables WHERE schemaname = '${schemaName}' AND relname = '${table}'`).execute(targetDb);
|
|
1030
1036
|
const count = Number(rows[0]?.count ?? 0);
|
|
1031
1037
|
if (count >= 1e7) {
|
|
1032
1038
|
logger3.warn("Subgraph table exceeds 10M rows (estimate)", {
|
|
@@ -1047,13 +1053,11 @@ var FLUSH_INTERVAL_MS = 60000;
|
|
|
1047
1053
|
|
|
1048
1054
|
class StatsAccumulator {
|
|
1049
1055
|
subgraphName;
|
|
1050
|
-
apiKeyId;
|
|
1051
1056
|
isCatchup;
|
|
1052
1057
|
current;
|
|
1053
1058
|
lastFlush = Date.now();
|
|
1054
|
-
constructor(subgraphName,
|
|
1059
|
+
constructor(subgraphName, isCatchup) {
|
|
1055
1060
|
this.subgraphName = subgraphName;
|
|
1056
|
-
this.apiKeyId = apiKeyId;
|
|
1057
1061
|
this.isCatchup = isCatchup;
|
|
1058
1062
|
this.current = this.newEntry();
|
|
1059
1063
|
}
|
|
@@ -1078,7 +1082,6 @@ class StatsAccumulator {
|
|
|
1078
1082
|
const avgOpsPerBlock = entry.blocksProcessed > 0 ? entry.totalOps / entry.blocksProcessed : 0;
|
|
1079
1083
|
await db.insertInto("subgraph_processing_stats").values({
|
|
1080
1084
|
subgraph_name: entry.subgraphName,
|
|
1081
|
-
api_key_id: entry.apiKeyId,
|
|
1082
1085
|
bucket_start: entry.bucketStart,
|
|
1083
1086
|
bucket_end: new Date,
|
|
1084
1087
|
blocks_processed: entry.blocksProcessed,
|
|
@@ -1094,7 +1097,6 @@ class StatsAccumulator {
|
|
|
1094
1097
|
newEntry() {
|
|
1095
1098
|
return {
|
|
1096
1099
|
subgraphName: this.subgraphName,
|
|
1097
|
-
apiKeyId: this.apiKeyId,
|
|
1098
1100
|
bucketStart: new Date,
|
|
1099
1101
|
blocksProcessed: 0,
|
|
1100
1102
|
totalTimeMs: 0,
|
|
@@ -1110,7 +1112,7 @@ class StatsAccumulator {
|
|
|
1110
1112
|
|
|
1111
1113
|
// src/runtime/reindex.ts
|
|
1112
1114
|
import { getErrorMessage as getErrorMessage2 } from "@secondlayer/shared";
|
|
1113
|
-
import {
|
|
1115
|
+
import { getRawClient, getSourceDb as getSourceDb2, getTargetDb as getTargetDb2 } from "@secondlayer/shared/db";
|
|
1114
1116
|
import {
|
|
1115
1117
|
recordGapBatch,
|
|
1116
1118
|
resolveGaps
|
|
@@ -1275,11 +1277,12 @@ function coalesceFailedBlocks(blocks) {
|
|
|
1275
1277
|
return ranges;
|
|
1276
1278
|
}
|
|
1277
1279
|
async function processBlockRange(def, opts) {
|
|
1278
|
-
const
|
|
1280
|
+
const sourceDb = getSourceDb2();
|
|
1281
|
+
const targetDb = getTargetDb2();
|
|
1279
1282
|
const subgraphName = def.name;
|
|
1280
1283
|
const { fromBlock, toBlock, status } = opts;
|
|
1281
1284
|
const totalBlocks = toBlock - fromBlock + 1;
|
|
1282
|
-
const stats = new StatsAccumulator(subgraphName, opts.
|
|
1285
|
+
const stats = new StatsAccumulator(subgraphName, opts.isCatchup);
|
|
1283
1286
|
let blocksProcessed = 0;
|
|
1284
1287
|
let totalEventsProcessed = 0;
|
|
1285
1288
|
let totalErrors = 0;
|
|
@@ -1287,7 +1290,7 @@ async function processBlockRange(def, opts) {
|
|
|
1287
1290
|
let currentHeight = fromBlock;
|
|
1288
1291
|
let aborted = false;
|
|
1289
1292
|
let nextBatchEnd = Math.min(currentHeight + batchSize - 1, toBlock);
|
|
1290
|
-
let nextBatchPromise = loadBlockRange(
|
|
1293
|
+
let nextBatchPromise = loadBlockRange(sourceDb, currentHeight, nextBatchEnd);
|
|
1291
1294
|
while (currentHeight <= toBlock) {
|
|
1292
1295
|
if (opts.signal?.aborted) {
|
|
1293
1296
|
aborted = true;
|
|
@@ -1303,7 +1306,7 @@ async function processBlockRange(def, opts) {
|
|
|
1303
1306
|
const nextStart = batchEnd + 1;
|
|
1304
1307
|
if (nextStart <= toBlock) {
|
|
1305
1308
|
nextBatchEnd = Math.min(nextStart + batchSize - 1, toBlock);
|
|
1306
|
-
nextBatchPromise = loadBlockRange(
|
|
1309
|
+
nextBatchPromise = loadBlockRange(sourceDb, nextStart, nextBatchEnd);
|
|
1307
1310
|
}
|
|
1308
1311
|
const batchFailedBlocks = [];
|
|
1309
1312
|
for (let height = currentHeight;height <= batchEnd; height++) {
|
|
@@ -1327,8 +1330,8 @@ async function processBlockRange(def, opts) {
|
|
|
1327
1330
|
error: errorMsg
|
|
1328
1331
|
});
|
|
1329
1332
|
batchFailedBlocks.push({ height, reason: "processing_error" });
|
|
1330
|
-
await updateSubgraphStatus2(
|
|
1331
|
-
await recordSubgraphProcessed2(
|
|
1333
|
+
await updateSubgraphStatus2(targetDb, subgraphName, status, height).catch(() => {});
|
|
1334
|
+
await recordSubgraphProcessed2(targetDb, subgraphName, 0, 1, errorMsg).catch(() => {});
|
|
1332
1335
|
blocksProcessed++;
|
|
1333
1336
|
totalErrors++;
|
|
1334
1337
|
continue;
|
|
@@ -1339,11 +1342,11 @@ async function processBlockRange(def, opts) {
|
|
|
1339
1342
|
if (result.timing) {
|
|
1340
1343
|
stats.record(result.timing, result.processed);
|
|
1341
1344
|
if (stats.shouldFlush()) {
|
|
1342
|
-
await stats.flush(
|
|
1345
|
+
await stats.flush(targetDb);
|
|
1343
1346
|
}
|
|
1344
1347
|
}
|
|
1345
1348
|
if (blocksProcessed % 100 === 0) {
|
|
1346
|
-
await updateSubgraphStatus2(
|
|
1349
|
+
await updateSubgraphStatus2(targetDb, subgraphName, status, height);
|
|
1347
1350
|
}
|
|
1348
1351
|
if (blocksProcessed % LOG_INTERVAL === 0) {
|
|
1349
1352
|
logger4.info(`${status === "reindexing" ? "Reindex" : "Backfill"} progress`, {
|
|
@@ -1357,7 +1360,7 @@ async function processBlockRange(def, opts) {
|
|
|
1357
1360
|
}
|
|
1358
1361
|
if (batchFailedBlocks.length > 0 && opts.subgraphId) {
|
|
1359
1362
|
const gaps = coalesceFailedBlocks(batchFailedBlocks);
|
|
1360
|
-
await recordGapBatch(
|
|
1363
|
+
await recordGapBatch(targetDb, opts.subgraphId, subgraphName, gaps).catch((err) => {
|
|
1361
1364
|
logger4.warn("Failed to record subgraph gaps", {
|
|
1362
1365
|
subgraph: subgraphName,
|
|
1363
1366
|
error: err instanceof Error ? err.message : String(err)
|
|
@@ -1371,16 +1374,16 @@ async function processBlockRange(def, opts) {
|
|
|
1371
1374
|
batchSize = Math.min(Math.round(batchSize * 1.5), MAX_BATCH_SIZE);
|
|
1372
1375
|
currentHeight = batchEnd + 1;
|
|
1373
1376
|
}
|
|
1374
|
-
await stats.flush(
|
|
1377
|
+
await stats.flush(targetDb);
|
|
1375
1378
|
return { blocksProcessed, totalEventsProcessed, totalErrors, aborted };
|
|
1376
1379
|
}
|
|
1377
|
-
async function resolveBlockRange(
|
|
1380
|
+
async function resolveBlockRange(sourceDb, def, opts) {
|
|
1378
1381
|
const fromBlock = opts?.fromBlock ?? def.startBlock ?? 1;
|
|
1379
1382
|
let toBlock;
|
|
1380
1383
|
if (opts?.toBlock != null) {
|
|
1381
1384
|
toBlock = opts.toBlock;
|
|
1382
1385
|
} else {
|
|
1383
|
-
const progress = await
|
|
1386
|
+
const progress = await sourceDb.selectFrom("index_progress").selectAll().where("network", "=", process.env.NETWORK ?? "mainnet").executeTakeFirst();
|
|
1384
1387
|
toBlock = progress?.highest_seen_block ?? 0;
|
|
1385
1388
|
}
|
|
1386
1389
|
return { fromBlock, toBlock };
|
|
@@ -1389,24 +1392,25 @@ async function clearReindexMetadata(db, subgraphName) {
|
|
|
1389
1392
|
await db.updateTable("subgraphs").set({ reindex_from_block: null, reindex_to_block: null }).where("name", "=", subgraphName).execute();
|
|
1390
1393
|
}
|
|
1391
1394
|
async function reindexSubgraph(def, opts) {
|
|
1392
|
-
const
|
|
1393
|
-
const
|
|
1395
|
+
const sourceDb = getSourceDb2();
|
|
1396
|
+
const targetDb = getTargetDb2();
|
|
1397
|
+
const client = getRawClient("target");
|
|
1394
1398
|
const subgraphName = def.name;
|
|
1395
1399
|
const schemaName = opts?.schemaName ?? pgSchemaName(subgraphName);
|
|
1396
|
-
await updateSubgraphStatus2(
|
|
1400
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "reindexing");
|
|
1397
1401
|
logger4.info("Reindex starting", { subgraph: subgraphName });
|
|
1398
1402
|
try {
|
|
1399
|
-
const { fromBlock, toBlock } = await resolveBlockRange(
|
|
1403
|
+
const { fromBlock, toBlock } = await resolveBlockRange(sourceDb, def, opts);
|
|
1400
1404
|
if (fromBlock > toBlock) {
|
|
1401
1405
|
logger4.info("No blocks to reindex", {
|
|
1402
1406
|
subgraph: subgraphName,
|
|
1403
1407
|
fromBlock,
|
|
1404
1408
|
toBlock
|
|
1405
1409
|
});
|
|
1406
|
-
await updateSubgraphStatus2(
|
|
1410
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", 0);
|
|
1407
1411
|
return { processed: 0 };
|
|
1408
1412
|
}
|
|
1409
|
-
await
|
|
1413
|
+
await targetDb.updateTable("subgraphs").set({ reindex_from_block: fromBlock, reindex_to_block: toBlock }).where("name", "=", subgraphName).execute();
|
|
1410
1414
|
await client.unsafe(`DROP SCHEMA IF EXISTS "${schemaName}" CASCADE`);
|
|
1411
1415
|
const { statements } = generateSubgraphSQL(def, schemaName);
|
|
1412
1416
|
for (const stmt of statements) {
|
|
@@ -1419,21 +1423,21 @@ async function reindexSubgraph(def, opts) {
|
|
|
1419
1423
|
toBlock,
|
|
1420
1424
|
totalBlocks: toBlock - fromBlock + 1
|
|
1421
1425
|
});
|
|
1422
|
-
const subgraphRow = await
|
|
1426
|
+
const subgraphRow = await targetDb.selectFrom("subgraphs").select(["id"]).where("name", "=", subgraphName).executeTakeFirst();
|
|
1423
1427
|
const result = await processBlockRange(def, {
|
|
1424
1428
|
fromBlock,
|
|
1425
1429
|
toBlock,
|
|
1426
1430
|
status: "reindexing",
|
|
1427
1431
|
isCatchup: false,
|
|
1428
|
-
apiKeyId:
|
|
1432
|
+
apiKeyId: null,
|
|
1429
1433
|
subgraphId: subgraphRow?.id,
|
|
1430
1434
|
signal: opts?.signal
|
|
1431
1435
|
});
|
|
1432
1436
|
if (result.aborted) {
|
|
1433
1437
|
const reason = String(opts?.signal?.reason ?? "unknown");
|
|
1434
1438
|
if (reason === "user-cancelled") {
|
|
1435
|
-
await updateSubgraphStatus2(
|
|
1436
|
-
await clearReindexMetadata(
|
|
1439
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active");
|
|
1440
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1437
1441
|
logger4.info("Reindex cancelled by user", { subgraph: subgraphName });
|
|
1438
1442
|
} else {
|
|
1439
1443
|
logger4.info("Reindex interrupted by shutdown, will resume", {
|
|
@@ -1444,10 +1448,10 @@ async function reindexSubgraph(def, opts) {
|
|
|
1444
1448
|
}
|
|
1445
1449
|
const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
|
|
1446
1450
|
if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
|
|
1447
|
-
await recordSubgraphProcessed3(
|
|
1451
|
+
await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during reindex` : undefined);
|
|
1448
1452
|
}
|
|
1449
|
-
await updateSubgraphStatus2(
|
|
1450
|
-
await clearReindexMetadata(
|
|
1453
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
1454
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1451
1455
|
logger4.info("Reindex complete", {
|
|
1452
1456
|
subgraph: subgraphName,
|
|
1453
1457
|
blocks: result.blocksProcessed,
|
|
@@ -1460,16 +1464,15 @@ async function reindexSubgraph(def, opts) {
|
|
|
1460
1464
|
subgraph: subgraphName,
|
|
1461
1465
|
error: getErrorMessage2(err)
|
|
1462
1466
|
});
|
|
1463
|
-
await updateSubgraphStatus2(
|
|
1467
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "error");
|
|
1464
1468
|
throw err;
|
|
1465
1469
|
}
|
|
1466
1470
|
}
|
|
1467
1471
|
async function resumeReindex(def, opts) {
|
|
1468
|
-
const
|
|
1472
|
+
const targetDb = getTargetDb2();
|
|
1469
1473
|
const subgraphName = def.name;
|
|
1470
|
-
const row = await
|
|
1474
|
+
const row = await targetDb.selectFrom("subgraphs").select([
|
|
1471
1475
|
"id",
|
|
1472
|
-
"api_key_id",
|
|
1473
1476
|
"last_processed_block",
|
|
1474
1477
|
"reindex_from_block",
|
|
1475
1478
|
"reindex_to_block"
|
|
@@ -1489,8 +1492,8 @@ async function resumeReindex(def, opts) {
|
|
|
1489
1492
|
const toBlock = row.reindex_to_block;
|
|
1490
1493
|
if (fromBlock > toBlock) {
|
|
1491
1494
|
logger4.info("Resume: no remaining blocks", { subgraph: subgraphName });
|
|
1492
|
-
await updateSubgraphStatus2(
|
|
1493
|
-
await clearReindexMetadata(
|
|
1495
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
1496
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1494
1497
|
return { processed: 0 };
|
|
1495
1498
|
}
|
|
1496
1499
|
logger4.info("Resuming reindex", {
|
|
@@ -1505,15 +1508,15 @@ async function resumeReindex(def, opts) {
|
|
|
1505
1508
|
toBlock,
|
|
1506
1509
|
status: "reindexing",
|
|
1507
1510
|
isCatchup: false,
|
|
1508
|
-
apiKeyId:
|
|
1511
|
+
apiKeyId: null,
|
|
1509
1512
|
subgraphId: row.id,
|
|
1510
1513
|
signal: opts.signal
|
|
1511
1514
|
});
|
|
1512
1515
|
if (result.aborted) {
|
|
1513
1516
|
const reason = String(opts.signal?.reason ?? "unknown");
|
|
1514
1517
|
if (reason === "user-cancelled") {
|
|
1515
|
-
await updateSubgraphStatus2(
|
|
1516
|
-
await clearReindexMetadata(
|
|
1518
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active");
|
|
1519
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1517
1520
|
logger4.info("Resume cancelled by user", { subgraph: subgraphName });
|
|
1518
1521
|
} else {
|
|
1519
1522
|
logger4.info("Resume interrupted by shutdown, will resume again", {
|
|
@@ -1524,10 +1527,10 @@ async function resumeReindex(def, opts) {
|
|
|
1524
1527
|
}
|
|
1525
1528
|
const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
|
|
1526
1529
|
if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
|
|
1527
|
-
await recordSubgraphProcessed3(
|
|
1530
|
+
await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during resumed reindex` : undefined);
|
|
1528
1531
|
}
|
|
1529
|
-
await updateSubgraphStatus2(
|
|
1530
|
-
await clearReindexMetadata(
|
|
1532
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
1533
|
+
await clearReindexMetadata(targetDb, subgraphName);
|
|
1531
1534
|
logger4.info("Resumed reindex complete", {
|
|
1532
1535
|
subgraph: subgraphName,
|
|
1533
1536
|
blocks: result.blocksProcessed
|
|
@@ -1538,12 +1541,12 @@ async function resumeReindex(def, opts) {
|
|
|
1538
1541
|
subgraph: subgraphName,
|
|
1539
1542
|
error: getErrorMessage2(err)
|
|
1540
1543
|
});
|
|
1541
|
-
await updateSubgraphStatus2(
|
|
1544
|
+
await updateSubgraphStatus2(targetDb, subgraphName, "error");
|
|
1542
1545
|
throw err;
|
|
1543
1546
|
}
|
|
1544
1547
|
}
|
|
1545
1548
|
async function backfillSubgraph(def, opts) {
|
|
1546
|
-
const
|
|
1549
|
+
const targetDb = getTargetDb2();
|
|
1547
1550
|
const subgraphName = def.name;
|
|
1548
1551
|
logger4.info("Backfill starting", {
|
|
1549
1552
|
subgraph: subgraphName,
|
|
@@ -1551,13 +1554,13 @@ async function backfillSubgraph(def, opts) {
|
|
|
1551
1554
|
to: opts.toBlock
|
|
1552
1555
|
});
|
|
1553
1556
|
try {
|
|
1554
|
-
const subgraphRow = await
|
|
1557
|
+
const subgraphRow = await targetDb.selectFrom("subgraphs").select(["id"]).where("name", "=", subgraphName).executeTakeFirst();
|
|
1555
1558
|
const result = await processBlockRange(def, {
|
|
1556
1559
|
fromBlock: opts.fromBlock,
|
|
1557
1560
|
toBlock: opts.toBlock,
|
|
1558
1561
|
status: "active",
|
|
1559
1562
|
isCatchup: false,
|
|
1560
|
-
apiKeyId:
|
|
1563
|
+
apiKeyId: null,
|
|
1561
1564
|
subgraphId: subgraphRow?.id,
|
|
1562
1565
|
signal: opts.signal
|
|
1563
1566
|
});
|
|
@@ -1565,7 +1568,7 @@ async function backfillSubgraph(def, opts) {
|
|
|
1565
1568
|
logger4.info("Backfill aborted", { subgraph: subgraphName });
|
|
1566
1569
|
return { processed: result.blocksProcessed };
|
|
1567
1570
|
}
|
|
1568
|
-
const resolved = await resolveGaps(
|
|
1571
|
+
const resolved = await resolveGaps(targetDb, subgraphName, opts.fromBlock, opts.toBlock).catch(() => 0);
|
|
1569
1572
|
if (resolved > 0) {
|
|
1570
1573
|
logger4.info("Resolved subgraph gaps via backfill", {
|
|
1571
1574
|
subgraph: subgraphName,
|
|
@@ -1574,7 +1577,7 @@ async function backfillSubgraph(def, opts) {
|
|
|
1574
1577
|
}
|
|
1575
1578
|
const { recordSubgraphProcessed: recordSubgraphProcessed3 } = await import("@secondlayer/shared/db/queries/subgraphs");
|
|
1576
1579
|
if (result.totalEventsProcessed > 0 || result.totalErrors > 0) {
|
|
1577
|
-
await recordSubgraphProcessed3(
|
|
1580
|
+
await recordSubgraphProcessed3(targetDb, subgraphName, result.totalEventsProcessed, result.totalErrors, result.totalErrors > 0 ? `${result.totalErrors} error(s) during backfill` : undefined);
|
|
1578
1581
|
}
|
|
1579
1582
|
logger4.info("Backfill complete", {
|
|
1580
1583
|
subgraph: subgraphName,
|
|
@@ -1829,5 +1832,5 @@ export {
|
|
|
1829
1832
|
backfillSubgraph
|
|
1830
1833
|
};
|
|
1831
1834
|
|
|
1832
|
-
//# debugId=
|
|
1835
|
+
//# debugId=6E312ED88F463C8164756E2164756E21
|
|
1833
1836
|
//# sourceMappingURL=index.js.map
|