@odatano/core 2.0.0-rc.13 → 2.0.0-rc.14
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/CardanoIndexerService/index.d.ts +1 -0
- package/db/schema.cds +6 -6
- package/package.json +1 -1
- package/srv/blockchain/backends/koios-backend.js +6 -4
- package/srv/blockchain/cardano-client.d.ts +9 -0
- package/srv/blockchain/cardano-client.js +18 -0
- package/srv/blockchain/crawler/crawler.d.ts +49 -0
- package/srv/blockchain/crawler/crawler.js +150 -29
- package/srv/cardano-indexer-service.cds +4 -0
- package/srv/cardano-indexer-service.js +3 -0
- package/srv/utils/types.d.ts +2 -1
|
@@ -87,6 +87,7 @@ export declare function _CrawlerStatusAspect<TBase extends new (...args: any[])
|
|
|
87
87
|
new (...args: any[]): {
|
|
88
88
|
running?: boolean | null
|
|
89
89
|
syncStatus?: string | null
|
|
90
|
+
source?: string | null
|
|
90
91
|
lastSlot?: string | null
|
|
91
92
|
lastHeight?: string | null
|
|
92
93
|
tipHeight?: string | null
|
package/db/schema.cds
CHANGED
|
@@ -158,7 +158,7 @@ entity Pools : temporal {
|
|
|
158
158
|
blocksMinted : Integer;
|
|
159
159
|
|
|
160
160
|
@title : 'Blocks in Epoch'
|
|
161
|
-
@description: 'Number of blocks minted in the current epoch'
|
|
161
|
+
@description: 'Number of blocks minted in the current epoch. Null when the backend that filled the row has no such figure (Koios); a 0 is a real zero'
|
|
162
162
|
blocksEpoch : Integer;
|
|
163
163
|
|
|
164
164
|
@title : 'Live Stake'
|
|
@@ -170,8 +170,8 @@ entity Pools : temporal {
|
|
|
170
170
|
liveSize : Decimal(5, 4);
|
|
171
171
|
|
|
172
172
|
@title : 'Live Saturation'
|
|
173
|
-
@description: 'Current live saturation as fraction of ideal size (1.0 = 100% saturated)'
|
|
174
|
-
liveSaturation : Decimal(
|
|
173
|
+
@description: 'Current live saturation as fraction of ideal size (1.0 = 100% saturated). Decimal(9, 4): a test-network pool can hold many times the saturation point'
|
|
174
|
+
liveSaturation : Decimal(9, 4);
|
|
175
175
|
|
|
176
176
|
@title : 'Live Delegators'
|
|
177
177
|
@description: 'Current number of live delegators'
|
|
@@ -227,7 +227,7 @@ entity PoolEpochSnapshots {
|
|
|
227
227
|
blocksMinted : Integer;
|
|
228
228
|
|
|
229
229
|
@title : 'Blocks in Epoch'
|
|
230
|
-
@description: 'Number of blocks minted in the epoch that was running at snapshot time'
|
|
230
|
+
@description: 'Number of blocks minted in the epoch that was running at snapshot time. Null when the enumerating backend has no such figure (Koios); a 0 is a real zero'
|
|
231
231
|
blocksEpoch : Integer;
|
|
232
232
|
|
|
233
233
|
@title : 'Live Stake'
|
|
@@ -239,8 +239,8 @@ entity PoolEpochSnapshots {
|
|
|
239
239
|
liveSize : Decimal(5, 4);
|
|
240
240
|
|
|
241
241
|
@title : 'Live Saturation'
|
|
242
|
-
@description: 'Live saturation as fraction of ideal size (1.0 = 100% saturated)'
|
|
243
|
-
liveSaturation : Decimal(
|
|
242
|
+
@description: 'Live saturation as fraction of ideal size (1.0 = 100% saturated). Decimal(9, 4): a test-network pool can hold many times the saturation point'
|
|
243
|
+
liveSaturation : Decimal(9, 4);
|
|
244
244
|
|
|
245
245
|
@title : 'Live Delegators'
|
|
246
246
|
@description: 'Number of live delegators'
|
package/package.json
CHANGED
|
@@ -461,15 +461,17 @@ class KoiosBackend {
|
|
|
461
461
|
blocksMinted: poolData.block_count,
|
|
462
462
|
// Koios pool_info has no blocks-in-current-epoch figure — epoch_no
|
|
463
463
|
// (the epoch NUMBER) was mapped here before, which is a different
|
|
464
|
-
// semantic than Blockfrost's blocks_epoch.
|
|
465
|
-
|
|
464
|
+
// semantic than Blockfrost's blocks_epoch. null = not available: a 0
|
|
465
|
+
// here read as "minted nothing this epoch" and produced leaderboards
|
|
466
|
+
// full of zeros downstream, indistinguishable from a real zero.
|
|
467
|
+
blocksEpoch: null,
|
|
466
468
|
liveStake: poolData.live_stake || '0',
|
|
467
469
|
liveSize: poolData.live_size || 0,
|
|
468
470
|
liveDelegators: poolData.live_delegators || 0,
|
|
469
471
|
// Koios reports saturation in PERCENT (75.42 = 75.42 %), Blockfrost as a
|
|
470
472
|
// fraction (0.7542). PoolData is a fraction everywhere — and the columns
|
|
471
|
-
// behind it are Decimal(
|
|
472
|
-
// through
|
|
473
|
+
// behind it are Decimal(9, 4) — so convert here. Passing the percent value
|
|
474
|
+
// through would overflow the column for a saturated pool and take the
|
|
473
475
|
// whole epoch snapshot down with it.
|
|
474
476
|
liveSaturation: (Number(poolData.live_saturation) || 0) / 100,
|
|
475
477
|
activeStake: poolData.active_stake || '0',
|
|
@@ -245,6 +245,15 @@ export declare class CardanoClient {
|
|
|
245
245
|
* uninitialized backend would wedge it.
|
|
246
246
|
*/
|
|
247
247
|
getChainSyncBackend(): ChainSyncBackend | null;
|
|
248
|
+
/**
|
|
249
|
+
* getChainSyncBackend(), but retrying the startup init of a chain-sync-capable backend
|
|
250
|
+
* that failed it. The crawler polls this while it crawls on pagination only because no
|
|
251
|
+
* chain-sync source was usable when it started: on a box where the node and ODATANO
|
|
252
|
+
* restart together, the node's chunk validation and ledger replay routinely outlast
|
|
253
|
+
* ODATANO's startup, so Ogmios refuses the init once and is healthy minutes later.
|
|
254
|
+
* Without this the crawler would stay on pagination for the rest of the process.
|
|
255
|
+
*/
|
|
256
|
+
recoverChainSyncBackend(): Promise<ChainSyncBackend | null>;
|
|
248
257
|
/**
|
|
249
258
|
* Get a backend that can enumerate the full pool/DRep set (Koios), or null. Used by the
|
|
250
259
|
* crawler's epoch-boundary snapshots; without one they stay off rather than degrade into
|
|
@@ -549,6 +549,24 @@ class CardanoClient {
|
|
|
549
549
|
}
|
|
550
550
|
return null;
|
|
551
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* getChainSyncBackend(), but retrying the startup init of a chain-sync-capable backend
|
|
554
|
+
* that failed it. The crawler polls this while it crawls on pagination only because no
|
|
555
|
+
* chain-sync source was usable when it started: on a box where the node and ODATANO
|
|
556
|
+
* restart together, the node's chunk validation and ledger replay routinely outlast
|
|
557
|
+
* ODATANO's startup, so Ogmios refuses the init once and is healthy minutes later.
|
|
558
|
+
* Without this the crawler would stay on pagination for the rest of the process.
|
|
559
|
+
*/
|
|
560
|
+
async recoverChainSyncBackend() {
|
|
561
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
562
|
+
for (const b of candidates) {
|
|
563
|
+
if (!b || !(0, cardano_backend_1.isChainSyncBackend)(b))
|
|
564
|
+
continue;
|
|
565
|
+
if (await this.ensureBackendInitialized(b))
|
|
566
|
+
return b;
|
|
567
|
+
}
|
|
568
|
+
return null;
|
|
569
|
+
}
|
|
552
570
|
/**
|
|
553
571
|
* Get a backend that can enumerate the full pool/DRep set (Koios), or null. Used by the
|
|
554
572
|
* crawler's epoch-boundary snapshots; without one they stay off rather than degrade into
|
|
@@ -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;
|
|
@@ -88,8 +90,25 @@ export declare class CardanoCrawler {
|
|
|
88
90
|
*/
|
|
89
91
|
private static readonly SNAPSHOT_RETRY_BASE_MS;
|
|
90
92
|
private static readonly SNAPSHOT_RETRY_MAX_MS;
|
|
93
|
+
/**
|
|
94
|
+
* How often a crawl that runs on pagination for lack of a chain-sync backend retries
|
|
95
|
+
* that backend's init. Pagination is roughly fifty times slower than chain-sync, so
|
|
96
|
+
* the cadence errs on the frequent side; the probe is free when no chain-sync backend
|
|
97
|
+
* is configured at all and bounded by the backend's init timeout when it is down.
|
|
98
|
+
*/
|
|
99
|
+
private static readonly CHAIN_SYNC_RETRY_MS;
|
|
91
100
|
private running;
|
|
92
101
|
private chainSyncHandle;
|
|
102
|
+
/** What the ingest loop is currently reading from; null while stopped. */
|
|
103
|
+
private activeSource;
|
|
104
|
+
/**
|
|
105
|
+
* Chain-sync init retry while the crawl runs on pagination for lack of one: its own
|
|
106
|
+
* timer (independent of the pagination cadence — a poll sleep can be an hour long),
|
|
107
|
+
* the in-flight recover call, and its outcome.
|
|
108
|
+
*/
|
|
109
|
+
private chainSyncProbeTimer;
|
|
110
|
+
private chainSyncProbe;
|
|
111
|
+
private chainSyncRecovered;
|
|
93
112
|
/** The detached ingest pipeline — awaited by stop() so teardown never races it. */
|
|
94
113
|
private pipeline;
|
|
95
114
|
/** Resolver that cancels a pending poll sleep (set while sleeping). */
|
|
@@ -125,6 +144,12 @@ export declare class CardanoCrawler {
|
|
|
125
144
|
isRunning(): boolean;
|
|
126
145
|
/** True once the crawler halted because of a failure (not via stop() or a lost lease). */
|
|
127
146
|
haltedWithError(): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* The source this crawler is ingesting from right now, or null while it is not
|
|
149
|
+
* running. Lets an operator see a crawl that degraded to pagination — it still makes
|
|
150
|
+
* progress, so the cursor alone looks healthy.
|
|
151
|
+
*/
|
|
152
|
+
getActiveSource(): CrawlSource | null;
|
|
128
153
|
/**
|
|
129
154
|
* Start crawling. Does NOT await the ingest pipeline (fire-and-forget).
|
|
130
155
|
* Refuses to start without a resume point: an explicit configured start block or an
|
|
@@ -157,6 +182,19 @@ export declare class CardanoCrawler {
|
|
|
157
182
|
*/
|
|
158
183
|
private beginHalt;
|
|
159
184
|
private runIngestPipeline;
|
|
185
|
+
/**
|
|
186
|
+
* Retry the init of a chain-sync backend that was unusable when the crawl began, on
|
|
187
|
+
* its own timer: the pagination loop may be asleep for a whole poll interval (up to
|
|
188
|
+
* an hour) or inside a slow batch, and neither must delay the retry. The probe runs
|
|
189
|
+
* in the background so no pagination round waits for it, and one at a time so a node
|
|
190
|
+
* that is still replaying is not hammered. On success `chainSyncRecovered` is set and
|
|
191
|
+
* a pending poll sleep is cut short; the pagination loop leaves at its next check
|
|
192
|
+
* (between rounds, or between blocks of a batch — the block in flight completes) and
|
|
193
|
+
* the ingest loop reopens chain-sync from the cursor.
|
|
194
|
+
*/
|
|
195
|
+
private startChainSyncProbing;
|
|
196
|
+
private scheduleChainSyncProbe;
|
|
197
|
+
private stopChainSyncProbing;
|
|
160
198
|
/** Bound a direct backend call — these bypass the client's timeout/breaker layer. */
|
|
161
199
|
private withTimeout;
|
|
162
200
|
private runChainSync;
|
|
@@ -196,8 +234,19 @@ export declare class CardanoCrawler {
|
|
|
196
234
|
* looping forever. Used to walk past a block the chain-sync stream cannot deliver and
|
|
197
235
|
* then hand back to it — pagination is roughly seven times slower, so staying on it
|
|
198
236
|
* for the rest of a backfill would be a poor trade.
|
|
237
|
+
* @param untilChainSync when set, keep retrying a chain-sync backend in the background
|
|
238
|
+
* and return once one is usable, so the ingest loop can hand over to it. Used when
|
|
239
|
+
* the crawl started without one (source 'auto', node still coming up).
|
|
199
240
|
*/
|
|
200
241
|
private runPagination;
|
|
242
|
+
private paginate;
|
|
243
|
+
/**
|
|
244
|
+
* Poll pause between pagination rounds. Skipped when a handover to chain-sync is
|
|
245
|
+
* already due: the probe's wake-up only reaches a sleep that has begun, so a probe
|
|
246
|
+
* that succeeded while the round was still fetching (tip, blocks) would otherwise be
|
|
247
|
+
* followed by a full poll interval — up to an hour — before the loop notices.
|
|
248
|
+
*/
|
|
249
|
+
private pollPause;
|
|
201
250
|
/**
|
|
202
251
|
* Pagination reorg recovery: walk back by height comparing the on-chain block hash with
|
|
203
252
|
* our stored one until they agree — that height is the fork point. If the last-indexed
|
|
@@ -84,8 +84,25 @@ class CardanoCrawler {
|
|
|
84
84
|
*/
|
|
85
85
|
static SNAPSHOT_RETRY_BASE_MS = 30_000;
|
|
86
86
|
static SNAPSHOT_RETRY_MAX_MS = 10 * 60_000;
|
|
87
|
+
/**
|
|
88
|
+
* How often a crawl that runs on pagination for lack of a chain-sync backend retries
|
|
89
|
+
* that backend's init. Pagination is roughly fifty times slower than chain-sync, so
|
|
90
|
+
* the cadence errs on the frequent side; the probe is free when no chain-sync backend
|
|
91
|
+
* is configured at all and bounded by the backend's init timeout when it is down.
|
|
92
|
+
*/
|
|
93
|
+
static CHAIN_SYNC_RETRY_MS = 30_000;
|
|
87
94
|
running = false;
|
|
88
95
|
chainSyncHandle = null;
|
|
96
|
+
/** What the ingest loop is currently reading from; null while stopped. */
|
|
97
|
+
activeSource = null;
|
|
98
|
+
/**
|
|
99
|
+
* Chain-sync init retry while the crawl runs on pagination for lack of one: its own
|
|
100
|
+
* timer (independent of the pagination cadence — a poll sleep can be an hour long),
|
|
101
|
+
* the in-flight recover call, and its outcome.
|
|
102
|
+
*/
|
|
103
|
+
chainSyncProbeTimer = null;
|
|
104
|
+
chainSyncProbe = null;
|
|
105
|
+
chainSyncRecovered = false;
|
|
89
106
|
/** The detached ingest pipeline — awaited by stop() so teardown never races it. */
|
|
90
107
|
pipeline = null;
|
|
91
108
|
/** Resolver that cancels a pending poll sleep (set while sleeping). */
|
|
@@ -131,6 +148,14 @@ class CardanoCrawler {
|
|
|
131
148
|
haltedWithError() {
|
|
132
149
|
return !this.running && this.finalStatus === 'error';
|
|
133
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* The source this crawler is ingesting from right now, or null while it is not
|
|
153
|
+
* running. Lets an operator see a crawl that degraded to pagination — it still makes
|
|
154
|
+
* progress, so the cursor alone looks healthy.
|
|
155
|
+
*/
|
|
156
|
+
getActiveSource() {
|
|
157
|
+
return this.running ? this.activeSource : null;
|
|
158
|
+
}
|
|
134
159
|
/**
|
|
135
160
|
* Start crawling. Does NOT await the ingest pipeline (fire-and-forget).
|
|
136
161
|
* Refuses to start without a resume point: an explicit configured start block or an
|
|
@@ -217,9 +242,11 @@ class CardanoCrawler {
|
|
|
217
242
|
if (this.finalStatus !== 'error' || finalStatus === 'error')
|
|
218
243
|
this.finalStatus = finalStatus;
|
|
219
244
|
this.running = false;
|
|
245
|
+
this.activeSource = null;
|
|
220
246
|
// Background asset enrichment belongs to the crawl — it must not outlive it.
|
|
221
247
|
this.indexer.stopAssetEnrichment();
|
|
222
248
|
this.wake?.(); // cancel a pending poll sleep so the loop exits now
|
|
249
|
+
this.stopChainSyncProbing();
|
|
223
250
|
this.streamEnded?.(); // release the ingest loop — beginHalt awaits the pipeline below
|
|
224
251
|
this.leaseWake?.();
|
|
225
252
|
for (const cancel of [...this.callCancels])
|
|
@@ -247,6 +274,8 @@ class CardanoCrawler {
|
|
|
247
274
|
}
|
|
248
275
|
if (this.leaseHeartbeat)
|
|
249
276
|
await this.leaseHeartbeat.catch(() => undefined);
|
|
277
|
+
if (this.chainSyncProbe)
|
|
278
|
+
await this.chainSyncProbe.catch(() => undefined);
|
|
250
279
|
try {
|
|
251
280
|
if (this.leaseOwner && this.leaseHeld) {
|
|
252
281
|
await cds_1.default.tx((tx) => (0, sync_state_1.releaseCrawlerLease)(tx, this.leaseOwner, this.finalStatus, this.latchOnHalt));
|
|
@@ -260,34 +289,92 @@ class CardanoCrawler {
|
|
|
260
289
|
});
|
|
261
290
|
}
|
|
262
291
|
async runIngestPipeline() {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
while (this.running) {
|
|
293
|
+
const chainSync = this.config.source !== 'pagination' ? this.client.getChainSyncBackend() : null;
|
|
294
|
+
if (chainSync) {
|
|
295
|
+
// One pass per chain-sync stream. A frame the client's parser cannot turn into an
|
|
296
|
+
// object ends the stream without ending the crawler: pagination fetches that one
|
|
297
|
+
// block over HTTP, and chain-sync takes over again as soon as it is behind the
|
|
298
|
+
// cursor. Any other stream error still halts, as it always did.
|
|
299
|
+
while (this.running) {
|
|
300
|
+
const streamEnd = new Promise((resolve) => { this.streamEnded = resolve; });
|
|
301
|
+
await this.runChainSync(chainSync);
|
|
302
|
+
if (!this.chainSyncHandle)
|
|
303
|
+
return; // open refused, halted, or stop() raced us
|
|
304
|
+
await streamEnd;
|
|
305
|
+
const failure = this.takeFrameFailure();
|
|
306
|
+
if (!this.running || failure?.height == null)
|
|
307
|
+
return;
|
|
308
|
+
logger.warn(`chain-sync cannot deliver block ${failure.height} — switching to pagination until it is behind the cursor`);
|
|
309
|
+
await this.runPagination({ untilHeight: failure.height + 1 });
|
|
310
|
+
}
|
|
311
|
+
return;
|
|
280
312
|
}
|
|
281
|
-
|
|
313
|
+
if (this.config.source === 'ogmios') {
|
|
314
|
+
// 'ogmios' means chain-sync ONLY — never silently degrade to the weaker
|
|
315
|
+
// pagination reorg handling the operator explicitly opted out of.
|
|
316
|
+
logger.error("Crawler source is 'ogmios' but no chain-sync backend is available — crawler not started (use source 'auto' to allow pagination fallback).");
|
|
317
|
+
await this.halt('error', true); // config error: a restart cannot fix it
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (this.config.source === 'pagination') {
|
|
321
|
+
await this.runPagination();
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
// 'auto', and no chain-sync backend is usable right now. After a restart of a box
|
|
325
|
+
// that hosts node and ODATANO together this is the normal case, not the exception:
|
|
326
|
+
// the node validates its chunks and replays the ledger for minutes while ODATANO is
|
|
327
|
+
// up in seconds, so Ogmios refused its init. Crawl on pagination meanwhile, but
|
|
328
|
+
// keep retrying chain-sync — a crawl that makes progress at a fiftieth of the
|
|
329
|
+
// speed looks healthy to every monitor that watches only the cursor.
|
|
330
|
+
logger.warn('No chain-sync backend usable — crawling on pagination and retrying chain-sync periodically');
|
|
331
|
+
await this.runPagination({ untilChainSync: true });
|
|
332
|
+
// Returned because chain-sync came back (or we stopped): the loop reopens it.
|
|
282
333
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Retry the init of a chain-sync backend that was unusable when the crawl began, on
|
|
337
|
+
* its own timer: the pagination loop may be asleep for a whole poll interval (up to
|
|
338
|
+
* an hour) or inside a slow batch, and neither must delay the retry. The probe runs
|
|
339
|
+
* in the background so no pagination round waits for it, and one at a time so a node
|
|
340
|
+
* that is still replaying is not hammered. On success `chainSyncRecovered` is set and
|
|
341
|
+
* a pending poll sleep is cut short; the pagination loop leaves at its next check
|
|
342
|
+
* (between rounds, or between blocks of a batch — the block in flight completes) and
|
|
343
|
+
* the ingest loop reopens chain-sync from the cursor.
|
|
344
|
+
*/
|
|
345
|
+
startChainSyncProbing() {
|
|
346
|
+
this.chainSyncRecovered = false;
|
|
347
|
+
// The startup init has only just failed — give the node a full interval first.
|
|
348
|
+
this.scheduleChainSyncProbe();
|
|
349
|
+
}
|
|
350
|
+
scheduleChainSyncProbe() {
|
|
351
|
+
if (!this.running || this.chainSyncRecovered || this.chainSyncProbeTimer)
|
|
288
352
|
return;
|
|
289
|
-
|
|
290
|
-
|
|
353
|
+
const timer = setTimeout(() => {
|
|
354
|
+
this.chainSyncProbeTimer = null;
|
|
355
|
+
if (!this.running || this.chainSyncRecovered)
|
|
356
|
+
return;
|
|
357
|
+
this.chainSyncProbe = this.client.recoverChainSyncBackend()
|
|
358
|
+
.then((backend) => {
|
|
359
|
+
if (!backend || !this.running)
|
|
360
|
+
return;
|
|
361
|
+
this.chainSyncRecovered = true;
|
|
362
|
+
this.wake?.(); // a poll sleep must not hold the handover back
|
|
363
|
+
})
|
|
364
|
+
.catch((err) => logger.debug('chain-sync probe failed:', err))
|
|
365
|
+
.finally(() => {
|
|
366
|
+
this.chainSyncProbe = null;
|
|
367
|
+
this.scheduleChainSyncProbe();
|
|
368
|
+
});
|
|
369
|
+
}, CardanoCrawler.CHAIN_SYNC_RETRY_MS);
|
|
370
|
+
timer.unref?.(); // never keep the process alive for a probe
|
|
371
|
+
this.chainSyncProbeTimer = timer;
|
|
372
|
+
}
|
|
373
|
+
stopChainSyncProbing() {
|
|
374
|
+
if (!this.chainSyncProbeTimer)
|
|
375
|
+
return;
|
|
376
|
+
clearTimeout(this.chainSyncProbeTimer);
|
|
377
|
+
this.chainSyncProbeTimer = null;
|
|
291
378
|
}
|
|
292
379
|
/** Bound a direct backend call — these bypass the client's timeout/breaker layer. */
|
|
293
380
|
withTimeout(p, label, ms = CardanoCrawler.CALL_TIMEOUT_MS) {
|
|
@@ -366,6 +453,7 @@ class CardanoCrawler {
|
|
|
366
453
|
return;
|
|
367
454
|
}
|
|
368
455
|
this.chainSyncHandle = handle;
|
|
456
|
+
this.activeSource = 'chain-sync';
|
|
369
457
|
logger.info(`Crawler running (chain-sync) from ${points[0].hash} (+${points.length - 1} fallback intersection point(s))`);
|
|
370
458
|
}
|
|
371
459
|
/** Read and clear the pending frame failure, so each stream starts from a clean slate. */
|
|
@@ -475,14 +563,28 @@ class CardanoCrawler {
|
|
|
475
563
|
* looping forever. Used to walk past a block the chain-sync stream cannot deliver and
|
|
476
564
|
* then hand back to it — pagination is roughly seven times slower, so staying on it
|
|
477
565
|
* for the rest of a backfill would be a poor trade.
|
|
566
|
+
* @param untilChainSync when set, keep retrying a chain-sync backend in the background
|
|
567
|
+
* and return once one is usable, so the ingest loop can hand over to it. Used when
|
|
568
|
+
* the crawl started without one (source 'auto', node still coming up).
|
|
478
569
|
*/
|
|
479
|
-
async runPagination(
|
|
570
|
+
async runPagination(opts = {}) {
|
|
571
|
+
if (opts.untilChainSync)
|
|
572
|
+
this.startChainSyncProbing();
|
|
573
|
+
try {
|
|
574
|
+
await this.paginate(opts);
|
|
575
|
+
}
|
|
576
|
+
finally {
|
|
577
|
+
this.stopChainSyncProbing();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async paginate({ untilHeight, untilChainSync = false }) {
|
|
480
581
|
const backend = this.client.getPaginatingBackend();
|
|
481
582
|
if (!backend) {
|
|
482
583
|
logger.error('No paginating backend available — cannot crawl without Ogmios or Blockfrost/Koios');
|
|
483
584
|
await this.halt('error', true); // config error: a restart cannot fix it
|
|
484
585
|
return;
|
|
485
586
|
}
|
|
587
|
+
this.activeSource = 'pagination';
|
|
486
588
|
logger.info('Crawler running (pagination)');
|
|
487
589
|
// Tip cache: during deep catch-up the exact tip is irrelevant (only "am I still
|
|
488
590
|
// behind the target" matters) — refetching it every round wasted one HTTP call
|
|
@@ -491,6 +593,10 @@ class CardanoCrawler {
|
|
|
491
593
|
let target = Number.NEGATIVE_INFINITY;
|
|
492
594
|
while (this.running) {
|
|
493
595
|
try {
|
|
596
|
+
if (untilChainSync && this.chainSyncRecovered) {
|
|
597
|
+
logger.info('chain-sync backend usable again — leaving pagination');
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
494
600
|
const cursor = await cds_1.default.tx((tx) => (0, sync_state_1.readCursor)(tx));
|
|
495
601
|
if (!cursor?.lastBlockHash) {
|
|
496
602
|
logger.error('Pagination refused: cursor has no resume block hash.');
|
|
@@ -522,7 +628,7 @@ class CardanoCrawler {
|
|
|
522
628
|
await this.halt('stopped');
|
|
523
629
|
return;
|
|
524
630
|
}
|
|
525
|
-
await this.
|
|
631
|
+
await this.pollPause(untilChainSync);
|
|
526
632
|
continue;
|
|
527
633
|
}
|
|
528
634
|
const blocks = await this.withTimeout(
|
|
@@ -530,7 +636,7 @@ class CardanoCrawler {
|
|
|
530
636
|
// on a fresh start without configured startHeight)
|
|
531
637
|
backend.getNextBlocks(cursor.lastBlockHash, this.config.batchSize, cursor.lastHeight > 0 ? cursor.lastHeight : undefined), 'getNextBlocks');
|
|
532
638
|
if (!blocks.length) {
|
|
533
|
-
await this.
|
|
639
|
+
await this.pollPause(untilChainSync);
|
|
534
640
|
continue;
|
|
535
641
|
}
|
|
536
642
|
for (const block of blocks) {
|
|
@@ -542,6 +648,10 @@ class CardanoCrawler {
|
|
|
542
648
|
const ok = await this.persistBlock(block, txs, tipPoint);
|
|
543
649
|
if (!ok)
|
|
544
650
|
return; // persistBlock already recorded + halted
|
|
651
|
+
// Chain-sync came back mid-batch: the block just written is complete and on the
|
|
652
|
+
// cursor, the rest of the batch is cheaper to stream than to fetch one by one.
|
|
653
|
+
if (untilChainSync && this.chainSyncRecovered)
|
|
654
|
+
break;
|
|
545
655
|
}
|
|
546
656
|
}
|
|
547
657
|
catch (err) {
|
|
@@ -567,10 +677,21 @@ class CardanoCrawler {
|
|
|
567
677
|
await this.halt('error');
|
|
568
678
|
return;
|
|
569
679
|
}
|
|
570
|
-
await this.
|
|
680
|
+
await this.pollPause(untilChainSync);
|
|
571
681
|
}
|
|
572
682
|
}
|
|
573
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
* Poll pause between pagination rounds. Skipped when a handover to chain-sync is
|
|
686
|
+
* already due: the probe's wake-up only reaches a sleep that has begun, so a probe
|
|
687
|
+
* that succeeded while the round was still fetching (tip, blocks) would otherwise be
|
|
688
|
+
* followed by a full poll interval — up to an hour — before the loop notices.
|
|
689
|
+
*/
|
|
690
|
+
async pollPause(untilChainSync) {
|
|
691
|
+
if (untilChainSync && this.chainSyncRecovered)
|
|
692
|
+
return;
|
|
693
|
+
await this.sleep(this.config.pollIntervalMs);
|
|
694
|
+
}
|
|
574
695
|
/**
|
|
575
696
|
* Pagination reorg recovery: walk back by height comparing the on-chain block hash with
|
|
576
697
|
* our stored one until they agree — that height is the fork point. If the last-indexed
|
|
@@ -42,6 +42,10 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
42
42
|
type CrawlerStatus {
|
|
43
43
|
running : Boolean;
|
|
44
44
|
syncStatus : String;
|
|
45
|
+
// 'chain-sync' | 'pagination' for the crawler in this process; null when this
|
|
46
|
+
// instance is not the one crawling. Pagination is ~50x slower, and a crawl that
|
|
47
|
+
// degraded to it still advances the cursor — this is how an operator tells.
|
|
48
|
+
source : String;
|
|
45
49
|
lastSlot : String;
|
|
46
50
|
lastHeight : String;
|
|
47
51
|
tipHeight : String;
|
|
@@ -29,6 +29,9 @@ module.exports = (srv) => {
|
|
|
29
29
|
return {
|
|
30
30
|
running: (0, sync_state_1.isCrawlerLeaseActive)(cursor),
|
|
31
31
|
syncStatus: cursor?.syncStatus ?? 'stopped',
|
|
32
|
+
// Process-local by nature: the source is what THIS instance ingests from. A
|
|
33
|
+
// standby that does not hold the lease reports null, as does a stopped crawler.
|
|
34
|
+
source: (0, crawler_1.getCrawler)()?.getActiveSource() ?? null,
|
|
32
35
|
lastSlot: String(cursor?.lastSlot ?? 0),
|
|
33
36
|
lastHeight: String(lastHeight),
|
|
34
37
|
tipHeight: String(tipHeight),
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -207,7 +207,8 @@ export interface PoolData {
|
|
|
207
207
|
poolId: string;
|
|
208
208
|
vrfKeyHash: string;
|
|
209
209
|
blocksMinted: number;
|
|
210
|
-
|
|
210
|
+
/** Blocks minted in the current epoch; null when the backend has no such figure (Koios). */
|
|
211
|
+
blocksEpoch: number | null;
|
|
211
212
|
liveStake: string;
|
|
212
213
|
liveSize: number;
|
|
213
214
|
/** Fraction of the ideal (saturated) pool size, NOT percent: 0.7542 = 75.42 %. */
|