@secondlayer/shared 17.1.0 → 18.0.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.
Files changed (38) hide show
  1. package/dist/src/archive/range-digest.d.ts +2 -65
  2. package/dist/src/archive/semantic-digest-builder.d.ts +2 -65
  3. package/dist/src/coverage/index.d.ts +12 -76
  4. package/dist/src/coverage/index.js +19 -60
  5. package/dist/src/coverage/index.js.map +3 -3
  6. package/dist/src/db/index.d.ts +3 -111
  7. package/dist/src/db/index.js +1 -34
  8. package/dist/src/db/index.js.map +5 -5
  9. package/dist/src/db/queries/chain-reorgs.d.ts +2 -65
  10. package/dist/src/db/queries/chain-reorgs.js +1 -34
  11. package/dist/src/db/queries/chain-reorgs.js.map +5 -5
  12. package/dist/src/db/queries/contracts.d.ts +2 -65
  13. package/dist/src/db/queries/contracts.js.map +2 -2
  14. package/dist/src/db/queries/instance.d.ts +2 -65
  15. package/dist/src/db/queries/integrity.d.ts +2 -65
  16. package/dist/src/db/queries/subgraph-gaps.d.ts +2 -65
  17. package/dist/src/db/queries/subgraph-operations.d.ts +2 -65
  18. package/dist/src/db/queries/subgraphs.d.ts +2 -65
  19. package/dist/src/db/queries/sync-scope.d.ts +2 -65
  20. package/dist/src/db/queries/webhook-replays.d.ts +2 -65
  21. package/dist/src/db/queries/webhooks.d.ts +2 -65
  22. package/dist/src/db/schema.d.ts +3 -64
  23. package/dist/src/db/schema.js.map +2 -2
  24. package/dist/src/index.d.ts +3 -111
  25. package/dist/src/index.js +1 -34
  26. package/dist/src/index.js.map +5 -5
  27. package/dist/src/insights/index.d.ts +2 -65
  28. package/dist/src/leader.js +1 -34
  29. package/dist/src/leader.js.map +5 -5
  30. package/dist/src/node/local-client.d.ts +2 -65
  31. package/dist/src/queue/listener.js +1 -34
  32. package/dist/src/queue/listener.js.map +5 -5
  33. package/migrations/0211_decoded_events_slim.ts +114 -0
  34. package/migrations/0212_events_transactions_redundant_indexes.ts +71 -0
  35. package/migrations/0213_drop_sbtc_token_events.ts +32 -0
  36. package/migrations/0214_drop_coverage_receipts.ts +24 -0
  37. package/migrations/0215_decoder_checkpoints_last_output_at.ts +33 -0
  38. package/package.json +1 -1
@@ -10,8 +10,6 @@ declare const NATIVE_CLOCKS: readonly ["block", "cursor", "queue"];
10
10
  type NativeClock = (typeof NATIVE_CLOCKS)[number];
11
11
  declare const REPAIR_MODES: readonly ["range_safe", "full_reindex", "archive_replay", "none"];
12
12
  type RepairMode = (typeof REPAIR_MODES)[number];
13
- declare const RUN_STATUSES: readonly ["pending", "running", "complete", "syncing", "lagging", "gap", "stale", "failed", "unverified_import", "unanchored", "source_unavailable", "out_of_scope", "disabled", "halted"];
14
- type RunStatus = (typeof RUN_STATUSES)[number];
15
13
  declare const FAILURE_UNITS: readonly ["block", "range", "cursor", "queue"];
16
14
  type FailureUnit = (typeof FAILURE_UNITS)[number];
17
15
  declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch", "crash", "reorg", "source_gap", "handler", "timeout", "unknown"];
