@secondlayer/subgraphs 3.23.0 → 3.23.2
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.d.ts +11 -7
- package/dist/src/index.js +59 -50
- package/dist/src/index.js.map +4 -4
- package/dist/src/runtime/block-processor.d.ts +62 -9
- package/dist/src/runtime/block-processor.js +30 -20
- package/dist/src/runtime/block-processor.js.map +4 -4
- package/dist/src/runtime/catchup.d.ts +11 -7
- package/dist/src/runtime/catchup.js +37 -28
- package/dist/src/runtime/catchup.js.map +4 -4
- package/dist/src/runtime/context.js +12 -3
- package/dist/src/runtime/context.js.map +3 -3
- package/dist/src/runtime/processor.js +98 -89
- package/dist/src/runtime/processor.js.map +4 -4
- package/dist/src/runtime/reindex.d.ts +11 -7
- package/dist/src/runtime/reindex.js +59 -50
- package/dist/src/runtime/reindex.js.map +4 -4
- package/dist/src/runtime/reorg.d.ts +11 -7
- package/dist/src/runtime/reorg.js +44 -35
- package/dist/src/runtime/reorg.js.map +4 -4
- package/dist/src/runtime/runner.d.ts +36 -32
- package/dist/src/runtime/source-matcher.d.ts +11 -7
- package/dist/src/runtime/stats.d.ts +3 -3
- package/dist/src/schema/index.d.ts +11 -7
- package/dist/src/service.js +101 -92
- package/dist/src/service.js.map +4 -4
- package/dist/src/testing/index.d.ts +32 -28
- package/dist/src/testing/index.js +17 -8
- package/dist/src/testing/index.js.map +3 -3
- package/dist/src/triggers/index.d.ts +11 -7
- package/dist/src/types.d.ts +11 -7
- package/dist/src/validate.d.ts +11 -7
- package/package.json +3 -3
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AbiContract as AbiContract2 } from "@secondlayer/stacks/clarity";
|
|
2
|
+
import { AssetIdentifier } from "@secondlayer/stacks/filters";
|
|
2
3
|
import { UnwrapResponse } from "@secondlayer/stacks/actions";
|
|
3
4
|
import { AbiContract, ExtractFunctionArgs, ExtractFunctionOutput, ExtractReadOnlyFunctions, ToCamelCase } from "@secondlayer/stacks/clarity";
|
|
4
5
|
/**
|
|
@@ -206,38 +207,38 @@ interface FactoryScope {
|
|
|
206
207
|
/** FT event filters */
|
|
207
208
|
interface FtTransferFilter extends TraitScope {
|
|
208
209
|
type: "ft_transfer";
|
|
209
|
-
assetIdentifier?:
|
|
210
|
+
assetIdentifier?: AssetIdentifier;
|
|
210
211
|
sender?: string;
|
|
211
212
|
recipient?: string;
|
|
212
213
|
minAmount?: bigint;
|
|
213
214
|
}
|
|
214
215
|
interface FtMintFilter extends TraitScope {
|
|
215
216
|
type: "ft_mint";
|
|
216
|
-
assetIdentifier?:
|
|
217
|
+
assetIdentifier?: AssetIdentifier;
|
|
217
218
|
recipient?: string;
|
|
218
219
|
minAmount?: bigint;
|
|
219
220
|
}
|
|
220
221
|
interface FtBurnFilter extends TraitScope {
|
|
221
222
|
type: "ft_burn";
|
|
222
|
-
assetIdentifier?:
|
|
223
|
+
assetIdentifier?: AssetIdentifier;
|
|
223
224
|
sender?: string;
|
|
224
225
|
minAmount?: bigint;
|
|
225
226
|
}
|
|
226
227
|
/** NFT event filters */
|
|
227
228
|
interface NftTransferFilter extends TraitScope {
|
|
228
229
|
type: "nft_transfer";
|
|
229
|
-
assetIdentifier?:
|
|
230
|
+
assetIdentifier?: AssetIdentifier;
|
|
230
231
|
sender?: string;
|
|
231
232
|
recipient?: string;
|
|
232
233
|
}
|
|
233
234
|
interface NftMintFilter extends TraitScope {
|
|
234
235
|
type: "nft_mint";
|
|
235
|
-
assetIdentifier?:
|
|
236
|
+
assetIdentifier?: AssetIdentifier;
|
|
236
237
|
recipient?: string;
|
|
237
238
|
}
|
|
238
239
|
interface NftBurnFilter extends TraitScope {
|
|
239
240
|
type: "nft_burn";
|
|
240
|
-
assetIdentifier?:
|
|
241
|
+
assetIdentifier?: AssetIdentifier;
|
|
241
242
|
sender?: string;
|
|
242
243
|
}
|
|
243
244
|
/**
|
|
@@ -335,7 +336,10 @@ type PrintField = ColumnType | {
|
|
|
335
336
|
interface PrintEventFilter extends TraitScope, FactoryScope {
|
|
336
337
|
type: "print_event";
|
|
337
338
|
/** One contract id, or a set of them (max 20). Supports `*` wildcards.
|
|
338
|
-
*
|
|
339
|
+
* COMPOSES with `trait` — the matcher ANDs them, so the pair means
|
|
340
|
+
* "contracts conforming to this trait, narrowed to these ids". (The Index
|
|
341
|
+
* read API refuses the combination, but that is its query planner's
|
|
342
|
+
* constraint, not a semantic one.) */
|
|
339
343
|
contractId?: string | readonly string[];
|
|
340
344
|
topic?: string;
|
|
341
345
|
/**
|
package/dist/src/index.js
CHANGED
|
@@ -217,7 +217,7 @@ function filterFieldsByType() {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
// src/runtime/context.ts
|
|
220
|
-
import { logger } from "@secondlayer/shared/logger";
|
|
220
|
+
import { logger as logger2 } from "@secondlayer/shared/logger";
|
|
221
221
|
import { formatUnits } from "@secondlayer/stacks/utils";
|
|
222
222
|
import { sql } from "kysely";
|
|
223
223
|
|
|
@@ -362,6 +362,7 @@ function generateSubgraphSQL(def, schemaNameOverride) {
|
|
|
362
362
|
|
|
363
363
|
// src/runtime/chain-read.ts
|
|
364
364
|
import { getSourceDb } from "@secondlayer/shared/db";
|
|
365
|
+
import { logger } from "@secondlayer/shared/logger";
|
|
365
366
|
import { http, createPublicClient } from "@secondlayer/stacks";
|
|
366
367
|
import {
|
|
367
368
|
ContractResponseError,
|
|
@@ -447,6 +448,14 @@ function createChainReadClient(ctx) {
|
|
|
447
448
|
const pinnedTo = constant ? null : ctx.indexBlockHash;
|
|
448
449
|
const cached = await db.selectFrom("chain_read_cache").select("result_hex").where("contract_id", "=", contractId).where("function_name", "=", fn.name).where("args_hash", "=", argsHash).where((eb) => pinnedTo === null ? eb("index_block_hash", "is", null) : eb("index_block_hash", "=", pinnedTo)).executeTakeFirst();
|
|
449
450
|
const resultHex = cached?.result_hex ?? await gate.run(async () => {
|
|
451
|
+
if (!ctx.indexBlockHash) {
|
|
452
|
+
logger.warn("Chain read is not pinned to a block (no index_block_hash)", {
|
|
453
|
+
contractId,
|
|
454
|
+
functionName: fn.name,
|
|
455
|
+
blockHeight: ctx.blockHeight,
|
|
456
|
+
note: 'cache: "contract-constant" asserts this value cannot change; the node answered at its own tip'
|
|
457
|
+
});
|
|
458
|
+
}
|
|
450
459
|
const value2 = await readContract(nodeClient(rpcUrl), {
|
|
451
460
|
contract: contractId,
|
|
452
461
|
functionName: fn.name,
|
|
@@ -561,7 +570,7 @@ class SubgraphContext {
|
|
|
561
570
|
data: { ...key, ...row, ...meta, _upsert_keys: keyColumns }
|
|
562
571
|
});
|
|
563
572
|
} else {
|
|
564
|
-
|
|
573
|
+
logger2.warn("upsert called without matching uniqueKeys constraint, using fallback", {
|
|
565
574
|
table,
|
|
566
575
|
keys: keyColumns
|
|
567
576
|
});
|
|
@@ -1121,7 +1130,7 @@ function decodeFunctionArgs(args) {
|
|
|
1121
1130
|
|
|
1122
1131
|
// src/runtime/runner.ts
|
|
1123
1132
|
import { getErrorMessage } from "@secondlayer/shared";
|
|
1124
|
-
import { logger as
|
|
1133
|
+
import { logger as logger3 } from "@secondlayer/shared/logger";
|
|
1125
1134
|
import {
|
|
1126
1135
|
clarityValueToJS,
|
|
1127
1136
|
deserializeCV as deserializeCV3,
|
|
@@ -1472,7 +1481,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
1472
1481
|
units.sort((a, b) => (a.tx.tx_index ?? 0) - (b.tx.tx_index ?? 0) || (a.event?.event_index ?? -1) - (b.event?.event_index ?? -1));
|
|
1473
1482
|
for (const { tx, event, sourceName } of units) {
|
|
1474
1483
|
if (errors >= threshold) {
|
|
1475
|
-
|
|
1484
|
+
logger3.error("Subgraph error threshold reached, skipping remaining events", {
|
|
1476
1485
|
subgraph: subgraph.name,
|
|
1477
1486
|
errors,
|
|
1478
1487
|
threshold
|
|
@@ -1481,7 +1490,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
1481
1490
|
}
|
|
1482
1491
|
const handler = subgraph.handlers[sourceName] ?? subgraph.handlers["*"] ?? null;
|
|
1483
1492
|
if (!handler) {
|
|
1484
|
-
|
|
1493
|
+
logger3.warn("No handler found for source", {
|
|
1485
1494
|
subgraph: subgraph.name,
|
|
1486
1495
|
sourceName,
|
|
1487
1496
|
txId: tx.tx_id
|
|
@@ -1538,7 +1547,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
1538
1547
|
const verdict = validatePrintPayload(filter.prints, printPayload.topic ?? "", printPayload.data ?? {});
|
|
1539
1548
|
if (!verdict.ok) {
|
|
1540
1549
|
skipped++;
|
|
1541
|
-
|
|
1550
|
+
logger3.warn("Print payload does not match declared prints schema", {
|
|
1542
1551
|
subgraph: subgraph.name,
|
|
1543
1552
|
sourceName,
|
|
1544
1553
|
topic: printPayload.topic,
|
|
@@ -1553,7 +1562,7 @@ async function runHandlers(subgraph, matched, ctx, opts) {
|
|
|
1553
1562
|
} catch (err) {
|
|
1554
1563
|
ctx.rollbackTo(checkpoint);
|
|
1555
1564
|
errors++;
|
|
1556
|
-
|
|
1565
|
+
logger3.error("Subgraph handler error", {
|
|
1557
1566
|
subgraph: subgraph.name,
|
|
1558
1567
|
sourceName,
|
|
1559
1568
|
txId: tx.tx_id,
|
|
@@ -1838,7 +1847,7 @@ import {
|
|
|
1838
1847
|
resolveSubgraphDb,
|
|
1839
1848
|
updateSubgraphStatus
|
|
1840
1849
|
} from "@secondlayer/shared/db/queries/subgraphs";
|
|
1841
|
-
import { logger as
|
|
1850
|
+
import { logger as logger6 } from "@secondlayer/shared/logger";
|
|
1842
1851
|
import { sql as sql3 } from "kysely";
|
|
1843
1852
|
|
|
1844
1853
|
// src/runtime/block-source.ts
|
|
@@ -1846,7 +1855,7 @@ import { getSourceDb as getSourceDb2 } from "@secondlayer/shared/db";
|
|
|
1846
1855
|
import {
|
|
1847
1856
|
IndexHttpClient
|
|
1848
1857
|
} from "@secondlayer/shared/index-http";
|
|
1849
|
-
import { logger as
|
|
1858
|
+
import { logger as logger4 } from "@secondlayer/shared/logger";
|
|
1850
1859
|
|
|
1851
1860
|
// src/runtime/batch-loader.ts
|
|
1852
1861
|
async function loadBlockRange(db, fromHeight, toHeight) {
|
|
@@ -2170,7 +2179,7 @@ class FallbackBlockSource {
|
|
|
2170
2179
|
try {
|
|
2171
2180
|
return await this.primary.getTip();
|
|
2172
2181
|
} catch (err) {
|
|
2173
|
-
|
|
2182
|
+
logger4.warn("block source primary getTip failed — using DB tap", {
|
|
2174
2183
|
error: err instanceof Error ? err.message : String(err)
|
|
2175
2184
|
});
|
|
2176
2185
|
return this.fallback.getTip();
|
|
@@ -2180,7 +2189,7 @@ class FallbackBlockSource {
|
|
|
2180
2189
|
try {
|
|
2181
2190
|
return await this.primary.loadBlockRange(fromHeight, toHeight);
|
|
2182
2191
|
} catch (err) {
|
|
2183
|
-
|
|
2192
|
+
logger4.warn("block source primary loadBlockRange failed — using DB tap", {
|
|
2184
2193
|
from: fromHeight,
|
|
2185
2194
|
to: toHeight,
|
|
2186
2195
|
error: err instanceof Error ? err.message : String(err)
|
|
@@ -2212,7 +2221,7 @@ function resolveBlockSource(subgraph) {
|
|
|
2212
2221
|
return new FallbackBlockSource(new PublicApiBlockSource(buildHttpClient(), referencedIndexEventTypes(subgraph), canSparseScan(subgraph) ? sparseProbeTargets(subgraph) : undefined, needsTransactionData(subgraph)), postgresBlockSource);
|
|
2213
2222
|
}
|
|
2214
2223
|
if (process.env.SUBGRAPH_SOURCE === "streams-index" && subgraph) {
|
|
2215
|
-
|
|
2224
|
+
logger4.debug("Subgraph not streams-index eligible, using DB tap", {
|
|
2216
2225
|
subgraph: subgraph.name
|
|
2217
2226
|
});
|
|
2218
2227
|
}
|
|
@@ -2221,7 +2230,7 @@ function resolveBlockSource(subgraph) {
|
|
|
2221
2230
|
|
|
2222
2231
|
// src/runtime/outbox-emit.ts
|
|
2223
2232
|
import { createHash as createHash2 } from "node:crypto";
|
|
2224
|
-
import { logger as
|
|
2233
|
+
import { logger as logger5 } from "@secondlayer/shared/logger";
|
|
2225
2234
|
var loggedKillSwitch = false;
|
|
2226
2235
|
var OP_VERB = {
|
|
2227
2236
|
insert: "created",
|
|
@@ -2245,7 +2254,7 @@ function stableStringify(obj) {
|
|
|
2245
2254
|
async function emitSubscriptionOutbox(tx, subgraphName, manifest, matcher, blockHeight) {
|
|
2246
2255
|
if (!isEmitOutboxEnabled()) {
|
|
2247
2256
|
if (!loggedKillSwitch) {
|
|
2248
|
-
|
|
2257
|
+
logger5.warn("SECONDLAYER_EMIT_OUTBOX=false — outbox emission bypassed");
|
|
2249
2258
|
loggedKillSwitch = true;
|
|
2250
2259
|
}
|
|
2251
2260
|
return 0;
|
|
@@ -2565,7 +2574,7 @@ async function processBlockWithRetry(subgraph, subgraphName, blockHeight, opts,
|
|
|
2565
2574
|
const delay = retryDelaysMs[attempt];
|
|
2566
2575
|
if (delay === undefined)
|
|
2567
2576
|
break;
|
|
2568
|
-
|
|
2577
|
+
logger6.warn("Block processing failed, retrying", {
|
|
2569
2578
|
subgraph: subgraphName,
|
|
2570
2579
|
blockHeight,
|
|
2571
2580
|
attempt: attempt + 1,
|
|
@@ -2597,7 +2606,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
2597
2606
|
} else {
|
|
2598
2607
|
const data = (await resolveBlockSource(subgraph).loadBlockRange(blockHeight, blockHeight)).get(blockHeight);
|
|
2599
2608
|
if (!data) {
|
|
2600
|
-
|
|
2609
|
+
logger6.debug("Block not found or non-canonical for subgraph processing", {
|
|
2601
2610
|
subgraph: subgraphName,
|
|
2602
2611
|
blockHeight
|
|
2603
2612
|
});
|
|
@@ -2738,7 +2747,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
2738
2747
|
});
|
|
2739
2748
|
} catch (err) {
|
|
2740
2749
|
if (err instanceof CursorRaceLostError) {
|
|
2741
|
-
|
|
2750
|
+
logger6.warn("cursor race lost — block already covered", {
|
|
2742
2751
|
subgraph: subgraphName,
|
|
2743
2752
|
blockHeight,
|
|
2744
2753
|
error: err.message
|
|
@@ -2762,7 +2771,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
2762
2771
|
const { rows } = await sql3.raw(`SELECT n_live_tup AS count FROM pg_stat_user_tables WHERE schemaname = '${schemaName}' AND relname = '${table}'`).execute(route.dataDb);
|
|
2763
2772
|
const count = Number(rows[0]?.count ?? 0);
|
|
2764
2773
|
if (count >= 1e7) {
|
|
2765
|
-
|
|
2774
|
+
logger6.warn("Subgraph table exceeds 10M rows (estimate)", {
|
|
2766
2775
|
subgraph: subgraphName,
|
|
2767
2776
|
table,
|
|
2768
2777
|
count
|
|
@@ -2770,7 +2779,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
|
|
|
2770
2779
|
}
|
|
2771
2780
|
}
|
|
2772
2781
|
} catch (err) {
|
|
2773
|
-
|
|
2782
|
+
logger6.debug("Row count sample failed", {
|
|
2774
2783
|
subgraph: subgraphName,
|
|
2775
2784
|
error: err instanceof Error ? err.message : String(err)
|
|
2776
2785
|
});
|
|
@@ -2860,11 +2869,11 @@ import {
|
|
|
2860
2869
|
recordSubgraphProcessed as recordSubgraphProcessed2,
|
|
2861
2870
|
updateSubgraphStatus as updateSubgraphStatus2
|
|
2862
2871
|
} from "@secondlayer/shared/db/queries/subgraphs";
|
|
2863
|
-
import { logger as
|
|
2872
|
+
import { logger as logger8 } from "@secondlayer/shared/logger";
|
|
2864
2873
|
|
|
2865
2874
|
// src/runtime/reindex-notify.ts
|
|
2866
2875
|
import { getErrorMessage as getErrorMessage2 } from "@secondlayer/shared";
|
|
2867
|
-
import { logger as
|
|
2876
|
+
import { logger as logger7 } from "@secondlayer/shared/logger";
|
|
2868
2877
|
async function notifyReindexComplete(db, subgraphName, stats) {
|
|
2869
2878
|
try {
|
|
2870
2879
|
const subgraph = await db.selectFrom("subgraphs").select(["account_id"]).where("name", "=", subgraphName).executeTakeFirst();
|
|
@@ -2875,7 +2884,7 @@ async function notifyReindexComplete(db, subgraphName, stats) {
|
|
|
2875
2884
|
return;
|
|
2876
2885
|
const resendKey = process.env.RESEND_API_KEY;
|
|
2877
2886
|
if (!resendKey) {
|
|
2878
|
-
|
|
2887
|
+
logger7.warn("RESEND_API_KEY unset — skipping reindex-complete email", {
|
|
2879
2888
|
subgraph: subgraphName
|
|
2880
2889
|
});
|
|
2881
2890
|
return;
|
|
@@ -2897,14 +2906,14 @@ async function notifyReindexComplete(db, subgraphName, stats) {
|
|
|
2897
2906
|
});
|
|
2898
2907
|
if (!res.ok) {
|
|
2899
2908
|
const text = await res.text().catch(() => "");
|
|
2900
|
-
|
|
2909
|
+
logger7.warn("reindex-complete email failed", {
|
|
2901
2910
|
subgraph: subgraphName,
|
|
2902
2911
|
status: res.status,
|
|
2903
2912
|
body: text.slice(0, 200)
|
|
2904
2913
|
});
|
|
2905
2914
|
}
|
|
2906
2915
|
} catch (err) {
|
|
2907
|
-
|
|
2916
|
+
logger7.warn("reindex-complete email threw", {
|
|
2908
2917
|
subgraph: subgraphName,
|
|
2909
2918
|
error: getErrorMessage2(err)
|
|
2910
2919
|
});
|
|
@@ -3016,7 +3025,7 @@ async function processBlockRange(def, opts) {
|
|
|
3016
3025
|
while (currentHeight <= toBlock) {
|
|
3017
3026
|
if (opts.signal?.aborted) {
|
|
3018
3027
|
aborted = true;
|
|
3019
|
-
|
|
3028
|
+
logger8.info("Block processing aborted", {
|
|
3020
3029
|
subgraph: subgraphName,
|
|
3021
3030
|
currentBlock: currentHeight,
|
|
3022
3031
|
reason: String(opts.signal.reason ?? "unknown")
|
|
@@ -3065,7 +3074,7 @@ async function processBlockRange(def, opts) {
|
|
|
3065
3074
|
});
|
|
3066
3075
|
} catch (err) {
|
|
3067
3076
|
const errorMsg = getErrorMessage3(err);
|
|
3068
|
-
|
|
3077
|
+
logger8.error("Block processing failed persistently", {
|
|
3069
3078
|
subgraph: subgraphName,
|
|
3070
3079
|
blockHeight: height,
|
|
3071
3080
|
error: errorMsg
|
|
@@ -3111,7 +3120,7 @@ async function processBlockRange(def, opts) {
|
|
|
3111
3120
|
lastProgressFlushAt = now;
|
|
3112
3121
|
}
|
|
3113
3122
|
if (blocksProcessed % LOG_INTERVAL === 0) {
|
|
3114
|
-
|
|
3123
|
+
logger8.info(`${status === "reindexing" ? "Reindex" : "Backfill"} progress`, {
|
|
3115
3124
|
subgraph: subgraphName,
|
|
3116
3125
|
processed: blocksProcessed,
|
|
3117
3126
|
total: totalBlocks,
|
|
@@ -3131,7 +3140,7 @@ async function processBlockRange(def, opts) {
|
|
|
3131
3140
|
if (batchFailedBlocks.length > 0 && opts.subgraphId) {
|
|
3132
3141
|
const gaps = coalesceFailedBlocks(batchFailedBlocks);
|
|
3133
3142
|
await recordGapBatch(targetDb, opts.subgraphId, subgraphName, gaps).catch((err) => {
|
|
3134
|
-
|
|
3143
|
+
logger8.warn("Failed to record subgraph gaps", {
|
|
3135
3144
|
subgraph: subgraphName,
|
|
3136
3145
|
error: err instanceof Error ? err.message : String(err)
|
|
3137
3146
|
});
|
|
@@ -3148,7 +3157,7 @@ async function processBlockRange(def, opts) {
|
|
|
3148
3157
|
} else {
|
|
3149
3158
|
await updateSubgraphStatus2(targetDb, subgraphName, status, jumpTo - 1);
|
|
3150
3159
|
}
|
|
3151
|
-
|
|
3160
|
+
logger8.info("Sparse skip", {
|
|
3152
3161
|
subgraph: subgraphName,
|
|
3153
3162
|
from: batchEnd + 1,
|
|
3154
3163
|
to: jumpTo - 1,
|
|
@@ -3188,11 +3197,11 @@ async function reindexSubgraph(def, opts) {
|
|
|
3188
3197
|
const subgraphName = def.name;
|
|
3189
3198
|
const schemaName = opts?.schemaName ?? pgSchemaName(subgraphName);
|
|
3190
3199
|
await updateSubgraphStatus2(targetDb, subgraphName, "reindexing");
|
|
3191
|
-
|
|
3200
|
+
logger8.info("Reindex starting", { subgraph: subgraphName });
|
|
3192
3201
|
try {
|
|
3193
3202
|
const { fromBlock, toBlock } = await resolveBlockRange(source, def, opts);
|
|
3194
3203
|
if (fromBlock > toBlock) {
|
|
3195
|
-
|
|
3204
|
+
logger8.info("No blocks to reindex", {
|
|
3196
3205
|
subgraph: subgraphName,
|
|
3197
3206
|
fromBlock,
|
|
3198
3207
|
toBlock
|
|
@@ -3206,7 +3215,7 @@ async function reindexSubgraph(def, opts) {
|
|
|
3206
3215
|
await client.unsafe(stmt);
|
|
3207
3216
|
}
|
|
3208
3217
|
await updateSubgraphStatus2(targetDb, subgraphName, "reindexing", Math.max(0, fromBlock - 1));
|
|
3209
|
-
|
|
3218
|
+
logger8.info("Schema recreated for reindex", {
|
|
3210
3219
|
subgraph: subgraphName,
|
|
3211
3220
|
cursorResetTo: Math.max(0, fromBlock - 1)
|
|
3212
3221
|
});
|
|
@@ -3220,7 +3229,7 @@ async function reindexSubgraph(def, opts) {
|
|
|
3220
3229
|
last_error_at: null,
|
|
3221
3230
|
updated_at: new Date
|
|
3222
3231
|
}).where("name", "=", subgraphName).execute();
|
|
3223
|
-
|
|
3232
|
+
logger8.info("Reindexing blocks", {
|
|
3224
3233
|
subgraph: subgraphName,
|
|
3225
3234
|
fromBlock,
|
|
3226
3235
|
toBlock,
|
|
@@ -3242,9 +3251,9 @@ async function reindexSubgraph(def, opts) {
|
|
|
3242
3251
|
if (reason === "user-cancelled") {
|
|
3243
3252
|
await updateSubgraphStatus2(targetDb, subgraphName, "active");
|
|
3244
3253
|
await clearReindexMetadata(targetDb, subgraphName);
|
|
3245
|
-
|
|
3254
|
+
logger8.info("Reindex cancelled by user", { subgraph: subgraphName });
|
|
3246
3255
|
} else {
|
|
3247
|
-
|
|
3256
|
+
logger8.info("Reindex interrupted by shutdown, will resume", {
|
|
3248
3257
|
subgraph: subgraphName
|
|
3249
3258
|
});
|
|
3250
3259
|
}
|
|
@@ -3252,7 +3261,7 @@ async function reindexSubgraph(def, opts) {
|
|
|
3252
3261
|
}
|
|
3253
3262
|
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
3254
3263
|
await clearReindexMetadata(targetDb, subgraphName);
|
|
3255
|
-
|
|
3264
|
+
logger8.info("Reindex complete", {
|
|
3256
3265
|
subgraph: subgraphName,
|
|
3257
3266
|
blocks: result.blocksProcessed,
|
|
3258
3267
|
events: result.totalEventsProcessed,
|
|
@@ -3265,7 +3274,7 @@ async function reindexSubgraph(def, opts) {
|
|
|
3265
3274
|
});
|
|
3266
3275
|
return { processed: result.blocksProcessed };
|
|
3267
3276
|
} catch (err) {
|
|
3268
|
-
|
|
3277
|
+
logger8.error("Reindex failed", {
|
|
3269
3278
|
subgraph: subgraphName,
|
|
3270
3279
|
error: getErrorMessage3(err)
|
|
3271
3280
|
});
|
|
@@ -3287,7 +3296,7 @@ async function resumeReindex(def, opts) {
|
|
|
3287
3296
|
const fromBlock = resolveReindexResumeBlock(row);
|
|
3288
3297
|
const toBlock = Number(row.reindex_to_block);
|
|
3289
3298
|
if (fromBlock == null) {
|
|
3290
|
-
|
|
3299
|
+
logger8.info("No reindex metadata, starting fresh reindex", {
|
|
3291
3300
|
subgraph: subgraphName
|
|
3292
3301
|
});
|
|
3293
3302
|
return reindexSubgraph(def, {
|
|
@@ -3296,12 +3305,12 @@ async function resumeReindex(def, opts) {
|
|
|
3296
3305
|
});
|
|
3297
3306
|
}
|
|
3298
3307
|
if (fromBlock > toBlock) {
|
|
3299
|
-
|
|
3308
|
+
logger8.info("Resume: no remaining blocks", { subgraph: subgraphName });
|
|
3300
3309
|
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
3301
3310
|
await clearReindexMetadata(targetDb, subgraphName);
|
|
3302
3311
|
return { processed: 0 };
|
|
3303
3312
|
}
|
|
3304
|
-
|
|
3313
|
+
logger8.info("Resuming reindex", {
|
|
3305
3314
|
subgraph: subgraphName,
|
|
3306
3315
|
fromBlock,
|
|
3307
3316
|
toBlock,
|
|
@@ -3323,9 +3332,9 @@ async function resumeReindex(def, opts) {
|
|
|
3323
3332
|
if (reason === "user-cancelled") {
|
|
3324
3333
|
await updateSubgraphStatus2(targetDb, subgraphName, "active");
|
|
3325
3334
|
await clearReindexMetadata(targetDb, subgraphName);
|
|
3326
|
-
|
|
3335
|
+
logger8.info("Resume cancelled by user", { subgraph: subgraphName });
|
|
3327
3336
|
} else {
|
|
3328
|
-
|
|
3337
|
+
logger8.info("Resume interrupted by shutdown, will resume again", {
|
|
3329
3338
|
subgraph: subgraphName
|
|
3330
3339
|
});
|
|
3331
3340
|
}
|
|
@@ -3333,13 +3342,13 @@ async function resumeReindex(def, opts) {
|
|
|
3333
3342
|
}
|
|
3334
3343
|
await updateSubgraphStatus2(targetDb, subgraphName, "active", toBlock);
|
|
3335
3344
|
await clearReindexMetadata(targetDb, subgraphName);
|
|
3336
|
-
|
|
3345
|
+
logger8.info("Resumed reindex complete", {
|
|
3337
3346
|
subgraph: subgraphName,
|
|
3338
3347
|
blocks: result.blocksProcessed
|
|
3339
3348
|
});
|
|
3340
3349
|
return { processed: result.blocksProcessed };
|
|
3341
3350
|
} catch (err) {
|
|
3342
|
-
|
|
3351
|
+
logger8.error("Resumed reindex failed", {
|
|
3343
3352
|
subgraph: subgraphName,
|
|
3344
3353
|
error: getErrorMessage3(err)
|
|
3345
3354
|
});
|
|
@@ -3350,7 +3359,7 @@ async function resumeReindex(def, opts) {
|
|
|
3350
3359
|
async function backfillSubgraph(def, opts) {
|
|
3351
3360
|
const targetDb = getTargetDb2();
|
|
3352
3361
|
const subgraphName = def.name;
|
|
3353
|
-
|
|
3362
|
+
logger8.info("Backfill starting", {
|
|
3354
3363
|
subgraph: subgraphName,
|
|
3355
3364
|
from: opts.fromBlock,
|
|
3356
3365
|
to: opts.toBlock
|
|
@@ -3368,17 +3377,17 @@ async function backfillSubgraph(def, opts) {
|
|
|
3368
3377
|
signal: opts.signal
|
|
3369
3378
|
});
|
|
3370
3379
|
if (result.aborted) {
|
|
3371
|
-
|
|
3380
|
+
logger8.info("Backfill aborted", { subgraph: subgraphName });
|
|
3372
3381
|
return { processed: result.blocksProcessed };
|
|
3373
3382
|
}
|
|
3374
3383
|
const resolved = await resolveGaps(targetDb, subgraphName, opts.fromBlock, opts.toBlock).catch(() => 0);
|
|
3375
3384
|
if (resolved > 0) {
|
|
3376
|
-
|
|
3385
|
+
logger8.info("Resolved subgraph gaps via backfill", {
|
|
3377
3386
|
subgraph: subgraphName,
|
|
3378
3387
|
resolved
|
|
3379
3388
|
});
|
|
3380
3389
|
}
|
|
3381
|
-
|
|
3390
|
+
logger8.info("Backfill complete", {
|
|
3382
3391
|
subgraph: subgraphName,
|
|
3383
3392
|
blocks: result.blocksProcessed,
|
|
3384
3393
|
events: result.totalEventsProcessed,
|
|
@@ -3386,7 +3395,7 @@ async function backfillSubgraph(def, opts) {
|
|
|
3386
3395
|
});
|
|
3387
3396
|
return { processed: result.blocksProcessed };
|
|
3388
3397
|
} catch (err) {
|
|
3389
|
-
|
|
3398
|
+
logger8.error("Backfill failed", {
|
|
3390
3399
|
subgraph: subgraphName,
|
|
3391
3400
|
error: getErrorMessage3(err)
|
|
3392
3401
|
});
|
|
@@ -4692,5 +4701,5 @@ export {
|
|
|
4692
4701
|
ByoBreakingChangeError
|
|
4693
4702
|
};
|
|
4694
4703
|
|
|
4695
|
-
//# debugId=
|
|
4704
|
+
//# debugId=EA579C34B6DF559E64756E2164756E21
|
|
4696
4705
|
//# sourceMappingURL=index.js.map
|