@odatano/core 2.0.0-rc.2 → 2.0.0-rc.21
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/@cds-models/CardanoAgentService/index.d.ts +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +139 -2
- package/@cds-models/CardanoIndexerService/index.js +18 -0
- package/@cds-models/CardanoODataService/index.d.ts +231 -6
- package/@cds-models/CardanoODataService/index.js +27 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
- package/@cds-models/odatano/cardano/index.d.ts +323 -6
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2133 -1633
- package/package.json +181 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +10 -10
- package/src/index.js +24 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +45 -158
- package/srv/blockchain/backends/cardano-backend.d.ts +83 -158
- package/srv/blockchain/backends/cardano-backend.js +14 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +293 -203
- package/srv/blockchain/backends/ogmios-backend.d.ts +69 -94
- package/srv/blockchain/backends/ogmios-backend.js +319 -185
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +57 -204
- package/srv/blockchain/cardano-client.js +94 -226
- package/srv/blockchain/cardano-indexer.d.ts +176 -240
- package/srv/blockchain/cardano-indexer.js +615 -338
- package/srv/blockchain/cardano-tx-builder.d.ts +29 -82
- package/srv/blockchain/cardano-tx-builder.js +88 -128
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +121 -53
- package/srv/blockchain/crawler/crawler.js +403 -89
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +44 -28
- package/srv/blockchain/crawler/sync-state.js +115 -43
- package/srv/blockchain/crawler/utxo-set-import.d.ts +69 -0
- package/srv/blockchain/crawler/utxo-set-import.js +269 -0
- package/srv/blockchain/ledger-state.d.ts +80 -0
- package/srv/blockchain/ledger-state.js +383 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +71 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +185 -260
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +42 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +39 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-indexer-service.cds +164 -73
- package/srv/cardano-indexer-service.js +156 -11
- package/srv/cardano-service.cds +45 -0
- package/srv/cardano-service.js +38 -96
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +136 -196
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +28 -86
- package/srv/server.js +95 -128
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +914 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +93 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +36 -179
- package/srv/utils/errors.js +62 -220
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +89 -214
- package/srv/utils/mappers.js +289 -301
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +57 -0
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +14 -20
- package/srv/utils/tx-request-parsers.js +33 -20
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +114 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CertificateBackfillError = void 0;
|
|
7
|
+
exports.intersectionBefore = intersectionBefore;
|
|
8
|
+
exports.backfillCertificates = backfillCertificates;
|
|
9
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
|
+
const mappers_1 = require("../../utils/mappers");
|
|
11
|
+
const sync_state_1 = require("./sync-state");
|
|
12
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
13
|
+
const { SELECT, UPSERT } = cds_1.default.ql;
|
|
14
|
+
const logger = cds_1.default.log('CertificateBackfill');
|
|
15
|
+
/**
|
|
16
|
+
* Fills `TransactionCertificates` and `TransactionWithdrawals` for blocks the crawl already
|
|
17
|
+
* holds, from a second chain-sync stream. Only those two tables are written, keyed so a
|
|
18
|
+
* repeat is idempotent; the cursor, the block and transaction rows stay untouched and the
|
|
19
|
+
* live crawler keeps its own stream. A block the index does not know (rolled back since) is
|
|
20
|
+
* skipped, so no row can point at a transaction that is not there.
|
|
21
|
+
*/
|
|
22
|
+
class CertificateBackfillError extends Error {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = 'CertificateBackfillError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CertificateBackfillError = CertificateBackfillError;
|
|
29
|
+
/**
|
|
30
|
+
* Newest indexed block strictly before `slot` inside the crawled range; the crawler's own
|
|
31
|
+
* start point when none is. Lazily indexed blocks below the crawl start are never picked:
|
|
32
|
+
* they may lie far back or on a fork the node no longer knows.
|
|
33
|
+
*/
|
|
34
|
+
async function intersectionBefore(db, slot) {
|
|
35
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
36
|
+
const floor = cursor?.startSlot ?? null;
|
|
37
|
+
const range = floor != null ? { between: floor, and: slot - 1 } : { '<': slot };
|
|
38
|
+
const row = floor != null && slot - 1 < floor ? null : (await db.run(SELECT.one.from(cardano_1.Block).columns('hash', 'slot', 'height').where({ slot: range }).orderBy('slot desc')));
|
|
39
|
+
if (row?.hash && row.slot != null)
|
|
40
|
+
return { slot: Number(row.slot), hash: row.hash, height: row.height == null ? undefined : Number(row.height) };
|
|
41
|
+
if (floor != null && cursor?.startBlockHash)
|
|
42
|
+
return { slot: floor, hash: cursor.startBlockHash };
|
|
43
|
+
return 'origin';
|
|
44
|
+
}
|
|
45
|
+
async function backfillCertificates(opts) {
|
|
46
|
+
const { client, fromSlot, toSlot } = opts;
|
|
47
|
+
if (!Number.isInteger(fromSlot) || !Number.isInteger(toSlot) || fromSlot < 0 || toSlot < fromSlot) {
|
|
48
|
+
throw new CertificateBackfillError(`Invalid slot range ${fromSlot}..${toSlot}`);
|
|
49
|
+
}
|
|
50
|
+
const backend = client.getChainSyncBackend();
|
|
51
|
+
if (!backend)
|
|
52
|
+
throw new CertificateBackfillError('No chain-sync backend available (the backfill streams from Ogmios).');
|
|
53
|
+
const batchBlocks = Math.max(1, opts.batchBlocks ?? 200);
|
|
54
|
+
const intersection = await cds_1.default.tx((tx) => intersectionBefore(tx, fromSlot));
|
|
55
|
+
const points = intersection === 'origin' ? 'origin' : [intersection];
|
|
56
|
+
const progress = { atSlot: intersection === 'origin' ? 0 : intersection.slot, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0 };
|
|
57
|
+
let pending = [];
|
|
58
|
+
/**
|
|
59
|
+
* Writes a batch: the index's blocks of the batch's slot range are read once (a sequential
|
|
60
|
+
* index range, not one random lookup per block) and only rows of blocks the index holds
|
|
61
|
+
* are written; a block it never had (rolled back since) is skipped.
|
|
62
|
+
*/
|
|
63
|
+
const flush = async () => {
|
|
64
|
+
if (!pending.length)
|
|
65
|
+
return;
|
|
66
|
+
const batch = pending;
|
|
67
|
+
pending = [];
|
|
68
|
+
const fromBatch = batch[0].slot, toBatch = batch[batch.length - 1].slot;
|
|
69
|
+
await cds_1.default.tx(async (tx) => {
|
|
70
|
+
const rows = (await tx.run(SELECT.from(cardano_1.Block).columns('hash').where({ slot: { between: fromBatch, and: toBatch } })));
|
|
71
|
+
const known = new Set(rows.map((r) => r.hash));
|
|
72
|
+
const certs = [], withdrawals = [];
|
|
73
|
+
for (const b of batch) {
|
|
74
|
+
if (!known.has(b.hash)) {
|
|
75
|
+
logger.warn(`Block ${b.hash} at slot ${b.slot} is not in the index — skipped`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
certs.push(...b.certs);
|
|
79
|
+
withdrawals.push(...b.withdrawals);
|
|
80
|
+
progress.blocks++;
|
|
81
|
+
progress.transactions += b.transactions;
|
|
82
|
+
progress.certificates += b.certs.length;
|
|
83
|
+
progress.withdrawals += b.withdrawals.length;
|
|
84
|
+
}
|
|
85
|
+
if (certs.length)
|
|
86
|
+
await tx.run(UPSERT.into(cardano_1.TransactionCertificates).entries(certs));
|
|
87
|
+
if (withdrawals.length)
|
|
88
|
+
await tx.run(UPSERT.into(cardano_1.TransactionWithdrawals).entries(withdrawals));
|
|
89
|
+
});
|
|
90
|
+
progress.atSlot = toBatch;
|
|
91
|
+
opts.onProgress?.({ ...progress });
|
|
92
|
+
};
|
|
93
|
+
let handle = null;
|
|
94
|
+
let settled = false;
|
|
95
|
+
const done = new Promise((resolve, reject) => {
|
|
96
|
+
const finish = (err) => {
|
|
97
|
+
if (settled)
|
|
98
|
+
return;
|
|
99
|
+
settled = true;
|
|
100
|
+
if (err)
|
|
101
|
+
reject(err);
|
|
102
|
+
else
|
|
103
|
+
resolve();
|
|
104
|
+
};
|
|
105
|
+
const onBlock = async (block, txs) => {
|
|
106
|
+
if (settled)
|
|
107
|
+
return;
|
|
108
|
+
const slot = block.slot ?? 0;
|
|
109
|
+
if (slot > toSlot) {
|
|
110
|
+
finish();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (slot < fromSlot)
|
|
114
|
+
return; // between the intersection and the range: skipped, not counted
|
|
115
|
+
pending.push({
|
|
116
|
+
hash: block.hash, slot, transactions: txs.length,
|
|
117
|
+
certs: txs.flatMap((t) => (0, mappers_1.mapTransactionCertificates)(t.hash, t.certificates ?? [])),
|
|
118
|
+
withdrawals: txs.flatMap((t) => (0, mappers_1.mapTransactionWithdrawals)(t.hash, t.withdrawals ?? [])),
|
|
119
|
+
});
|
|
120
|
+
if (pending.length >= batchBlocks)
|
|
121
|
+
await flush();
|
|
122
|
+
if (slot === toSlot)
|
|
123
|
+
finish();
|
|
124
|
+
};
|
|
125
|
+
backend.openChainSync(points, {
|
|
126
|
+
rollForward: (block, txs) => onBlock(block, txs).catch(finish),
|
|
127
|
+
// The handshake acknowledges the intersection; a reorg mid-run is the crawler's to undo,
|
|
128
|
+
// it deletes the rows of the rolled-back transactions.
|
|
129
|
+
rollBackward: async () => undefined,
|
|
130
|
+
onError: async (err) => finish(err),
|
|
131
|
+
}).then((h) => { handle = h; if (settled)
|
|
132
|
+
void h.close().catch(() => undefined); }, finish);
|
|
133
|
+
});
|
|
134
|
+
try {
|
|
135
|
+
await done;
|
|
136
|
+
await flush();
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
const h = handle;
|
|
140
|
+
if (h) {
|
|
141
|
+
try {
|
|
142
|
+
await h.close();
|
|
143
|
+
}
|
|
144
|
+
catch { /* best effort */ }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
logger.info(`Certificate backfill ${fromSlot}..${toSlot}: ${progress.blocks} blocks, ${progress.certificates} certificates, ${progress.withdrawals} withdrawals`);
|
|
148
|
+
return { ...progress, fromSlot, toSlot, intersection };
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=certificate-backfill.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CardanoClient } from '../cardano-client';
|
|
2
2
|
import type { CardanoIndexer } from '../cardano-indexer';
|
|
3
3
|
import { type CrawlSyncStatusValue } from './sync-state';
|
|
4
|
+
/** The source a running crawler is currently ingesting from. */
|
|
5
|
+
export type CrawlSource = 'chain-sync' | 'pagination';
|
|
4
6
|
/** Runtime configuration for the chain crawler (loaded from cds.requires by the server). */
|
|
5
7
|
export interface CrawlerConfig {
|
|
6
8
|
enabled: boolean;
|
|
@@ -16,21 +18,32 @@ export interface CrawlerConfig {
|
|
|
16
18
|
confirmationDepth: number;
|
|
17
19
|
/** Poll cadence when caught up / on transient errors (pagination path). */
|
|
18
20
|
pollIntervalMs: number;
|
|
21
|
+
/** Write mint/burn rows into AssetHistory. Free — no provider call. */
|
|
22
|
+
assetHistory: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* `off` — nothing; `bare` — one Assets row per unit from block data alone (free);
|
|
25
|
+
* `enrich` — additionally resolve supply/registry data in the background, rate limited.
|
|
26
|
+
*/
|
|
27
|
+
assetCatalogue: 'off' | 'bare' | 'enrich';
|
|
28
|
+
/** Units per second the background enrichment resolves (`assetCatalogue: 'enrich'` only). */
|
|
29
|
+
assetEnrichRate: number;
|
|
30
|
+
/** Snapshot every pool and DRep at each epoch boundary. Requires an enumerating backend (Koios). */
|
|
31
|
+
epochSnapshots: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Write TransactionCertificates + TransactionWithdrawals per block (ledger-state
|
|
34
|
+
* coverage). Free on Ogmios chain-sync and Koios; Blockfrost does not report them.
|
|
35
|
+
*/
|
|
36
|
+
certificates: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Maintain the crawler-fed UTxO set (`LedgerUTxOs` / `LedgerAddresses` / `LedgerAccounts`).
|
|
39
|
+
* Needs a one-off snapshot import (`importUtxoSet`) to become active.
|
|
40
|
+
*/
|
|
41
|
+
utxoSet: boolean;
|
|
19
42
|
}
|
|
20
43
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Two sources (see CRAWLER_DESIGN.md):
|
|
26
|
-
* - **Ogmios chain-sync** (primary): ordered rollForward + native rollBackward (reorg).
|
|
27
|
-
* - **Blockfrost/Koios pagination** (fallback): forward walk + parent-hash reorg recovery.
|
|
28
|
-
*
|
|
29
|
-
* Lifecycle: start() launches the ingest pipeline detached so the HTTP server binds
|
|
30
|
-
* immediately, but the pipeline promise is retained — stop() halts the loops (waking
|
|
31
|
-
* any pending poll sleep) and AWAITS the pipeline, so shutdown never races in-flight
|
|
32
|
-
* block writes. All per-block writes are atomic. The crawler NEVER crawls from genesis
|
|
33
|
-
* implicitly — it requires an explicit configured start point or an existing cursor.
|
|
44
|
+
* Pre-sync engine: streams the chain forward from a start block and bulk-indexes it. Sources:
|
|
45
|
+
* Ogmios chain-sync (primary, native rollBackward) or Blockfrost/Koios pagination (fallback).
|
|
46
|
+
* Per-block writes are atomic; stop() awaits the detached pipeline; no implicit genesis crawl.
|
|
34
47
|
*/
|
|
35
48
|
export declare class CardanoCrawler {
|
|
36
49
|
private readonly client;
|
|
@@ -41,10 +54,32 @@ export declare class CardanoCrawler {
|
|
|
41
54
|
private readonly leaseOwner?;
|
|
42
55
|
/** Transient-failure retries per block before giving up. */
|
|
43
56
|
private static readonly PERSIST_RETRIES;
|
|
57
|
+
/** Final persist failures for the same block across restarts before the crawler latches off (poison block). */
|
|
58
|
+
private static readonly POISON_BLOCK_THRESHOLD;
|
|
59
|
+
/** Process-wide, survives instance restarts: the block currently failing and how often. */
|
|
60
|
+
private static poison;
|
|
61
|
+
/**
|
|
62
|
+
* Errors deterministic for the block's data — only these count towards the poison latch.
|
|
63
|
+
* Outages, statement timeouts and exhausted pools are fixed by a restart and must not latch.
|
|
64
|
+
*/
|
|
65
|
+
private static readonly DATA_REJECTION_PATTERNS;
|
|
44
66
|
/** Timeout for direct backend calls (the crawler bypasses the client's resilience layer). */
|
|
45
67
|
private static readonly CALL_TIMEOUT_MS;
|
|
68
|
+
/** Epoch snapshots are ~100 batched provider requests on mainnet; wider bound, cancelled by beginHalt. */
|
|
69
|
+
private static readonly SNAPSHOT_TIMEOUT_MS;
|
|
70
|
+
/** Backoff after a failed snapshot attempt, doubling up to the cap; the marker is only set on success. */
|
|
71
|
+
private static readonly SNAPSHOT_RETRY_BASE_MS;
|
|
72
|
+
private static readonly SNAPSHOT_RETRY_MAX_MS;
|
|
73
|
+
/** Retry cadence for a chain-sync backend's init while the crawl runs on pagination. */
|
|
74
|
+
private static readonly CHAIN_SYNC_RETRY_MS;
|
|
46
75
|
private running;
|
|
47
76
|
private chainSyncHandle;
|
|
77
|
+
/** What the ingest loop is currently reading from; null while stopped. */
|
|
78
|
+
private activeSource;
|
|
79
|
+
/** Chain-sync init retry while on pagination: own timer, in-flight probe, outcome. */
|
|
80
|
+
private chainSyncProbeTimer;
|
|
81
|
+
private chainSyncProbe;
|
|
82
|
+
private chainSyncRecovered;
|
|
48
83
|
/** The detached ingest pipeline — awaited by stop() so teardown never races it. */
|
|
49
84
|
private pipeline;
|
|
50
85
|
/** Resolver that cancels a pending poll sleep (set while sleeping). */
|
|
@@ -54,9 +89,19 @@ export declare class CardanoCrawler {
|
|
|
54
89
|
/** Chain-sync callback promises outlive openChainSync(); stop() explicitly drains them. */
|
|
55
90
|
private readonly inFlightCallbacks;
|
|
56
91
|
private haltPromise;
|
|
92
|
+
/** An unparseable chain-sync frame; the ingest loop fetches that block via pagination, then reopens chain-sync. */
|
|
93
|
+
private frameFailure;
|
|
94
|
+
/** Resolves the ingest loop's wait for the current chain-sync stream to end. */
|
|
95
|
+
private streamEnded;
|
|
57
96
|
private finalStatus;
|
|
58
97
|
/** Set only by an unrecoverable halt — clears desiredRunning so restarts stay down. */
|
|
59
98
|
private latchOnHalt;
|
|
99
|
+
/** Epoch whose pool/DRep snapshot this process has settled, and the in-flight attempt. */
|
|
100
|
+
private snapshotedEpoch;
|
|
101
|
+
private snapshotInFlight;
|
|
102
|
+
/** Consecutive snapshot failures and the earliest time the next attempt may run. */
|
|
103
|
+
private snapshotFailures;
|
|
104
|
+
private snapshotRetryAfter;
|
|
60
105
|
private leaseHeld;
|
|
61
106
|
private leaseHeartbeat;
|
|
62
107
|
private leaseWake;
|
|
@@ -64,6 +109,10 @@ export declare class CardanoCrawler {
|
|
|
64
109
|
/** Present for production instances created by index.ts; omitted in engine unit tests. */
|
|
65
110
|
leaseOwner?: string | undefined);
|
|
66
111
|
isRunning(): boolean;
|
|
112
|
+
/** True once the crawler halted because of a failure (not via stop() or a lost lease). */
|
|
113
|
+
haltedWithError(): boolean;
|
|
114
|
+
/** Source ingested from right now, or null while not running (a crawl degraded to pagination still advances the cursor). */
|
|
115
|
+
getActiveSource(): CrawlSource | null;
|
|
67
116
|
/**
|
|
68
117
|
* Start crawling. Does NOT await the ingest pipeline (fire-and-forget).
|
|
69
118
|
* Refuses to start without a resume point: an explicit configured start block or an
|
|
@@ -71,50 +120,62 @@ export declare class CardanoCrawler {
|
|
|
71
120
|
*/
|
|
72
121
|
start(): Promise<void>;
|
|
73
122
|
/**
|
|
74
|
-
* Stop crawling and
|
|
75
|
-
*
|
|
76
|
-
* final status, then awaits the detached pipeline so callers (shutdownAppContext)
|
|
77
|
-
* can safely tear down backends/DB afterwards.
|
|
123
|
+
* Stop crawling and await the pipeline's in-flight step, so callers can tear down
|
|
124
|
+
* backends/DB afterwards.
|
|
78
125
|
*/
|
|
79
126
|
stop(finalStatus?: CrawlSyncStatusValue): Promise<void>;
|
|
80
127
|
/**
|
|
81
|
-
* Halt without awaiting the pipeline —
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
/**
|
|
86
|
-
* @param latch clears `desiredRunning`, so NO restart brings the crawler back —
|
|
87
|
-
* only an operator's resumeCrawler does. Reserved for failures a restart cannot
|
|
88
|
-
* fix (misconfiguration, missing resume point). Runtime failures — a dropped
|
|
89
|
-
* chain-sync socket, a provider outage, a node restart — must leave it false,
|
|
90
|
-
* otherwise a routine node restart silently disables the pre-sync for good.
|
|
128
|
+
* Halt without awaiting the pipeline — safe to call from inside it.
|
|
129
|
+
* @param latch clears `desiredRunning` so no restart brings the crawler back; only for failures
|
|
130
|
+
* a restart cannot fix (misconfiguration, missing resume point), never for runtime outages.
|
|
91
131
|
*/
|
|
92
132
|
private halt;
|
|
93
|
-
/**
|
|
94
|
-
* Start teardown without awaiting it. Internal callers can therefore halt from
|
|
95
|
-
* inside a tracked callback/pipeline without waiting on their own promise.
|
|
96
|
-
*/
|
|
133
|
+
/** Start teardown without awaiting it, so tracked callbacks can halt from inside themselves. */
|
|
97
134
|
private beginHalt;
|
|
98
135
|
private runIngestPipeline;
|
|
136
|
+
/**
|
|
137
|
+
* Retry the init of a chain-sync backend on its own timer (a poll sleep can be an hour long),
|
|
138
|
+
* one probe at a time. On success `chainSyncRecovered` is set and a pending sleep is cut short;
|
|
139
|
+
* the pagination loop leaves at its next check and the ingest loop reopens chain-sync.
|
|
140
|
+
*/
|
|
141
|
+
private startChainSyncProbing;
|
|
142
|
+
private scheduleChainSyncProbe;
|
|
143
|
+
private stopChainSyncProbing;
|
|
99
144
|
/** Bound a direct backend call — these bypass the client's timeout/breaker layer. */
|
|
100
145
|
private withTimeout;
|
|
101
146
|
private runChainSync;
|
|
147
|
+
/** Read and clear the pending frame failure, so each stream starts from a clean slate. */
|
|
148
|
+
private takeFrameFailure;
|
|
149
|
+
/**
|
|
150
|
+
* Whether an unparseable frame can be worked around over HTTP: needs a height, a paginating
|
|
151
|
+
* backend, and a source not pinned to 'ogmios' (chain-sync only).
|
|
152
|
+
*/
|
|
153
|
+
private canDegradeToPagination;
|
|
154
|
+
/**
|
|
155
|
+
* End the chain-sync stream and hand back to the ingest loop, which continues on pagination
|
|
156
|
+
* past the offending block. The error is recorded first so `lastError` names the block.
|
|
157
|
+
*/
|
|
158
|
+
private degradeToPagination;
|
|
102
159
|
/**
|
|
103
|
-
* Candidate intersection points,
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* Why more than the cursor: if the cursor's block was orphaned while the crawler
|
|
108
|
-
* was down, a single-point intersection fails outright ("No intersection found")
|
|
109
|
-
* and the stream never opens. With ancestors on the list the node intersects at
|
|
110
|
-
* the last common block and reports it as a rollBackward — the ordinary reorg path
|
|
111
|
-
* that handleReorg already implements. Doubling offsets cover ~32k blocks with 16
|
|
112
|
-
* points; anything deeper is past any realistic rollback and should fail loudly.
|
|
160
|
+
* Candidate intersection points, newest first: the cursor, a ladder of already-crawled
|
|
161
|
+
* ancestors, then the configured start block. If the cursor's block was orphaned while the
|
|
162
|
+
* crawler was down, the node intersects at the last common ancestor and reports a rollBackward.
|
|
113
163
|
*/
|
|
114
164
|
private buildIntersectionPoints;
|
|
115
165
|
/** Track streamed callbacks because closing a socket does not imply DB callbacks finished. */
|
|
116
166
|
private trackCallback;
|
|
167
|
+
/**
|
|
168
|
+
* @param untilHeight return once the cursor reaches it — walks past a block chain-sync
|
|
169
|
+
* cannot deliver, then hands back.
|
|
170
|
+
* @param untilChainSync retry a chain-sync backend in the background; return once one is usable.
|
|
171
|
+
*/
|
|
117
172
|
private runPagination;
|
|
173
|
+
private paginate;
|
|
174
|
+
/**
|
|
175
|
+
* Poll pause between pagination rounds; skipped when a chain-sync handover is already due,
|
|
176
|
+
* since the probe's wake-up only reaches a sleep that has begun.
|
|
177
|
+
*/
|
|
178
|
+
private pollPause;
|
|
118
179
|
/**
|
|
119
180
|
* Pagination reorg recovery: walk back by height comparing the on-chain block hash with
|
|
120
181
|
* our stored one until they agree — that height is the fork point. If the last-indexed
|
|
@@ -122,26 +183,33 @@ export declare class CardanoCrawler {
|
|
|
122
183
|
*/
|
|
123
184
|
private tryReorgRecovery;
|
|
124
185
|
/**
|
|
125
|
-
* Persist one block atomically and advance the cursor. Transient failures are retried
|
|
126
|
-
*
|
|
127
|
-
* the cursor is not advanced on failure, so a resume re-syncs cleanly from it.
|
|
128
|
-
* Marks the cursor 'synced' when the block is at the reported tip.
|
|
186
|
+
* Persist one block atomically and advance the cursor. Transient failures are retried; the
|
|
187
|
+
* cursor is not advanced on failure, so a resume re-syncs from it. Marks 'synced' at the tip.
|
|
129
188
|
* @returns true when the block was persisted, false when the crawler was stopped
|
|
130
189
|
*/
|
|
131
190
|
private persistBlock;
|
|
191
|
+
/** Epoch a slot belongs to, from the network's Shelley anchor (same math as the Ogmios mapper). */
|
|
192
|
+
private epochOfSlot;
|
|
193
|
+
/**
|
|
194
|
+
* Pool/DRep snapshot once per epoch, detached from the triggering block and ONLY at the tip:
|
|
195
|
+
* the enumerating providers report current state (no epoch parameter), so epochs passed
|
|
196
|
+
* during a backfill are skipped permanently. Authority is the `PoolEpochSnapshots` row.
|
|
197
|
+
*/
|
|
198
|
+
private maybeSnapshotEpoch;
|
|
132
199
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* the cursor to the fork
|
|
136
|
-
*
|
|
137
|
-
* The cut runs on the absolute-slot axis of Blocks (same axis as the fork point), and
|
|
138
|
-
* transactions are resolved via their blockHash — so:
|
|
139
|
-
* - an unresolvable fork height can never widen the delete (no height-0 fallback), and
|
|
140
|
-
* - lazily-indexed transactions of blocks the crawler never wrote are left untouched.
|
|
200
|
+
* Chain rollback in one transaction: delete blocks with slot > fork (absolute-slot axis, never
|
|
201
|
+
* height), their transactions resolved via blockHash (lazily indexed txs of other blocks are
|
|
202
|
+
* untouched), reset the cursor to the fork and write a CardanoReorgLog row.
|
|
141
203
|
*/
|
|
142
204
|
private handleReorg;
|
|
143
205
|
/** Renew the lease while an Ogmios stream is idle; block writes renew it transactionally. */
|
|
144
206
|
private startLeaseHeartbeat;
|
|
207
|
+
/** Whether a persist error is deterministic for the block's data (see DATA_REJECTION_PATTERNS). */
|
|
208
|
+
static isDataRejection(err: unknown): boolean;
|
|
209
|
+
/** Count final persist failures per block hash (a different hash resets the count). */
|
|
210
|
+
private static notePersistFailure;
|
|
211
|
+
/** Test seam: forget the poison-block memory (process-wide state). */
|
|
212
|
+
static resetPoisonMemory(): void;
|
|
145
213
|
/** Record state only while this instance still owns the lease. */
|
|
146
214
|
private recordCrawlerError;
|
|
147
215
|
private leaseSleep;
|