@@ -452,7 +450,6 @@ interface DecodedEventsTable {
452
450
  tx_index: number;
453
451
  event_index: number;
454
452
  event_type: string;
455
- microblock_hash: string | null;
456
453
  canonical: Generated<boolean>;
457
454
  contract_id: string | null;
458
455
  sender: string | null;
@@ -464,13 +461,14 @@ interface DecodedEventsTable {
464
461
  /** Decoded payload for event types that don't fit the flat columns
465
462
  * (e.g. `print`: { topic, value, raw_value }). Null for transfer types. */
466
463
  payload: unknown | null;
467
- source_cursor: string;
468
464
  created_at: Generated<Date>;
469
465
  }
470
466
  interface DecoderCheckpointsTable {
471
467
  decoder_name: string;
472
468
  last_cursor: string | null;
473
469
  updated_at: Generated<Date>;
470
+ /** Last commit that wrote output rows; health's real-work signal. */
471
+ last_output_at: Date | null;
474
472
  }
475
473
  interface ChainReorgsTable {
476
474
  id: Generated<string>;
@@ -598,23 +596,6 @@ interface SbtcEventsTable {
598
596
  source_cursor: string;
599
597
  created_at: Generated<Date>;
600
598
  }
601
- type SbtcTokenEventType = "transfer" | "mint" | "burn";
602
- interface SbtcTokenEventsTable {
603
- cursor: string;
604
- block_height: number;
605
- block_time: Date;
606
- tx_id: string;
607
- tx_index: number;
608
- event_index: number;
609
- event_type: SbtcTokenEventType;
610
- sender: string | null;
611
- recipient: string | null;
612
- amount: string;
613
- memo: string | null;
614
- canonical: Generated<boolean>;
615
- source_cursor: string;
616
- created_at: Generated<Date>;
617
- }
618
599
  /**
619
600
  * BTC L1 settlement status for sBTC withdrawal sweeps. Filled by the indexer's
620
601
  * settlement-confirmer worker, which polls our own bitcoind for confirmations of
@@ -796,50 +777,10 @@ interface StageRegistryTable {
796
777
  enabled: Generated<boolean>;
797
778
  created_at: Generated<Date>;
798
779
  }
799
- /** One versioned sweep of a stage. Nothing writes this table yet; kept because the receipts and failures tables reference it. */
800
- interface StageRunsTable {
801
- id: Generated<string>;
802
- stage_id: string;
803
- code_hash: string;
804
- config_hash: string;
805
- handler_hash: string | null;
806
- target_height: number | null;
807
- target_cursor: string | null;
808
- status: RunStatus;
809
- complete_through: number | null;
810
- started_at: Generated<Date>;
811
- finished_at: Date | null;
812
- }
813
- /** Per-block acknowledgement. Unique on (stage, height, hash). */
814
- interface StageBlockReceiptsTable {
815
- id: Generated<string>;
816
- stage_id: string;
817
- run_id: string | null;
818
- block_height: number;
819
- block_hash: string;
820
- input_count: number;
821
- input_digest: string;
822
- effect_digest: string;
823
- finalized: Generated<boolean>;
824
- compacted_at: Date | null;
825
- created_at: Generated<Date>;
826
- }
827
- /** Compacted finalized range. Only sealed after receipts in the range finalize. */
828
- interface CoverageSegmentsTable {
829
- id: Generated<string>;
830
- stage_id: string;
831
- from_height: number;
832
- to_height: number;
833
- chain_digest: string;
834
- input_digest: string;
835
- output_digest: string;
836
- sealed_at: Generated<Date>;
837
- }
838
780
  /** Exact unit or range that failed, plus retry/retention state. */
839
781
  interface StageFailuresTable {
840
782
  id: Generated<string>;
841
783
  stage_id: string;
842
- run_id: string | null;
843
784
  unit_kind: FailureUnit;
844
785
  from_height: number | null;
845
786
  to_height: number | null;
@@ -909,7 +850,6 @@ interface Database {
909
850
  burn_block_rewards: BurnBlockRewardsTable;
910
851
  burn_block_reward_slots: BurnBlockRewardSlotsTable;
911
852
  sbtc_events: SbtcEventsTable;
912
- sbtc_token_events: SbtcTokenEventsTable;
913
853
  sbtc_settlements: SbtcSettlementsTable;
914
854
  bns_name_events: BnsNameEventsTable;
915
855
  bns_namespace_events: BnsNamespaceEventsTable;
@@ -922,9 +862,6 @@ interface Database {
922
862
  observer_journal: ObserverJournalTable;
923
863
  sync_scopes: SyncScopesTable;
924
864
  stage_registry: StageRegistryTable;
925
- stage_runs: StageRunsTable;
926
- stage_block_receipts: StageBlockReceiptsTable;
927
- coverage_segments: CoverageSegmentsTable;
928
865
  stage_failures: StageFailuresTable;
929
866
  archive_fetches: ArchiveFetchesTable;
930
867
  usage_ledger: UsageLedgerTable;
@@ -10,8 +10,6 @@ declare const NATIVE_CLOCKS: readonly ["block", "cursor", "queue"];
10
10
  type NativeClock = (typeof NATIVE_CLOCKS)[number];
11
11
  declare const REPAIR_MODES: readonly ["range_safe", "full_reindex", "archive_replay", "none"];
12
12
  type RepairMode = (typeof REPAIR_MODES)[number];
13
- declare const RUN_STATUSES: readonly ["pending", "running", "complete", "syncing", "lagging", "gap", "stale", "failed", "unverified_import", "unanchored", "source_unavailable", "out_of_scope", "disabled", "halted"];
14
- type RunStatus = (typeof RUN_STATUSES)[number];
15
13
  declare const FAILURE_UNITS: readonly ["block", "range", "cursor", "queue"];
16
14
  type FailureUnit = (typeof FAILURE_UNITS)[number];
17
15
  declare const FAILURE_CLASSES: readonly ["omission", "version", "digest_mismatch", "crash", "reorg", "source_gap", "handler", "timeout", "unknown"];
@@ -452,7 +450,6 @@ interface DecodedEventsTable {
452
450
  tx_index: number;
453
451
  event_index: number;
454
452
  event_type: string;
455
- microblock_hash: string | null;
456
453
  canonical: Generated<boolean>;
457
454
  contract_id: string | null;
458
455
  sender: string | null;
@@ -464,13 +461,14 @@ interface DecodedEventsTable {
464
461
  /** Decoded payload for event types that don't fit the flat columns
465
462
  * (e.g. `print`: { topic, value, raw_value }). Null for transfer types. */
466
463
  payload: unknown | null;
467
- source_cursor: string;
468
464
  created_at: Generated<Date>;
469
465
  }
470
466
  interface DecoderCheckpointsTable {
471
467
  decoder_name: string;
472
468
  last_cursor: string | null;
473
469
  updated_at: Generated<Date>;
470
+ /** Last commit that wrote output rows; health's real-work signal. */
471
+ last_output_at: Date | null;
474
472
  }
475
473
  interface ChainReorgsTable {
476
474
  id: Generated<string>;
@@ -598,23 +596,6 @@ interface SbtcEventsTable {
598
596
  source_cursor: string;
599
597
  created_at: Generated<Date>;
600
598
  }
601
- type SbtcTokenEventType = "transfer" | "mint" | "burn";
602
- interface SbtcTokenEventsTable {
603
- cursor: string;
604
- block_height: number;
605
- block_time: Date;
606
- tx_id: string;
607
- tx_index: number;
608
- event_index: number;
609
- event_type: SbtcTokenEventType;
610
- sender: string | null;
611
- recipient: string | null;
612
- amount: string;
613
- memo: string | null;
614
- canonical: Generated<boolean>;
615
- source_cursor: string;
616
- created_at: Generated<Date>;
617
- }
618
599
  /**
619
600
  * BTC L1 settlement status for sBTC withdrawal sweeps. Filled by the indexer's
620
601
  * settlement-confirmer worker, which polls our own bitcoind for confirmations of
@@ -796,50 +777,10 @@ interface StageRegistryTable {
796
777
  enabled: Generated<boolean>;
797
778
  created_at: Generated<Date>;
798
779
  }
799
- /** One versioned sweep of a stage. Nothing writes this table yet; kept because the receipts and failures tables reference it. */
800
- interface StageRunsTable {
801
- id: Generated<string>;
802
- stage_id: string;
803
- code_hash: string;
804
- config_hash: string;
805
- handler_hash: string | null;
806
- target_height: number | null;
807
- target_cursor: string | null;
808
- status: RunStatus;
809
- complete_through: number | null;
810
- started_at: Generated<Date>;
811
- finished_at: Date | null;
812
- }
813
- /** Per-block acknowledgement. Unique on (stage, height, hash). */
814
- interface StageBlockReceiptsTable {
815
- id: Generated<string>;
816
- stage_id: string;
817
- run_id: string | null;
818
- block_height: number;
819
- block_hash: string;
820
- input_count: number;
821
- input_digest: string;
822
- effect_digest: string;
823
- finalized: Generated<boolean>;
824
- compacted_at: Date | null;
825
- created_at: Generated<Date>;
826
- }
827
- /** Compacted finalized range. Only sealed after receipts in the range finalize. */
828
- interface CoverageSegmentsTable {
829
- id: Generated<string>;
830
- stage_id: string;
831
- from_height: number;
832
- to_height: number;
833
- chain_digest: string;
834
- input_digest: string;
835
- output_digest: string;
836
- sealed_at: Generated<Date>;
837
- }
838
780
  /** Exact unit or range that failed, plus retry/retention state. */
839
781
  interface StageFailuresTable {
840
782
  id: Generated<string>;
841
783
  stage_id: string;
842
- run_id: string | null;
843
784
  unit_kind: FailureUnit;
844
785
  from_height: number | null;
845
786
  to_height: number | null;
@@ -909,7 +850,6 @@ interface Database {
909
850
  burn_block_rewards: BurnBlockRewardsTable;
910
851
  burn_block_reward_slots: BurnBlockRewardSlotsTable;
911
852
  sbtc_events: SbtcEventsTable;
912
- sbtc_token_events: SbtcTokenEventsTable;
913
853
  sbtc_settlements: SbtcSettlementsTable;
914
854
  bns_name_events: BnsNameEventsTable;
915
855
  bns_namespace_events: BnsNamespaceEventsTable;
@@ -922,9 +862,6 @@ interface Database {
922
862
  observer_journal: ObserverJournalTable;
923
863
  sync_scopes: SyncScopesTable;
924
864
  stage_registry: StageRegistryTable;
925
- stage_runs: StageRunsTable;
926
- stage_block_receipts: StageBlockReceiptsTable;
927
- coverage_segments: CoverageSegmentsTable;
928
865
  stage_failures: StageFailuresTable;
929
866
  archive_fetches: ArchiveFetchesTable;
930
867
  usage_ledger: UsageLedgerTable;
@@ -769,7 +769,6 @@ interface DecodedEventsTable {
769
769
  tx_index: number;
770
770
  event_index: number;
771
771
  event_type: string;
772
- microblock_hash: string | null;
773
772
  canonical: Generated<boolean>;
774
773
  contract_id: string | null;
775
774
  sender: string | null;
@@ -781,13 +780,14 @@ interface DecodedEventsTable {
781
780
  /** Decoded payload for event types that don't fit the flat columns
782
781
  * (e.g. `print`: { topic, value, raw_value }). Null for transfer types. */
783
782
  payload: unknown | null;
784
- source_cursor: string;
785
783
  created_at: Generated<Date>;
786
784
  }
787
785
  interface DecoderCheckpointsTable {
788
786
  decoder_name: string;
789
787
  last_cursor: string | null;
790
788
  updated_at: Generated<Date>;
789
+ /** Last commit that wrote output rows; health's real-work signal. */
790
+ last_output_at: Date | null;
791
791
  }
792
792
  interface ChainReorgsTable {
793
793
  id: Generated<string>;
@@ -915,23 +915,6 @@ interface SbtcEventsTable {
915
915
  source_cursor: string;
916
916
  created_at: Generated<Date>;
917
917
  }
918
- type SbtcTokenEventType = "transfer" | "mint" | "burn";
919
- interface SbtcTokenEventsTable {
920
- cursor: string;
921
- block_height: number;
922
- block_time: Date;
923
- tx_id: string;
924
- tx_index: number;
925
- event_index: number;
926
- event_type: SbtcTokenEventType;
927
- sender: string | null;
928
- recipient: string | null;
929
- amount: string;
930
- memo: string | null;
931
- canonical: Generated<boolean>;
932
- source_cursor: string;
933
- created_at: Generated<Date>;
934
- }
935
918
  /**
936
919
  * BTC L1 settlement status for sBTC withdrawal sweeps. Filled by the indexer's
937
920
  * settlement-confirmer worker, which polls our own bitcoind for confirmations of
@@ -1113,50 +1096,10 @@ interface StageRegistryTable {
1113
1096
  enabled: Generated<boolean>;
1114
1097
  created_at: Generated<Date>;
1115
1098
  }
1116
- /** One versioned sweep of a stage. Nothing writes this table yet; kept because the receipts and failures tables reference it. */
1117
- interface StageRunsTable {
1118
- id: Generated<string>;
1119
- stage_id: string;
1120
- code_hash: string;
1121
- config_hash: string;
1122
- handler_hash: string | null;
1123
- target_height: number | null;
1124
- target_cursor: string | null;
1125
- status: RunStatus;
1126
- complete_through: number | null;
1127
- started_at: Generated<Date>;
1128
- finished_at: Date | null;
1129
- }
1130
- /** Per-block acknowledgement. Unique on (stage, height, hash). */
1131
- interface StageBlockReceiptsTable {
1132
- id: Generated<string>;
1133
- stage_id: string;
1134
- run_id: string | null;
1135
- block_height: number;
1136
- block_hash: string;
1137
- input_count: number;
1138
- input_digest: string;
1139
- effect_digest: string;
1140
- finalized: Generated<boolean>;
1141
- compacted_at: Date | null;
1142
- created_at: Generated<Date>;
1143
- }
1144
- /** Compacted finalized range. Only sealed after receipts in the range finalize. */
1145
- interface CoverageSegmentsTable {
1146
- id: Generated<string>;
1147
- stage_id: string;
1148
- from_height: number;
1149
- to_height: number;
1150
- chain_digest: string;
1151
- input_digest: string;
1152
- output_digest: string;
1153
- sealed_at: Generated<Date>;
1154
- }
1155
1099
  /** Exact unit or range that failed, plus retry/retention state. */
1156
1100
  interface StageFailuresTable {
1157
1101
  id: Generated<string>;
1158
1102
  stage_id: string;
1159
- run_id: string | null;
1160
1103
  unit_kind: FailureUnit;
1161
1104
  from_height: number | null;
1162
1105
  to_height: number | null;
@@ -1226,7 +1169,6 @@ interface Database {
1226
1169
  burn_block_rewards: BurnBlockRewardsTable;
1227
1170
  burn_block_reward_slots: BurnBlockRewardSlotsTable;
1228
1171
  sbtc_events: SbtcEventsTable;
1229
- sbtc_token_events: SbtcTokenEventsTable;
1230
1172
  sbtc_settlements: SbtcSettlementsTable;
1231
1173
  bns_name_events: BnsNameEventsTable;
1232
1174
  bns_namespace_events: BnsNamespaceEventsTable;
@@ -1239,9 +1181,6 @@ interface Database {
1239
1181
  observer_journal: ObserverJournalTable;
1240
1182
  sync_scopes: SyncScopesTable;
1241
1183
  stage_registry: StageRegistryTable;
1242
- stage_runs: StageRunsTable;
1243
- stage_block_receipts: StageBlockReceiptsTable;
1244
- coverage_segments: CoverageSegmentsTable;
1245
1184
  stage_failures: StageFailuresTable;
1246
1185
  archive_fetches: ArchiveFetchesTable;
1247
1186
  usage_ledger: UsageLedgerTable;
@@ -1762,7 +1701,7 @@ interface FeedbackTicketsTable {
1762
1701
  classified_at: Date | null;
1763
1702
  created_at: Generated<Date>;
1764
1703
  }
1765
- declare const DECODER_COMMIT_STEPS: readonly ["output", "checkpoint", "receipt", "failure"];
1704
+ declare const DECODER_COMMIT_STEPS: readonly ["output", "checkpoint", "failure"];
1766
1705
  type DecoderCommitStep = (typeof DECODER_COMMIT_STEPS)[number];
1767
1706
  declare class DecoderAdapterCrash extends Error {
1768
1707
  readonly step: DecoderCommitStep;
@@ -1778,22 +1717,19 @@ type DecoderAdapterFailure = {
1778
1717
  error: string | null
1779
1718
  retry_count?: number
1780
1719
  };
1781
- type DecoderAdapterReceipt = DecoderClockReceipt & {
1782
- effect_digest: string
1783
- };
1784
1720
  type DecoderAdapterCommit = {
1785
1721
  stage_id: string
1786
- run_id?: string | null
1787
1722
  decoder_name: string
1788
1723
  /** Null = do not move the checkpoint (empty page). */
1789
1724
  checkpoint_cursor: string | null
1790
- receipts: readonly DecoderAdapterReceipt[]
1791
1725
  failure?: DecoderAdapterFailure | null
1792
1726
  writeOutput: (tx: Kysely<Database>) => Promise<void>
1727
+ /** Rows `writeOutput` writes. When > 0 the commit stamps
1728
+ * `decoder_checkpoints.last_output_at`, which decoder health reads. */
1729
+ output_count?: number
1793
1730
  crashAfter?: DecoderCommitStep
1794
1731
  };
1795
1732
  declare function runDecoderCommitSteps(steps: Record<DecoderCommitStep, () => Promise<void>>, crashAfter?: DecoderCommitStep): Promise<void>;
1796
- declare function applyDecoderReceipts(state: RunnerState, receipts: readonly DecoderAdapterReceipt[]): RunnerResult;
1797
1733
  /**
1798
1734
  * Set a decoder's checkpoint to `cursor`, backward or forward. The one
1799
1735
  * unconditional checkpoint writer: reorg handlers rewind decoders to the fork
@@ -1802,9 +1738,9 @@ declare function applyDecoderReceipts(state: RunnerState, receipts: readonly Dec
1802
1738
  */
1803
1739
  declare function rewindDecoderCheckpoint(db: Kysely<Database>, decoderName: string, cursor: string | null): Promise<void>;
1804
1740
  /**
1805
- * Persist output + checkpoint + receipts + failure in one transaction.
1806
- * Runner validation is the caller's job (`applyDecoderReceipts`) so a
1807
- * rejected ack never opens a transaction.
1741
+ * Persist output + checkpoint + failure in one transaction. The registry row
1742
+ * is upserted only when a failure is written, to satisfy the
1743
+ * `stage_failures.stage_id` foreign key.
1808
1744
  *
1809
1745
  * No production caller (decoders use the batch form); kept as the exported
1810
1746
  * single-decoder entry point and covered by decoder-adapter-crash.test.ts.
@@ -1817,8 +1753,8 @@ declare function commitDecoderAdapter(db: Kysely<Database>, input: DecoderAdapte
1817
1753
  * checkpoints + their decoded rows land together, so a crash mid-batch
1818
1754
  * cannot leave one type's checkpoint ahead of another's rows.
1819
1755
  *
1820
- * Steps run in four PASSES across the whole batch, not step-by-step per
1821
- * entry, so the global order stays output → checkpoint → receipt → failure
1756
+ * Steps run in three PASSES across the whole batch, not step-by-step per
1757
+ * entry, so the global order stays output → checkpoint → failure
1822
1758
  * (matching the single-entry commit) while every entry's output — including
1823
1759
  * its `assertCheckpointUnmoved` FOR UPDATE check — lands before any entry's
1824
1760
  * new checkpoint is written. Entries are locked in the order given, which
@@ -2029,4 +1965,4 @@ declare function reportVerify(opts: {
2029
1965
  diverged?: boolean
2030
1966
  detail?: string
2031
1967
  }): VerifyReport;
2032
- export { BootstrapSource, COVERAGE_REPORT_SCHEMA_VERSION, COVERAGE_STATES, CanonicalBlock, CoverageRange, CoverageReport, CoverageState, DECODER_COMMIT_STEPS, DEFAULT_MAX_RETRIES, DecoderAdapterCommit, DecoderAdapterCrash, DecoderAdapterFailure, DecoderAdapterReceipt, DecoderClockEvent, DecoderClockInput, DecoderClockReceipt, DecoderClockResult, DecoderCommitStep, DeepVerifyResult, EffectMutation, EffectOp, EvaluatorInput, EvaluatorOptions, FAILURE_CLASSES, FAILURE_RETENTION_DAYS, FAILURE_UNITS, FailureClass, FailureRow, FailureUnit, NATIVE_CLOCKS, NativeClock, OpenFailure, QUEUE_STAGES, QueueApply, QueueCounters, QueueEvent, QueueStage, QueueState, REPAIR_MODES, RETRY_STATES, RUNNER_EVENT_TYPES, RUNNER_STATUSES, RUNNER_TRANSITION_TABLE, RUN_STATUSES, ReceiptRow, RepairDefect, RepairMode, RepairPlan, RetryState, RowSnapshot, RunStatus, RunnerEffect, RunnerEvent, RunnerEventType, RunnerFailure, RunnerResult, RunnerState, RunnerStatus, RunnerVersion, SAFE_REPAIR_MODES, STAGE_KINDS, SUBGRAPH_COMMIT_STEPS, SealResult, SealableReceipt, SealedSegment, SourceClock, StageCoverage, StageDeclaration, StageEvidence, StageKind, StageRunView, SubgraphAdapterCrash, SubgraphCommitInput, SubgraphCommitStep, SyncScope, TransitionRule, VERIFY_EXIT, VerifyExit, VerifyMode, VerifyReport, VerifyTarget, applyDecoderReceipts, applyMutations, applyQueueEvent, applyRunnerEvent, canonicalizeMutations, commitDecoderAdapter, commitDecoderAdapterBatch, commitSubgraphAdapter, contiguousThrough, createRunnerState, cursorHeight, cursorIsAfterBlock, cursorIsBeforeBlock, datasetMatchesTarget, deepVerify, defaultRetainUntil, emptyQueueState, evaluateCoverage, expectedAckHeight, failureRangeHolds, failureRetentionHolds, finalRowDigest, findRangeGaps, hashEffectManifest, inputDigest, isFailureClass, isFailureUnit, isNativeClock, isNonNegativeInt, isRepairMode, isRetryState, isRunStatus, isStageKind, lookupTransition, manifestsEqual, mergeRanges, parseVerifyTarget, planDecoderReceipts, planRepair, proofsAgree, queueCaughtUp, rangeDigestOf, rangeIsOrdered, receiptRetentionHolds, receiptsAfterReorg, reportVerify, rewindDecoderCheckpoint, runDecoderCommitSteps, runSubgraphCommitSteps, sealFinalizedRange, segmentsOverlap, segmentsSurviveReorg, sequentialDigests, sparseDigests, topoSort, versionsEqual };
1968
+ export { BootstrapSource, COVERAGE_REPORT_SCHEMA_VERSION, COVERAGE_STATES, CanonicalBlock, CoverageRange, CoverageReport, CoverageState, DECODER_COMMIT_STEPS, DEFAULT_MAX_RETRIES, DecoderAdapterCommit, DecoderAdapterCrash, DecoderAdapterFailure, DecoderClockEvent, DecoderClockInput, DecoderClockReceipt, DecoderClockResult, DecoderCommitStep, DeepVerifyResult, EffectMutation, EffectOp, EvaluatorInput, EvaluatorOptions, FAILURE_CLASSES, FAILURE_RETENTION_DAYS, FAILURE_UNITS, FailureClass, FailureRow, FailureUnit, NATIVE_CLOCKS, NativeClock, OpenFailure, QUEUE_STAGES, QueueApply, QueueCounters, QueueEvent, QueueStage, QueueState, REPAIR_MODES, RETRY_STATES, RUNNER_EVENT_TYPES, RUNNER_STATUSES, RUNNER_TRANSITION_TABLE, RUN_STATUSES, ReceiptRow, RepairDefect, RepairMode, RepairPlan, RetryState, RowSnapshot, RunStatus, RunnerEffect, RunnerEvent, RunnerEventType, RunnerFailure, RunnerResult, RunnerState, RunnerStatus, RunnerVersion, SAFE_REPAIR_MODES, STAGE_KINDS, SUBGRAPH_COMMIT_STEPS, SealResult, SealableReceipt, SealedSegment, SourceClock, StageCoverage, StageDeclaration, StageEvidence, StageKind, StageRunView, SubgraphAdapterCrash, SubgraphCommitInput, SubgraphCommitStep, SyncScope, TransitionRule, VERIFY_EXIT, VerifyExit, VerifyMode, VerifyReport, VerifyTarget, applyMutations, applyQueueEvent, applyRunnerEvent, canonicalizeMutations, commitDecoderAdapter, commitDecoderAdapterBatch, commitSubgraphAdapter, contiguousThrough, createRunnerState, cursorHeight, cursorIsAfterBlock, cursorIsBeforeBlock, datasetMatchesTarget, deepVerify, defaultRetainUntil, emptyQueueState, evaluateCoverage, expectedAckHeight, failureRangeHolds, failureRetentionHolds, finalRowDigest, findRangeGaps, hashEffectManifest, inputDigest, isFailureClass, isFailureUnit, isNativeClock, isNonNegativeInt, isRepairMode, isRetryState, isRunStatus, isStageKind, lookupTransition, manifestsEqual, mergeRanges, parseVerifyTarget, planDecoderReceipts, planRepair, proofsAgree, queueCaughtUp, rangeDigestOf, rangeIsOrdered, receiptRetentionHolds, receiptsAfterReorg, reportVerify, rewindDecoderCheckpoint, runDecoderCommitSteps, runSubgraphCommitSteps, sealFinalizedRange, segmentsOverlap, segmentsSurviveReorg, sequentialDigests, sparseDigests, topoSort, versionsEqual };
@@ -934,7 +934,6 @@ import { sql } from "kysely";
934
934
  var DECODER_COMMIT_STEPS = [
935
935
  "output",
936
936
  "checkpoint",
937
- "receipt",
938
937
  "failure"
939
938
  ];
940
939
 
@@ -953,29 +952,10 @@ async function runDecoderCommitSteps(steps, crashAfter) {
953
952
  throw new DecoderAdapterCrash(step);
954
953
  }
955
954
  }
956
- function applyDecoderReceipts(state, receipts) {
957
- let current = state;
958
- if (current.status === "pending") {
959
- const started = applyRunnerEvent(current, { type: "start" });
960
- if (!started.ok)
961
- return started;
962
- current = started.state;
963
- }
964
- for (const receipt of receipts) {
965
- const event = {
966
- type: "ack",
967
- height: receipt.height,
968
- hash: receipt.hash,
969
- input_count: receipt.input_count,
970
- input_digest: receipt.input_digest,
971
- effect_digest: receipt.effect_digest
972
- };
973
- const next = applyRunnerEvent(current, event);
974
- if (!next.ok)
975
- return next;
976
- current = next.state;
977
- }
978
- return { ok: true, state: current, effects: [] };
955
+ async function stampLastOutput(tx, input) {
956
+ if (!input.output_count || input.output_count <= 0)
957
+ return;
958
+ await tx.updateTable("decoder_checkpoints").set({ last_output_at: sql`now()` }).where("decoder_name", "=", input.decoder_name).execute();
979
959
  }
980
960
  async function upsertRegistry(tx, stageId) {
981
961
  await tx.insertInto("stage_registry").values({
@@ -1021,32 +1001,9 @@ async function writeCheckpoint(tx, decoderName, cursor) {
1021
1001
  return;
1022
1002
  await sql`SELECT pg_notify('index:tip', ${decoderName})`.execute(tx);
1023
1003
  }
1024
- var RECEIPTS_CHUNK_SIZE = 1000;
1025
- async function writeReceipts(tx, stageId, runId, receipts) {
1026
- if (receipts.length === 0)
1027
- return;
1028
- for (let i = 0;i < receipts.length; i += RECEIPTS_CHUNK_SIZE) {
1029
- const chunk = receipts.slice(i, i + RECEIPTS_CHUNK_SIZE);
1030
- await tx.insertInto("stage_block_receipts").values(chunk.map((receipt) => ({
1031
- stage_id: stageId,
1032
- run_id: runId,
1033
- block_height: receipt.height,
1034
- block_hash: receipt.hash,
1035
- input_count: receipt.input_count,
1036
- input_digest: receipt.input_digest,
1037
- effect_digest: receipt.effect_digest
1038
- }))).onConflict((oc) => oc.columns(["stage_id", "block_height", "block_hash"]).doUpdateSet((eb) => ({
1039
- input_count: eb.ref("excluded.input_count"),
1040
- input_digest: eb.ref("excluded.input_digest"),
1041
- effect_digest: eb.ref("excluded.effect_digest"),
1042
- run_id: eb.ref("excluded.run_id")
1043
- }))).execute();
1044
- }
1045
- }
1046
- async function writeFailure(tx, stageId, runId, failure) {
1004
+ async function writeFailure(tx, stageId, failure) {
1047
1005
  await tx.insertInto("stage_failures").values({
1048
1006
  stage_id: stageId,
1049
- run_id: runId,
1050
1007
  unit_kind: failure.unit_kind,
1051
1008
  from_height: failure.from_height,
1052
1009
  to_height: failure.to_height,
@@ -1057,23 +1014,25 @@ async function writeFailure(tx, stageId, runId, failure) {
1057
1014
  }).execute();
1058
1015
  }
1059
1016
  async function commitDecoderAdapter(db, input) {
1060
- const runId = input.run_id ?? null;
1061
1017
  const failure = input.failure ?? null;
1062
1018
  await db.transaction().execute(async (tx) => {
1063
- await upsertRegistry(tx, input.stage_id);
1064
1019
  await runDecoderCommitSteps({
1065
1020
  output: () => input.writeOutput(tx),
1066
- checkpoint: () => writeCheckpoint(tx, input.decoder_name, input.checkpoint_cursor),
1067
- receipt: () => writeReceipts(tx, input.stage_id, runId, input.receipts),
1068
- failure: () => failure ? writeFailure(tx, input.stage_id, runId, failure) : Promise.resolve()
1021
+ checkpoint: async () => {
1022
+ await writeCheckpoint(tx, input.decoder_name, input.checkpoint_cursor);
1023
+ await stampLastOutput(tx, input);
1024
+ },
1025
+ failure: async () => {
1026
+ if (!failure)
1027
+ return;
1028
+ await upsertRegistry(tx, input.stage_id);
1029
+ await writeFailure(tx, input.stage_id, failure);
1030
+ }
1069
1031
  }, input.crashAfter);
1070
1032
  });
1071
1033
  }
1072
1034
  async function commitDecoderAdapterBatch(db, inputs) {
1073
1035
  await db.transaction().execute(async (tx) => {
1074
- for (const input of inputs) {
1075
- await upsertRegistry(tx, input.stage_id);
1076
- }
1077
1036
  for (const input of inputs) {
1078
1037
  await input.writeOutput(tx);
1079
1038
  }
@@ -1081,12 +1040,13 @@ async function commitDecoderAdapterBatch(db, inputs) {
1081
1040
  await writeCheckpoint(tx, input.decoder_name, input.checkpoint_cursor);
1082
1041
  }
1083
1042
  for (const input of inputs) {
1084
- await writeReceipts(tx, input.stage_id, input.run_id ?? null, input.receipts);
1043
+ await stampLastOutput(tx, input);
1085
1044
  }
1086
1045
  for (const input of inputs) {
1087
1046
  const failure = input.failure ?? null;
1088
1047
  if (failure) {
1089
- await writeFailure(tx, input.stage_id, input.run_id ?? null, failure);
1048
+ await upsertRegistry(tx, input.stage_id);
1049
+ await writeFailure(tx, input.stage_id, failure);
1090
1050
  }
1091
1051
  }
1092
1052
  });
@@ -1533,7 +1493,6 @@ export {
1533
1493
  SUBGRAPH_COMMIT_STEPS,
1534
1494
  SubgraphAdapterCrash,
1535
1495
  VERIFY_EXIT,
1536
- applyDecoderReceipts,
1537
1496
  applyMutations,
1538
1497
  applyQueueEvent,
1539
1498
  applyRunnerEvent,
@@ -1591,5 +1550,5 @@ export {
1591
1550
  versionsEqual
1592
1551
  };
1593
1552
 
1594
- //# debugId=DE87B2B03C092AB764756E2164756E21
1553
+ //# debugId=79523CE79087EE7864756E2164756E21
1595
1554
  //# sourceMappingURL=index.js.map