@secondlayer/shared 11.10.1 → 11.11.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/coverage/index.js +3 -1
- package/dist/src/coverage/index.js.map +3 -3
- package/dist/src/index-http.d.ts +42 -4
- package/dist/src/index-http.js +42 -10
- package/dist/src/index-http.js.map +3 -3
- package/dist/src/queue/listener.d.ts +19 -1
- package/dist/src/queue/listener.js +21 -1
- package/dist/src/queue/listener.js.map +3 -3
- package/package.json +1 -1
|
@@ -896,6 +896,7 @@ function planDecoderReceipts(input) {
|
|
|
896
896
|
return { ok: true, receipts, through_cursor: input.to_cursor };
|
|
897
897
|
}
|
|
898
898
|
// src/coverage/adapter.ts
|
|
899
|
+
import { sql } from "kysely";
|
|
899
900
|
var DECODER_COMMIT_STEPS = [
|
|
900
901
|
"output",
|
|
901
902
|
"checkpoint",
|
|
@@ -962,6 +963,7 @@ async function writeCheckpoint(tx, decoderName, cursor) {
|
|
|
962
963
|
last_cursor: cursor,
|
|
963
964
|
updated_at: new Date
|
|
964
965
|
})).execute();
|
|
966
|
+
await sql`SELECT pg_notify('index:tip', ${decoderName})`.execute(tx);
|
|
965
967
|
}
|
|
966
968
|
async function writeReceipts(tx, stageId, runId, receipts) {
|
|
967
969
|
if (receipts.length === 0)
|
|
@@ -1465,5 +1467,5 @@ export {
|
|
|
1465
1467
|
versionsEqual
|
|
1466
1468
|
};
|
|
1467
1469
|
|
|
1468
|
-
//# debugId=
|
|
1470
|
+
//# debugId=E07B1E2F14B6478664756E2164756E21
|
|
1469
1471
|
//# sourceMappingURL=index.js.map
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"/**\n * Coverage evaluator — one library for stage state.\n *\n * Pure. Callers assemble evidence; this file does not touch the database.\n * `complete` is coverage through the recorded target, not currency.\n * `caught_up` additionally requires a fresh source tip and coverage through\n * the finalized boundary. `complete_through` is never conflated with\n * `source_tip`.\n */\n\nimport { decodeStreamsCursor } from \"../streams-cursor.ts\";\nimport {\n\ttype CoverageRange,\n\ttype FailureClass,\n\ttype FailureUnit,\n\ttype NativeClock,\n\ttype RepairMode,\n\ttype RetryState,\n\ttype RunStatus,\n\ttype StageKind,\n\trangeIsOrdered,\n} from \"./constraints.ts\";\n\nexport const COVERAGE_REPORT_SCHEMA_VERSION = 1 as const;\n\nexport const COVERAGE_STATES = [\n\t\"complete\",\n\t\"syncing\",\n\t\"lagging\",\n\t\"gap\",\n\t\"stale\",\n\t\"failed\",\n\t\"unverified_import\",\n\t\"unanchored\",\n\t\"source_unavailable\",\n\t\"out_of_scope\",\n\t\"disabled\",\n] as const;\nexport type CoverageState = (typeof COVERAGE_STATES)[number];\n\nconst HARD_DEP_STATES = new Set<CoverageState>([\n\t\"disabled\",\n\t\"failed\",\n\t\"source_unavailable\",\n\t\"out_of_scope\",\n\t\"unverified_import\",\n\t\"unanchored\",\n\t\"gap\",\n]);\n\nconst DEFAULT_MAX_BLOCKS_BEHIND_FINALIZED = 256;\nconst DEFAULT_MAX_SOURCE_AGE_SECONDS = 300;\n\nexport type BootstrapSource = \"archive\" | \"genesis\" | \"import\";\n\nexport type SyncScope = {\n\tnetwork: string;\n\tstart_height: number;\n\ttarget_height: number | null;\n\tbootstrap: {\n\t\tsource: BootstrapSource;\n\t\tmanifest_digest: string | null;\n\t\tgenesis_hash: string | null;\n\t};\n};\n\nexport type StageDeclaration = {\n\tid: string;\n\tkind: StageKind;\n\tdepends_on: string | null;\n\tnative_clock: NativeClock;\n\tproducer_version: string;\n\trepair_mode: RepairMode;\n\tenabled: boolean;\n};\n\nexport type StageRunView = {\n\tstage_id: string;\n\tcode_hash: string;\n\tconfig_hash: string;\n\thandler_hash: string | null;\n\ttarget_height: number | null;\n\ttarget_cursor: string | null;\n\tstatus: RunStatus;\n\tcomplete_through: number | null;\n};\n\nexport type OpenFailure = {\n\tunit_kind: FailureUnit;\n\tclass: FailureClass;\n\tretry_state: Exclude<RetryState, \"resolved\">;\n\tfrom_height: number | null;\n\tto_height: number | null;\n};\n\nexport type QueueCounters = {\n\taccepted: number;\n\tdecided: number;\n\tenqueued: number;\n\tdelivered: number;\n\tdead: number;\n\tfence_cursor: string | null;\n};\n\nexport type StageEvidence = {\n\tstage_id: string;\n\tranges: CoverageRange[];\n\topen_failures: OpenFailure[];\n\tcursor: string | null;\n\tqueue: QueueCounters | null;\n\tunanchored: boolean;\n\tunverified_import: boolean;\n\t/** False when this stage's native source (node, bitcoin RPC, …) is down. */\n\tsource_available: boolean;\n};\n\nexport type SourceClock = {\n\ttip_height: number | null;\n\tfinalized_height: number | null;\n\tobserved_at: string | null;\n};\n\nexport type EvaluatorOptions = {\n\tnow: Date;\n\tmaxBlocksBehindFinalized?: number;\n\tmaxSourceAgeSeconds?: number;\n};\n\nexport type EvaluatorInput = {\n\tscope: SyncScope;\n\tstages: StageDeclaration[];\n\truns: StageRunView[];\n\tevidence: StageEvidence[];\n\tsource: SourceClock;\n\toptions: EvaluatorOptions;\n};\n\nexport type StageCoverage = {\n\tstage_id: string;\n\tkind: StageKind;\n\tnative_clock: NativeClock;\n\tdepends_on: string | null;\n\tstate: CoverageState;\n\tdetail: string;\n\tcomplete_through: number | null;\n\tsource_tip: number | null;\n\tfinalized_height: number | null;\n\trecorded_target: number | null;\n\tdeclared_range: { from_height: number; to_height: number } | null;\n\tgaps: CoverageRange[];\n\tcaught_up: boolean;\n\tblocked_by: string | null;\n};\n\nexport type CoverageReport = {\n\tschema_version: typeof COVERAGE_REPORT_SCHEMA_VERSION;\n\tnetwork: string;\n\tgenerated_at: string;\n\tsource_tip: number | null;\n\tfinalized_height: number | null;\n\tstages: StageCoverage[];\n\tevaluation_order: string[];\n\tcycles: string[][];\n};\n\nexport function mergeRanges(ranges: readonly CoverageRange[]): CoverageRange[] {\n\tconst sorted = ranges\n\t\t.filter((r) => rangeIsOrdered(r.from_height, r.to_height))\n\t\t.map((r) => ({ from_height: r.from_height, to_height: r.to_height }))\n\t\t.sort((a, b) => a.from_height - b.from_height || a.to_height - b.to_height);\n\tconst out: CoverageRange[] = [];\n\tfor (const range of sorted) {\n\t\tconst last = out[out.length - 1];\n\t\tif (last && range.from_height <= last.to_height + 1) {\n\t\t\tlast.to_height = Math.max(last.to_height, range.to_height);\n\t\t} else {\n\t\t\tout.push(range);\n\t\t}\n\t}\n\treturn out;\n}\n\n/** Highest height reachable from `start` without a hole. */\nexport function contiguousThrough(\n\tranges: readonly CoverageRange[],\n\tstart: number,\n): number | null {\n\tconst merged = mergeRanges(ranges);\n\tlet through: number | null = null;\n\tlet need = start;\n\tfor (const range of merged) {\n\t\tif (range.to_height < need) continue;\n\t\tif (range.from_height > need) break;\n\t\tthrough = range.to_height;\n\t\tneed = range.to_height + 1;\n\t}\n\treturn through;\n}\n\nexport function findRangeGaps(\n\tranges: readonly CoverageRange[],\n\tfrom: number,\n\tto: number,\n): CoverageRange[] {\n\tif (to < from) return [];\n\tconst merged = mergeRanges(ranges);\n\tconst gaps: CoverageRange[] = [];\n\tlet cursor = from;\n\tfor (const range of merged) {\n\t\tif (range.to_height < from) continue;\n\t\tif (range.from_height > to) break;\n\t\tif (range.from_height > cursor) {\n\t\t\tgaps.push({\n\t\t\t\tfrom_height: cursor,\n\t\t\t\tto_height: Math.min(range.from_height - 1, to),\n\t\t\t});\n\t\t}\n\t\tcursor = Math.max(cursor, range.to_height + 1);\n\t\tif (cursor > to) break;\n\t}\n\tif (cursor <= to) {\n\t\tgaps.push({ from_height: cursor, to_height: to });\n\t}\n\treturn gaps;\n}\n\nexport function cursorHeight(cursor: string | null): number | null {\n\tif (!cursor) return null;\n\ttry {\n\t\treturn decodeStreamsCursor(cursor).block_height;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport function topoSort(stages: readonly StageDeclaration[]): {\n\torder: string[];\n\tcycles: string[][];\n} {\n\tconst ids = new Set(stages.map((s) => s.id));\n\tconst incoming = new Map<string, number>();\n\tconst outgoing = new Map<string, string[]>();\n\tfor (const stage of stages) {\n\t\tincoming.set(stage.id, 0);\n\t\toutgoing.set(stage.id, []);\n\t}\n\tfor (const stage of stages) {\n\t\tif (!stage.depends_on || !ids.has(stage.depends_on)) continue;\n\t\toutgoing.get(stage.depends_on)?.push(stage.id);\n\t\tincoming.set(stage.id, (incoming.get(stage.id) ?? 0) + 1);\n\t}\n\tconst queue = [...incoming.entries()]\n\t\t.filter(([, n]) => n === 0)\n\t\t.map(([id]) => id)\n\t\t.sort();\n\tconst order: string[] = [];\n\twhile (queue.length > 0) {\n\t\tconst id = queue.shift();\n\t\tif (!id) break;\n\t\torder.push(id);\n\t\tfor (const next of outgoing.get(id) ?? []) {\n\t\t\tconst left = (incoming.get(next) ?? 1) - 1;\n\t\t\tincoming.set(next, left);\n\t\t\tif (left === 0) queue.push(next);\n\t\t\tqueue.sort();\n\t\t}\n\t}\n\tconst leftover = stages.map((s) => s.id).filter((id) => !order.includes(id));\n\treturn { order, cycles: leftover.length > 0 ? [leftover.sort()] : [] };\n}\n\nfunction lastByStage<T extends { stage_id: string }>(\n\trows: readonly T[],\n): Map<string, T> {\n\tconst map = new Map<string, T>();\n\tfor (const row of rows) map.set(row.stage_id, row);\n\treturn map;\n}\n\nfunction emptyEvidence(stageId: string): StageEvidence {\n\treturn {\n\t\tstage_id: stageId,\n\t\tranges: [],\n\t\topen_failures: [],\n\t\tcursor: null,\n\t\tqueue: null,\n\t\tunanchored: false,\n\t\tunverified_import: false,\n\t\tsource_available: true,\n\t};\n}\n\nfunction declaredEnd(args: {\n\trun: StageRunView | undefined;\n\tscope: SyncScope;\n\tsource: SourceClock;\n}): number | null {\n\treturn (\n\t\targs.run?.target_height ??\n\t\targs.scope.target_height ??\n\t\targs.source.finalized_height ??\n\t\targs.source.tip_height\n\t);\n}\n\nfunction clockRanges(\n\tstage: StageDeclaration,\n\tevidence: StageEvidence,\n): {\n\tranges: CoverageRange[];\n\tinvalidCursor: boolean;\n} {\n\tif (stage.native_clock === \"block\") {\n\t\treturn { ranges: evidence.ranges, invalidCursor: false };\n\t}\n\tconst cursor =\n\t\tstage.native_clock === \"cursor\"\n\t\t\t? evidence.cursor\n\t\t\t: (evidence.queue?.fence_cursor ?? null);\n\tif (!cursor) return { ranges: evidence.ranges, invalidCursor: false };\n\tconst height = cursorHeight(cursor);\n\tif (height === null) return { ranges: evidence.ranges, invalidCursor: true };\n\treturn {\n\t\tranges: mergeRanges([\n\t\t\t...evidence.ranges,\n\t\t\t{ from_height: 0, to_height: height },\n\t\t]),\n\t\tinvalidCursor: false,\n\t};\n}\n\nfunction queueCaught(queue: QueueCounters | null): boolean {\n\tif (!queue) return false;\n\treturn (\n\t\tqueue.accepted === queue.decided &&\n\t\tqueue.delivered + queue.dead === queue.accepted\n\t);\n}\n\nfunction sourceAgeSeconds(source: SourceClock, now: Date): number | null {\n\tif (!source.observed_at) return source.tip_height === null ? null : 0;\n\tconst observed = Date.parse(source.observed_at);\n\tif (Number.isNaN(observed)) return null;\n\treturn Math.max(0, Math.round((now.getTime() - observed) / 1000));\n}\n\nfunction evaluateOne(\n\tstage: StageDeclaration,\n\tinput: EvaluatorInput,\n\trun: StageRunView | undefined,\n\tevidence: StageEvidence,\n\tdep: StageCoverage | null,\n\tmissingDep: boolean,\n\tinCycle: boolean,\n): StageCoverage {\n\tconst sourceTip = input.source.tip_height;\n\tconst finalized = input.source.finalized_height;\n\tconst recordedTarget = run?.target_height ?? input.scope.target_height;\n\tconst maxBehind =\n\t\tinput.options.maxBlocksBehindFinalized ??\n\t\tDEFAULT_MAX_BLOCKS_BEHIND_FINALIZED;\n\tconst maxAge =\n\t\tinput.options.maxSourceAgeSeconds ?? DEFAULT_MAX_SOURCE_AGE_SECONDS;\n\tconst age = sourceAgeSeconds(input.source, input.options.now);\n\tconst sourceFresh =\n\t\tsourceTip !== null && finalized !== null && (age === null || age <= maxAge);\n\n\tconst base = {\n\t\tstage_id: stage.id,\n\t\tkind: stage.kind,\n\t\tnative_clock: stage.native_clock,\n\t\tdepends_on: stage.depends_on,\n\t\tsource_tip: sourceTip,\n\t\tfinalized_height: finalized,\n\t\trecorded_target: recordedTarget,\n\t};\n\n\tconst done = (\n\t\tstate: CoverageState,\n\t\tdetail: string,\n\t\textra: Partial<StageCoverage> = {},\n\t): StageCoverage => {\n\t\tconst completeThrough = extra.complete_through ?? null;\n\t\tconst caughtUp =\n\t\t\textra.caught_up ??\n\t\t\t(state !== \"disabled\" &&\n\t\t\t\tstate !== \"failed\" &&\n\t\t\t\tstate !== \"gap\" &&\n\t\t\t\tstate !== \"out_of_scope\" &&\n\t\t\t\tstate !== \"unverified_import\" &&\n\t\t\t\tstate !== \"unanchored\" &&\n\t\t\t\tstate !== \"source_unavailable\" &&\n\t\t\t\tcompleteThrough !== null &&\n\t\t\t\tfinalized !== null &&\n\t\t\t\tcompleteThrough >= finalized &&\n\t\t\t\tsourceFresh);\n\t\treturn {\n\t\t\t...base,\n\t\t\tstate,\n\t\t\tdetail,\n\t\t\tcomplete_through: completeThrough,\n\t\t\tdeclared_range: extra.declared_range ?? null,\n\t\t\tgaps: extra.gaps ?? [],\n\t\t\tcaught_up: caughtUp,\n\t\t\tblocked_by: extra.blocked_by ?? null,\n\t\t};\n\t};\n\n\tif (!stage.enabled) {\n\t\treturn done(\"disabled\", \"stage is disabled\");\n\t}\n\tif (inCycle) {\n\t\treturn done(\"failed\", \"dependency cycle\");\n\t}\n\tif (missingDep) {\n\t\treturn done(\"failed\", `depends on unknown stage ${stage.depends_on}`);\n\t}\n\tif (dep && HARD_DEP_STATES.has(dep.state)) {\n\t\treturn done(dep.state, `blocked by ${dep.stage_id}: ${dep.detail}`, {\n\t\t\tcomplete_through: dep.complete_through,\n\t\t\tblocked_by: dep.stage_id,\n\t\t\tdeclared_range: dep.declared_range,\n\t\t\tgaps: dep.gaps,\n\t\t\tcaught_up: false,\n\t\t});\n\t}\n\n\tif (evidence.open_failures.length > 0 || run?.status === \"failed\") {\n\t\tconst first = evidence.open_failures[0];\n\t\treturn done(\n\t\t\t\"failed\",\n\t\t\tfirst\n\t\t\t\t? `open ${first.class} failure (${first.retry_state})`\n\t\t\t\t: \"run marked failed\",\n\t\t);\n\t}\n\tif (evidence.unverified_import || run?.status === \"unverified_import\") {\n\t\treturn done(\"unverified_import\", \"imported data has not been audited\");\n\t}\n\tif (evidence.unanchored || run?.status === \"unanchored\") {\n\t\treturn done(\n\t\t\t\"unanchored\",\n\t\t\t\"receipts are missing a block hash or node anchor\",\n\t\t);\n\t}\n\tif (!evidence.source_available) {\n\t\treturn done(\"source_unavailable\", \"native source is unavailable\");\n\t}\n\n\tconst { ranges, invalidCursor } = clockRanges(stage, evidence);\n\tif (invalidCursor) {\n\t\treturn done(\"failed\", \"native clock cursor is not a valid streams cursor\");\n\t}\n\n\tconst end = declaredEnd({ run, scope: input.scope, source: input.source });\n\tif (end !== null && end < input.scope.start_height) {\n\t\treturn done(\"out_of_scope\", \"recorded target is below the instance start\");\n\t}\n\n\tconst sourceSilent =\n\t\tsourceTip === null && finalized === null && recordedTarget === null;\n\tif (sourceSilent) {\n\t\treturn done(\n\t\t\t\"source_unavailable\",\n\t\t\t\"the chain source could not be reached, so the declared range is unknown\",\n\t\t);\n\t}\n\n\tif (end === null) {\n\t\treturn done(\n\t\t\t\"source_unavailable\",\n\t\t\t\"no recorded target and the source tip is unknown\",\n\t\t);\n\t}\n\n\tconst declaredRange = {\n\t\tfrom_height: input.scope.start_height,\n\t\tto_height: end,\n\t};\n\tlet completeThrough = contiguousThrough(ranges, input.scope.start_height);\n\tif (dep?.complete_through !== null && dep?.complete_through !== undefined) {\n\t\tif (completeThrough === null) {\n\t\t\t// stay null\n\t\t} else {\n\t\t\tcompleteThrough = Math.min(completeThrough, dep.complete_through);\n\t\t}\n\t} else if (dep && dep.complete_through === null) {\n\t\tcompleteThrough = null;\n\t}\n\n\tconst gaps = findRangeGaps(\n\t\tranges,\n\t\tdeclaredRange.from_height,\n\t\tdeclaredRange.to_height,\n\t);\n\tconst tiled =\n\t\tgaps.length === 0 &&\n\t\tcompleteThrough !== null &&\n\t\tcompleteThrough >= declaredRange.to_height;\n\t// A single suffix still ahead of the prefix is unfinished work, not a hole.\n\tconst trailingGap =\n\t\tgaps.length === 1 &&\n\t\tgaps[0].to_height === declaredRange.to_height &&\n\t\t(completeThrough === null\n\t\t\t? gaps[0].from_height === declaredRange.from_height\n\t\t\t: gaps[0].from_height === completeThrough + 1);\n\n\tconst queueIncomplete =\n\t\tstage.native_clock === \"queue\" && !queueCaught(evidence.queue);\n\n\tif (gaps.length > 0 && !trailingGap) {\n\t\tconst first = gaps[0];\n\t\treturn done(\"gap\", `missing ${first.from_height}–${first.to_height}`, {\n\t\t\tcomplete_through: completeThrough,\n\t\t\tdeclared_range: declaredRange,\n\t\t\tgaps,\n\t\t\tcaught_up: false,\n\t\t});\n\t}\n\n\tif (queueIncomplete || !tiled) {\n\t\treturn done(\n\t\t\t\"syncing\",\n\t\t\t\"contiguous from start, not yet through the recorded target\",\n\t\t\t{\n\t\t\t\tcomplete_through: completeThrough,\n\t\t\t\tdeclared_range: declaredRange,\n\t\t\t\tgaps,\n\t\t\t\tcaught_up: false,\n\t\t\t},\n\t\t);\n\t}\n\n\tconst sourceStale = age !== null && age > maxAge;\n\tconst behindFinalized =\n\t\tfinalized !== null && completeThrough !== null\n\t\t\t? Math.max(0, finalized - completeThrough)\n\t\t\t: null;\n\tconst behindTip =\n\t\tsourceTip !== null && completeThrough !== null\n\t\t\t? Math.max(0, sourceTip - completeThrough)\n\t\t\t: null;\n\t// A target below the current finalized height is a pin, not a live follow.\n\t// That instance is complete through what it asked for — not lagging.\n\tconst pinned =\n\t\trecordedTarget !== null && finalized !== null && recordedTarget < finalized;\n\n\tif (sourceStale) {\n\t\treturn done(\n\t\t\t\"stale\",\n\t\t\t`source observation is ${age}s old, beyond the ${maxAge}s freshness objective`,\n\t\t\t{\n\t\t\t\tcomplete_through: completeThrough,\n\t\t\t\tdeclared_range: declaredRange,\n\t\t\t\tgaps,\n\t\t\t\tcaught_up: false,\n\t\t\t},\n\t\t);\n\t}\n\n\tif (behindFinalized !== null && behindFinalized > maxBehind) {\n\t\treturn done(\n\t\t\t\"stale\",\n\t\t\t`${behindFinalized} blocks behind the finalized height, beyond the ${maxBehind} threshold`,\n\t\t\t{\n\t\t\t\tcomplete_through: completeThrough,\n\t\t\t\tdeclared_range: declaredRange,\n\t\t\t\tgaps,\n\t\t\t\tcaught_up: false,\n\t\t\t},\n\t\t);\n\t}\n\n\tif (!pinned && behindFinalized !== null && behindFinalized > 0) {\n\t\treturn done(\n\t\t\t\"lagging\",\n\t\t\t`${behindFinalized} blocks behind the finalized height`,\n\t\t\t{\n\t\t\t\tcomplete_through: completeThrough,\n\t\t\t\tdeclared_range: declaredRange,\n\t\t\t\tgaps,\n\t\t\t\tcaught_up: false,\n\t\t\t},\n\t\t);\n\t}\n\n\tif (!pinned && behindTip !== null && behindTip > 0) {\n\t\treturn done(\"lagging\", `${behindTip} blocks behind the chain tip`, {\n\t\t\tcomplete_through: completeThrough,\n\t\t\tdeclared_range: declaredRange,\n\t\t\tgaps,\n\t\t});\n\t}\n\n\treturn done(\"complete\", \"processed every unit through the recorded target\", {\n\t\tcomplete_through: completeThrough,\n\t\tdeclared_range: declaredRange,\n\t\tgaps,\n\t});\n}\n\nexport function evaluateCoverage(input: EvaluatorInput): CoverageReport {\n\tconst { order, cycles } = topoSort(input.stages);\n\tconst cyclic = new Set(cycles.flat());\n\tconst known = new Set(input.stages.map((s) => s.id));\n\tconst runs = lastByStage(input.runs);\n\tconst evidence = lastByStage(input.evidence);\n\tconst byId = new Map(input.stages.map((s) => [s.id, s]));\n\tconst evaluated = new Map<string, StageCoverage>();\n\n\tconst visit = (id: string): void => {\n\t\tconst stage = byId.get(id);\n\t\tif (!stage || evaluated.has(id)) return;\n\t\tconst depId = stage.depends_on;\n\t\tconst missingDep = Boolean(depId && !known.has(depId));\n\t\tconst dep = depId && !missingDep ? (evaluated.get(depId) ?? null) : null;\n\t\tevaluated.set(\n\t\t\tid,\n\t\t\tevaluateOne(\n\t\t\t\tstage,\n\t\t\t\tinput,\n\t\t\t\truns.get(id),\n\t\t\t\tevidence.get(id) ?? emptyEvidence(id),\n\t\t\t\tdep,\n\t\t\t\tmissingDep,\n\t\t\t\tcyclic.has(id),\n\t\t\t),\n\t\t);\n\t};\n\n\tfor (const id of order) visit(id);\n\tfor (const id of cyclic) visit(id);\n\n\tconst stages = [...evaluated.values()].sort((a, b) =>\n\t\ta.stage_id.localeCompare(b.stage_id),\n\t);\n\n\treturn {\n\t\tschema_version: COVERAGE_REPORT_SCHEMA_VERSION,\n\t\tnetwork: input.scope.network,\n\t\tgenerated_at: input.options.now.toISOString(),\n\t\tsource_tip: input.source.tip_height,\n\t\tfinalized_height: input.source.finalized_height,\n\t\tstages,\n\t\tevaluation_order: order,\n\t\tcycles,\n\t};\n}\n",
|
|
8
8
|
"/**\n * Stage runner state machine.\n *\n * Pure. Adapters (P4.5+) persist the returned state and effects.\n * Acknowledgements are ordered; a reorg invalidates overlapping receipts\n * before any replacement ack is accepted. A version change cannot continue\n * the current run — it seals or halts and asks for a new one.\n */\n\nimport type { FailureClass, FailureUnit, RetryState } from \"./constraints.ts\";\nimport type { CoverageRange } from \"./constraints.ts\";\n\nexport const RUNNER_STATUSES = [\n\t\"pending\",\n\t\"running\",\n\t\"complete\",\n\t\"failed\",\n\t\"halted\",\n] as const;\nexport type RunnerStatus = (typeof RUNNER_STATUSES)[number];\n\nexport const RUNNER_EVENT_TYPES = [\n\t\"start\",\n\t\"ack\",\n\t\"fail\",\n\t\"retry\",\n\t\"halt\",\n\t\"resume\",\n\t\"reorg\",\n\t\"version\",\n\t\"finish\",\n] as const;\nexport type RunnerEventType = (typeof RUNNER_EVENT_TYPES)[number];\n\nexport const DEFAULT_MAX_RETRIES = 3;\n\nexport type RunnerVersion = {\n\tcode_hash: string;\n\tconfig_hash: string;\n\thandler_hash: string | null;\n};\n\nexport type RunnerFailure = {\n\tunit_kind: FailureUnit;\n\tclass: FailureClass;\n\tretry_state: Exclude<RetryState, \"resolved\">;\n\tfrom_height: number | null;\n\tto_height: number | null;\n\terror: string | null;\n};\n\nexport type RunnerState = {\n\tstage_id: string;\n\tstatus: RunnerStatus;\n\tversion: RunnerVersion;\n\tstart_height: number;\n\ttarget_height: number | null;\n\tcomplete_through: number | null;\n\tlast_acked_hash: string | null;\n\tretry_count: number;\n\topen_failure: RunnerFailure | null;\n};\n\nexport type RunnerEvent =\n\t| { type: \"start\" }\n\t| {\n\t\t\ttype: \"ack\";\n\t\t\theight: number;\n\t\t\thash: string;\n\t\t\tinput_count: number;\n\t\t\tinput_digest: string;\n\t\t\teffect_digest: string;\n\t }\n\t| {\n\t\t\ttype: \"fail\";\n\t\t\tunit_kind: FailureUnit;\n\t\t\tclass: FailureClass;\n\t\t\tfrom_height: number | null;\n\t\t\tto_height: number | null;\n\t\t\terror: string | null;\n\t }\n\t| { type: \"retry\" }\n\t| { type: \"halt\" }\n\t| { type: \"resume\" }\n\t| { type: \"reorg\"; fork_point: number }\n\t| { type: \"version\"; version: RunnerVersion }\n\t| { type: \"finish\" };\n\nexport type RunnerEffect =\n\t| { type: \"invalidate_receipts\"; range: CoverageRange }\n\t| { type: \"spawn_run\"; version: RunnerVersion }\n\t| { type: \"open_failure\"; failure: RunnerFailure }\n\t| { type: \"resolve_failure\" };\n\nexport type RunnerResult =\n\t| { ok: true; state: RunnerState; effects: RunnerEffect[] }\n\t| { ok: false; reason: string; state: RunnerState };\n\nexport type TransitionRule = {\n\tfrom: RunnerStatus;\n\tevent: RunnerEventType;\n\tto: RunnerStatus | \"reject\";\n};\n\n/**\n * Structural transition table. Guards (order, retry budget, version\n * equality, reorg overlap) are applied on top in `applyRunnerEvent`.\n */\nexport const RUNNER_TRANSITION_TABLE: readonly TransitionRule[] = [\n\t{ from: \"pending\", event: \"start\", to: \"running\" },\n\t{ from: \"pending\", event: \"ack\", to: \"reject\" },\n\t{ from: \"pending\", event: \"fail\", to: \"reject\" },\n\t{ from: \"pending\", event: \"retry\", to: \"reject\" },\n\t{ from: \"pending\", event: \"halt\", to: \"reject\" },\n\t{ from: \"pending\", event: \"resume\", to: \"reject\" },\n\t{ from: \"pending\", event: \"reorg\", to: \"reject\" },\n\t{ from: \"pending\", event: \"version\", to: \"pending\" },\n\t{ from: \"pending\", event: \"finish\", to: \"reject\" },\n\n\t{ from: \"running\", event: \"start\", to: \"reject\" },\n\t{ from: \"running\", event: \"ack\", to: \"running\" },\n\t{ from: \"running\", event: \"fail\", to: \"failed\" },\n\t{ from: \"running\", event: \"retry\", to: \"reject\" },\n\t{ from: \"running\", event: \"halt\", to: \"halted\" },\n\t{ from: \"running\", event: \"resume\", to: \"running\" },\n\t{ from: \"running\", event: \"reorg\", to: \"running\" },\n\t{ from: \"running\", event: \"version\", to: \"halted\" },\n\t{ from: \"running\", event: \"finish\", to: \"complete\" },\n\n\t{ from: \"complete\", event: \"start\", to: \"reject\" },\n\t{ from: \"complete\", event: \"ack\", to: \"reject\" },\n\t{ from: \"complete\", event: \"fail\", to: \"reject\" },\n\t{ from: \"complete\", event: \"retry\", to: \"reject\" },\n\t{ from: \"complete\", event: \"halt\", to: \"reject\" },\n\t{ from: \"complete\", event: \"resume\", to: \"reject\" },\n\t{ from: \"complete\", event: \"reorg\", to: \"running\" },\n\t{ from: \"complete\", event: \"version\", to: \"complete\" },\n\t{ from: \"complete\", event: \"finish\", to: \"complete\" },\n\n\t{ from: \"failed\", event: \"start\", to: \"reject\" },\n\t{ from: \"failed\", event: \"ack\", to: \"reject\" },\n\t{ from: \"failed\", event: \"fail\", to: \"reject\" },\n\t{ from: \"failed\", event: \"retry\", to: \"running\" },\n\t{ from: \"failed\", event: \"halt\", to: \"halted\" },\n\t{ from: \"failed\", event: \"resume\", to: \"running\" },\n\t{ from: \"failed\", event: \"reorg\", to: \"failed\" },\n\t{ from: \"failed\", event: \"version\", to: \"halted\" },\n\t{ from: \"failed\", event: \"finish\", to: \"reject\" },\n\n\t{ from: \"halted\", event: \"start\", to: \"reject\" },\n\t{ from: \"halted\", event: \"ack\", to: \"reject\" },\n\t{ from: \"halted\", event: \"fail\", to: \"reject\" },\n\t{ from: \"halted\", event: \"retry\", to: \"running\" },\n\t{ from: \"halted\", event: \"halt\", to: \"halted\" },\n\t{ from: \"halted\", event: \"resume\", to: \"running\" },\n\t{ from: \"halted\", event: \"reorg\", to: \"halted\" },\n\t{ from: \"halted\", event: \"version\", to: \"halted\" },\n\t{ from: \"halted\", event: \"finish\", to: \"reject\" },\n];\n\nconst RULE_INDEX = new Map<string, TransitionRule>(\n\tRUNNER_TRANSITION_TABLE.map((rule) => [`${rule.from}:${rule.event}`, rule]),\n);\n\nexport function lookupTransition(\n\tfrom: RunnerStatus,\n\tevent: RunnerEventType,\n): TransitionRule {\n\tconst rule = RULE_INDEX.get(`${from}:${event}`);\n\tif (!rule) {\n\t\tthrow new Error(`missing transition ${from} + ${event}`);\n\t}\n\treturn rule;\n}\n\nexport function versionsEqual(a: RunnerVersion, b: RunnerVersion): boolean {\n\treturn (\n\t\ta.code_hash === b.code_hash &&\n\t\ta.config_hash === b.config_hash &&\n\t\ta.handler_hash === b.handler_hash\n\t);\n}\n\n/** Next height this run must acknowledge. */\nexport function expectedAckHeight(state: RunnerState): number {\n\treturn state.complete_through === null\n\t\t? state.start_height\n\t\t: state.complete_through + 1;\n}\n\nexport function createRunnerState(init: {\n\tstage_id: string;\n\tstart_height: number;\n\ttarget_height?: number | null;\n\tversion: RunnerVersion;\n}): RunnerState {\n\treturn {\n\t\tstage_id: init.stage_id,\n\t\tstatus: \"pending\",\n\t\tversion: init.version,\n\t\tstart_height: init.start_height,\n\t\ttarget_height: init.target_height ?? null,\n\t\tcomplete_through: null,\n\t\tlast_acked_hash: null,\n\t\tretry_count: 0,\n\t\topen_failure: null,\n\t};\n}\n\nfunction ok(state: RunnerState, effects: RunnerEffect[] = []): RunnerResult {\n\treturn { ok: true, state, effects };\n}\n\nfunction reject(state: RunnerState, reason: string): RunnerResult {\n\treturn { ok: false, reason, state };\n}\n\nfunction clone(state: RunnerState, patch: Partial<RunnerState>): RunnerState {\n\treturn { ...state, ...patch };\n}\n\nfunction rewind(\n\tstate: RunnerState,\n\tforkPoint: number,\n): { next: RunnerState; effects: RunnerEffect[] } {\n\tconst from = Math.max(forkPoint, state.start_height);\n\tconst through = state.complete_through;\n\tif (through === null || through < from) {\n\t\treturn { next: state, effects: [] };\n\t}\n\tconst completeThrough = from <= state.start_height ? null : from - 1;\n\treturn {\n\t\tnext: clone(state, {\n\t\t\tcomplete_through: completeThrough,\n\t\t\tlast_acked_hash: null,\n\t\t}),\n\t\teffects: [\n\t\t\t{\n\t\t\t\ttype: \"invalidate_receipts\",\n\t\t\t\trange: { from_height: from, to_height: through },\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction applyRetry(state: RunnerState, maxRetries: number): RunnerResult {\n\tif (state.retry_count >= maxRetries) {\n\t\tconst failure = state.open_failure\n\t\t\t? { ...state.open_failure, retry_state: \"halted\" as const }\n\t\t\t: null;\n\t\treturn ok(clone(state, { status: \"halted\", open_failure: failure }));\n\t}\n\tconst failure = state.open_failure\n\t\t? { ...state.open_failure, retry_state: \"retrying\" as const }\n\t\t: null;\n\treturn ok(\n\t\tclone(state, {\n\t\t\tstatus: \"running\",\n\t\t\tretry_count: state.retry_count + 1,\n\t\t\topen_failure: failure,\n\t\t}),\n\t);\n}\n\nexport function applyRunnerEvent(\n\tstate: RunnerState,\n\tevent: RunnerEvent,\n\topts?: { maxRetries?: number },\n): RunnerResult {\n\tconst maxRetries = opts?.maxRetries ?? DEFAULT_MAX_RETRIES;\n\tconst rule = lookupTransition(state.status, event.type);\n\tif (rule.to === \"reject\") {\n\t\treturn reject(state, `${state.status} cannot ${event.type}`);\n\t}\n\tconst nextStatus = rule.to;\n\n\tswitch (event.type) {\n\t\tcase \"start\":\n\t\t\treturn ok(clone(state, { status: \"running\" }));\n\n\t\tcase \"ack\": {\n\t\t\tif (event.height === state.complete_through) {\n\t\t\t\tif (event.hash === state.last_acked_hash) return ok(state);\n\t\t\t\treturn reject(\n\t\t\t\t\tstate,\n\t\t\t\t\t`ack at ${event.height} has a different hash; reorg first`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst expected = expectedAckHeight(state);\n\t\t\tif (event.height !== expected) {\n\t\t\t\treturn reject(\n\t\t\t\t\tstate,\n\t\t\t\t\t`ack at ${event.height} skips ${expected}; acknowledgements must be ordered`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst effects: RunnerEffect[] = [];\n\t\t\tconst failure = state.open_failure;\n\t\t\tconst coversFailure =\n\t\t\t\tfailure &&\n\t\t\t\tfailure.from_height !== null &&\n\t\t\t\tevent.height >= failure.from_height &&\n\t\t\t\t(failure.to_height === null || event.height <= failure.to_height);\n\t\t\tif (coversFailure) effects.push({ type: \"resolve_failure\" });\n\t\t\treturn ok(\n\t\t\t\tclone(state, {\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tcomplete_through: event.height,\n\t\t\t\t\tlast_acked_hash: event.hash,\n\t\t\t\t\topen_failure: coversFailure ? null : failure,\n\t\t\t\t}),\n\t\t\t\teffects,\n\t\t\t);\n\t\t}\n\n\t\tcase \"fail\": {\n\t\t\tconst failure: RunnerFailure = {\n\t\t\t\tunit_kind: event.unit_kind,\n\t\t\t\tclass: event.class,\n\t\t\t\tretry_state: \"open\",\n\t\t\t\tfrom_height: event.from_height,\n\t\t\t\tto_height: event.to_height,\n\t\t\t\terror: event.error,\n\t\t\t};\n\t\t\treturn ok(clone(state, { status: \"failed\", open_failure: failure }), [\n\t\t\t\t{ type: \"open_failure\", failure },\n\t\t\t]);\n\t\t}\n\n\t\tcase \"retry\":\n\t\t\treturn applyRetry(state, maxRetries);\n\n\t\tcase \"halt\": {\n\t\t\tconst failure = state.open_failure\n\t\t\t\t? { ...state.open_failure, retry_state: \"halted\" as const }\n\t\t\t\t: state.open_failure;\n\t\t\treturn ok(clone(state, { status: \"halted\", open_failure: failure }));\n\t\t}\n\n\t\tcase \"resume\":\n\t\t\tif (state.status === \"running\") return ok(state);\n\t\t\tif (state.open_failure) return applyRetry(state, maxRetries);\n\t\t\treturn ok(clone(state, { status: \"running\" }));\n\n\t\tcase \"reorg\": {\n\t\t\tif (event.fork_point < state.start_height) {\n\t\t\t\treturn reject(\n\t\t\t\t\tstate,\n\t\t\t\t\t`reorg fork ${event.fork_point} is below start ${state.start_height}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst { next, effects } = rewind(state, event.fork_point);\n\t\t\tif (effects.length === 0) return ok(state);\n\t\t\treturn ok(clone(next, { status: nextStatus }), effects);\n\t\t}\n\n\t\tcase \"version\": {\n\t\t\tif (versionsEqual(state.version, event.version)) return ok(state);\n\t\t\tif (state.status === \"pending\") {\n\t\t\t\treturn ok(clone(state, { version: event.version }));\n\t\t\t}\n\t\t\tconst sealed: RunnerStatus =\n\t\t\t\tstate.status === \"complete\" ? \"complete\" : \"halted\";\n\t\t\treturn ok(clone(state, { status: sealed }), [\n\t\t\t\t{ type: \"spawn_run\", version: event.version },\n\t\t\t]);\n\t\t}\n\n\t\tcase \"finish\": {\n\t\t\tif (state.status === \"complete\") return ok(state);\n\t\t\tif (state.target_height === null) {\n\t\t\t\treturn reject(state, \"cannot finish a follow-the-chain run\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\tstate.complete_through === null ||\n\t\t\t\tstate.complete_through < state.target_height\n\t\t\t) {\n\t\t\t\treturn reject(\n\t\t\t\t\tstate,\n\t\t\t\t\t`cannot finish: complete_through ${state.complete_through} is short of target ${state.target_height}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn ok(clone(state, { status: \"complete\" }));\n\t\t}\n\t}\n}\n",
|
|
9
9
|
"/**\n * Decoder clock — pair Streams cursor order with per-block receipts.\n *\n * A filtered firehose can jump from `100:5` to `105:0` and never mention\n * 101–104. Coverage still needs a receipt for every canonical height,\n * including no-match blocks. This library is that seam: cursors stay\n * monotonic, receipts stay one-per-height, empty blocks still ack.\n *\n * Only fully closed blocks in `(from_cursor, to_cursor]` emit receipts.\n * Mid-block resumes wait until the cursor is past the block.\n */\n\nimport { createHash } from \"node:crypto\";\nimport {\n\ttype StreamsCursor,\n\tblockEndCursor,\n\tcompareStreamsCursor,\n\tdecodeStreamsCursor,\n\tencodeStreamsCursor,\n\tisEmptyRangeCursor,\n} from \"../streams-cursor.ts\";\n\nexport type CanonicalBlock = {\n\theight: number;\n\thash: string;\n};\n\nexport type DecoderClockEvent = {\n\tcursor: string;\n\tblock_hash: string;\n\tmatched: boolean;\n};\n\nexport type DecoderClockInput = {\n\tstart_height: number;\n\t/** Exclusive. Null = before `start_height`. */\n\tfrom_cursor: string | null;\n\t/** Exclusive high-water after this batch. */\n\tto_cursor: string;\n\tblocks: readonly CanonicalBlock[];\n\tevents: readonly DecoderClockEvent[];\n};\n\nexport type DecoderClockReceipt = {\n\theight: number;\n\thash: string;\n\tinput_count: number;\n\tinput_cursors: string[];\n\tinput_digest: string;\n\tthrough_cursor: string;\n\tno_match: boolean;\n};\n\nexport type DecoderClockResult =\n\t| { ok: true; receipts: DecoderClockReceipt[]; through_cursor: string }\n\t| { ok: false; reason: string; receipts: DecoderClockReceipt[] };\n\nexport function inputDigest(cursors: readonly string[]): string {\n\tif (cursors.length === 0) {\n\t\treturn createHash(\"sha256\").update(\"no-match\\n\").digest(\"hex\");\n\t}\n\tconst hash = createHash(\"sha256\");\n\tfor (const cursor of cursors) hash.update(`${cursor}\\n`);\n\treturn hash.digest(\"hex\");\n}\n\nexport function cursorIsAfterBlock(\n\tcursor: StreamsCursor,\n\theight: number,\n): boolean {\n\treturn compareStreamsCursor(cursor, blockEndCursor(height)) >= 0;\n}\n\n/** True when `from` is strictly before the first event that can live in `height`. */\nexport function cursorIsBeforeBlock(\n\tcursor: StreamsCursor,\n\theight: number,\n): boolean {\n\treturn cursor.block_height < height;\n}\n\nfunction parseCursor(\n\tvalue: string,\n\tlabel: string,\n): { ok: true; cursor: StreamsCursor } | { ok: false; reason: string } {\n\ttry {\n\t\treturn { ok: true, cursor: decodeStreamsCursor(value) };\n\t} catch {\n\t\treturn { ok: false, reason: `${label} is not a valid streams cursor` };\n\t}\n}\n\nexport function planDecoderReceipts(\n\tinput: DecoderClockInput,\n): DecoderClockResult {\n\tconst to = parseCursor(input.to_cursor, \"to_cursor\");\n\tif (!to.ok) return { ok: false, reason: to.reason, receipts: [] };\n\n\tlet from: StreamsCursor | null = null;\n\tif (input.from_cursor !== null) {\n\t\tconst parsed = parseCursor(input.from_cursor, \"from_cursor\");\n\t\tif (!parsed.ok) return { ok: false, reason: parsed.reason, receipts: [] };\n\t\tfrom = parsed.cursor;\n\t\tif (compareStreamsCursor(from, to.cursor) >= 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: \"to_cursor must be after from_cursor\",\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t}\n\n\t// A mid-block from_cursor (100:2) or a closed one (100:SENTINEL) both\n\t// mean the next fully-visible block is 101. Receipts are whole blocks.\n\tconst startFull = from === null ? input.start_height : from.block_height + 1;\n\tconst lastFull = isEmptyRangeCursor(to.cursor)\n\t\t? to.cursor.block_height\n\t\t: to.cursor.block_height - 1;\n\n\tif (lastFull < startFull) {\n\t\treturn { ok: true, receipts: [], through_cursor: input.to_cursor };\n\t}\n\n\tif (startFull < input.start_height) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `window starts at ${startFull}, below start_height ${input.start_height}`,\n\t\t\treceipts: [],\n\t\t};\n\t}\n\n\tconst byHeight = new Map<number, CanonicalBlock>();\n\tlet prevHeight: number | null = null;\n\tfor (const block of input.blocks) {\n\t\tif (prevHeight !== null && block.height !== prevHeight + 1) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `blocks are not contiguous (${prevHeight} → ${block.height})`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tif (byHeight.has(block.height)) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `duplicate canonical height ${block.height}`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tbyHeight.set(block.height, block);\n\t\tprevHeight = block.height;\n\t}\n\n\tfor (let height = startFull; height <= lastFull; height++) {\n\t\tif (!byHeight.has(height)) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `missing canonical block ${height}`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t}\n\n\tconst decoded: {\n\t\tcursor: StreamsCursor;\n\t\tencoded: string;\n\t\tblock_hash: string;\n\t\tmatched: boolean;\n\t}[] = [];\n\tlet previous: StreamsCursor | null = from;\n\tfor (const event of input.events) {\n\t\tconst parsed = parseCursor(event.cursor, \"event.cursor\");\n\t\tif (!parsed.ok) return { ok: false, reason: parsed.reason, receipts: [] };\n\t\tif (previous && compareStreamsCursor(parsed.cursor, previous) <= 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `event cursor ${event.cursor} is not after ${encodeStreamsCursor(previous)}`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tif (compareStreamsCursor(parsed.cursor, to.cursor) >= 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `event cursor ${event.cursor} is not before to_cursor`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tif (from && compareStreamsCursor(parsed.cursor, from) <= 0) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `event cursor ${event.cursor} is not after from_cursor`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tconst block = byHeight.get(parsed.cursor.block_height);\n\t\tif (!block) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `event ${event.cursor} has no canonical block`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tif (block.hash !== event.block_hash) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `event ${event.cursor} hash ${event.block_hash} does not match canonical ${block.hash}`,\n\t\t\t\treceipts: [],\n\t\t\t};\n\t\t}\n\t\tdecoded.push({\n\t\t\tcursor: parsed.cursor,\n\t\t\tencoded: event.cursor,\n\t\t\tblock_hash: event.block_hash,\n\t\t\tmatched: event.matched,\n\t\t});\n\t\tprevious = parsed.cursor;\n\t}\n\n\tconst receipts: DecoderClockReceipt[] = [];\n\tfor (let height = startFull; height <= lastFull; height++) {\n\t\tconst block = byHeight.get(height);\n\t\tif (!block) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `missing canonical block ${height}`,\n\t\t\t\treceipts,\n\t\t\t};\n\t\t}\n\t\tconst inBlock = decoded.filter((e) => e.cursor.block_height === height);\n\t\tconst matched = inBlock.filter((e) => e.matched);\n\t\tconst last = inBlock[inBlock.length - 1];\n\t\tconst through = last\n\t\t\t? last.encoded\n\t\t\t: encodeStreamsCursor(blockEndCursor(height));\n\t\treceipts.push({\n\t\t\theight,\n\t\t\thash: block.hash,\n\t\t\tinput_count: matched.length,\n\t\t\tinput_cursors: matched.map((e) => e.encoded),\n\t\t\tinput_digest: inputDigest(matched.map((e) => e.encoded)),\n\t\t\tthrough_cursor: through,\n\t\t\tno_match: matched.length === 0,\n\t\t});\n\t}\n\n\treturn { ok: true, receipts, through_cursor: input.to_cursor };\n}\n",
|
|
10
|
-
"/**\n * Atomic decoder adapter.\n *\n * One transaction writes decoded output, the decoder checkpoint, block\n * receipts, and an optional failure. A crash after any step rolls all\n * four back — the property `commitDecodedBatch` already had for rows+\n * checkpoint, now covering the coverage kernel too.\n *\n * `crashAfter` is a test probe. It throws inside the transaction so the\n * matrix can abort after each step without simulating a real process kill.\n */\n\nimport type { Kysely } from \"kysely\";\nimport type { Database } from \"../db/types.ts\";\nimport type { FailureClass, FailureUnit, RetryState } from \"./constraints.ts\";\nimport type { DecoderClockReceipt } from \"./decoder-clock.ts\";\nimport {\n\ttype RunnerEvent,\n\ttype RunnerResult,\n\ttype RunnerState,\n\tapplyRunnerEvent,\n} from \"./runner.ts\";\n\nexport const DECODER_COMMIT_STEPS = [\n\t\"output\",\n\t\"checkpoint\",\n\t\"receipt\",\n\t\"failure\",\n] as const;\nexport type DecoderCommitStep = (typeof DECODER_COMMIT_STEPS)[number];\n\nexport class DecoderAdapterCrash extends Error {\n\treadonly name = \"DecoderAdapterCrash\";\n\tconstructor(readonly step: DecoderCommitStep) {\n\t\tsuper(`decoder adapter crash after ${step}`);\n\t}\n}\n\nexport type DecoderAdapterFailure = {\n\tunit_kind: FailureUnit;\n\tclass: FailureClass;\n\tretry_state: Exclude<RetryState, \"resolved\">;\n\tfrom_height: number | null;\n\tto_height: number | null;\n\terror: string | null;\n\tretry_count?: number;\n};\n\nexport type DecoderAdapterReceipt = DecoderClockReceipt & {\n\teffect_digest: string;\n};\n\nexport type DecoderAdapterCommit = {\n\tstage_id: string;\n\trun_id?: string | null;\n\tdecoder_name: string;\n\t/** Null = do not move the checkpoint (empty page). */\n\tcheckpoint_cursor: string | null;\n\treceipts: readonly DecoderAdapterReceipt[];\n\tfailure?: DecoderAdapterFailure | null;\n\twriteOutput: (tx: Kysely<Database>) => Promise<void>;\n\tcrashAfter?: DecoderCommitStep;\n};\n\nexport async function runDecoderCommitSteps(\n\tsteps: Record<DecoderCommitStep, () => Promise<void>>,\n\tcrashAfter?: DecoderCommitStep,\n): Promise<void> {\n\tfor (const step of DECODER_COMMIT_STEPS) {\n\t\tawait steps[step]();\n\t\tif (crashAfter === step) throw new DecoderAdapterCrash(step);\n\t}\n}\n\nexport function applyDecoderReceipts(\n\tstate: RunnerState,\n\treceipts: readonly DecoderAdapterReceipt[],\n): RunnerResult {\n\tlet current = state;\n\tif (current.status === \"pending\") {\n\t\tconst started = applyRunnerEvent(current, { type: \"start\" });\n\t\tif (!started.ok) return started;\n\t\tcurrent = started.state;\n\t}\n\tfor (const receipt of receipts) {\n\t\tconst event: RunnerEvent = {\n\t\t\ttype: \"ack\",\n\t\t\theight: receipt.height,\n\t\t\thash: receipt.hash,\n\t\t\tinput_count: receipt.input_count,\n\t\t\tinput_digest: receipt.input_digest,\n\t\t\teffect_digest: receipt.effect_digest,\n\t\t};\n\t\tconst next = applyRunnerEvent(current, event);\n\t\tif (!next.ok) return next;\n\t\tcurrent = next.state;\n\t}\n\treturn { ok: true, state: current, effects: [] };\n}\n\nasync function upsertRegistry(\n\ttx: Kysely<Database>,\n\tstageId: string,\n): Promise<void> {\n\tawait tx\n\t\t.insertInto(\"stage_registry\")\n\t\t.values({\n\t\t\tid: stageId,\n\t\t\tkind: \"decode\",\n\t\t\tdepends_on: null,\n\t\t\tnative_clock: \"block\",\n\t\t\tproducer_version: \"v1\",\n\t\t\trepair_mode: \"full_reindex\",\n\t\t})\n\t\t.onConflict((oc) => oc.column(\"id\").doNothing())\n\t\t.execute();\n}\n\nasync function writeCheckpoint(\n\ttx: Kysely<Database>,\n\tdecoderName: string,\n\tcursor: string | null,\n): Promise<void> {\n\tif (cursor === null) return;\n\tawait tx\n\t\t.insertInto(\"decoder_checkpoints\")\n\t\t.values({\n\t\t\tdecoder_name: decoderName,\n\t\t\tlast_cursor: cursor,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.column(\"decoder_name\").doUpdateSet({\n\t\t\t\tlast_cursor: cursor,\n\t\t\t\tupdated_at: new Date(),\n\t\t\t}),\n\t\t)\n\t\t.execute();\n}\n\nasync function writeReceipts(\n\ttx: Kysely<Database>,\n\tstageId: string,\n\trunId: string | null,\n\treceipts: readonly DecoderAdapterReceipt[],\n): Promise<void> {\n\tif (receipts.length === 0) return;\n\tawait tx\n\t\t.insertInto(\"stage_block_receipts\")\n\t\t.values(\n\t\t\treceipts.map((receipt) => ({\n\t\t\t\tstage_id: stageId,\n\t\t\t\trun_id: runId,\n\t\t\t\tblock_height: receipt.height,\n\t\t\t\tblock_hash: receipt.hash,\n\t\t\t\tinput_count: receipt.input_count,\n\t\t\t\tinput_digest: receipt.input_digest,\n\t\t\t\teffect_digest: receipt.effect_digest,\n\t\t\t})),\n\t\t)\n\t\t.onConflict((oc) =>\n\t\t\toc\n\t\t\t\t.columns([\"stage_id\", \"block_height\", \"block_hash\"])\n\t\t\t\t.doUpdateSet((eb) => ({\n\t\t\t\t\tinput_count: eb.ref(\"excluded.input_count\"),\n\t\t\t\t\tinput_digest: eb.ref(\"excluded.input_digest\"),\n\t\t\t\t\teffect_digest: eb.ref(\"excluded.effect_digest\"),\n\t\t\t\t\trun_id: eb.ref(\"excluded.run_id\"),\n\t\t\t\t})),\n\t\t)\n\t\t.execute();\n}\n\nasync function writeFailure(\n\ttx: Kysely<Database>,\n\tstageId: string,\n\trunId: string | null,\n\tfailure: DecoderAdapterFailure,\n): Promise<void> {\n\tawait tx\n\t\t.insertInto(\"stage_failures\")\n\t\t.values({\n\t\t\tstage_id: stageId,\n\t\t\trun_id: runId,\n\t\t\tunit_kind: failure.unit_kind,\n\t\t\tfrom_height: failure.from_height,\n\t\t\tto_height: failure.to_height,\n\t\t\tclass: failure.class,\n\t\t\tretry_state: failure.retry_state,\n\t\t\tretry_count: failure.retry_count ?? 0,\n\t\t\tlast_error: failure.error,\n\t\t})\n\t\t.execute();\n}\n\n/**\n * Persist output + checkpoint + receipts + failure in one transaction.\n * Runner validation is the caller's job (`applyDecoderReceipts`) so a\n * rejected ack never opens a transaction.\n */\nexport async function commitDecoderAdapter(\n\tdb: Kysely<Database>,\n\tinput: DecoderAdapterCommit,\n): Promise<void> {\n\tconst runId = input.run_id ?? null;\n\tconst failure = input.failure ?? null;\n\tawait db.transaction().execute(async (tx) => {\n\t\tawait upsertRegistry(tx, input.stage_id);\n\t\tawait runDecoderCommitSteps(\n\t\t\t{\n\t\t\t\toutput: () => input.writeOutput(tx),\n\t\t\t\tcheckpoint: () =>\n\t\t\t\t\twriteCheckpoint(tx, input.decoder_name, input.checkpoint_cursor),\n\t\t\t\treceipt: () => writeReceipts(tx, input.stage_id, runId, input.receipts),\n\t\t\t\tfailure: () =>\n\t\t\t\t\tfailure\n\t\t\t\t\t\t? writeFailure(tx, input.stage_id, runId, failure)\n\t\t\t\t\t\t: Promise.resolve(),\n\t\t\t},\n\t\t\tinput.crashAfter,\n\t\t);\n\t});\n}\n",
|
|
10
|
+
"/**\n * Atomic decoder adapter.\n *\n * One transaction writes decoded output, the decoder checkpoint, block\n * receipts, and an optional failure. A crash after any step rolls all\n * four back — the property `commitDecodedBatch` already had for rows+\n * checkpoint, now covering the coverage kernel too.\n *\n * `crashAfter` is a test probe. It throws inside the transaction so the\n * matrix can abort after each step without simulating a real process kill.\n */\n\nimport { sql } from \"kysely\";\nimport type { Kysely } from \"kysely\";\nimport type { Database } from \"../db/types.ts\";\nimport type { FailureClass, FailureUnit, RetryState } from \"./constraints.ts\";\nimport type { DecoderClockReceipt } from \"./decoder-clock.ts\";\nimport {\n\ttype RunnerEvent,\n\ttype RunnerResult,\n\ttype RunnerState,\n\tapplyRunnerEvent,\n} from \"./runner.ts\";\n\nexport const DECODER_COMMIT_STEPS = [\n\t\"output\",\n\t\"checkpoint\",\n\t\"receipt\",\n\t\"failure\",\n] as const;\nexport type DecoderCommitStep = (typeof DECODER_COMMIT_STEPS)[number];\n\nexport class DecoderAdapterCrash extends Error {\n\treadonly name = \"DecoderAdapterCrash\";\n\tconstructor(readonly step: DecoderCommitStep) {\n\t\tsuper(`decoder adapter crash after ${step}`);\n\t}\n}\n\nexport type DecoderAdapterFailure = {\n\tunit_kind: FailureUnit;\n\tclass: FailureClass;\n\tretry_state: Exclude<RetryState, \"resolved\">;\n\tfrom_height: number | null;\n\tto_height: number | null;\n\terror: string | null;\n\tretry_count?: number;\n};\n\nexport type DecoderAdapterReceipt = DecoderClockReceipt & {\n\teffect_digest: string;\n};\n\nexport type DecoderAdapterCommit = {\n\tstage_id: string;\n\trun_id?: string | null;\n\tdecoder_name: string;\n\t/** Null = do not move the checkpoint (empty page). */\n\tcheckpoint_cursor: string | null;\n\treceipts: readonly DecoderAdapterReceipt[];\n\tfailure?: DecoderAdapterFailure | null;\n\twriteOutput: (tx: Kysely<Database>) => Promise<void>;\n\tcrashAfter?: DecoderCommitStep;\n};\n\nexport async function runDecoderCommitSteps(\n\tsteps: Record<DecoderCommitStep, () => Promise<void>>,\n\tcrashAfter?: DecoderCommitStep,\n): Promise<void> {\n\tfor (const step of DECODER_COMMIT_STEPS) {\n\t\tawait steps[step]();\n\t\tif (crashAfter === step) throw new DecoderAdapterCrash(step);\n\t}\n}\n\nexport function applyDecoderReceipts(\n\tstate: RunnerState,\n\treceipts: readonly DecoderAdapterReceipt[],\n): RunnerResult {\n\tlet current = state;\n\tif (current.status === \"pending\") {\n\t\tconst started = applyRunnerEvent(current, { type: \"start\" });\n\t\tif (!started.ok) return started;\n\t\tcurrent = started.state;\n\t}\n\tfor (const receipt of receipts) {\n\t\tconst event: RunnerEvent = {\n\t\t\ttype: \"ack\",\n\t\t\theight: receipt.height,\n\t\t\thash: receipt.hash,\n\t\t\tinput_count: receipt.input_count,\n\t\t\tinput_digest: receipt.input_digest,\n\t\t\teffect_digest: receipt.effect_digest,\n\t\t};\n\t\tconst next = applyRunnerEvent(current, event);\n\t\tif (!next.ok) return next;\n\t\tcurrent = next.state;\n\t}\n\treturn { ok: true, state: current, effects: [] };\n}\n\nasync function upsertRegistry(\n\ttx: Kysely<Database>,\n\tstageId: string,\n): Promise<void> {\n\tawait tx\n\t\t.insertInto(\"stage_registry\")\n\t\t.values({\n\t\t\tid: stageId,\n\t\t\tkind: \"decode\",\n\t\t\tdepends_on: null,\n\t\t\tnative_clock: \"block\",\n\t\t\tproducer_version: \"v1\",\n\t\t\trepair_mode: \"full_reindex\",\n\t\t})\n\t\t.onConflict((oc) => oc.column(\"id\").doNothing())\n\t\t.execute();\n}\n\nasync function writeCheckpoint(\n\ttx: Kysely<Database>,\n\tdecoderName: string,\n\tcursor: string | null,\n): Promise<void> {\n\tif (cursor === null) return;\n\tawait tx\n\t\t.insertInto(\"decoder_checkpoints\")\n\t\t.values({\n\t\t\tdecoder_name: decoderName,\n\t\t\tlast_cursor: cursor,\n\t\t})\n\t\t.onConflict((oc) =>\n\t\t\toc.column(\"decoder_name\").doUpdateSet({\n\t\t\t\tlast_cursor: cursor,\n\t\t\t\tupdated_at: new Date(),\n\t\t\t}),\n\t\t)\n\t\t.execute();\n\n\t// Every decoder (classic + protocol) funnels its checkpoint write through\n\t// here, so this is the one place a `index:tip` NOTIFY can cover the whole\n\t// decoder set. Postgres defers delivery until the transaction commits,\n\t// so a rewound/rolled-back commit never fires it. A caller (the Index\n\t// API's long-poll wake, plan-063) only needs to know \"something committed,\n\t// go recheck\" — it re-reads the real committed height itself, so the\n\t// payload doesn't need to be more specific than the decoder name.\n\tawait sql`SELECT pg_notify('index:tip', ${decoderName})`.execute(tx);\n}\n\nasync function writeReceipts(\n\ttx: Kysely<Database>,\n\tstageId: string,\n\trunId: string | null,\n\treceipts: readonly DecoderAdapterReceipt[],\n): Promise<void> {\n\tif (receipts.length === 0) return;\n\tawait tx\n\t\t.insertInto(\"stage_block_receipts\")\n\t\t.values(\n\t\t\treceipts.map((receipt) => ({\n\t\t\t\tstage_id: stageId,\n\t\t\t\trun_id: runId,\n\t\t\t\tblock_height: receipt.height,\n\t\t\t\tblock_hash: receipt.hash,\n\t\t\t\tinput_count: receipt.input_count,\n\t\t\t\tinput_digest: receipt.input_digest,\n\t\t\t\teffect_digest: receipt.effect_digest,\n\t\t\t})),\n\t\t)\n\t\t.onConflict((oc) =>\n\t\t\toc\n\t\t\t\t.columns([\"stage_id\", \"block_height\", \"block_hash\"])\n\t\t\t\t.doUpdateSet((eb) => ({\n\t\t\t\t\tinput_count: eb.ref(\"excluded.input_count\"),\n\t\t\t\t\tinput_digest: eb.ref(\"excluded.input_digest\"),\n\t\t\t\t\teffect_digest: eb.ref(\"excluded.effect_digest\"),\n\t\t\t\t\trun_id: eb.ref(\"excluded.run_id\"),\n\t\t\t\t})),\n\t\t)\n\t\t.execute();\n}\n\nasync function writeFailure(\n\ttx: Kysely<Database>,\n\tstageId: string,\n\trunId: string | null,\n\tfailure: DecoderAdapterFailure,\n): Promise<void> {\n\tawait tx\n\t\t.insertInto(\"stage_failures\")\n\t\t.values({\n\t\t\tstage_id: stageId,\n\t\t\trun_id: runId,\n\t\t\tunit_kind: failure.unit_kind,\n\t\t\tfrom_height: failure.from_height,\n\t\t\tto_height: failure.to_height,\n\t\t\tclass: failure.class,\n\t\t\tretry_state: failure.retry_state,\n\t\t\tretry_count: failure.retry_count ?? 0,\n\t\t\tlast_error: failure.error,\n\t\t})\n\t\t.execute();\n}\n\n/**\n * Persist output + checkpoint + receipts + failure in one transaction.\n * Runner validation is the caller's job (`applyDecoderReceipts`) so a\n * rejected ack never opens a transaction.\n */\nexport async function commitDecoderAdapter(\n\tdb: Kysely<Database>,\n\tinput: DecoderAdapterCommit,\n): Promise<void> {\n\tconst runId = input.run_id ?? null;\n\tconst failure = input.failure ?? null;\n\tawait db.transaction().execute(async (tx) => {\n\t\tawait upsertRegistry(tx, input.stage_id);\n\t\tawait runDecoderCommitSteps(\n\t\t\t{\n\t\t\t\toutput: () => input.writeOutput(tx),\n\t\t\t\tcheckpoint: () =>\n\t\t\t\t\twriteCheckpoint(tx, input.decoder_name, input.checkpoint_cursor),\n\t\t\t\treceipt: () => writeReceipts(tx, input.stage_id, runId, input.receipts),\n\t\t\t\tfailure: () =>\n\t\t\t\t\tfailure\n\t\t\t\t\t\t? writeFailure(tx, input.stage_id, runId, failure)\n\t\t\t\t\t\t: Promise.resolve(),\n\t\t\t},\n\t\t\tinput.crashAfter,\n\t\t);\n\t});\n}\n",
|
|
11
11
|
"/**\n * Segment sealer — compact only finalized receipts after recomputing\n * range digests. A crash or deep reorg must not leave a sealed green\n * range over unfinalized or invalidated receipts.\n */\n\nimport { createHash } from \"node:crypto\";\nimport type { CoverageRange } from \"./constraints.ts\";\nimport type { DecoderClockReceipt } from \"./decoder-clock.ts\";\n\nexport type SealableReceipt = {\n\theight: number;\n\thash: string;\n\tinput_digest: string;\n\teffect_digest: string;\n\tfinalized: boolean;\n};\n\nexport type SealedSegment = {\n\tfrom_height: number;\n\tto_height: number;\n\tchain_digest: string;\n\tinput_digest: string;\n\toutput_digest: string;\n};\n\nexport type SealResult =\n\t| { ok: true; segment: SealedSegment; compacted: number }\n\t| { ok: false; reason: string };\n\nexport function rangeDigestOf(parts: readonly string[]): string {\n\tconst hash = createHash(\"sha256\");\n\tfor (const part of parts) hash.update(`${part}\\n`);\n\treturn hash.digest(\"hex\");\n}\n\nexport function sealFinalizedRange(\n\treceipts: readonly SealableReceipt[],\n\trange: CoverageRange,\n): SealResult {\n\tconst inRange = receipts\n\t\t.filter((r) => r.height >= range.from_height && r.height <= range.to_height)\n\t\t.sort((a, b) => a.height - b.height);\n\tif (inRange.length === 0) {\n\t\treturn { ok: false, reason: \"no receipts in range\" };\n\t}\n\tlet expected = range.from_height;\n\tfor (const receipt of inRange) {\n\t\tif (!receipt.finalized) {\n\t\t\treturn { ok: false, reason: `unfinalized receipt at ${receipt.height}` };\n\t\t}\n\t\tif (receipt.height !== expected) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\treason: `gap at ${expected} before ${receipt.height}`,\n\t\t\t};\n\t\t}\n\t\texpected += 1;\n\t}\n\tif (inRange[inRange.length - 1]?.height !== range.to_height) {\n\t\treturn { ok: false, reason: \"range is not fully covered\" };\n\t}\n\treturn {\n\t\tok: true,\n\t\tcompacted: inRange.length,\n\t\tsegment: {\n\t\t\tfrom_height: range.from_height,\n\t\t\tto_height: range.to_height,\n\t\t\tchain_digest: rangeDigestOf(inRange.map((r) => `${r.height}:${r.hash}`)),\n\t\t\tinput_digest: rangeDigestOf(inRange.map((r) => r.input_digest)),\n\t\t\toutput_digest: rangeDigestOf(inRange.map((r) => r.effect_digest)),\n\t\t},\n\t};\n}\n\n/** After a reorg at `fork`, any sealed segment that overlaps cannot stay green. */\nexport function segmentsSurviveReorg(\n\tsegments: readonly SealedSegment[],\n\tfork: number,\n): SealedSegment[] {\n\treturn segments.filter((s) => s.to_height < fork);\n}\n\nexport function receiptsAfterReorg(\n\treceipts: readonly SealableReceipt[],\n\tfork: number,\n): SealableReceipt[] {\n\treturn receipts.filter((r) => r.height < fork);\n}\n\nexport type ClockReceipt = DecoderClockReceipt;\n",
|
|
12
12
|
"/**\n * Effect manifests — canonical hash of ordered subgraph mutations per block.\n * Retry and equivalent reorderings of the same ops are stable; a historical\n * defect (different op, table, key, or value) differs.\n */\n\nimport { createHash } from \"node:crypto\";\n\nexport type EffectOp = \"insert\" | \"update\" | \"delete\" | \"increment\";\n\nexport type EffectMutation = {\n\top: EffectOp;\n\ttable: string;\n\tkey: Record<string, string | number | boolean | null>;\n\tvalue?: Record<string, string | number | boolean | null>;\n};\n\nexport function canonicalizeMutations(\n\tops: readonly EffectMutation[],\n): EffectMutation[] {\n\treturn ops.map((op) => ({\n\t\top: op.op,\n\t\ttable: op.table,\n\t\tkey: sortRecord(op.key),\n\t\tvalue: op.value ? sortRecord(op.value) : undefined,\n\t}));\n}\n\nfunction sortRecord(\n\trecord: Record<string, string | number | boolean | null>,\n): Record<string, string | number | boolean | null> {\n\tconst out: Record<string, string | number | boolean | null> = {};\n\tfor (const key of Object.keys(record).sort()) out[key] = record[key] ?? null;\n\treturn out;\n}\n\nexport function hashEffectManifest(ops: readonly EffectMutation[]): string {\n\tconst canonical = canonicalizeMutations(ops);\n\tconst hash = createHash(\"sha256\");\n\thash.update(JSON.stringify(canonical));\n\treturn hash.digest(\"hex\");\n}\n\nexport function manifestsEqual(\n\ta: readonly EffectMutation[],\n\tb: readonly EffectMutation[],\n): boolean {\n\treturn hashEffectManifest(a) === hashEffectManifest(b);\n}\n",
|
|
13
13
|
"/**\n * Atomic subgraph adapter — commit effects, rows, journal, cursor,\n * receipt, and failure in one transaction.\n */\n\nimport type { DecoderAdapterFailure } from \"./adapter.ts\";\nimport type { DecoderClockReceipt } from \"./decoder-clock.ts\";\nimport type { EffectMutation } from \"./effect-manifest.ts\";\n\nexport const SUBGRAPH_COMMIT_STEPS = [\n\t\"effects\",\n\t\"rows\",\n\t\"journal\",\n\t\"cursor\",\n\t\"receipt\",\n\t\"failure\",\n] as const;\nexport type SubgraphCommitStep = (typeof SUBGRAPH_COMMIT_STEPS)[number];\n\nexport class SubgraphAdapterCrash extends Error {\n\treadonly name = \"SubgraphAdapterCrash\";\n\tconstructor(readonly step: SubgraphCommitStep) {\n\t\tsuper(`subgraph adapter crash after ${step}`);\n\t}\n}\n\nexport type SubgraphCommitInput = {\n\tstage_id: string;\n\teffects: readonly EffectMutation[];\n\treceipts: readonly (DecoderClockReceipt & { effect_digest: string })[];\n\tfailure?: DecoderAdapterFailure | null;\n\twriteEffects: () => Promise<void>;\n\twriteRows: () => Promise<void>;\n\twriteJournal: () => Promise<void>;\n\twriteCursor: () => Promise<void>;\n\twriteReceipts: () => Promise<void>;\n\twriteFailure: () => Promise<void>;\n\tcrashAfter?: SubgraphCommitStep;\n};\n\nexport async function runSubgraphCommitSteps(\n\tsteps: Record<SubgraphCommitStep, () => Promise<void>>,\n\tcrashAfter?: SubgraphCommitStep,\n): Promise<void> {\n\tfor (const step of SUBGRAPH_COMMIT_STEPS) {\n\t\tawait steps[step]();\n\t\tif (crashAfter === step) throw new SubgraphAdapterCrash(step);\n\t}\n}\n\nexport async function commitSubgraphAdapter(\n\tinput: SubgraphCommitInput,\n\twrap: (fn: () => Promise<void>) => Promise<void> = (fn) => fn(),\n): Promise<void> {\n\tawait wrap(() =>\n\t\trunSubgraphCommitSteps(\n\t\t\t{\n\t\t\t\teffects: input.writeEffects,\n\t\t\t\trows: input.writeRows,\n\t\t\t\tjournal: input.writeJournal,\n\t\t\t\tcursor: input.writeCursor,\n\t\t\t\treceipt: input.writeReceipts,\n\t\t\t\tfailure: input.writeFailure,\n\t\t\t},\n\t\t\tinput.crashAfter,\n\t\t),\n\t);\n}\n",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"/**\n * Repair SAFETY GATE — decides whether a proposed repair is allowed to run.\n * Only registered safe modes pass; unsafe ranges and mode/defect mismatches are\n * refused.\n *\n * This file plans and refuses. It does not repair. The executor that actually\n * writes is `secondlayer repair --apply` (packages/cli/src/commands/repair.ts),\n * which rewrites blocks from a signed archive inside a transaction.\n *\n * There used to be an `applyRepair` here that returned `{applied: true}`\n * without touching anything. It was removed in 2026-08 rather than\n * implemented: a second executor would have been a fake one, and drills that\n * \"recovered\" through it would have proven nothing.\n */\n\nimport type { RepairMode } from \"./constraints.ts\";\nimport type { CoverageRange } from \"./constraints.ts\";\n\nexport const SAFE_REPAIR_MODES: readonly RepairMode[] = [\n\t\"range_safe\",\n\t\"full_reindex\",\n\t\"archive_replay\",\n];\n\nexport type RepairDefect =\n\t| \"gap\"\n\t| \"digest_mismatch\"\n\t| \"omission\"\n\t| \"version\"\n\t| \"reorg\"\n\t| \"source_gap\";\n\nexport type RepairPlan = {\n\tstage_id: string;\n\trange: CoverageRange;\n\tmode: RepairMode;\n\tdefect: RepairDefect;\n\tsafe: boolean;\n\treason: string;\n};\n\nexport function planRepair(input: {\n\tstage_id: string;\n\trange: CoverageRange;\n\tmode: RepairMode;\n\tdefect: RepairDefect;\n\trange_safe_proven?: boolean;\n}): RepairPlan {\n\tif (input.range.from_height > input.range.to_height) {\n\t\treturn {\n\t\t\t...input,\n\t\t\tsafe: false,\n\t\t\treason: \"inverted range\",\n\t\t};\n\t}\n\tif (!(SAFE_REPAIR_MODES as readonly string[]).includes(input.mode)) {\n\t\treturn {\n\t\t\t...input,\n\t\t\tsafe: false,\n\t\t\treason: `mode ${input.mode} is not registered`,\n\t\t};\n\t}\n\tif (input.mode === \"range_safe\" && !input.range_safe_proven) {\n\t\treturn {\n\t\t\t...input,\n\t\t\tsafe: false,\n\t\t\treason: \"range_safe requires a proven range\",\n\t\t};\n\t}\n\tif (input.defect === \"source_gap\" && input.mode !== \"archive_replay\") {\n\t\treturn {\n\t\t\t...input,\n\t\t\tsafe: false,\n\t\t\treason: \"raw/source gaps require archive_replay\",\n\t\t};\n\t}\n\treturn {\n\t\t...input,\n\t\tsafe: true,\n\t\treason: `dry-run ${input.mode} for ${input.defect}`,\n\t};\n}\n",
|
|
18
18
|
"/**\n * Unified verify targets — library used by CLI (and REST later).\n * Exit codes match `sl verify`: 0 clean, 1 diverged, 2 unanchored.\n */\n\nexport const VERIFY_EXIT = {\n\tCLEAN: 0,\n\tDIVERGED: 1,\n\tUNANCHORED: 2,\n} as const;\nexport type VerifyExit = (typeof VERIFY_EXIT)[keyof typeof VERIFY_EXIT];\n\nexport type VerifyTarget =\n\t| { kind: \"all\" }\n\t| { kind: \"raw\" }\n\t| { kind: \"decode\"; name: string }\n\t| { kind: \"subgraph\"; name: string };\n\nexport type VerifyMode = \"quick\" | \"deep\" | \"anchor\";\n\nexport function parseVerifyTarget(value: string | undefined): VerifyTarget {\n\tconst raw = (value ?? \"raw\").trim();\n\tif (raw === \"all\") return { kind: \"all\" };\n\tif (raw === \"raw\" || raw === \"\") return { kind: \"raw\" };\n\tif (raw.startsWith(\"decode:\")) {\n\t\tconst name = raw.slice(\"decode:\".length).trim();\n\t\tif (!name) throw new Error(\"decode: target needs a decoder name\");\n\t\treturn { kind: \"decode\", name };\n\t}\n\tif (raw.startsWith(\"subgraph:\")) {\n\t\tconst name = raw.slice(\"subgraph:\".length).trim();\n\t\tif (!name) throw new Error(\"subgraph: target needs a subgraph name\");\n\t\treturn { kind: \"subgraph\", name };\n\t}\n\tthrow new Error(\n\t\t`verify target must be all | raw | decode:<name> | subgraph:<name> (got ${value})`,\n\t);\n}\n\nconst RAW_DATASETS = new Set([\"blocks\", \"transactions\", \"events\"]);\n\n/** Whether an archive/coverage dataset belongs to this verify target. */\nexport function datasetMatchesTarget(\n\tdataset: string,\n\ttarget: VerifyTarget,\n): boolean {\n\tif (target.kind === \"all\") return true;\n\tconst name = dataset.toLowerCase();\n\tif (target.kind === \"raw\") return RAW_DATASETS.has(name);\n\tif (target.kind === \"decode\") {\n\t\treturn (\n\t\t\tname === target.name.toLowerCase() ||\n\t\t\tname === `decode:${target.name.toLowerCase()}` ||\n\t\t\tname.endsWith(`_${target.name.toLowerCase()}`)\n\t\t);\n\t}\n\treturn (\n\t\tname === target.name.toLowerCase() ||\n\t\tname === `subgraph:${target.name.toLowerCase()}` ||\n\t\tname.startsWith(`${target.name.toLowerCase()}_`)\n\t);\n}\n\nexport type VerifyReport = {\n\ttarget: VerifyTarget;\n\tmode: VerifyMode;\n\texit: VerifyExit;\n\tstatus: \"clean\" | \"diverged\" | \"unanchored\";\n\tdetail: string;\n};\n\nexport function reportVerify(opts: {\n\ttarget: VerifyTarget;\n\tmode?: VerifyMode;\n\tanchored?: boolean;\n\tdiverged?: boolean;\n\tdetail?: string;\n}): VerifyReport {\n\tconst mode = opts.mode ?? \"quick\";\n\tif (opts.anchored === false) {\n\t\treturn {\n\t\t\ttarget: opts.target,\n\t\t\tmode,\n\t\t\texit: VERIFY_EXIT.UNANCHORED,\n\t\t\tstatus: \"unanchored\",\n\t\t\tdetail: opts.detail ?? \"reference unavailable or unverifiable\",\n\t\t};\n\t}\n\tif (opts.diverged) {\n\t\treturn {\n\t\t\ttarget: opts.target,\n\t\t\tmode,\n\t\t\texit: VERIFY_EXIT.DIVERGED,\n\t\t\tstatus: \"diverged\",\n\t\t\tdetail: opts.detail ?? \"coverage or archive diverged\",\n\t\t};\n\t}\n\tconst label =\n\t\topts.target.kind === \"decode\"\n\t\t\t? `decode:${opts.target.name}`\n\t\t\t: opts.target.kind === \"subgraph\"\n\t\t\t\t? `subgraph:${opts.target.name}`\n\t\t\t\t: opts.target.kind;\n\treturn {\n\t\ttarget: opts.target,\n\t\tmode,\n\t\texit: VERIFY_EXIT.CLEAN,\n\t\tstatus: \"clean\",\n\t\tdetail: opts.detail ?? `${label} ${mode} is clean`,\n\t};\n}\n"
|
|
19
19
|
],
|
|
20
|
-
"mappings": ";AAKO,IAAM,cAAc,CAAC,OAAO,UAAU,YAAY,OAAO;AAGzD,IAAM,gBAAgB,CAAC,SAAS,UAAU,OAAO;AAGjD,IAAM,eAAe;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;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AAK,OAAO,SAAS,WAClB,UAAU,KAAK,OAAO,SACtB,KAAK,OAAO,SAAS,aACpB,YAAY,KAAK,OAAO,SACxB,KAAK,OAAO;AAAA,EACjB,OAAO;AAAA,IACN,QAAQ,KAAK;AAAA,IACb;AAAA,IACA,MAAM,YAAY;AAAA,IAClB,QAAQ;AAAA,IACR,QAAQ,KAAK,UAAU,GAAG,SAAS;AAAA,EACpC;AAAA;",
|
|
21
|
+
"debugId": "E07B1E2F14B6478664756E2164756E21",
|
|
22
22
|
"names": []
|
|
23
23
|
}
|
package/dist/src/index-http.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/** Ceiling on the Index long-poll `wait` param (seconds), shared by client and
|
|
2
|
+
* server so neither drifts from the other. Kept comfortably under app-server
|
|
3
|
+
* Caddy's `reverse_proxy` (no read/write timeout override, so this is a
|
|
4
|
+
* self-imposed ceiling, not one it's protecting against) and Bun's own
|
|
5
|
+
* 90s idleTimeout on the api listener. */
|
|
6
|
+
declare const MAX_INDEX_WAIT_SECONDS = 25;
|
|
7
|
+
/** A non-2xx Index/Streams response, carrying the status so a caller can
|
|
8
|
+
* distinguish "the server rejected this request" (e.g. a `wait`/`from_height`
|
|
9
|
+
* param an older server's `validateQueryParams` doesn't recognize, HTTP 400)
|
|
10
|
+
* from a transient outage — see `getIndexTipEnvelope`'s wait fallback. */
|
|
11
|
+
declare class IndexHttpStatusError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
constructor(status: number, message: string);
|
|
14
|
+
}
|
|
1
15
|
type IndexBlockRow = {
|
|
2
16
|
block_height: number
|
|
3
17
|
block_hash: string
|
|
@@ -140,6 +154,10 @@ declare class IndexHttpClient {
|
|
|
140
154
|
* `getIndexSourceTip`) so `getDecodedHeights()` can read the SAME response
|
|
141
155
|
* synchronously instead of making a second request. */
|
|
142
156
|
private lastTipEnvelope;
|
|
157
|
+
/** Flips false the first time a `wait` request 400s — see
|
|
158
|
+
* `getIndexTipEnvelope`'s catch. Per-instance, not global: a fresh client
|
|
159
|
+
* (e.g. against a different/upgraded server) always tries wait again. */
|
|
160
|
+
private waitSupported;
|
|
143
161
|
constructor(opts: IndexHttpOptions);
|
|
144
162
|
private get;
|
|
145
163
|
/** Fetch a single cursor page of an Index collection. */
|
|
@@ -175,10 +193,23 @@ declare class IndexHttpClient {
|
|
|
175
193
|
* Highest block height the Index data plane can serve (tip is inline in every
|
|
176
194
|
* envelope). This is the data-availability bound — a consumer must not
|
|
177
195
|
* process past it, even if the Streams clock is ahead.
|
|
196
|
+
*
|
|
197
|
+
* `opts.wait` (seconds, clamped to `MAX_INDEX_WAIT_SECONDS`) long-polls:
|
|
198
|
+
* the server holds the request until a fresher tip than `opts.knownHeight`
|
|
199
|
+
* is available or `wait` elapses (plan-063 3.4/3.5). Pass `knownHeight` —
|
|
200
|
+
* the last tip THIS caller observed — or `wait` is a no-op (nothing to
|
|
201
|
+
* compare against). A caller that only wants the plain tip omits both.
|
|
178
202
|
*/
|
|
179
|
-
getIndexTip(
|
|
180
|
-
|
|
181
|
-
|
|
203
|
+
getIndexTip(opts?: {
|
|
204
|
+
wait?: number
|
|
205
|
+
knownHeight?: number
|
|
206
|
+
}): Promise<number>;
|
|
207
|
+
/** Ingest tip. VM rows land with the block; decoded `block_height` can lag.
|
|
208
|
+
* Same `wait`/`knownHeight` long-poll contract as {@link getIndexTip}. */
|
|
209
|
+
getIndexSourceTip(opts?: {
|
|
210
|
+
wait?: number
|
|
211
|
+
knownHeight?: number
|
|
212
|
+
}): Promise<number>;
|
|
182
213
|
/**
|
|
183
214
|
* Per-decoder committed heights from the last tip envelope fetched by
|
|
184
215
|
* `getIndexTip()`/`getIndexSourceTip()` — reads the cached response, no
|
|
@@ -188,6 +219,13 @@ declare class IndexHttpClient {
|
|
|
188
219
|
* the conservative cross-decoder floor `block_height` itself carries.
|
|
189
220
|
*/
|
|
190
221
|
getDecodedHeights(): Record<string, number | null> | undefined;
|
|
222
|
+
/** False once a `wait` request has 400'd on THIS client instance (see the
|
|
223
|
+
* catch in `getIndexTipEnvelope`) — an older server that doesn't recognize
|
|
224
|
+
* the long-poll params. A caller that reuses one client across many calls
|
|
225
|
+
* (the chain evaluator, plan-063 3.5) uses this to stop scheduling itself
|
|
226
|
+
* as if `wait` actually blocked, instead of re-discovering the 400 on
|
|
227
|
+
* every single call. */
|
|
228
|
+
waitIsSupported(): boolean;
|
|
191
229
|
private getIndexTipEnvelope;
|
|
192
230
|
/** Reorgs since a resume token (wall-clock `detected_at`-keyed). */
|
|
193
231
|
listReorgs(since: string): Promise<{
|
|
@@ -197,4 +235,4 @@ declare class IndexHttpClient {
|
|
|
197
235
|
}
|
|
198
236
|
/** Decoder + subgraph processor client. One env contract; omits bearer when no key. */
|
|
199
237
|
declare function createInternalIndexHttpClient(): IndexHttpClient;
|
|
200
|
-
export { IndexBlockRow, IndexEventRow, IndexHttpClient, IndexHttpOptions, IndexTipEnvelope, IndexTransactionRow, StreamsReorgRow, createInternalIndexHttpClient };
|
|
238
|
+
export { IndexBlockRow, IndexEventRow, IndexHttpClient, IndexHttpOptions, IndexHttpStatusError, IndexTipEnvelope, IndexTransactionRow, MAX_INDEX_WAIT_SECONDS, StreamsReorgRow, createInternalIndexHttpClient };
|
package/dist/src/index-http.js
CHANGED
|
@@ -40,17 +40,28 @@ function defaultInternalIndexBaseUrl() {
|
|
|
40
40
|
|
|
41
41
|
// src/index-http.ts
|
|
42
42
|
var PAGE_LIMIT = 1000;
|
|
43
|
+
var MAX_INDEX_WAIT_SECONDS = 25;
|
|
43
44
|
var MAX_ATTEMPTS = 4;
|
|
44
45
|
var RETRY_BASE_MS = 150;
|
|
45
46
|
var RETRYABLE_STATUS = new Set([502, 503, 504]);
|
|
46
47
|
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
47
48
|
|
|
49
|
+
class IndexHttpStatusError extends Error {
|
|
50
|
+
status;
|
|
51
|
+
constructor(status, message) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.status = status;
|
|
54
|
+
this.name = "IndexHttpStatusError";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
class IndexHttpClient {
|
|
49
59
|
indexBaseUrl;
|
|
50
60
|
indexApiKey;
|
|
51
61
|
streamsBaseUrl;
|
|
52
62
|
streamsApiKey;
|
|
53
63
|
lastTipEnvelope;
|
|
64
|
+
waitSupported = true;
|
|
54
65
|
constructor(opts) {
|
|
55
66
|
this.indexBaseUrl = opts.indexBaseUrl.replace(/\/+$/, "");
|
|
56
67
|
this.indexApiKey = opts.indexApiKey ?? defaultInternalIndexApiKey();
|
|
@@ -79,7 +90,7 @@ class IndexHttpClient {
|
|
|
79
90
|
await delay(RETRY_BASE_MS * 2 ** (attempt - 1));
|
|
80
91
|
continue;
|
|
81
92
|
}
|
|
82
|
-
throw new
|
|
93
|
+
throw new IndexHttpStatusError(res.status, `GET ${url} → ${res.status} ${await res.text()}`);
|
|
83
94
|
}
|
|
84
95
|
return await res.json();
|
|
85
96
|
}
|
|
@@ -148,21 +159,40 @@ class IndexHttpClient {
|
|
|
148
159
|
const tip = await this.get(`${this.streamsBaseUrl}/v1/streams/tip`, this.streamsApiKey);
|
|
149
160
|
return Number(tip.block_height) || 0;
|
|
150
161
|
}
|
|
151
|
-
async getIndexTip() {
|
|
152
|
-
const env = await this.getIndexTipEnvelope();
|
|
162
|
+
async getIndexTip(opts) {
|
|
163
|
+
const env = await this.getIndexTipEnvelope(opts);
|
|
153
164
|
return Number(env.tip?.block_height) || 0;
|
|
154
165
|
}
|
|
155
|
-
async getIndexSourceTip() {
|
|
156
|
-
const env = await this.getIndexTipEnvelope();
|
|
166
|
+
async getIndexSourceTip(opts) {
|
|
167
|
+
const env = await this.getIndexTipEnvelope(opts);
|
|
157
168
|
return Number(env.tip?.source_block_height ?? env.tip?.block_height) || 0;
|
|
158
169
|
}
|
|
159
170
|
getDecodedHeights() {
|
|
160
171
|
return this.lastTipEnvelope?.tip.decoded_heights;
|
|
161
172
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
waitIsSupported() {
|
|
174
|
+
return this.waitSupported;
|
|
175
|
+
}
|
|
176
|
+
async getIndexTipEnvelope(opts) {
|
|
177
|
+
const wantsWait = this.waitSupported && (opts?.wait ?? 0) > 0;
|
|
178
|
+
const params = new URLSearchParams({ limit: "1" });
|
|
179
|
+
if (wantsWait) {
|
|
180
|
+
params.set("wait", String(Math.min(MAX_INDEX_WAIT_SECONDS, Math.max(0, opts?.wait ?? 0))));
|
|
181
|
+
if (opts?.knownHeight !== undefined) {
|
|
182
|
+
params.set("from_height", String(opts.knownHeight + 1));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const env = await this.get(`${this.indexBaseUrl}/v1/index/blocks?${params}`, this.indexApiKey);
|
|
187
|
+
this.lastTipEnvelope = env;
|
|
188
|
+
return env;
|
|
189
|
+
} catch (err) {
|
|
190
|
+
if (wantsWait && err instanceof IndexHttpStatusError && err.status === 400) {
|
|
191
|
+
this.waitSupported = false;
|
|
192
|
+
return this.getIndexTipEnvelope(opts);
|
|
193
|
+
}
|
|
194
|
+
throw err;
|
|
195
|
+
}
|
|
166
196
|
}
|
|
167
197
|
async listReorgs(since) {
|
|
168
198
|
const params = new URLSearchParams({ since });
|
|
@@ -180,8 +210,10 @@ function createInternalIndexHttpClient() {
|
|
|
180
210
|
}
|
|
181
211
|
export {
|
|
182
212
|
IndexHttpClient,
|
|
213
|
+
IndexHttpStatusError,
|
|
214
|
+
MAX_INDEX_WAIT_SECONDS,
|
|
183
215
|
createInternalIndexHttpClient
|
|
184
216
|
};
|
|
185
217
|
|
|
186
|
-
//# debugId=
|
|
218
|
+
//# debugId=37F334A2DFE5546164756E2164756E21
|
|
187
219
|
//# sourceMappingURL=index-http.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/index-internal-auth.ts", "../src/index-http.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"// Internal service credentials for first-party consumers of /v1/index and\n// /v1/streams over HTTP (decoder, subgraph processor PublicApiBlockSource).\n// Seeded as internal tenants with NO account_id, so these reads are\n// unmetered (metering gates on account_id). Lives in shared so the API (seed)\n// and the consumers import it without a cycle.\n//\n// Resolution: STREAMS_INTERNAL_API_KEY / INDEX_INTERNAL_API_KEY, then\n// INSTANCE_TOKEN (OSS). No committed fallback. Empty-string env values fall\n// through (`trim()`, then empty): compose interpolates\n// `${STREAMS_INTERNAL_API_KEY:-}` which is \"\" when unset.\n//\n// Archive keys must not use the `sk-sl_` prefix; generate with `sl-int_`.\n// OSS compose should omit the internal env and send INSTANCE_TOKEN.\nexport const INDEX_INTERNAL_TENANT_ID = \"tenant_index_internal\";\nexport const INTERNAL_STREAMS_TENANT_ID = \"tenant_streams_decode_internal\";\n\nconst DEFAULT_INTERNAL_INDEX_BASE_URL = \"http://api:3800\";\n\nconst MISSING_INTERNAL_STREAMS_API_KEY =\n\t\"Set STREAMS_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Empty env no longer falls back to a committed secret.\";\n\nconst MISSING_INTERNAL_INDEX_API_KEY =\n\t\"Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads carry no credential and platform mode 401s every one of them.\";\n\nexport function defaultInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.INDEX_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\nexport function defaultInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.STREAMS_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\n/**\n * Platform-mode Index consumer: refuse to run with neither credential.\n *\n * Platform mode requires a credential on every Index read (a keyless read\n * 401s, `api/src/index/auth.ts`) — a first-party consumer with no internal\n * key would fail every request at call time. Fail here at startup instead.\n *\n * Self-hosted (oss/dedicated) instances are not gated, so they must NOT call\n * this — `defaultInternalIndexApiKey()` returning undefined is correct there.\n */\nexport function requireInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalIndexApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_INDEX_API_KEY);\n\treturn key;\n}\n\n/** Decoder startup: refuse to run with neither credential. */\nexport function requireInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalStreamsApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_STREAMS_API_KEY);\n\treturn key;\n}\n\n/** Shared env contract for decoder + subgraph HTTP dogfood. */\nexport function defaultInternalIndexBaseUrl(): string {\n\treturn (\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ||\n\t\tprocess.env.STREAMS_API_URL ||\n\t\tDEFAULT_INTERNAL_INDEX_BASE_URL\n\t);\n}\n",
|
|
6
|
-
"import {\n\tdefaultInternalIndexApiKey,\n\tdefaultInternalIndexBaseUrl,\n\tdefaultInternalStreamsApiKey,\n} from \"./index-internal-auth.ts\";\n\n/**\n * Low-level transport for the public Index (`/v1/index`) + Streams clock\n * (`/v1/streams`) HTTP APIs: cursor-paginated reads, tip, reorgs. Lives in\n * `shared` (a leaf both the SDK and the subgraph runtime depend on) so the wire\n * format has one home and no package cycle. The SDK's ergonomic client should\n * eventually consume these row types too (see the plan's convergence task).\n *\n * This is intentionally minimal — just the GETs the subgraph runtime's\n * PublicApiBlockSource needs. It is NOT the SDK's full client (walk/consume/\n * retries/auth resolution).\n */\n\nconst PAGE_LIMIT = 1000;\n\n// Transport resilience for the streams-index data plane. The api runs N>1\n// replicas behind Caddy; during a rolling deploy one replica is briefly\n// unreachable, surfacing as a thrown fetch (connection refused/reset) or a\n// Caddy 502/503/504 while it fails over. Retrying a few times with backoff\n// makes a single-replica recreate transparent to the subgraph-processor /\n// decoder — closing the processors-depend-on-api coupling.\nconst MAX_ATTEMPTS = 4;\nconst RETRY_BASE_MS = 150;\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nconst delay = (ms: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(resolve, ms));\n\ntype Envelope<K extends string, T> = {\n\t[P in K]: T[];\n} & { next_cursor: string | null };\n\n// ── Index API wire shapes (single source of truth) ─────────────────────────\nexport type IndexBlockRow = {\n\tblock_height: number;\n\tblock_hash: string;\n\tparent_hash: string;\n\tburn_block_height: number;\n\tburn_block_hash: string | null;\n\t/** Nakamoto StacksBlockId. Absent from pre-2026-07 API deployments. */\n\tindex_block_hash?: string | null;\n\tblock_time: string | null;\n};\n\ntype IndexEventCommon = {\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index?: number;\n\tevent_index: number;\n\tcontract_id: string | null;\n\t/** Submitting-tx context — present only when the read passed `tx_context=true`.\n\t * Lets a consumer build the tx for `ctx.tx` without a separate\n\t * walkTransactions (the ~37x reindex over-fetch; see indexing-speed plan). */\n\ttx_sender?: string | null;\n\ttx_type?: string | null;\n\ttx_status?: string | null;\n\ttx_contract_id?: string | null;\n\ttx_function_name?: string | null;\n};\n\nexport type IndexEventRow = IndexEventCommon &\n\t(\n\t\t| {\n\t\t\t\tevent_type: \"ft_transfer\" | \"ft_mint\" | \"ft_burn\";\n\t\t\t\tasset_identifier: string;\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tamount: string;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"nft_transfer\" | \"nft_mint\" | \"nft_burn\";\n\t\t\t\tasset_identifier: string;\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tvalue: string;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"stx_transfer\" | \"stx_mint\" | \"stx_burn\";\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tamount: string;\n\t\t\t\tmemo?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"stx_lock\";\n\t\t\t\tsender: string;\n\t\t\t\tamount: string;\n\t\t\t\tpayload: { unlock_height: string | null };\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"print\";\n\t\t\t\tpayload: {\n\t\t\t\t\ttopic: string | null;\n\t\t\t\t\tvalue: unknown;\n\t\t\t\t\traw_value: string | null;\n\t\t\t\t};\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"nested_contract_call\";\n\t\t\t\tsender?: string | null;\n\t\t\t\tcaller: string;\n\t\t\t\tfunction_name: string;\n\t\t\t\tfunction_args?: unknown;\n\t\t\t\traw_result?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"var_set\";\n\t\t\t\tvar_name: string;\n\t\t\t\traw_value?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"map_set\" | \"map_insert\";\n\t\t\t\tmap: string;\n\t\t\t\traw_key?: string | null;\n\t\t\t\traw_value?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"map_delete\";\n\t\t\t\tmap: string;\n\t\t\t\traw_key?: string | null;\n\t\t }\n\t);\n\nexport type IndexTransactionRow = {\n\ttx_id: string;\n\tblock_height: number;\n\tblock_time?: string | null;\n\tburn_block_height?: number | null;\n\ttx_index: number;\n\ttx_type: string;\n\tsender: string;\n\tstatus: string;\n\tcontract_call?: {\n\t\tcontract_id: string;\n\t\tfunction_name: string;\n\t\tfunction_args_hex?: string[] | null;\n\t\tresult_hex?: string | null;\n\t} | null;\n\tsmart_contract?: { contract_id: string | null } | null;\n};\n\nexport type StreamsReorgRow = {\n\tid: string;\n\tdetected_at: string;\n\tfork_point_height: number;\n\torphaned_range: { from: string; to: string };\n\tnew_canonical_tip: string;\n};\n\nexport type IndexHttpOptions = {\n\t/** Base URL for /v1/index (the decoded data plane). */\n\tindexBaseUrl: string;\n\t/** Bearer for /v1/index. Empty/unset omits the header. */\n\tindexApiKey?: string;\n\t/** Base URL for /v1/streams (the canonical clock). */\n\tstreamsBaseUrl: string;\n\t/** Bearer for /v1/streams. Empty/unset omits the header. */\n\tstreamsApiKey?: string;\n};\n\n/** `/v1/index/blocks?limit=1`'s envelope — read for its `tip`, not its rows. */\nexport type IndexTipEnvelope = {\n\ttip: {\n\t\tblock_height: number;\n\t\tsource_block_height?: number;\n\t\t/**\n\t\t * Committed height per classic decoded event_type (plan-063), e.g.\n\t\t * `{ ft_transfer: 950, stx_transfer: 940 }`. `null` means that decoder\n\t\t * has no checkpoint yet (fail-closed for a caller that references it,\n\t\t * not \"committed to height 0\"); a missing key means an older server\n\t\t * that doesn't send this field at all. Absent on an instance built\n\t\t * before plan-063 shipped it.\n\t\t */\n\t\tdecoded_heights?: Record<string, number | null>;\n\t};\n};\n\nexport class IndexHttpClient {\n\tprivate readonly indexBaseUrl: string;\n\tprivate readonly indexApiKey: string | undefined;\n\tprivate readonly streamsBaseUrl: string;\n\tprivate readonly streamsApiKey: string | undefined;\n\t/** Populated by the last `getIndexTipEnvelope()` call (via `getIndexTip`/\n\t * `getIndexSourceTip`) so `getDecodedHeights()` can read the SAME response\n\t * synchronously instead of making a second request. */\n\tprivate lastTipEnvelope: IndexTipEnvelope | undefined;\n\n\tconstructor(opts: IndexHttpOptions) {\n\t\tthis.indexBaseUrl = opts.indexBaseUrl.replace(/\\/+$/, \"\");\n\t\tthis.indexApiKey = opts.indexApiKey ?? defaultInternalIndexApiKey();\n\t\tthis.streamsBaseUrl = opts.streamsBaseUrl.replace(/\\/+$/, \"\");\n\t\tthis.streamsApiKey = opts.streamsApiKey;\n\t}\n\n\tprivate async get<T>(url: string, apiKey: string | undefined): Promise<T> {\n\t\t// Index reads are anon — omit the header entirely when no key is set, so\n\t\t// an empty key reads anonymously rather than 401-ing as an invalid bearer.\n\t\tconst headers: Record<string, string> = apiKey\n\t\t\t? { authorization: `Bearer ${apiKey}` }\n\t\t\t: {};\n\t\tlet lastErr: unknown;\n\t\tfor (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {\n\t\t\tlet res: Response;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url, { headers });\n\t\t\t} catch (err) {\n\t\t\t\t// An explicit abort/cancel is intentional — surface it immediately\n\t\t\t\t// rather than burning the retry budget masking it as transient.\n\t\t\t\tif (err instanceof Error && err.name === \"AbortError\") throw err;\n\t\t\t\t// Otherwise a transport-level failure (connection refused/reset) —\n\t\t\t\t// e.g. an api replica mid-recreate. Retry; the next attempt\n\t\t\t\t// round-robins to a healthy replica.\n\t\t\t\tlastErr = err;\n\t\t\t\tif (attempt >= MAX_ATTEMPTS) break;\n\t\t\t\tawait delay(RETRY_BASE_MS * 2 ** (attempt - 1));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!res.ok) {\n\t\t\t\tif (RETRYABLE_STATUS.has(res.status) && attempt < MAX_ATTEMPTS) {\n\t\t\t\t\t// Drain the body so the connection can be reused, then back off.\n\t\t\t\t\tawait res.text().catch(() => {});\n\t\t\t\t\tawait delay(RETRY_BASE_MS * 2 ** (attempt - 1));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new Error(`GET ${url} → ${res.status} ${await res.text()}`);\n\t\t\t}\n\t\t\treturn (await res.json()) as T;\n\t\t}\n\t\tthrow (\n\t\t\tlastErr ?? new Error(`GET ${url} failed after ${MAX_ATTEMPTS} attempts`)\n\t\t);\n\t}\n\n\t/** Fetch a single cursor page of an Index collection. */\n\tprivate async getPage<K extends string, T>(\n\t\tpath: string,\n\t\tkey: K,\n\t\tparams: URLSearchParams,\n\t): Promise<{ items: T[]; next_cursor: string | null }> {\n\t\tconst env: Envelope<K, T> = await this.get(\n\t\t\t`${this.indexBaseUrl}${path}?${params}`,\n\t\t\tthis.indexApiKey,\n\t\t);\n\t\treturn { items: env[key], next_cursor: env.next_cursor };\n\t}\n\n\t/** Drain a cursor-paginated Index collection over [fromHeight, toHeight]. */\n\tprivate async walk<K extends string, T>(\n\t\tpath: string,\n\t\tkey: K,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\textraParams: Record<string, string> = {},\n\t): Promise<T[]> {\n\t\tconst out: T[] = [];\n\t\tlet cursor: string | null = null;\n\t\tdo {\n\t\t\tconst params = new URLSearchParams({\n\t\t\t\tto_height: String(toHeight),\n\t\t\t\tlimit: String(PAGE_LIMIT),\n\t\t\t\t...extraParams,\n\t\t\t});\n\t\t\t// from_height and cursor are mutually exclusive — anchor the first page\n\t\t\t// by height, then page forward by cursor only.\n\t\t\tif (cursor) params.set(\"cursor\", cursor);\n\t\t\telse params.set(\"from_height\", String(fromHeight));\n\t\t\tconst { items, next_cursor } = await this.getPage<K, T>(\n\t\t\t\tpath,\n\t\t\t\tkey,\n\t\t\t\tparams,\n\t\t\t);\n\t\t\tout.push(...items);\n\t\t\tcursor = next_cursor;\n\t\t} while (cursor);\n\t\treturn out;\n\t}\n\n\t/**\n\t * Fetch ONE page of contract-call transactions filtered to `contractId`.\n\t * Unlike walk(), this does NOT drain — the caller pages by feeding back\n\t * next_cursor — so a sparse high-volume filter (e.g. a single contract over\n\t * all history) costs one request per batch, not O(all-history) per tick.\n\t * `cursor` is exclusive (rows strictly after it); on the first call pass\n\t * `fromHeight` to anchor the backfill start instead.\n\t */\n\tasync fetchContractCalls(\n\t\tcontractId: string,\n\t\topts: {\n\t\t\ttoHeight: number;\n\t\t\tcursor?: string | null;\n\t\t\tfromHeight?: number;\n\t\t\tlimit?: number;\n\t\t},\n\t): Promise<{\n\t\ttransactions: IndexTransactionRow[];\n\t\tnext_cursor: string | null;\n\t}> {\n\t\tconst params = new URLSearchParams({\n\t\t\tto_height: String(opts.toHeight),\n\t\t\tlimit: String(opts.limit ?? PAGE_LIMIT),\n\t\t\tcontract_id: contractId,\n\t\t});\n\t\tif (opts.cursor) params.set(\"cursor\", opts.cursor);\n\t\telse params.set(\"from_height\", String(opts.fromHeight ?? 0));\n\t\tconst { items, next_cursor } = await this.getPage<\n\t\t\t\"transactions\",\n\t\t\tIndexTransactionRow\n\t\t>(\"/v1/index/transactions\", \"transactions\", params);\n\t\treturn { transactions: items, next_cursor };\n\t}\n\n\twalkBlocks(fromHeight: number, toHeight: number): Promise<IndexBlockRow[]> {\n\t\treturn this.walk<\"blocks\", IndexBlockRow>(\n\t\t\t\"/v1/index/blocks\",\n\t\t\t\"blocks\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t);\n\t}\n\n\t/** Lowest block height in [fromHeight, toHeight] with a matching event, or\n\t * null. One page, limit 1 — built for sparse-scan probes. */\n\tasync firstEventHeight(\n\t\teventType: string,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\tcontractId?: string,\n\t): Promise<number | null> {\n\t\tconst params = new URLSearchParams({\n\t\t\tevent_type: eventType,\n\t\t\tfrom_height: String(fromHeight),\n\t\t\tto_height: String(toHeight),\n\t\t\tlimit: \"1\",\n\t\t\t...(contractId ? { contract_id: contractId } : {}),\n\t\t});\n\t\tconst { items } = await this.getPage<\"events\", IndexEventRow>(\n\t\t\t\"/v1/index/events\",\n\t\t\t\"events\",\n\t\t\tparams,\n\t\t);\n\t\treturn items[0]?.block_height ?? null;\n\t}\n\n\twalkEvents(\n\t\teventType: string,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\t/** Join the submitting tx so each row carries `tx_*` — lets an event-only\n\t\t * subgraph skip walkTransactions and build `ctx.tx` from the event. */\n\t\twithTx = false,\n\t): Promise<IndexEventRow[]> {\n\t\treturn this.walk<\"events\", IndexEventRow>(\n\t\t\t\"/v1/index/events\",\n\t\t\t\"events\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t\t{\n\t\t\t\tevent_type: eventType,\n\t\t\t\t...(withTx ? { tx_context: \"true\" } : {}),\n\t\t\t},\n\t\t);\n\t}\n\n\twalkTransactions(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<IndexTransactionRow[]> {\n\t\treturn this.walk<\"transactions\", IndexTransactionRow>(\n\t\t\t\"/v1/index/transactions\",\n\t\t\t\"transactions\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t);\n\t}\n\n\t/** Canonical tip height from the Streams clock. */\n\tasync getStreamsTip(): Promise<number> {\n\t\tconst tip = await this.get<{ block_height: number }>(\n\t\t\t`${this.streamsBaseUrl}/v1/streams/tip`,\n\t\t\tthis.streamsApiKey,\n\t\t);\n\t\treturn Number(tip.block_height) || 0;\n\t}\n\n\t/**\n\t * Highest block height the Index data plane can serve (tip is inline in every\n\t * envelope). This is the data-availability bound — a consumer must not\n\t * process past it, even if the Streams clock is ahead.\n\t */\n\tasync getIndexTip(): Promise<number> {\n\t\tconst env = await this.getIndexTipEnvelope();\n\t\treturn Number(env.tip?.block_height) || 0;\n\t}\n\n\t/** Ingest tip. VM rows land with the block; decoded `block_height` can lag. */\n\tasync getIndexSourceTip(): Promise<number> {\n\t\tconst env = await this.getIndexTipEnvelope();\n\t\treturn Number(env.tip?.source_block_height ?? env.tip?.block_height) || 0;\n\t}\n\n\t/**\n\t * Per-decoder committed heights from the last tip envelope fetched by\n\t * `getIndexTip()`/`getIndexSourceTip()` — reads the cached response, no\n\t * extra request. `undefined` before either has been called, or against an\n\t * older server that doesn't send the field. A caller (the chain evaluator)\n\t * uses this to bound itself by the decoders it actually reads instead of\n\t * the conservative cross-decoder floor `block_height` itself carries.\n\t */\n\tgetDecodedHeights(): Record<string, number | null> | undefined {\n\t\treturn this.lastTipEnvelope?.tip.decoded_heights;\n\t}\n\n\tprivate async getIndexTipEnvelope(): Promise<IndexTipEnvelope> {\n\t\tconst env = await this.get<IndexTipEnvelope>(\n\t\t\t`${this.indexBaseUrl}/v1/index/blocks?limit=1`,\n\t\t\tthis.indexApiKey,\n\t\t);\n\t\tthis.lastTipEnvelope = env;\n\t\treturn env;\n\t}\n\n\t/** Reorgs since a resume token (wall-clock `detected_at`-keyed). */\n\tasync listReorgs(\n\t\tsince: string,\n\t): Promise<{ reorgs: StreamsReorgRow[]; next_since: string | null }> {\n\t\tconst params = new URLSearchParams({ since });\n\t\treturn this.get(\n\t\t\t`${this.streamsBaseUrl}/v1/streams/reorgs?${params}`,\n\t\t\tthis.streamsApiKey,\n\t\t);\n\t}\n}\n\n/** Decoder + subgraph processor client. One env contract; omits bearer when no key. */\nexport function createInternalIndexHttpClient(): IndexHttpClient {\n\tconst baseUrl = defaultInternalIndexBaseUrl();\n\treturn new IndexHttpClient({\n\t\tindexBaseUrl: baseUrl,\n\t\tstreamsBaseUrl: baseUrl,\n\t\tindexApiKey: defaultInternalIndexApiKey(),\n\t\tstreamsApiKey: defaultInternalStreamsApiKey(),\n\t});\n}\n"
|
|
6
|
+
"import {\n\tdefaultInternalIndexApiKey,\n\tdefaultInternalIndexBaseUrl,\n\tdefaultInternalStreamsApiKey,\n} from \"./index-internal-auth.ts\";\n\n/**\n * Low-level transport for the public Index (`/v1/index`) + Streams clock\n * (`/v1/streams`) HTTP APIs: cursor-paginated reads, tip, reorgs. Lives in\n * `shared` (a leaf both the SDK and the subgraph runtime depend on) so the wire\n * format has one home and no package cycle. The SDK's ergonomic client should\n * eventually consume these row types too (see the plan's convergence task).\n *\n * This is intentionally minimal — just the GETs the subgraph runtime's\n * PublicApiBlockSource needs. It is NOT the SDK's full client (walk/consume/\n * retries/auth resolution).\n */\n\nconst PAGE_LIMIT = 1000;\n\n/** Ceiling on the Index long-poll `wait` param (seconds), shared by client and\n * server so neither drifts from the other. Kept comfortably under app-server\n * Caddy's `reverse_proxy` (no read/write timeout override, so this is a\n * self-imposed ceiling, not one it's protecting against) and Bun's own\n * 90s idleTimeout on the api listener. */\nexport const MAX_INDEX_WAIT_SECONDS = 25;\n\n// Transport resilience for the streams-index data plane. The api runs N>1\n// replicas behind Caddy; during a rolling deploy one replica is briefly\n// unreachable, surfacing as a thrown fetch (connection refused/reset) or a\n// Caddy 502/503/504 while it fails over. Retrying a few times with backoff\n// makes a single-replica recreate transparent to the subgraph-processor /\n// decoder — closing the processors-depend-on-api coupling.\nconst MAX_ATTEMPTS = 4;\nconst RETRY_BASE_MS = 150;\nconst RETRYABLE_STATUS = new Set([502, 503, 504]);\n\nconst delay = (ms: number): Promise<void> =>\n\tnew Promise((resolve) => setTimeout(resolve, ms));\n\n/** A non-2xx Index/Streams response, carrying the status so a caller can\n * distinguish \"the server rejected this request\" (e.g. a `wait`/`from_height`\n * param an older server's `validateQueryParams` doesn't recognize, HTTP 400)\n * from a transient outage — see `getIndexTipEnvelope`'s wait fallback. */\nexport class IndexHttpStatusError extends Error {\n\tconstructor(\n\t\treadonly status: number,\n\t\tmessage: string,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"IndexHttpStatusError\";\n\t}\n}\n\ntype Envelope<K extends string, T> = {\n\t[P in K]: T[];\n} & { next_cursor: string | null };\n\n// ── Index API wire shapes (single source of truth) ─────────────────────────\nexport type IndexBlockRow = {\n\tblock_height: number;\n\tblock_hash: string;\n\tparent_hash: string;\n\tburn_block_height: number;\n\tburn_block_hash: string | null;\n\t/** Nakamoto StacksBlockId. Absent from pre-2026-07 API deployments. */\n\tindex_block_hash?: string | null;\n\tblock_time: string | null;\n};\n\ntype IndexEventCommon = {\n\tblock_height: number;\n\ttx_id: string;\n\ttx_index?: number;\n\tevent_index: number;\n\tcontract_id: string | null;\n\t/** Submitting-tx context — present only when the read passed `tx_context=true`.\n\t * Lets a consumer build the tx for `ctx.tx` without a separate\n\t * walkTransactions (the ~37x reindex over-fetch; see indexing-speed plan). */\n\ttx_sender?: string | null;\n\ttx_type?: string | null;\n\ttx_status?: string | null;\n\ttx_contract_id?: string | null;\n\ttx_function_name?: string | null;\n};\n\nexport type IndexEventRow = IndexEventCommon &\n\t(\n\t\t| {\n\t\t\t\tevent_type: \"ft_transfer\" | \"ft_mint\" | \"ft_burn\";\n\t\t\t\tasset_identifier: string;\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tamount: string;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"nft_transfer\" | \"nft_mint\" | \"nft_burn\";\n\t\t\t\tasset_identifier: string;\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tvalue: string;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"stx_transfer\" | \"stx_mint\" | \"stx_burn\";\n\t\t\t\tsender?: string;\n\t\t\t\trecipient?: string;\n\t\t\t\tamount: string;\n\t\t\t\tmemo?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"stx_lock\";\n\t\t\t\tsender: string;\n\t\t\t\tamount: string;\n\t\t\t\tpayload: { unlock_height: string | null };\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"print\";\n\t\t\t\tpayload: {\n\t\t\t\t\ttopic: string | null;\n\t\t\t\t\tvalue: unknown;\n\t\t\t\t\traw_value: string | null;\n\t\t\t\t};\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"nested_contract_call\";\n\t\t\t\tsender?: string | null;\n\t\t\t\tcaller: string;\n\t\t\t\tfunction_name: string;\n\t\t\t\tfunction_args?: unknown;\n\t\t\t\traw_result?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"var_set\";\n\t\t\t\tvar_name: string;\n\t\t\t\traw_value?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"map_set\" | \"map_insert\";\n\t\t\t\tmap: string;\n\t\t\t\traw_key?: string | null;\n\t\t\t\traw_value?: string | null;\n\t\t }\n\t\t| {\n\t\t\t\tevent_type: \"map_delete\";\n\t\t\t\tmap: string;\n\t\t\t\traw_key?: string | null;\n\t\t }\n\t);\n\nexport type IndexTransactionRow = {\n\ttx_id: string;\n\tblock_height: number;\n\tblock_time?: string | null;\n\tburn_block_height?: number | null;\n\ttx_index: number;\n\ttx_type: string;\n\tsender: string;\n\tstatus: string;\n\tcontract_call?: {\n\t\tcontract_id: string;\n\t\tfunction_name: string;\n\t\tfunction_args_hex?: string[] | null;\n\t\tresult_hex?: string | null;\n\t} | null;\n\tsmart_contract?: { contract_id: string | null } | null;\n};\n\nexport type StreamsReorgRow = {\n\tid: string;\n\tdetected_at: string;\n\tfork_point_height: number;\n\torphaned_range: { from: string; to: string };\n\tnew_canonical_tip: string;\n};\n\nexport type IndexHttpOptions = {\n\t/** Base URL for /v1/index (the decoded data plane). */\n\tindexBaseUrl: string;\n\t/** Bearer for /v1/index. Empty/unset omits the header. */\n\tindexApiKey?: string;\n\t/** Base URL for /v1/streams (the canonical clock). */\n\tstreamsBaseUrl: string;\n\t/** Bearer for /v1/streams. Empty/unset omits the header. */\n\tstreamsApiKey?: string;\n};\n\n/** `/v1/index/blocks?limit=1`'s envelope — read for its `tip`, not its rows. */\nexport type IndexTipEnvelope = {\n\ttip: {\n\t\tblock_height: number;\n\t\tsource_block_height?: number;\n\t\t/**\n\t\t * Committed height per classic decoded event_type (plan-063), e.g.\n\t\t * `{ ft_transfer: 950, stx_transfer: 940 }`. `null` means that decoder\n\t\t * has no checkpoint yet (fail-closed for a caller that references it,\n\t\t * not \"committed to height 0\"); a missing key means an older server\n\t\t * that doesn't send this field at all. Absent on an instance built\n\t\t * before plan-063 shipped it.\n\t\t */\n\t\tdecoded_heights?: Record<string, number | null>;\n\t};\n};\n\nexport class IndexHttpClient {\n\tprivate readonly indexBaseUrl: string;\n\tprivate readonly indexApiKey: string | undefined;\n\tprivate readonly streamsBaseUrl: string;\n\tprivate readonly streamsApiKey: string | undefined;\n\t/** Populated by the last `getIndexTipEnvelope()` call (via `getIndexTip`/\n\t * `getIndexSourceTip`) so `getDecodedHeights()` can read the SAME response\n\t * synchronously instead of making a second request. */\n\tprivate lastTipEnvelope: IndexTipEnvelope | undefined;\n\t/** Flips false the first time a `wait` request 400s — see\n\t * `getIndexTipEnvelope`'s catch. Per-instance, not global: a fresh client\n\t * (e.g. against a different/upgraded server) always tries wait again. */\n\tprivate waitSupported = true;\n\n\tconstructor(opts: IndexHttpOptions) {\n\t\tthis.indexBaseUrl = opts.indexBaseUrl.replace(/\\/+$/, \"\");\n\t\tthis.indexApiKey = opts.indexApiKey ?? defaultInternalIndexApiKey();\n\t\tthis.streamsBaseUrl = opts.streamsBaseUrl.replace(/\\/+$/, \"\");\n\t\tthis.streamsApiKey = opts.streamsApiKey;\n\t}\n\n\tprivate async get<T>(url: string, apiKey: string | undefined): Promise<T> {\n\t\t// Index reads are anon — omit the header entirely when no key is set, so\n\t\t// an empty key reads anonymously rather than 401-ing as an invalid bearer.\n\t\tconst headers: Record<string, string> = apiKey\n\t\t\t? { authorization: `Bearer ${apiKey}` }\n\t\t\t: {};\n\t\tlet lastErr: unknown;\n\t\tfor (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {\n\t\t\tlet res: Response;\n\t\t\ttry {\n\t\t\t\tres = await fetch(url, { headers });\n\t\t\t} catch (err) {\n\t\t\t\t// An explicit abort/cancel is intentional — surface it immediately\n\t\t\t\t// rather than burning the retry budget masking it as transient.\n\t\t\t\tif (err instanceof Error && err.name === \"AbortError\") throw err;\n\t\t\t\t// Otherwise a transport-level failure (connection refused/reset) —\n\t\t\t\t// e.g. an api replica mid-recreate. Retry; the next attempt\n\t\t\t\t// round-robins to a healthy replica.\n\t\t\t\tlastErr = err;\n\t\t\t\tif (attempt >= MAX_ATTEMPTS) break;\n\t\t\t\tawait delay(RETRY_BASE_MS * 2 ** (attempt - 1));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!res.ok) {\n\t\t\t\tif (RETRYABLE_STATUS.has(res.status) && attempt < MAX_ATTEMPTS) {\n\t\t\t\t\t// Drain the body so the connection can be reused, then back off.\n\t\t\t\t\tawait res.text().catch(() => {});\n\t\t\t\t\tawait delay(RETRY_BASE_MS * 2 ** (attempt - 1));\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new IndexHttpStatusError(\n\t\t\t\t\tres.status,\n\t\t\t\t\t`GET ${url} → ${res.status} ${await res.text()}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn (await res.json()) as T;\n\t\t}\n\t\tthrow (\n\t\t\tlastErr ?? new Error(`GET ${url} failed after ${MAX_ATTEMPTS} attempts`)\n\t\t);\n\t}\n\n\t/** Fetch a single cursor page of an Index collection. */\n\tprivate async getPage<K extends string, T>(\n\t\tpath: string,\n\t\tkey: K,\n\t\tparams: URLSearchParams,\n\t): Promise<{ items: T[]; next_cursor: string | null }> {\n\t\tconst env: Envelope<K, T> = await this.get(\n\t\t\t`${this.indexBaseUrl}${path}?${params}`,\n\t\t\tthis.indexApiKey,\n\t\t);\n\t\treturn { items: env[key], next_cursor: env.next_cursor };\n\t}\n\n\t/** Drain a cursor-paginated Index collection over [fromHeight, toHeight]. */\n\tprivate async walk<K extends string, T>(\n\t\tpath: string,\n\t\tkey: K,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\textraParams: Record<string, string> = {},\n\t): Promise<T[]> {\n\t\tconst out: T[] = [];\n\t\tlet cursor: string | null = null;\n\t\tdo {\n\t\t\tconst params = new URLSearchParams({\n\t\t\t\tto_height: String(toHeight),\n\t\t\t\tlimit: String(PAGE_LIMIT),\n\t\t\t\t...extraParams,\n\t\t\t});\n\t\t\t// from_height and cursor are mutually exclusive — anchor the first page\n\t\t\t// by height, then page forward by cursor only.\n\t\t\tif (cursor) params.set(\"cursor\", cursor);\n\t\t\telse params.set(\"from_height\", String(fromHeight));\n\t\t\tconst { items, next_cursor } = await this.getPage<K, T>(\n\t\t\t\tpath,\n\t\t\t\tkey,\n\t\t\t\tparams,\n\t\t\t);\n\t\t\tout.push(...items);\n\t\t\tcursor = next_cursor;\n\t\t} while (cursor);\n\t\treturn out;\n\t}\n\n\t/**\n\t * Fetch ONE page of contract-call transactions filtered to `contractId`.\n\t * Unlike walk(), this does NOT drain — the caller pages by feeding back\n\t * next_cursor — so a sparse high-volume filter (e.g. a single contract over\n\t * all history) costs one request per batch, not O(all-history) per tick.\n\t * `cursor` is exclusive (rows strictly after it); on the first call pass\n\t * `fromHeight` to anchor the backfill start instead.\n\t */\n\tasync fetchContractCalls(\n\t\tcontractId: string,\n\t\topts: {\n\t\t\ttoHeight: number;\n\t\t\tcursor?: string | null;\n\t\t\tfromHeight?: number;\n\t\t\tlimit?: number;\n\t\t},\n\t): Promise<{\n\t\ttransactions: IndexTransactionRow[];\n\t\tnext_cursor: string | null;\n\t}> {\n\t\tconst params = new URLSearchParams({\n\t\t\tto_height: String(opts.toHeight),\n\t\t\tlimit: String(opts.limit ?? PAGE_LIMIT),\n\t\t\tcontract_id: contractId,\n\t\t});\n\t\tif (opts.cursor) params.set(\"cursor\", opts.cursor);\n\t\telse params.set(\"from_height\", String(opts.fromHeight ?? 0));\n\t\tconst { items, next_cursor } = await this.getPage<\n\t\t\t\"transactions\",\n\t\t\tIndexTransactionRow\n\t\t>(\"/v1/index/transactions\", \"transactions\", params);\n\t\treturn { transactions: items, next_cursor };\n\t}\n\n\twalkBlocks(fromHeight: number, toHeight: number): Promise<IndexBlockRow[]> {\n\t\treturn this.walk<\"blocks\", IndexBlockRow>(\n\t\t\t\"/v1/index/blocks\",\n\t\t\t\"blocks\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t);\n\t}\n\n\t/** Lowest block height in [fromHeight, toHeight] with a matching event, or\n\t * null. One page, limit 1 — built for sparse-scan probes. */\n\tasync firstEventHeight(\n\t\teventType: string,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\tcontractId?: string,\n\t): Promise<number | null> {\n\t\tconst params = new URLSearchParams({\n\t\t\tevent_type: eventType,\n\t\t\tfrom_height: String(fromHeight),\n\t\t\tto_height: String(toHeight),\n\t\t\tlimit: \"1\",\n\t\t\t...(contractId ? { contract_id: contractId } : {}),\n\t\t});\n\t\tconst { items } = await this.getPage<\"events\", IndexEventRow>(\n\t\t\t\"/v1/index/events\",\n\t\t\t\"events\",\n\t\t\tparams,\n\t\t);\n\t\treturn items[0]?.block_height ?? null;\n\t}\n\n\twalkEvents(\n\t\teventType: string,\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t\t/** Join the submitting tx so each row carries `tx_*` — lets an event-only\n\t\t * subgraph skip walkTransactions and build `ctx.tx` from the event. */\n\t\twithTx = false,\n\t): Promise<IndexEventRow[]> {\n\t\treturn this.walk<\"events\", IndexEventRow>(\n\t\t\t\"/v1/index/events\",\n\t\t\t\"events\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t\t{\n\t\t\t\tevent_type: eventType,\n\t\t\t\t...(withTx ? { tx_context: \"true\" } : {}),\n\t\t\t},\n\t\t);\n\t}\n\n\twalkTransactions(\n\t\tfromHeight: number,\n\t\ttoHeight: number,\n\t): Promise<IndexTransactionRow[]> {\n\t\treturn this.walk<\"transactions\", IndexTransactionRow>(\n\t\t\t\"/v1/index/transactions\",\n\t\t\t\"transactions\",\n\t\t\tfromHeight,\n\t\t\ttoHeight,\n\t\t);\n\t}\n\n\t/** Canonical tip height from the Streams clock. */\n\tasync getStreamsTip(): Promise<number> {\n\t\tconst tip = await this.get<{ block_height: number }>(\n\t\t\t`${this.streamsBaseUrl}/v1/streams/tip`,\n\t\t\tthis.streamsApiKey,\n\t\t);\n\t\treturn Number(tip.block_height) || 0;\n\t}\n\n\t/**\n\t * Highest block height the Index data plane can serve (tip is inline in every\n\t * envelope). This is the data-availability bound — a consumer must not\n\t * process past it, even if the Streams clock is ahead.\n\t *\n\t * `opts.wait` (seconds, clamped to `MAX_INDEX_WAIT_SECONDS`) long-polls:\n\t * the server holds the request until a fresher tip than `opts.knownHeight`\n\t * is available or `wait` elapses (plan-063 3.4/3.5). Pass `knownHeight` —\n\t * the last tip THIS caller observed — or `wait` is a no-op (nothing to\n\t * compare against). A caller that only wants the plain tip omits both.\n\t */\n\tasync getIndexTip(opts?: {\n\t\twait?: number;\n\t\tknownHeight?: number;\n\t}): Promise<number> {\n\t\tconst env = await this.getIndexTipEnvelope(opts);\n\t\treturn Number(env.tip?.block_height) || 0;\n\t}\n\n\t/** Ingest tip. VM rows land with the block; decoded `block_height` can lag.\n\t * Same `wait`/`knownHeight` long-poll contract as {@link getIndexTip}. */\n\tasync getIndexSourceTip(opts?: {\n\t\twait?: number;\n\t\tknownHeight?: number;\n\t}): Promise<number> {\n\t\tconst env = await this.getIndexTipEnvelope(opts);\n\t\treturn Number(env.tip?.source_block_height ?? env.tip?.block_height) || 0;\n\t}\n\n\t/**\n\t * Per-decoder committed heights from the last tip envelope fetched by\n\t * `getIndexTip()`/`getIndexSourceTip()` — reads the cached response, no\n\t * extra request. `undefined` before either has been called, or against an\n\t * older server that doesn't send the field. A caller (the chain evaluator)\n\t * uses this to bound itself by the decoders it actually reads instead of\n\t * the conservative cross-decoder floor `block_height` itself carries.\n\t */\n\tgetDecodedHeights(): Record<string, number | null> | undefined {\n\t\treturn this.lastTipEnvelope?.tip.decoded_heights;\n\t}\n\n\t/** False once a `wait` request has 400'd on THIS client instance (see the\n\t * catch in `getIndexTipEnvelope`) — an older server that doesn't recognize\n\t * the long-poll params. A caller that reuses one client across many calls\n\t * (the chain evaluator, plan-063 3.5) uses this to stop scheduling itself\n\t * as if `wait` actually blocked, instead of re-discovering the 400 on\n\t * every single call. */\n\twaitIsSupported(): boolean {\n\t\treturn this.waitSupported;\n\t}\n\n\tprivate async getIndexTipEnvelope(opts?: {\n\t\twait?: number;\n\t\tknownHeight?: number;\n\t}): Promise<IndexTipEnvelope> {\n\t\tconst wantsWait = this.waitSupported && (opts?.wait ?? 0) > 0;\n\t\tconst params = new URLSearchParams({ limit: \"1\" });\n\t\tif (wantsWait) {\n\t\t\tparams.set(\n\t\t\t\t\"wait\",\n\t\t\t\tString(Math.min(MAX_INDEX_WAIT_SECONDS, Math.max(0, opts?.wait ?? 0))),\n\t\t\t);\n\t\t\t// `from_height` is what makes the wait meaningful here: with no cursor,\n\t\t\t// `/v1/index/blocks?limit=1` always returns a row (the default window's\n\t\t\t// oldest block), so the server would never see \"nothing new\" to wait\n\t\t\t// on. Anchoring one past the last height THIS caller saw makes the page\n\t\t\t// empty until a fresher block lands — the same signal the endpoint\n\t\t\t// already uses for a normal forward walk.\n\t\t\tif (opts?.knownHeight !== undefined) {\n\t\t\t\tparams.set(\"from_height\", String(opts.knownHeight + 1));\n\t\t\t}\n\t\t}\n\t\ttry {\n\t\t\tconst env = await this.get<IndexTipEnvelope>(\n\t\t\t\t`${this.indexBaseUrl}/v1/index/blocks?${params}`,\n\t\t\t\tthis.indexApiKey,\n\t\t\t);\n\t\t\tthis.lastTipEnvelope = env;\n\t\t\treturn env;\n\t\t} catch (err) {\n\t\t\t// An older server's `validateQueryParams` 400s on `wait`/`from_height`\n\t\t\t// it doesn't recognize. Treat that ONE status as \"this server predates\n\t\t\t// long-poll\", not an outage: disable wait for the rest of this client's\n\t\t\t// life and retry plainly, so `FallbackBlockSource` never mistakes a\n\t\t\t// version-skew 400 for the api being down and routes to the DB tap.\n\t\t\tif (\n\t\t\t\twantsWait &&\n\t\t\t\terr instanceof IndexHttpStatusError &&\n\t\t\t\terr.status === 400\n\t\t\t) {\n\t\t\t\tthis.waitSupported = false;\n\t\t\t\treturn this.getIndexTipEnvelope(opts);\n\t\t\t}\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\t/** Reorgs since a resume token (wall-clock `detected_at`-keyed). */\n\tasync listReorgs(\n\t\tsince: string,\n\t): Promise<{ reorgs: StreamsReorgRow[]; next_since: string | null }> {\n\t\tconst params = new URLSearchParams({ since });\n\t\treturn this.get(\n\t\t\t`${this.streamsBaseUrl}/v1/streams/reorgs?${params}`,\n\t\t\tthis.streamsApiKey,\n\t\t);\n\t}\n}\n\n/** Decoder + subgraph processor client. One env contract; omits bearer when no key. */\nexport function createInternalIndexHttpClient(): IndexHttpClient {\n\tconst baseUrl = defaultInternalIndexBaseUrl();\n\treturn new IndexHttpClient({\n\t\tindexBaseUrl: baseUrl,\n\t\tstreamsBaseUrl: baseUrl,\n\t\tindexApiKey: defaultInternalIndexApiKey(),\n\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
|
11
11
|
}
|
|
@@ -20,5 +20,23 @@ declare function sourceListenerUrl(): string | undefined;
|
|
|
20
20
|
*/
|
|
21
21
|
declare function targetListenerUrl(): string | undefined;
|
|
22
22
|
declare function listen(channel: string, callback: (payload?: string) => void, opts?: ListenOptions): Promise<() => Promise<void>>;
|
|
23
|
+
/** A shareable wake point: any number of callers can `wait()` for the next
|
|
24
|
+
* NOTIFY on `channel`, each getting their own promise. One LISTEN connection
|
|
25
|
+
* backs every waiter, so a decoder pool or an API replica needs only one
|
|
26
|
+
* `createWakeBus` per process per channel, not one per caller. */
|
|
27
|
+
type WakeBus = {
|
|
28
|
+
/** Resolves on the next NOTIFY. A fresh promise every call — safe to call
|
|
29
|
+
* again immediately after it resolves. */
|
|
30
|
+
wait: () => Promise<void>
|
|
31
|
+
/** Close the underlying LISTEN connection and resolve every pending waiter
|
|
32
|
+
* (so nothing blocks forever on shutdown). */
|
|
33
|
+
stop: () => Promise<void>
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Start a `WakeBus` on `channel`. Callers that only need a fallback timer if
|
|
37
|
+
* this fails should catch the rejection and keep polling — a wake bus is an
|
|
38
|
+
* optimization, never the only path to progress (see plan-063 D3).
|
|
39
|
+
*/
|
|
40
|
+
declare function createWakeBus(channel: string, opts?: ListenOptions): Promise<WakeBus>;
|
|
23
41
|
declare function notify(channel: string, payload?: string, opts?: ListenOptions): Promise<void>;
|
|
24
|
-
export { listen, notify, sourceListenerUrl, targetListenerUrl };
|
|
42
|
+
export { WakeBus, createWakeBus, listen, notify, sourceListenerUrl, targetListenerUrl };
|
|
@@ -25,6 +25,25 @@ async function listen(channel, callback, opts) {
|
|
|
25
25
|
await client.end();
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
async function createWakeBus(channel, opts) {
|
|
29
|
+
let waiters = new Set;
|
|
30
|
+
const stopListening = await listen(channel, () => {
|
|
31
|
+
const pending = waiters;
|
|
32
|
+
waiters = new Set;
|
|
33
|
+
for (const resolve of pending)
|
|
34
|
+
resolve();
|
|
35
|
+
}, opts);
|
|
36
|
+
return {
|
|
37
|
+
wait: () => new Promise((resolve) => waiters.add(resolve)),
|
|
38
|
+
stop: async () => {
|
|
39
|
+
const pending = waiters;
|
|
40
|
+
waiters = new Set;
|
|
41
|
+
for (const resolve of pending)
|
|
42
|
+
resolve();
|
|
43
|
+
await stopListening();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
28
47
|
async function notify(channel, payload, opts) {
|
|
29
48
|
const client = postgres(resolveUrl(opts), { max: 1 });
|
|
30
49
|
try {
|
|
@@ -38,11 +57,12 @@ async function notify(channel, payload, opts) {
|
|
|
38
57
|
}
|
|
39
58
|
}
|
|
40
59
|
export {
|
|
60
|
+
createWakeBus,
|
|
41
61
|
listen,
|
|
42
62
|
notify,
|
|
43
63
|
sourceListenerUrl,
|
|
44
64
|
targetListenerUrl
|
|
45
65
|
};
|
|
46
66
|
|
|
47
|
-
//# debugId=
|
|
67
|
+
//# debugId=6CB62612CF7C450A64756E2164756E21
|
|
48
68
|
//# sourceMappingURL=listener.js.map
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/queue/listener.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import postgres from \"postgres\";\n\ninterface ListenOptions {\n\t/**\n\t * Connection string to LISTEN on. Defaults to `process.env.DATABASE_URL`.\n\t * In dual-DB mode, pass `SOURCE_DATABASE_URL` for indexer-fired channels\n\t * (`indexer:new_block`, `subgraph_reorg`, `tx:confirmed`) and\n\t * `TARGET_DATABASE_URL` for tenant-local channels (`subgraph_changes`).\n\t */\n\tconnectionString?: string;\n}\n\n/**\n * LISTEN/NOTIFY connection for indexer-fired channels (`indexer:new_block`,\n * `subgraph_reorg`, `tx:confirmed`) — they fire on the SOURCE (chain) DB.\n * `||` (not `??`) so an empty-string env (an unset `SOURCE_DATABASE_URL` passed\n * through docker-compose as `\"\"`) falls back to `DATABASE_URL`.\n */\nexport function sourceListenerUrl(): string | undefined {\n\treturn process.env.SOURCE_DATABASE_URL || process.env.DATABASE_URL;\n}\n\n/**\n * LISTEN/NOTIFY connection for control-plane channels (`webhooks:new_outbox`,\n * `webhooks:changed`, subgraph operations) — they fire on the TARGET DB.\n */\nexport function targetListenerUrl(): string | undefined {\n\treturn process.env.TARGET_DATABASE_URL || process.env.DATABASE_URL;\n}\n\nfunction resolveUrl(opts?: ListenOptions): string {\n\t// `||` not `??`: an empty-string connectionString (e.g. an unset\n\t// SOURCE_/TARGET_DATABASE_URL passed through docker-compose as \"\") must fall\n\t// back to DATABASE_URL, not be treated as a valid value.\n\tconst url = opts?.connectionString || process.env.DATABASE_URL;\n\tif (!url) {\n\t\tthrow new Error(\n\t\t\t\"listen/notify requires a connection string (opts.connectionString or DATABASE_URL)\",\n\t\t);\n\t}\n\treturn url;\n}\n\nexport async function listen(\n\tchannel: string,\n\tcallback: (payload?: string) => void,\n\topts?: ListenOptions,\n): Promise<() => Promise<void>> {\n\tconst client = postgres(resolveUrl(opts), {\n\t\tmax: 1,\n\t\tonnotice: () => {},\n\t});\n\n\tawait client.listen(channel, (payload) => {\n\t\tcallback(payload);\n\t});\n\n\treturn async () => {\n\t\tawait client.end();\n\t};\n}\n\nexport async function notify(\n\tchannel: string,\n\tpayload?: string,\n\topts?: ListenOptions,\n): Promise<void> {\n\tconst client = postgres(resolveUrl(opts), { max: 1 });\n\n\ttry {\n\t\tif (payload) {\n\t\t\tawait client`SELECT pg_notify(${channel}, ${payload})`;\n\t\t} else {\n\t\t\tawait client`SELECT pg_notify(${channel}, '')`;\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"
|
|
5
|
+
"import postgres from \"postgres\";\n\ninterface ListenOptions {\n\t/**\n\t * Connection string to LISTEN on. Defaults to `process.env.DATABASE_URL`.\n\t * In dual-DB mode, pass `SOURCE_DATABASE_URL` for indexer-fired channels\n\t * (`indexer:new_block`, `subgraph_reorg`, `tx:confirmed`) and\n\t * `TARGET_DATABASE_URL` for tenant-local channels (`subgraph_changes`).\n\t */\n\tconnectionString?: string;\n}\n\n/**\n * LISTEN/NOTIFY connection for indexer-fired channels (`indexer:new_block`,\n * `subgraph_reorg`, `tx:confirmed`) — they fire on the SOURCE (chain) DB.\n * `||` (not `??`) so an empty-string env (an unset `SOURCE_DATABASE_URL` passed\n * through docker-compose as `\"\"`) falls back to `DATABASE_URL`.\n */\nexport function sourceListenerUrl(): string | undefined {\n\treturn process.env.SOURCE_DATABASE_URL || process.env.DATABASE_URL;\n}\n\n/**\n * LISTEN/NOTIFY connection for control-plane channels (`webhooks:new_outbox`,\n * `webhooks:changed`, subgraph operations) — they fire on the TARGET DB.\n */\nexport function targetListenerUrl(): string | undefined {\n\treturn process.env.TARGET_DATABASE_URL || process.env.DATABASE_URL;\n}\n\nfunction resolveUrl(opts?: ListenOptions): string {\n\t// `||` not `??`: an empty-string connectionString (e.g. an unset\n\t// SOURCE_/TARGET_DATABASE_URL passed through docker-compose as \"\") must fall\n\t// back to DATABASE_URL, not be treated as a valid value.\n\tconst url = opts?.connectionString || process.env.DATABASE_URL;\n\tif (!url) {\n\t\tthrow new Error(\n\t\t\t\"listen/notify requires a connection string (opts.connectionString or DATABASE_URL)\",\n\t\t);\n\t}\n\treturn url;\n}\n\nexport async function listen(\n\tchannel: string,\n\tcallback: (payload?: string) => void,\n\topts?: ListenOptions,\n): Promise<() => Promise<void>> {\n\tconst client = postgres(resolveUrl(opts), {\n\t\tmax: 1,\n\t\tonnotice: () => {},\n\t});\n\n\tawait client.listen(channel, (payload) => {\n\t\tcallback(payload);\n\t});\n\n\treturn async () => {\n\t\tawait client.end();\n\t};\n}\n\n/** A shareable wake point: any number of callers can `wait()` for the next\n * NOTIFY on `channel`, each getting their own promise. One LISTEN connection\n * backs every waiter, so a decoder pool or an API replica needs only one\n * `createWakeBus` per process per channel, not one per caller. */\nexport type WakeBus = {\n\t/** Resolves on the next NOTIFY. A fresh promise every call — safe to call\n\t * again immediately after it resolves. */\n\twait: () => Promise<void>;\n\t/** Close the underlying LISTEN connection and resolve every pending waiter\n\t * (so nothing blocks forever on shutdown). */\n\tstop: () => Promise<void>;\n};\n\n/**\n * Start a `WakeBus` on `channel`. Callers that only need a fallback timer if\n * this fails should catch the rejection and keep polling — a wake bus is an\n * optimization, never the only path to progress (see plan-063 D3).\n */\nexport async function createWakeBus(\n\tchannel: string,\n\topts?: ListenOptions,\n): Promise<WakeBus> {\n\tlet waiters = new Set<() => void>();\n\tconst stopListening = await listen(\n\t\tchannel,\n\t\t() => {\n\t\t\tconst pending = waiters;\n\t\t\twaiters = new Set();\n\t\t\tfor (const resolve of pending) resolve();\n\t\t},\n\t\topts,\n\t);\n\treturn {\n\t\twait: () => new Promise<void>((resolve) => waiters.add(resolve)),\n\t\tstop: async () => {\n\t\t\tconst pending = waiters;\n\t\t\twaiters = new Set();\n\t\t\tfor (const resolve of pending) resolve();\n\t\t\tawait stopListening();\n\t\t},\n\t};\n}\n\nexport async function notify(\n\tchannel: string,\n\tpayload?: string,\n\topts?: ListenOptions,\n): Promise<void> {\n\tconst client = postgres(resolveUrl(opts), { max: 1 });\n\n\ttry {\n\t\tif (payload) {\n\t\t\tawait client`SELECT pg_notify(${channel}, ${payload})`;\n\t\t} else {\n\t\t\tawait client`SELECT pg_notify(${channel}, '')`;\n\t\t}\n\t} finally {\n\t\tawait client.end();\n\t}\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA;AAkBO,SAAS,iBAAiB,GAAuB;AAAA,EACvD,OAAO,QAAQ,IAAI,uBAAuB,QAAQ,IAAI;AAAA;AAOhD,SAAS,iBAAiB,GAAuB;AAAA,EACvD,OAAO,QAAQ,IAAI,uBAAuB,QAAQ,IAAI;AAAA;AAGvD,SAAS,UAAU,CAAC,MAA8B;AAAA,EAIjD,MAAM,MAAM,MAAM,oBAAoB,QAAQ,IAAI;AAAA,EAClD,IAAI,CAAC,KAAK;AAAA,IACT,MA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