@secondlayer/subgraphs 3.26.1 → 3.26.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.
@@ -3045,7 +3045,7 @@ class StatsAccumulator {
3045
3045
  }
3046
3046
 
3047
3047
  // src/runtime/catchup.ts
3048
- import { getTargetDb as getTargetDb2 } from "@secondlayer/shared/db";
3048
+ import { getTargetDb as getTargetDb2, sql as sql4 } from "@secondlayer/shared/db";
3049
3049
  import { getSubgraph } from "@secondlayer/shared/db/queries/subgraphs";
3050
3050
  import { logger as logger8 } from "@secondlayer/shared/logger";
3051
3051
 
@@ -3116,6 +3116,15 @@ async function withSubgraphBlockLock(name, fn) {
3116
3116
  release();
3117
3117
  }
3118
3118
  }
3119
+ async function withSubgraphBlockAdvisoryLock(name, fn) {
3120
+ return getTargetDb2().transaction().execute(async (lockTx) => {
3121
+ await sql4`SELECT pg_advisory_xact_lock(hashtext(${`subgraph-block:${name}`}))`.execute(lockTx);
3122
+ return fn();
3123
+ });
3124
+ }
3125
+ async function withSubgraphBlockWriteLock(name, fn) {
3126
+ return withSubgraphBlockLock(name, () => withSubgraphBlockAdvisoryLock(name, fn));
3127
+ }
3119
3128
  function bumpReorgEpoch(name) {
3120
3129
  reorgEpoch.set(name, (reorgEpoch.get(name) ?? 0) + 1);
3121
3130
  }
@@ -3244,7 +3253,7 @@ async function catchUpSubgraph(subgraph, subgraphName) {
3244
3253
  const preloaded = blockData;
3245
3254
  let result;
3246
3255
  try {
3247
- result = await withSubgraphBlockLock(subgraphName, async () => {
3256
+ result = await withSubgraphBlockWriteLock(subgraphName, async () => {
3248
3257
  if (getReorgEpoch(subgraphName) !== walkEpoch) {
3249
3258
  throw new ReorgEpochChangedError(subgraphName);
3250
3259
  }
@@ -3312,7 +3321,7 @@ import {
3312
3321
  resolveSubgraphRawClient
3313
3322
  } from "@secondlayer/shared/db/queries/subgraphs";
3314
3323
  import { logger as logger9 } from "@secondlayer/shared/logger";
3315
- import { sql as sql4 } from "kysely";
3324
+ import { sql as sql5 } from "kysely";
3316
3325
  async function handleSubgraphReorg(blockHeight, loadSubgraphDef) {
3317
3326
  const targetDb = getTargetDb3();
3318
3327
  const activeSubgraphs = (await listSubgraphs(targetDb)).filter((v) => v.status === "active");
@@ -3330,7 +3339,7 @@ async function handleSubgraphReorg(blockHeight, loadSubgraphDef) {
3330
3339
  bumpReorgEpoch(sg.name);
3331
3340
  await withSubgraphBlockLock(sg.name, async () => {
3332
3341
  await getTargetDb3().transaction().execute(async (lockTx) => {
3333
- await sql4`SELECT pg_advisory_xact_lock(hashtext(${`subgraph-reorg:${sg.name}`}))`.execute(lockTx);
3342
+ await sql5`SELECT pg_advisory_xact_lock(hashtext(${`subgraph-reorg:${sg.name}`}))`.execute(lockTx);
3334
3343
  await reorgOneSubgraph(sg, schema, blockHeight, loadSubgraphDef);
3335
3344
  });
3336
3345
  });
@@ -3441,5 +3450,5 @@ export {
3441
3450
  handleSubgraphReorg
3442
3451
  };
3443
3452
 
3444
- //# debugId=9D5D02929028624564756E2164756E21
3453
+ //# debugId=902B28BBF3E6B7B064756E2164756E21
3445
3454
  //# sourceMappingURL=reorg.js.map