@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45
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 +0 -46
- package/@cds-models/CardanoBackendService/index.d.ts +0 -10
- package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +19 -47
- package/@cds-models/CardanoSignService/index.d.ts +3 -18
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
- package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
- package/@cds-models/index.d.ts +17 -0
- package/@cds-models/index.js +2 -0
- package/@cds-models/odatano/cardano/index.d.ts +1 -34
- package/README.md +6 -6
- package/db/schema.cds +29 -44
- package/db/types.cds +22 -5
- package/package.json +3 -1
- package/scripts/migrate-slot-leader.mjs +3 -11
- package/scripts/migrate-txseq.mjs +3 -12
- package/src/index.d.ts +0 -4
- package/src/index.js +3 -5
- package/src/plugin.js +4 -8
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -10
- package/srv/blockchain/backends/blockfrost-backend.js +15 -21
- package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
- package/srv/blockchain/backends/koios-backend.d.ts +14 -147
- package/srv/blockchain/backends/koios-backend.js +40 -164
- package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
- package/srv/blockchain/backends/odatano-backend.js +11 -12
- package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
- package/srv/blockchain/backends/ogmios-backend.js +48 -175
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
- package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
- package/srv/blockchain/cardano-client.d.ts +12 -80
- package/srv/blockchain/cardano-client.js +36 -88
- package/srv/blockchain/cardano-indexer.d.ts +12 -192
- package/srv/blockchain/cardano-indexer.js +132 -222
- package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
- package/srv/blockchain/cardano-tx-builder.js +17 -34
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
- package/srv/blockchain/crawler/certificate-backfill.js +8 -22
- package/srv/blockchain/crawler/crawler.d.ts +16 -93
- package/srv/blockchain/crawler/crawler.js +85 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
- package/srv/blockchain/crawler/credential-backfill.js +6 -6
- package/srv/blockchain/crawler/hooks.d.ts +1 -5
- package/srv/blockchain/crawler/index.d.ts +0 -12
- package/srv/blockchain/crawler/index.js +6 -20
- package/srv/blockchain/crawler/sync-state.d.ts +6 -44
- package/srv/blockchain/crawler/sync-state.js +18 -53
- package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
- package/srv/blockchain/crawler/transaction-backfill.js +11 -30
- package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
- package/srv/blockchain/crawler/utxo-set-import.js +27 -53
- package/srv/blockchain/ledger-state.d.ts +10 -54
- package/srv/blockchain/ledger-state.js +11 -27
- package/srv/blockchain/pending-spends.d.ts +0 -12
- package/srv/blockchain/pending-spends.js +4 -12
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +0 -9
- package/srv/blockchain/signing/cose-verifier.js +4 -10
- package/srv/blockchain/signing/external-signer.d.ts +1 -4
- package/srv/blockchain/signing/external-signer.js +2 -8
- package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
- package/srv/blockchain/signing/hsm-signer.js +16 -28
- package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
- package/srv/blockchain/signing/signature-verifier.js +9 -19
- package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
- package/srv/blockchain/signing/submission-finalizer.js +48 -19
- package/srv/blockchain/stored-chain.d.ts +1 -14
- package/srv/blockchain/stored-chain.js +3 -8
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
- package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
- package/srv/blockchain/transaction-building/caller-datums.js +3 -9
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
- package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
- package/srv/blockchain/wallet-worker/build-request.js +6 -9
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -5
- package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
- package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
- package/srv/blockchain/wallet-worker/signers.js +3 -6
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
- package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
- package/srv/cardano-agent-service.cds +123 -146
- package/srv/cardano-agent-service.js +2 -5
- package/srv/cardano-backend-service.cds +10 -17
- package/srv/cardano-backend-service.js +7 -12
- package/srv/cardano-indexer-service.cds +35 -37
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +64 -33
- package/srv/cardano-service.cds +56 -40
- package/srv/cardano-service.js +42 -69
- package/srv/cardano-sign-service.cds +14 -23
- package/srv/cardano-sign-service.js +18 -24
- package/srv/cardano-tx-service.cds +27 -29
- package/srv/cardano-tx-service.js +60 -122
- package/srv/cardano-worker-service.cds +109 -125
- package/srv/cardano-worker-service.js +21 -31
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +6 -1
- package/srv/cbor/parse.d.ts +3 -18
- package/srv/cbor/parse.js +2 -7
- package/srv/cbor/plutus-data-json.d.ts +0 -4
- package/srv/server.d.ts +5 -36
- package/srv/server.js +30 -51
- package/srv/utils/agent-grants-config.d.ts +0 -18
- package/srv/utils/agent-grants-config.js +6 -13
- package/srv/utils/agent-grants.d.ts +14 -68
- package/srv/utils/agent-grants.js +42 -60
- package/srv/utils/agent-token-auth.d.ts +0 -5
- package/srv/utils/agent-token-auth.js +2 -5
- package/srv/utils/backend-request-handler.d.ts +1 -1
- package/srv/utils/collections.d.ts +1 -4
- package/srv/utils/collections.js +1 -4
- package/srv/utils/const.d.ts +0 -18
- package/srv/utils/const.js +7 -18
- package/srv/utils/crypto.js +3 -5
- package/srv/utils/db-indexes.d.ts +2 -0
- package/srv/utils/db-indexes.js +22 -9
- package/srv/utils/db-sanitize.d.ts +1 -8
- package/srv/utils/db-sanitize.js +3 -8
- package/srv/utils/epoch-slots.d.ts +1 -8
- package/srv/utils/epoch-slots.js +3 -8
- package/srv/utils/error-codes.d.ts +0 -4
- package/srv/utils/error-codes.js +2 -4
- package/srv/utils/errors.d.ts +2 -22
- package/srv/utils/errors.js +13 -27
- package/srv/utils/liveness.d.ts +0 -4
- package/srv/utils/liveness.js +2 -4
- package/srv/utils/mappers.d.ts +0 -37
- package/srv/utils/mappers.js +22 -39
- package/srv/utils/network-context.js +2 -4
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.js +3 -7
- package/srv/utils/pg-order-nulls.js +2 -5
- package/srv/utils/plutus-placeholders.d.ts +0 -13
- package/srv/utils/plutus-placeholders.js +6 -13
- package/srv/utils/rate-limiter.d.ts +0 -8
- package/srv/utils/rate-limiter.js +2 -4
- package/srv/utils/reference-script.d.ts +0 -18
- package/srv/utils/reference-script.js +8 -19
- package/srv/utils/service-events.d.ts +0 -4
- package/srv/utils/service-events.js +2 -4
- package/srv/utils/signing-helper.d.ts +1 -8
- package/srv/utils/signing-helper.js +3 -8
- package/srv/utils/tx-build-helper.d.ts +2 -32
- package/srv/utils/tx-build-helper.js +26 -40
- package/srv/utils/tx-request-parsers.d.ts +1 -25
- package/srv/utils/tx-request-parsers.js +10 -25
- package/srv/utils/tx-utils.d.ts +0 -8
- package/srv/utils/tx-utils.js +10 -13
- package/srv/utils/types.d.ts +2 -37
- package/srv/utils/validators.d.ts +0 -4
- package/srv/utils/validators.js +2 -4
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fills the payment credential of UTxO-shaped rows written before the column existed:
|
|
3
|
-
* TransactionOutputs, TransactionInputs and LedgerUTxOs. Each table is walked once in key
|
|
4
|
-
* order; rows that already carry a credential are skipped, so a second run changes nothing.
|
|
5
|
-
*/
|
|
6
1
|
export interface CredentialBackfillProgress {
|
|
7
2
|
/** Table being walked; null when finished. */
|
|
8
3
|
table: 'TransactionOutputs' | 'TransactionInputs' | 'LedgerUTxOs' | null;
|
|
@@ -28,10 +23,6 @@ export interface CredentialTableSpec {
|
|
|
28
23
|
counter: 'outputs' | 'inputs' | 'ledgerUtxos';
|
|
29
24
|
}
|
|
30
25
|
export declare const CREDENTIAL_TABLES: readonly CredentialTableSpec[];
|
|
31
|
-
/**
|
|
32
|
-
* One UPDATE per chunk: the fills travel as a JSON array and are joined on the key. Only rows
|
|
33
|
-
* still without a credential are touched. Postgres and SQLite; other databases get one UPDATE per row.
|
|
34
|
-
*/
|
|
35
26
|
export declare function credentialFillStatement(kind: string, spec: CredentialTableSpec): string | null;
|
|
36
27
|
export declare function backfillUtxoCredentials(opts?: CredentialBackfillOptions): Promise<CredentialBackfillProgress>;
|
|
37
28
|
//# sourceMappingURL=credential-backfill.d.ts.map
|
|
@@ -17,10 +17,8 @@ exports.CREDENTIAL_TABLES = [
|
|
|
17
17
|
{ name: 'TransactionInputs', entity: cardano_1.TransactionInputs, table: 'odatano_cardano_TransactionInputs', keys: ['txSeq', 'inputIndex'], firstKeyType: 'bigint', column: 'utxoData_paymentCredential', address: 'address_address', counter: 'inputs' },
|
|
18
18
|
{ name: 'LedgerUTxOs', entity: cardano_1.LedgerUTxOs, table: 'odatano_cardano_LedgerUTxOs', keys: ['txHash', 'outputIndex'], firstKeyType: 'text', column: 'utxo_paymentCredential', address: 'address', counter: 'ledgerUtxos' },
|
|
19
19
|
];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* still without a credential are touched. Postgres and SQLite; other databases get one UPDATE per row.
|
|
23
|
-
*/
|
|
20
|
+
// One UPDATE per chunk that joins a JSON array of fills on the key. Touches only rows without a
|
|
21
|
+
// credential. Null for databases other than Postgres and SQLite, which update row by row.
|
|
24
22
|
function credentialFillStatement(kind, spec) {
|
|
25
23
|
const [k1, k2] = spec.keys;
|
|
26
24
|
if (kind === 'postgres') {
|
|
@@ -60,7 +58,7 @@ async function fillTable(spec, chunkSize, onChunk) {
|
|
|
60
58
|
const decoded = new Map();
|
|
61
59
|
for (;;) {
|
|
62
60
|
const done = await cds_1.default.tx(async (tx) => {
|
|
63
|
-
const where = {
|
|
61
|
+
const where = {};
|
|
64
62
|
if (cursor?.within) {
|
|
65
63
|
where[k1] = cursor.first;
|
|
66
64
|
where[k2] = { '>': cursor.second };
|
|
@@ -68,7 +66,7 @@ async function fillTable(spec, chunkSize, onChunk) {
|
|
|
68
66
|
else if (cursor) {
|
|
69
67
|
where[k1] = { '>': cursor.first };
|
|
70
68
|
}
|
|
71
|
-
const rows = (await tx.run(SELECT.from(spec.entity).columns(k1, k2, spec.address).where(where).orderBy(k1, k2).limit(chunkSize))) ?? [];
|
|
69
|
+
const rows = (await tx.run(SELECT.from(spec.entity).columns(k1, k2, spec.address, spec.column).where(where).orderBy(k1, k2).limit(chunkSize))) ?? [];
|
|
72
70
|
const wasWithin = cursor?.within ?? false;
|
|
73
71
|
if (!rows.length) {
|
|
74
72
|
if (!wasWithin)
|
|
@@ -84,6 +82,8 @@ async function fillTable(spec, chunkSize, onChunk) {
|
|
|
84
82
|
const complete = full && !allSame ? rows.filter((r) => r[k1] !== lastFirst) : rows;
|
|
85
83
|
const fills = [];
|
|
86
84
|
for (const r of complete) {
|
|
85
|
+
if (r[spec.column] != null)
|
|
86
|
+
continue;
|
|
87
87
|
const address = r[spec.address];
|
|
88
88
|
if (!address)
|
|
89
89
|
continue;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Listener registry for crawler progress: `blockIndexed` after each persisted block,
|
|
3
|
-
* `reorg` after a completed rollback. Listener failures are logged and swallowed.
|
|
4
|
-
*/
|
|
5
1
|
export interface BlockIndexedEvent {
|
|
6
2
|
hash: string;
|
|
7
3
|
slot: number | null;
|
|
@@ -12,7 +8,7 @@ export interface BlockIndexedEvent {
|
|
|
12
8
|
tipHeight: number | null;
|
|
13
9
|
}
|
|
14
10
|
export interface ReorgEvent {
|
|
15
|
-
/** Absolute slot of the fork point
|
|
11
|
+
/** Absolute slot of the fork point. Everything after it was rolled back. */
|
|
16
12
|
forkSlot: number;
|
|
17
13
|
/** How many blocks the rollback removed (0 when the fork was already the tip). */
|
|
18
14
|
blocksRolledBack?: number;
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { CardanoClient } from '../cardano-client';
|
|
2
2
|
import type { CardanoIndexer } from '../cardano-indexer';
|
|
3
3
|
import { CardanoCrawler, type CrawlerConfig } from './crawler';
|
|
4
|
-
/**
|
|
5
|
-
* Delay before the next standby start attempt: 5 s for a healthy standby; after a local
|
|
6
|
-
* error halt, exponential backoff (5 s … 5 min) driven by the shared cursor's error streak.
|
|
7
|
-
*/
|
|
8
4
|
export declare function standbyDelayMs(consecutiveErrors: number): number;
|
|
9
5
|
export interface StartCrawlerDeps {
|
|
10
6
|
client: CardanoClient;
|
|
@@ -12,15 +8,7 @@ export interface StartCrawlerDeps {
|
|
|
12
8
|
network: string;
|
|
13
9
|
config: CrawlerConfig;
|
|
14
10
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Start the crawler (idempotent — a no-op if one is already running). Fire-and-forget:
|
|
17
|
-
* returns once the ingest pipeline is launched, not when catch-up completes.
|
|
18
|
-
*/
|
|
19
11
|
export declare function startCrawler(deps: StartCrawlerDeps, resumeCluster?: boolean): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Stop the local crawler. `pauseCluster=true` additionally fences every instance via
|
|
22
|
-
* shared DB intent; ordinary app shutdown leaves the desired state intact for failover.
|
|
23
|
-
*/
|
|
24
12
|
export declare function stopCrawler(pauseCluster?: boolean): Promise<void>;
|
|
25
13
|
/** Whether a crawler is currently running. */
|
|
26
14
|
export declare function isCrawlerRunning(): boolean;
|
|
@@ -14,10 +14,7 @@ const node_crypto_1 = require("node:crypto");
|
|
|
14
14
|
const crawler_1 = require("./crawler");
|
|
15
15
|
const sync_state_1 = require("./sync-state");
|
|
16
16
|
const logger = cds_1.default.log('CardanoCrawler');
|
|
17
|
-
|
|
18
|
-
* Process-wide crawler singleton: started fire-and-forget from the `served` hook,
|
|
19
|
-
* controlled (pause/resume/status) via the indexer service.
|
|
20
|
-
*/
|
|
17
|
+
// Process-wide crawler, started from the `served` hook and controlled via the indexer service.
|
|
21
18
|
let active = null;
|
|
22
19
|
let lifecycleQueue = Promise.resolve();
|
|
23
20
|
let standbyDeps = null;
|
|
@@ -25,19 +22,14 @@ let standbyTimer = null;
|
|
|
25
22
|
let standbyGeneration = 0;
|
|
26
23
|
const STANDBY_RETRY_MS = 5_000;
|
|
27
24
|
const STANDBY_MAX_BACKOFF_MS = 5 * 60_000;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* error halt, exponential backoff (5 s … 5 min) driven by the shared cursor's error streak.
|
|
31
|
-
*/
|
|
25
|
+
// Delay before the next standby start: 5 s when healthy. After an error halt it grows
|
|
26
|
+
// exponentially up to 5 min with the shared cursor's error streak.
|
|
32
27
|
function standbyDelayMs(consecutiveErrors) {
|
|
33
28
|
if (!Number.isFinite(consecutiveErrors) || consecutiveErrors <= 1)
|
|
34
29
|
return STANDBY_RETRY_MS;
|
|
35
30
|
return Math.min(STANDBY_MAX_BACKOFF_MS, STANDBY_RETRY_MS * 2 ** Math.min(consecutiveErrors - 1, 10));
|
|
36
31
|
}
|
|
37
|
-
|
|
38
|
-
* Start the crawler (idempotent — a no-op if one is already running). Fire-and-forget:
|
|
39
|
-
* returns once the ingest pipeline is launched, not when catch-up completes.
|
|
40
|
-
*/
|
|
32
|
+
// Start the crawler, a no-op if one runs. Returns once the pipeline is launched, not when caught up.
|
|
41
33
|
async function startCrawler(deps, resumeCluster = false) {
|
|
42
34
|
const generation = ++standbyGeneration;
|
|
43
35
|
standbyDeps = deps;
|
|
@@ -80,10 +72,7 @@ async function startCrawlerAttempt(deps, resumeCluster, generation) {
|
|
|
80
72
|
active = null;
|
|
81
73
|
});
|
|
82
74
|
}
|
|
83
|
-
|
|
84
|
-
* Stop the local crawler. `pauseCluster=true` additionally fences every instance via
|
|
85
|
-
* shared DB intent; ordinary app shutdown leaves the desired state intact for failover.
|
|
86
|
-
*/
|
|
75
|
+
// Stop the local crawler. `pauseCluster` stops every instance. A normal shutdown keeps failover possible.
|
|
87
76
|
async function stopCrawler(pauseCluster = false) {
|
|
88
77
|
++standbyGeneration; // invalidate callbacks that already left the timer queue
|
|
89
78
|
standbyDeps = null;
|
|
@@ -145,10 +134,7 @@ function scheduleStandby(generation, delayMs = STANDBY_RETRY_MS) {
|
|
|
145
134
|
}, delayMs);
|
|
146
135
|
standbyTimer.unref?.();
|
|
147
136
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Backoff from the shared cursor's error streak after a local failure; the base delay
|
|
150
|
-
* otherwise — a healthy tick costs no DB round-trip.
|
|
151
|
-
*/
|
|
137
|
+
/** Backoff from the error streak after a local failure. A healthy tick costs no DB read. */
|
|
152
138
|
async function nextStandbyDelay(failedHere) {
|
|
153
139
|
if (!failedHere)
|
|
154
140
|
return STANDBY_RETRY_MS;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import type { Transaction as CapTransaction } from '@sap/cds';
|
|
2
|
-
/**
|
|
3
|
-
* Cursor helpers for `CardanoSyncState`, the singleton row recording how far the crawler
|
|
4
|
-
* has indexed. Integer64/Decimal columns come back from the DB as strings, so every read
|
|
5
|
-
* coerces numeric fields; callers get a numeric `SyncCursor`.
|
|
6
|
-
*/
|
|
7
2
|
export declare const SINGLETON_ID = "SINGLETON";
|
|
8
3
|
/** Circuit-breaker threshold: pause crawling after this many back-to-back failures. */
|
|
9
4
|
export declare const MAX_CONSECUTIVE_ERRORS = 10;
|
|
@@ -39,61 +34,32 @@ export interface SyncCursor {
|
|
|
39
34
|
tipHeight: number | null;
|
|
40
35
|
syncStatus: CrawlSyncStatusValue;
|
|
41
36
|
consecutiveErrors: number;
|
|
37
|
+
lastIndexedAt: string | null;
|
|
42
38
|
desiredRunning: boolean;
|
|
43
39
|
leaseOwner: string | null;
|
|
44
40
|
leaseUntil: string | null;
|
|
45
41
|
utxoSet: UtxoSetState;
|
|
46
42
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Ensure the singleton cursor row exists and return it; a fresh DB gets the configured
|
|
49
|
-
* start point and status 'stopped'.
|
|
50
|
-
*/
|
|
43
|
+
/** Ensure the cursor row exists and return it. A fresh DB gets the configured start point. */
|
|
51
44
|
export declare function ensureSyncStateSingleton(db: CapTransaction, network: string, start?: CrawlPoint): Promise<SyncCursor>;
|
|
52
45
|
/** Read the current cursor, or null if it has not been initialized yet. */
|
|
53
46
|
export declare function readCursor(db: CapTransaction): Promise<SyncCursor | null>;
|
|
54
47
|
/** Whether the shared lease currently represents a live cluster-wide crawler. */
|
|
55
48
|
export declare function isCrawlerLeaseActive(cursor: SyncCursor | null, now?: Date): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Acquire an expired/unowned lease with compare-and-swap semantics. Verified by a read-back
|
|
58
|
-
* SELECT: affected-row return shapes differ between SQLite and HANA.
|
|
59
|
-
*/
|
|
49
|
+
/** Take a free or expired lease. Verified by reading back, since affected-row results differ per database. */
|
|
60
50
|
export declare function tryAcquireCrawlerLease(db: CapTransaction, owner: string, now?: Date, ttlMs?: number): Promise<boolean>;
|
|
61
|
-
/**
|
|
62
|
-
* Renew/fence a lease. Call this inside the same transaction as every crawler write:
|
|
63
|
-
* the conditional UPDATE serializes a former leader against a newly elected one.
|
|
64
|
-
*/
|
|
51
|
+
/** Renew the lease inside every crawler write transaction, so a former leader cannot write after a takeover. */
|
|
65
52
|
export declare function renewCrawlerLease(db: CapTransaction, owner: string, now?: Date, ttlMs?: number): Promise<boolean>;
|
|
66
|
-
/**
|
|
67
|
-
* Release only the caller's lease. `pauseCluster` clears `desiredRunning`, which no restart
|
|
68
|
-
* undoes — reserve it for failures a restart cannot fix (misconfiguration, no resume point).
|
|
69
|
-
*/
|
|
70
53
|
export declare function releaseCrawlerLease(db: CapTransaction, owner: string, status: CrawlSyncStatusValue, pauseCluster?: boolean): Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Persist the pause/resume intent shared by every instance. Resuming clears the error
|
|
73
|
-
* streak so the standby backoff restarts at its base.
|
|
74
|
-
*/
|
|
54
|
+
/** Store the pause intent for all instances. Resuming clears the error streak, so the backoff restarts. */
|
|
75
55
|
export declare function setCrawlerDesiredRunning(db: CapTransaction, desiredRunning: boolean): Promise<void>;
|
|
76
|
-
/**
|
|
77
|
-
* Latch the cluster off because of a poison block. Deliberately not lease-scoped: the poison
|
|
78
|
-
* is a property of the block, not of the instance. Only resumeCrawler brings the crawler back.
|
|
79
|
-
*/
|
|
80
56
|
export declare function latchPoisonBlock(db: CapTransaction, message: string): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Advance the cursor to a freshly indexed block, clear the error streak and optionally
|
|
83
|
-
* record the latest known tip. Pass status 'synced' when the block is at the tip.
|
|
84
|
-
* With `leaseOwner` the same UPDATE renews and fences the crawler lease (see renewCrawlerLease).
|
|
85
|
-
* @returns false when the lease is no longer held; the caller must roll back
|
|
86
|
-
*/
|
|
87
57
|
export declare function advanceCursor(db: CapTransaction, block: CrawlPoint, tip?: {
|
|
88
58
|
slot: number;
|
|
89
59
|
height?: number;
|
|
90
60
|
}, status?: CrawlSyncStatusValue,
|
|
91
61
|
/** Extra cursor columns written in the same statement (e.g. the ledger's `utxoAppliedSlot`). */
|
|
92
62
|
extra?: Record<string, unknown>, leaseOwner?: string, now?: Date, ttlMs?: number): Promise<boolean>;
|
|
93
|
-
/**
|
|
94
|
-
* Lease for the UTxO set import, on the crawler's lease columns: a crawler start on any
|
|
95
|
-
* instance and a second import are refused while it is held. Does not require `desiredRunning`.
|
|
96
|
-
*/
|
|
97
63
|
export declare function tryAcquireImportLease(db: CapTransaction, owner: string, now?: Date, ttlMs?: number): Promise<boolean>;
|
|
98
64
|
export declare function renewImportLease(db: CapTransaction, owner: string, now?: Date, ttlMs?: number): Promise<boolean>;
|
|
99
65
|
export declare function releaseImportLease(db: CapTransaction, owner: string): Promise<void>;
|
|
@@ -103,10 +69,6 @@ export declare function setUtxoSetState(db: CapTransaction, state: Partial<UtxoS
|
|
|
103
69
|
export declare function resetCursorTo(db: CapTransaction, point: CrawlPoint): Promise<void>;
|
|
104
70
|
/** Set the crawler status (e.g. 'synced' when caught up, 'stopped' on shutdown). */
|
|
105
71
|
export declare function setSyncStatus(db: CapTransaction, status: CrawlSyncStatusValue, pauseCluster?: boolean): Promise<void>;
|
|
106
|
-
/**
|
|
107
|
-
* Record a crawler error. Increments the consecutive-error counter and flips status
|
|
108
|
-
* to 'error' once the circuit-breaker threshold is reached. Returns the new streak
|
|
109
|
-
* length so the caller can decide whether to back off / stop.
|
|
110
|
-
*/
|
|
72
|
+
/** Record a crawler error and return the new streak. Sets status 'error' at the threshold. -1 means the lease is lost. */
|
|
111
73
|
export declare function recordError(db: CapTransaction, err: unknown, leaseOwner?: string): Promise<number>;
|
|
112
74
|
//# sourceMappingURL=sync-state.d.ts.map
|
|
@@ -25,17 +25,13 @@ const cardano_1 = require("#cds-models/odatano/cardano");
|
|
|
25
25
|
const errors_1 = require("../../utils/errors");
|
|
26
26
|
const { SELECT, INSERT, UPDATE } = cds_1.default.ql;
|
|
27
27
|
const logger = cds_1.default.log('CardanoCrawler');
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* has indexed. Integer64/Decimal columns come back from the DB as strings, so every read
|
|
31
|
-
* coerces numeric fields; callers get a numeric `SyncCursor`.
|
|
32
|
-
*/
|
|
28
|
+
// Cursor helpers for the singleton `CardanoSyncState` row.
|
|
29
|
+
// Numeric columns come back from the DB as strings, so every read converts them to numbers.
|
|
33
30
|
exports.SINGLETON_ID = 'SINGLETON';
|
|
34
31
|
/** Circuit-breaker threshold: pause crawling after this many back-to-back failures. */
|
|
35
32
|
exports.MAX_CONSECUTIVE_ERRORS = 10;
|
|
36
33
|
/** A short, renewable DB lease prevents two app instances from advancing one cursor. */
|
|
37
34
|
exports.CRAWLER_LEASE_TTL_MS = 15_000;
|
|
38
|
-
/** Coerce a numeric-as-string (or number/bigint/null) into a JS number. */
|
|
39
35
|
function optionalNum(v) {
|
|
40
36
|
if (v === null || v === undefined || v === '')
|
|
41
37
|
return null;
|
|
@@ -52,10 +48,7 @@ function timestamp(v) {
|
|
|
52
48
|
return v.toISOString();
|
|
53
49
|
return String(v);
|
|
54
50
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Import-lease read-back: ownership and deadline only. Unlike the crawler lease it does not
|
|
57
|
-
* require `desiredRunning`, which is cleared while an import runs.
|
|
58
|
-
*/
|
|
51
|
+
/** Unlike the crawler lease, this ignores `desiredRunning`, which is cleared while an import runs. */
|
|
59
52
|
function importLeaseHeld(cursor, owner, expectedMs) {
|
|
60
53
|
if (!cursor || cursor.leaseOwner !== owner || !cursor.leaseUntil)
|
|
61
54
|
return false;
|
|
@@ -70,7 +63,6 @@ function leaseDeadlineReached(cursor, owner, expectedMs) {
|
|
|
70
63
|
// that representation change without accepting an old lease interval.
|
|
71
64
|
return Number.isFinite(actualMs) && actualMs >= expectedMs - 1_000;
|
|
72
65
|
}
|
|
73
|
-
/** Map a raw DB row into the normalized numeric cursor. */
|
|
74
66
|
function toCursor(row) {
|
|
75
67
|
return {
|
|
76
68
|
network: row.network ?? null,
|
|
@@ -83,6 +75,7 @@ function toCursor(row) {
|
|
|
83
75
|
tipHeight: optionalNum(row.tipHeight),
|
|
84
76
|
syncStatus: (row.syncStatus ?? 'stopped'),
|
|
85
77
|
consecutiveErrors: requiredNum(row.consecutiveErrors),
|
|
78
|
+
lastIndexedAt: timestamp(row.lastIndexedAt),
|
|
86
79
|
desiredRunning: row.desiredRunning !== false,
|
|
87
80
|
leaseOwner: row.leaseOwner ?? null,
|
|
88
81
|
leaseUntil: timestamp(row.leaseUntil),
|
|
@@ -96,10 +89,7 @@ function toCursor(row) {
|
|
|
96
89
|
},
|
|
97
90
|
};
|
|
98
91
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Ensure the singleton cursor row exists and return it; a fresh DB gets the configured
|
|
101
|
-
* start point and status 'stopped'.
|
|
102
|
-
*/
|
|
92
|
+
/** Ensure the cursor row exists and return it. A fresh DB gets the configured start point. */
|
|
103
93
|
async function ensureSyncStateSingleton(db, network, start) {
|
|
104
94
|
const existing = await db.run(SELECT.one.from(cardano_1.CardanoSyncState).where({ ID: exports.SINGLETON_ID }));
|
|
105
95
|
if (existing) {
|
|
@@ -147,10 +137,7 @@ function isCrawlerLeaseActive(cursor, now = new Date()) {
|
|
|
147
137
|
const deadline = Date.parse(cursor.leaseUntil);
|
|
148
138
|
return Number.isFinite(deadline) && deadline > now.getTime();
|
|
149
139
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Acquire an expired/unowned lease with compare-and-swap semantics. Verified by a read-back
|
|
152
|
-
* SELECT: affected-row return shapes differ between SQLite and HANA.
|
|
153
|
-
*/
|
|
140
|
+
/** Take a free or expired lease. Verified by reading back, since affected-row results differ per database. */
|
|
154
141
|
async function tryAcquireCrawlerLease(db, owner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
155
142
|
const raw = await db.run(SELECT.one.from(cardano_1.CardanoSyncState).where({ ID: exports.SINGLETON_ID }));
|
|
156
143
|
if (!raw)
|
|
@@ -161,9 +148,8 @@ async function tryAcquireCrawlerLease(db, owner, now = new Date(), ttlMs = expor
|
|
|
161
148
|
const deadline = current.leaseUntil ? Date.parse(current.leaseUntil) : Number.NEGATIVE_INFINITY;
|
|
162
149
|
if (current.leaseOwner && current.leaseOwner !== owner && deadline > now.getTime())
|
|
163
150
|
return false;
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
// after a leader crash. A concurrently renewing old owner is fenced by its next renew.
|
|
151
|
+
// Compare the owner only. Some adapters reformat timestamps, so a leaseUntil match could fail forever.
|
|
152
|
+
// An old owner that renews meanwhile is fenced by its next renewal.
|
|
167
153
|
const where = {
|
|
168
154
|
ID: exports.SINGLETON_ID,
|
|
169
155
|
leaseOwner: raw.leaseOwner ?? null,
|
|
@@ -176,10 +162,7 @@ async function tryAcquireCrawlerLease(db, owner, now = new Date(), ttlMs = expor
|
|
|
176
162
|
const verified = await readCursor(db);
|
|
177
163
|
return leaseDeadlineReached(verified, owner, now.getTime() + ttlMs);
|
|
178
164
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Renew/fence a lease. Call this inside the same transaction as every crawler write:
|
|
181
|
-
* the conditional UPDATE serializes a former leader against a newly elected one.
|
|
182
|
-
*/
|
|
165
|
+
/** Renew the lease inside every crawler write transaction, so a former leader cannot write after a takeover. */
|
|
183
166
|
async function renewCrawlerLease(db, owner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
184
167
|
const leaseUntil = new Date(now.getTime() + ttlMs).toISOString();
|
|
185
168
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set({ leaseUntil }).where({
|
|
@@ -190,10 +173,8 @@ async function renewCrawlerLease(db, owner, now = new Date(), ttlMs = exports.CR
|
|
|
190
173
|
const verified = await readCursor(db);
|
|
191
174
|
return leaseDeadlineReached(verified, owner, now.getTime() + ttlMs);
|
|
192
175
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
* undoes — reserve it for failures a restart cannot fix (misconfiguration, no resume point).
|
|
196
|
-
*/
|
|
176
|
+
// Release only the caller's lease. `pauseCluster` keeps the crawler down across restarts.
|
|
177
|
+
// Use it only for failures a restart cannot fix, such as misconfiguration.
|
|
197
178
|
async function releaseCrawlerLease(db, owner, status, pauseCluster = false) {
|
|
198
179
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set({
|
|
199
180
|
leaseOwner: null,
|
|
@@ -202,10 +183,7 @@ async function releaseCrawlerLease(db, owner, status, pauseCluster = false) {
|
|
|
202
183
|
...(pauseCluster ? { desiredRunning: false } : {}),
|
|
203
184
|
}).where({ ID: exports.SINGLETON_ID, leaseOwner: owner }));
|
|
204
185
|
}
|
|
205
|
-
/**
|
|
206
|
-
* Persist the pause/resume intent shared by every instance. Resuming clears the error
|
|
207
|
-
* streak so the standby backoff restarts at its base.
|
|
208
|
-
*/
|
|
186
|
+
/** Store the pause intent for all instances. Resuming clears the error streak, so the backoff restarts. */
|
|
209
187
|
async function setCrawlerDesiredRunning(db, desiredRunning) {
|
|
210
188
|
const set = { desiredRunning };
|
|
211
189
|
if (desiredRunning)
|
|
@@ -214,10 +192,8 @@ async function setCrawlerDesiredRunning(db, desiredRunning) {
|
|
|
214
192
|
set.syncStatus = 'stopped';
|
|
215
193
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set(set).where({ ID: exports.SINGLETON_ID }));
|
|
216
194
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
* is a property of the block, not of the instance. Only resumeCrawler brings the crawler back.
|
|
220
|
-
*/
|
|
195
|
+
// Latch the cluster off for a poison block. Not tied to the lease, since the fault is in the block.
|
|
196
|
+
// Only resumeCrawler brings the crawler back.
|
|
221
197
|
async function latchPoisonBlock(db, message) {
|
|
222
198
|
await db.run(UPDATE.entity(cardano_1.CardanoSyncState).set({
|
|
223
199
|
desiredRunning: false,
|
|
@@ -226,12 +202,8 @@ async function latchPoisonBlock(db, message) {
|
|
|
226
202
|
lastErrorAt: new Date().toISOString(),
|
|
227
203
|
}).where({ ID: exports.SINGLETON_ID }));
|
|
228
204
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
* record the latest known tip. Pass status 'synced' when the block is at the tip.
|
|
232
|
-
* With `leaseOwner` the same UPDATE renews and fences the crawler lease (see renewCrawlerLease).
|
|
233
|
-
* @returns false when the lease is no longer held; the caller must roll back
|
|
234
|
-
*/
|
|
205
|
+
// Advance the cursor to an indexed block and clear the error streak. With `leaseOwner` the
|
|
206
|
+
// same UPDATE renews the lease. Returns false when the lease is lost, and the caller must roll back.
|
|
235
207
|
async function advanceCursor(db, block, tip, status = 'syncing',
|
|
236
208
|
/** Extra cursor columns written in the same statement (e.g. the ledger's `utxoAppliedSlot`). */
|
|
237
209
|
extra, leaseOwner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
@@ -263,10 +235,7 @@ extra, leaseOwner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
|
263
235
|
const verified = await readCursor(db);
|
|
264
236
|
return leaseDeadlineReached(verified, leaseOwner, now.getTime() + ttlMs);
|
|
265
237
|
}
|
|
266
|
-
|
|
267
|
-
* Lease for the UTxO set import, on the crawler's lease columns: a crawler start on any
|
|
268
|
-
* instance and a second import are refused while it is held. Does not require `desiredRunning`.
|
|
269
|
-
*/
|
|
238
|
+
// Lease for the UTxO set import on the crawler's lease columns. Blocks crawler starts and other imports.
|
|
270
239
|
async function tryAcquireImportLease(db, owner, now = new Date(), ttlMs = exports.CRAWLER_LEASE_TTL_MS) {
|
|
271
240
|
const raw = await db.run(SELECT.one.from(cardano_1.CardanoSyncState).where({ ID: exports.SINGLETON_ID }));
|
|
272
241
|
if (!raw)
|
|
@@ -328,11 +297,7 @@ async function setSyncStatus(db, status, pauseCluster = false) {
|
|
|
328
297
|
...(pauseCluster ? { desiredRunning: false } : {}),
|
|
329
298
|
}).where({ ID: exports.SINGLETON_ID }));
|
|
330
299
|
}
|
|
331
|
-
/**
|
|
332
|
-
* Record a crawler error. Increments the consecutive-error counter and flips status
|
|
333
|
-
* to 'error' once the circuit-breaker threshold is reached. Returns the new streak
|
|
334
|
-
* length so the caller can decide whether to back off / stop.
|
|
335
|
-
*/
|
|
300
|
+
/** Record a crawler error and return the new streak. Sets status 'error' at the threshold. -1 means the lease is lost. */
|
|
336
301
|
async function recordError(db, err, leaseOwner) {
|
|
337
302
|
if (leaseOwner && !(await renewCrawlerLease(db, leaseOwner)))
|
|
338
303
|
return -1;
|
|
@@ -3,12 +3,6 @@ import type { CardanoClient } from '../cardano-client';
|
|
|
3
3
|
import type { ChainPoint } from '../backends/cardano-backend';
|
|
4
4
|
import type { Transaction } from '../../utils/types';
|
|
5
5
|
import type { LedgerLookup } from '../ledger-state';
|
|
6
|
-
/**
|
|
7
|
-
* Completes transactions the crawl already holds from a second chain-sync stream: input
|
|
8
|
-
* outpoints (spentTxHash / spentOutputIndex), the spent output's datum and reference-script
|
|
9
|
-
* hash, a missing input address, the redeemers and the witness datums. Only empty input fields
|
|
10
|
-
* are filled; a transaction whose stored inputs do not line up with the stream is left as it is.
|
|
11
|
-
*/
|
|
12
6
|
export declare class TransactionBackfillError extends Error {
|
|
13
7
|
constructor(message: string);
|
|
14
8
|
}
|
|
@@ -43,11 +37,6 @@ export interface TransactionBackfillResult extends TransactionBackfillProgress {
|
|
|
43
37
|
toSlot: number;
|
|
44
38
|
intersection: ChainPoint | 'origin';
|
|
45
39
|
}
|
|
46
|
-
/**
|
|
47
|
-
* One UPDATE per chunk: the fills travel as a JSON array and are joined on (txSeq, inputIndex).
|
|
48
|
-
* COALESCE keeps any value that is already there. Postgres and SQLite; other databases get one
|
|
49
|
-
* UPDATE per row.
|
|
50
|
-
*/
|
|
51
40
|
export declare function inputFillStatement(kind: string): string | null;
|
|
52
41
|
export declare function backfillTransactions(opts: TransactionBackfillOptions): Promise<TransactionBackfillResult>;
|
|
53
42
|
//# sourceMappingURL=transaction-backfill.d.ts.map
|
|
@@ -13,12 +13,8 @@ const certificate_backfill_1 = require("./certificate-backfill");
|
|
|
13
13
|
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
14
14
|
const { SELECT, UPDATE, UPSERT, DELETE } = cds_1.default.ql;
|
|
15
15
|
const logger = cds_1.default.log('TransactionBackfill');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* outpoints (spentTxHash / spentOutputIndex), the spent output's datum and reference-script
|
|
19
|
-
* hash, a missing input address, the redeemers and the witness datums. Only empty input fields
|
|
20
|
-
* are filled; a transaction whose stored inputs do not line up with the stream is left as it is.
|
|
21
|
-
*/
|
|
16
|
+
// Complete crawled transactions from a second chain-sync stream: spent outputs, input fields,
|
|
17
|
+
// redeemers and witness datums. Only empty fields are filled. Mismatching transactions stay as they are.
|
|
22
18
|
class TransactionBackfillError extends Error {
|
|
23
19
|
constructor(message) {
|
|
24
20
|
super(message);
|
|
@@ -28,11 +24,8 @@ class TransactionBackfillError extends Error {
|
|
|
28
24
|
exports.TransactionBackfillError = TransactionBackfillError;
|
|
29
25
|
const key = (txSeq, inputIndex) => `${Number(txSeq)}#${Number(inputIndex)}`;
|
|
30
26
|
const lovelaceOf = (i) => i.amount?.find((a) => a.unit === 'lovelace')?.quantity ?? null;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* one is stored, same address and lovelace where both sides know them. A stored address the
|
|
34
|
-
* stream cannot resolve is unverifiable, so it does not match.
|
|
35
|
-
*/
|
|
27
|
+
// Whether a stored and a streamed input are the same: same flags, output, address and lovelace
|
|
28
|
+
// where known. A stored address the stream cannot resolve does not match.
|
|
36
29
|
function sameInput(row, fresh, storedLovelace) {
|
|
37
30
|
if (Boolean(row.isCollateral) !== Boolean(fresh.isCollateral) || Boolean(row.isReference) !== Boolean(fresh.isReference))
|
|
38
31
|
return false;
|
|
@@ -48,10 +41,7 @@ function sameInput(row, fresh, storedLovelace) {
|
|
|
48
41
|
const freshLovelace = lovelaceOf(fresh);
|
|
49
42
|
return storedLovelace == null || freshLovelace == null || String(storedLovelace) === String(freshLovelace);
|
|
50
43
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Stored rows in the stream's order when they hold the same outpoints with the same flags, each
|
|
53
|
-
* once; null otherwise (a row without outpoint cannot be placed).
|
|
54
|
-
*/
|
|
44
|
+
/** Stored rows in stream order if they hold the same outputs once each, else null. */
|
|
55
45
|
function reorderByOutpoint(rows, fresh) {
|
|
56
46
|
if (rows.length !== fresh.length || rows.some((r) => r.spentTxHash == null))
|
|
57
47
|
return null;
|
|
@@ -110,11 +100,8 @@ const FILL_COLUMNS = [
|
|
|
110
100
|
['hasAddresses', 'boolean'],
|
|
111
101
|
['hasAssets', 'boolean'],
|
|
112
102
|
];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
* COALESCE keeps any value that is already there. Postgres and SQLite; other databases get one
|
|
116
|
-
* UPDATE per row.
|
|
117
|
-
*/
|
|
103
|
+
// One UPDATE per chunk that joins a JSON array of fills on the input key. COALESCE keeps existing
|
|
104
|
+
// values. Null for databases other than Postgres and SQLite, which update row by row.
|
|
118
105
|
function inputFillStatement(kind) {
|
|
119
106
|
const set = FILL_COLUMNS
|
|
120
107
|
.map(([c]) => c.startsWith('has')
|
|
@@ -154,10 +141,7 @@ async function writeInputFills(tx, fills) {
|
|
|
154
141
|
await tx.run(sql, [JSON.stringify(records)]);
|
|
155
142
|
}
|
|
156
143
|
}
|
|
157
|
-
|
|
158
|
-
* Rewrites the input rows of one transaction as the ledger view: the kept rows (and their assets)
|
|
159
|
-
* move to their position, rows left out are dropped, empty fields are filled on the way.
|
|
160
|
-
*/
|
|
144
|
+
// Rewrite one transaction's inputs in ledger order. Rows left out are dropped, empty fields filled.
|
|
161
145
|
async function rewriteInOrder(tx, seq, ordered, fresh) {
|
|
162
146
|
const assets = (await tx.run(SELECT.from(cardano_1.TransactionInputAssets).where({ input_txSeq: seq }))) ?? [];
|
|
163
147
|
const newIndex = new Map(ordered.map((r, i) => [Number(r.inputIndex), i]));
|
|
@@ -172,11 +156,8 @@ async function rewriteInOrder(tx, seq, ordered, fresh) {
|
|
|
172
156
|
if (movedAssets.length)
|
|
173
157
|
await tx.run(UPSERT.into(cardano_1.TransactionInputAssets).entries(movedAssets));
|
|
174
158
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* valid transaction, and the declared outputs of a phase-2 failure. Only when every output of the
|
|
178
|
-
* stream is stored, so a gap is never mistaken for an extra. Returns the transactions touched.
|
|
179
|
-
*/
|
|
159
|
+
// Delete outputs the ledger never produced, which some providers list for phase-2 results.
|
|
160
|
+
// Runs only when every streamed output is stored. Returns the transactions touched.
|
|
180
161
|
async function dropUnappliedOutputs(tx, txs) {
|
|
181
162
|
const wanted = new Map(txs.map((t) => [(0, mappers_1.txSeqOf)(t.slot, t.index), new Set((t.outputs ?? []).map((o) => o.outputIndex))]));
|
|
182
163
|
const stored = new Map();
|
|
@@ -250,7 +231,7 @@ async function backfillTransactions(opts) {
|
|
|
250
231
|
continue;
|
|
251
232
|
}
|
|
252
233
|
progress.skipped++;
|
|
253
|
-
logger.debug(`Transaction ${t.hash}: stored inputs differ from the stream
|
|
234
|
+
logger.debug(`Transaction ${t.hash}: stored inputs differ from the stream, left as it is`);
|
|
254
235
|
continue;
|
|
255
236
|
}
|
|
256
237
|
for (let i = 0; i < inputs.length; i++) {
|
|
@@ -2,11 +2,6 @@ import type { CardanoClient } from '../cardano-client';
|
|
|
2
2
|
import type { CardanoIndexer } from '../cardano-indexer';
|
|
3
3
|
import type { Amount, ReferenceScriptType } from '../../utils/types';
|
|
4
4
|
import { type LedgerAnchor } from '../ledger-state';
|
|
5
|
-
/**
|
|
6
|
-
* One-off import of the UTxO set at the anchor `crawler.utxoSet` builds on: from Ogmios
|
|
7
|
-
* (`queryLedgerState/utxo` at the cursor point) or a `cardano-cli query utxo --whole-utxo`
|
|
8
|
-
* dump (`.json` parsed whole; `.ndjson`/`.jsonl` streamed, one entry or `{key,value}` per line).
|
|
9
|
-
*/
|
|
10
5
|
export declare class UtxoSetImportError extends Error {
|
|
11
6
|
constructor(message: string);
|
|
12
7
|
}
|
|
@@ -48,32 +43,14 @@ export interface CliUtxoValue {
|
|
|
48
43
|
inlineDatumRaw?: string | null;
|
|
49
44
|
referenceScript?: unknown;
|
|
50
45
|
}
|
|
51
|
-
/**
|
|
52
|
-
* `JSON.parse` for a cardano-cli dump that keeps every integer exact: integer literals outside
|
|
53
|
-
* strings are quoted before parsing, so a quantity above 2^53 is never rounded.
|
|
54
|
-
*/
|
|
46
|
+
/** `JSON.parse` that quotes integer literals first, so quantities above 2^53 are never rounded. */
|
|
55
47
|
export declare function parseJsonLossless<T = unknown>(text: string): T;
|
|
56
48
|
/** Parse one `"txHash#index": {…}` entry of a cardano-cli dump; null when malformed. */
|
|
57
49
|
export declare function parseCliUtxoEntry(key: string, value: CliUtxoValue | null | undefined): UtxoSetEntry | null;
|
|
58
50
|
/** Stream a cardano-cli dump. See the module doc for the accepted layouts. */
|
|
59
51
|
export declare function readUtxoSetFile(filePath: string): AsyncGenerator<UtxoSetEntry>;
|
|
60
|
-
/**
|
|
61
|
-
* The three aggregate statements that derive the running sums from the imported rows.
|
|
62
|
-
* Plain SQL because millions of addresses do not fit an in-memory map and a per-row
|
|
63
|
-
* UPSERT would take hours; the syntax is the portable subset (sqlite, PostgreSQL, HANA).
|
|
64
|
-
*/
|
|
65
52
|
export declare function aggregateStatements(): string[];
|
|
66
|
-
/**
|
|
67
|
-
* Run the import. Throws `UtxoSetImportError` on a precondition failure before anything is
|
|
68
|
-
* written; a failure mid-way leaves the set marked `invalid` (never half-`active`).
|
|
69
|
-
*/
|
|
70
53
|
export declare function importUtxoSet(opts: UtxoSetImportOptions): Promise<UtxoSetImportResult>;
|
|
71
|
-
/**
|
|
72
|
-
* Rebuild only the sums (LedgerAddresses, LedgerAddressAssets, LedgerAccounts) from the rows an
|
|
73
|
-
* earlier import left at the stored anchor, e.g. after the aggregate phase failed. Nothing may have
|
|
74
|
-
* been applied since the anchor; a cursor past it is set back to the anchor, and the blocks after
|
|
75
|
-
* it are crawled again (idempotent writes) so the set follows them.
|
|
76
|
-
*/
|
|
77
54
|
export declare function rebuildUtxoSetAggregates(opts: {
|
|
78
55
|
indexer: CardanoIndexer;
|
|
79
56
|
}): Promise<UtxoSetImportResult>;
|
|
@@ -83,12 +60,6 @@ export interface UtxoSetScriptRefreshResult {
|
|
|
83
60
|
/** Rows looked at: dump entries carrying a script, or stored rows with a hash but no size. */
|
|
84
61
|
candidates: number;
|
|
85
62
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Fill the reference-script columns (hash, size, type) of `LedgerUTxOs` rows an earlier import
|
|
88
|
-
* left empty: from the same cardano-cli dump, or, without a file, from the node for the unspent
|
|
89
|
-
* rows that hold a hash but no size. Takes the cursor lease like an import, so the crawler must
|
|
90
|
-
* be paused; the set stays `active` throughout.
|
|
91
|
-
*/
|
|
92
63
|
export declare function refreshUtxoSetReferenceScripts(opts: {
|
|
93
64
|
filePath?: string;
|
|
94
65
|
client: CardanoClient;
|