@eclesia/indexer-engine 2.10.0-next.2 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/indexer/index.cjs +33 -4
- package/dist/indexer/index.cjs.map +1 -1
- package/dist/indexer/index.d.cts +3 -2
- package/dist/indexer/index.d.cts.map +1 -1
- package/dist/indexer/index.d.ts +3 -2
- package/dist/indexer/index.d.ts.map +1 -1
- package/dist/indexer/index.js +33 -4
- package/dist/indexer/index.js.map +1 -1
- package/dist/metrics/index.cjs +72 -0
- package/dist/metrics/index.cjs.map +1 -1
- package/dist/metrics/index.d.cts +52 -0
- package/dist/metrics/index.d.cts.map +1 -1
- package/dist/metrics/index.d.ts +52 -0
- package/dist/metrics/index.d.ts.map +1 -1
- package/dist/metrics/index.js +72 -0
- package/dist/metrics/index.js.map +1 -1
- package/package.json +1 -1
package/dist/indexer/index.js
CHANGED
|
@@ -108,6 +108,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
108
108
|
]
|
|
109
109
|
});
|
|
110
110
|
const queueErrorHandler = (e) => {
|
|
111
|
+
this.prometheus?.recordError("block_queue");
|
|
111
112
|
this.log.error("Error enqueueing block data: " + e);
|
|
112
113
|
};
|
|
113
114
|
if (this.config.minimal) this.blockQueue = new CircularBuffer(this.config.batchSize, queueErrorHandler);
|
|
@@ -125,9 +126,10 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
125
126
|
}, (err) => {
|
|
126
127
|
if (err) {
|
|
127
128
|
this.log.error(err);
|
|
129
|
+
this.prometheus?.recordError("metrics_server");
|
|
128
130
|
this.emit("fatal-error", {
|
|
129
131
|
error: err,
|
|
130
|
-
message: "Failed to start
|
|
132
|
+
message: "Failed to start metrics server"
|
|
131
133
|
});
|
|
132
134
|
}
|
|
133
135
|
});
|
|
@@ -153,6 +155,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
153
155
|
}, (err) => {
|
|
154
156
|
if (err) {
|
|
155
157
|
this.log.error(err);
|
|
158
|
+
this.prometheus?.recordError("health_check_server");
|
|
156
159
|
this.emit("fatal-error", {
|
|
157
160
|
error: err,
|
|
158
161
|
message: "Failed to start health check server"
|
|
@@ -182,6 +185,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
182
185
|
return true;
|
|
183
186
|
} catch (error) {
|
|
184
187
|
this.log.error(error);
|
|
188
|
+
this.prometheus?.recordError("connect_rpc_error");
|
|
185
189
|
this.tryToRecover = true;
|
|
186
190
|
return false;
|
|
187
191
|
}
|
|
@@ -196,6 +200,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
196
200
|
if (this.config.init) await this.config.init();
|
|
197
201
|
} catch (e) {
|
|
198
202
|
this.log.error("Failed to initialize indexer: " + e);
|
|
203
|
+
this.prometheus?.recordError("init_error");
|
|
199
204
|
this.setStatus("FAILED");
|
|
200
205
|
throw e;
|
|
201
206
|
}
|
|
@@ -203,6 +208,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
203
208
|
if (this.config.genesisPath) await this.parseGenesis();
|
|
204
209
|
} catch (e) {
|
|
205
210
|
this.log.error("Failed to parse genesis: " + e);
|
|
211
|
+
this.prometheus?.recordError("genesis_error");
|
|
206
212
|
this.setStatus("FAILED");
|
|
207
213
|
throw e;
|
|
208
214
|
}
|
|
@@ -221,20 +227,26 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
221
227
|
this.heightToProcess = await this.config.getNextHeight();
|
|
222
228
|
if (this.config.usePolling) this.pollForBlock();
|
|
223
229
|
else if (this.subscription) this.subscription.addListener(this.blockListener);
|
|
224
|
-
else
|
|
230
|
+
else {
|
|
231
|
+
this.prometheus?.recordError("subscription_error");
|
|
232
|
+
throw new Error("Could not subscribe to new blocks");
|
|
233
|
+
}
|
|
225
234
|
} catch (e) {
|
|
226
235
|
this.log.error("Failed to set up block listening: " + e);
|
|
236
|
+
this.prometheus?.recordError("block_listening_error");
|
|
227
237
|
this.setStatus("FAILED");
|
|
228
238
|
throw e;
|
|
229
239
|
}
|
|
230
240
|
this.tryToRecover = false;
|
|
231
241
|
this.fetcher().catch((e) => {
|
|
232
242
|
this.setStatus("FAILED");
|
|
243
|
+
this.prometheus?.recordError("fetching_error");
|
|
233
244
|
throw new Error("Error in fetching service: " + e);
|
|
234
245
|
});
|
|
235
246
|
const hrTime = process.hrtime();
|
|
236
247
|
let ms = hrTime[0] * 1e6 + hrTime[1] / 1e3;
|
|
237
248
|
while (this.blockQueue.size() > 0 && !this.tryToRecover) {
|
|
249
|
+
if (this.config.enablePrometheus) this.prometheus.updateRetryCount(this.retryCount);
|
|
238
250
|
try {
|
|
239
251
|
if (this.tryToRecover) throw new Error("Exiting processing loop. Attempting to recover indexer");
|
|
240
252
|
await this.config.beginTransaction();
|
|
@@ -246,7 +258,10 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
246
258
|
});
|
|
247
259
|
const toProcess = await Promise.race([this.blockQueue.dequeue(), timeoutPromise]);
|
|
248
260
|
this.log.silly("Retrieved block data");
|
|
249
|
-
if (!toProcess || !toProcess[0] || !toProcess[1])
|
|
261
|
+
if (!toProcess || !toProcess[0] || !toProcess[1]) {
|
|
262
|
+
this.prometheus?.recordError("rpc_error");
|
|
263
|
+
throw new Error("Could not fetch block");
|
|
264
|
+
}
|
|
250
265
|
height = toProcess[0].block.header.height;
|
|
251
266
|
timestamp = toRfc3339WithNanoseconds(toProcess[0].block.header.time);
|
|
252
267
|
await this.processBlock(toProcess[0], toProcess[1]);
|
|
@@ -256,7 +271,10 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
256
271
|
});
|
|
257
272
|
const toProcess = await Promise.race([this.blockQueue.dequeue(), timeoutPromise]);
|
|
258
273
|
this.log.silly("Retrieved block data");
|
|
259
|
-
if (!toProcess || !toProcess[0] || !toProcess[1] || !toProcess[2])
|
|
274
|
+
if (!toProcess || !toProcess[0] || !toProcess[1] || !toProcess[2]) {
|
|
275
|
+
this.prometheus?.recordError("rpc_error");
|
|
276
|
+
throw new Error("Could not fetch block");
|
|
277
|
+
}
|
|
260
278
|
this.log.silly("Decoded block");
|
|
261
279
|
height = toProcess[0].block.header.height;
|
|
262
280
|
timestamp = toRfc3339WithNanoseconds(toProcess[0].block.header.time);
|
|
@@ -289,11 +307,13 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
289
307
|
await this.config.endTransaction(true);
|
|
290
308
|
this.log.silly("Committed db tx");
|
|
291
309
|
} catch (e) {
|
|
310
|
+
this.prometheus?.recordError("block_processing_error");
|
|
292
311
|
this.log.error("" + e);
|
|
293
312
|
this.setStatus("FAILED");
|
|
294
313
|
try {
|
|
295
314
|
await this.config.endTransaction(false);
|
|
296
315
|
} catch (dbe) {
|
|
316
|
+
this.prometheus?.recordError("database");
|
|
297
317
|
this.log.error("Error ending transaction. Must be a DB error: " + dbe);
|
|
298
318
|
}
|
|
299
319
|
this.tryToRecover = true;
|
|
@@ -319,6 +339,8 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
319
339
|
async processBlock(block, block_results, validators) {
|
|
320
340
|
let processStart = [0, 0];
|
|
321
341
|
if (this.config.logLevel == "silly") processStart = process.hrtime();
|
|
342
|
+
let endTimer;
|
|
343
|
+
if (this.config.enablePrometheus) endTimer = this.prometheus.timeBlockProcessing();
|
|
322
344
|
const height = block.block.header.height;
|
|
323
345
|
this.log.debug("Processing block: %d", height);
|
|
324
346
|
const timestamp = toRfc3339WithNanoseconds(block.block.header.time);
|
|
@@ -424,6 +446,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
424
446
|
}
|
|
425
447
|
}
|
|
426
448
|
this.log.silly("Modules handled msg events");
|
|
449
|
+
if (this.config.enablePrometheus) this.prometheus.recordTransactions(block.block.txs.length);
|
|
427
450
|
await this.asyncEmit("end_block", {
|
|
428
451
|
value: endBlockEvents,
|
|
429
452
|
height,
|
|
@@ -435,6 +458,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
435
458
|
const processTime = processEnd[0] * 1e3 + processEnd[1] / 1e6;
|
|
436
459
|
this.log.silly("Processed block %d in %d ms", height, processTime.toFixed(2));
|
|
437
460
|
}
|
|
461
|
+
if (this.config.enablePrometheus) endTimer();
|
|
438
462
|
if (this.config.enablePrometheus) this.prometheus.updateBlockMetrics(height, this.latestHeight, this.blockQueue.size());
|
|
439
463
|
}
|
|
440
464
|
async fetcher() {
|
|
@@ -489,15 +513,18 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
489
513
|
}
|
|
490
514
|
async callABCI(path, data, height, adHoc = true) {
|
|
491
515
|
try {
|
|
516
|
+
const endTimer = this.prometheus?.timeRpcCall(path) ?? void 0;
|
|
492
517
|
const abciq = await (adHoc ? this.client : this.blockClient).abciQuery({
|
|
493
518
|
path,
|
|
494
519
|
data,
|
|
495
520
|
height
|
|
496
521
|
});
|
|
522
|
+
endTimer?.();
|
|
497
523
|
if (abciq) return abciq.value;
|
|
498
524
|
else {
|
|
499
525
|
this.tryToRecover = true;
|
|
500
526
|
this.setStatus("FAILED");
|
|
527
|
+
this.prometheus?.recordError("abci_query_error");
|
|
501
528
|
throw new Error("RPC not responding. Query at: " + path);
|
|
502
529
|
}
|
|
503
530
|
} catch (_e) {
|
|
@@ -513,6 +540,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
513
540
|
if (this.blockQueue.synced && !this.tryToRecover) {
|
|
514
541
|
this.latestHeight = height;
|
|
515
542
|
if (this.blockQueue.size() + 1 == this.config.batchSize) {
|
|
543
|
+
this.prometheus?.recordError("block_queue_full");
|
|
516
544
|
this.log.error("Block queue is full. Cannot add new block");
|
|
517
545
|
this.tryToRecover = true;
|
|
518
546
|
this.retryCount++;
|
|
@@ -647,6 +675,7 @@ var EcleciaIndexer = class extends EclesiaEmitter {
|
|
|
647
675
|
try {
|
|
648
676
|
await this.config.endTransaction(false);
|
|
649
677
|
} catch (dbe) {
|
|
678
|
+
this.prometheus?.recordError("database_error");
|
|
650
679
|
this.log.error("Error ending transaction. Must be a DB error: " + dbe);
|
|
651
680
|
}
|
|
652
681
|
this.log.error("Failed to import genesis");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["uuidv4","timeoutPromise: ReturnType<typeof this.blockQueue.dequeue>","hrTime","processStart: [number, number]","beginBlockEvents: readonly Event[] | readonly Event38[]","endBlockEvents: readonly Event[] | readonly Event38[]","events: Array<{\n msg_index?: number\n events: (Event | Event38)[]\n }>","eventsToAdd: typeof events","events","timeoutPromise: Promise<[BlockResponse, BlockResultsResponse]>","timeoutPromise: Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>"],"sources":["../../src/indexer/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\n/* eslint-disable max-lines */\nimport {\n createHash,\n} from \"node:crypto\";\nimport * as fs from \"node:fs\";\n\nimport {\n BlockResponse, BlockResultsResponse, CometClient, connectComet, Event, toRfc3339WithNanoseconds,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n BlockResultsResponse as BlockResultsResponse38, Event as Event38,\n} from \"@cosmjs/tendermint-rpc/build/comet38/responses.js\";\nimport {\n MsgExec,\n} from \"cosmjs-types/cosmos/authz/v1beta1/tx.js\";\nimport {\n QueryValidatorsRequest,\n QueryValidatorsResponse,\n} from \"cosmjs-types/cosmos/staking/v1beta1/query.js\";\nimport {\n Validator,\n} from \"cosmjs-types/cosmos/staking/v1beta1/staking.js\";\nimport {\n Tx,\n} from \"cosmjs-types/cosmos/tx/v1beta1/tx.js\";\nimport Fastify, {\n FastifyInstance,\n} from \"fastify\";\nimport {\n chain,\n} from \"stream-chain\";\nimport Parser from \"stream-json\";\nimport Pick from \"stream-json/filters/Pick.js\";\nimport StreamArray from \"stream-json/streamers/StreamArray.js\";\nimport StreamValues from \"stream-json/streamers/StreamValues.js\";\nimport Batch from \"stream-json/utils/Batch.js\";\nimport {\n v4 as uuidv4,\n} from \"uuid\";\nimport * as winston from \"winston\";\n\nimport {\n DEFAULT_BATCH_SIZE, DEFAULT_HEALTH_CHECK_PORT, DEFAULT_POLLING_INTERVAL_MS, DEFAULT_START_HEIGHT,\n GENESIS_BATCH_SIZE, PAGINATION_LIMITS, PERIODIC_INTERVALS, QUEUE_DEQUEUE_TIMEOUT_MS, RPC_TIMEOUT_MS,\n} from \"../constants.js\";\nimport {\n EclesiaEmitter,\n} from \"../emitter/index.js\";\nimport {\n IndexerMetrics,\n} from \"../metrics/index.js\";\nimport {\n CircularBuffer,\n} from \"../promise-queue/index.js\";\nimport {\n BlockQueue, EcleciaIndexerConfig, EmitFunc, MinimalBlockQueue,\n UUIDEvent, WithHeightAndUUID,\n} from \"../types/index.js\";\nimport {\n decodeAttr,\n} from \"../utils/index.js\";\nimport {\n validateFilePath, validatePort, validatePositiveInteger, validateUrl,\n} from \"../validation/index.js\";\n\n/** Default configuration for the Eclesia indexer */\nexport const defaultIndexerConfig = {\n startHeight: DEFAULT_START_HEIGHT, // Start indexing from block 1\n batchSize: DEFAULT_BATCH_SIZE, // Process blocks in batches of 500\n modules: [], // No modules enabled by default\n getNextHeight: () => DEFAULT_START_HEIGHT, // Default height retrieval function\n logLevel: \"info\" as EcleciaIndexerConfig[\"logLevel\"], // Default log level\n usePolling: false, // Use WebSocket subscription by default\n pollingInterval: DEFAULT_POLLING_INTERVAL_MS, // Poll every 5 seconds when polling enabled\n shouldProcessGenesis: () => false, // Skip genesis processing by default\n minimal: true, // Use minimal indexing by default\n healthCheckPort: DEFAULT_HEALTH_CHECK_PORT, // Default health check port\n enablePrometheus: false, // Disable Prometheus metrics server by default\n prometheusPort: 9090, // Default Prometheus metrics server port\n init: () => Promise.resolve(), // No-op initialization function\n beginTransaction: () => Promise.resolve(), // No-op transaction begin function\n endTransaction: (_status: boolean) => Promise.resolve(), // No-op transaction end function\n};\n\n/**\n * Core blockchain indexer that connects to Tendermint RPC and processes blocks\n * Extends EclesiaEmitter to provide event-driven architecture for modules\n */\nexport class EcleciaIndexer extends EclesiaEmitter {\n /** Indexer configuration settings */\n private config: EcleciaIndexerConfig;\n\n /** Fastify HTTP server for health checks */\n private fastify: FastifyInstance;\n\n /** Prometheus HTTP server instance */\n private prometheusServer: FastifyInstance | null = null;\n\n /** Queue for managing block processing pipeline */\n private blockQueue: BlockQueue;\n\n /** Latest block height from the chain */\n private latestHeight!: number;\n\n /** Next block height to process */\n private heightToProcess!: number;\n\n /** Whether the indexer has been initialized */\n private initialized = false;\n\n /** Prometheus metrics server instance */\n private prometheus: IndexerMetrics | null = null;\n\n /** Number of retry attempts for error recovery */\n private retryCount = 0;\n\n /** CometBFT client for ad-hoc queries */\n public client!: CometClient;\n\n /** CometBFT client for block and validator queries */\n public blockClient!: CometClient;\n\n /** Winston logger instance */\n public log: winston.Logger;\n\n /** Flag indicating if indexer should attempt recovery */\n private tryToRecover: boolean = false;\n\n /** Health check status for monitoring */\n private healthCheck = {\n status: \"CONNECTING\",\n };\n\n /** WebSocket subscription for new block notifications */\n private subscription: ReturnType<CometClient[\"subscribeNewBlock\"]> | null = null;\n\n /**\n * Creates a new Eclesia indexer instance\n * @param config - Indexer configuration options\n */\n constructor(config: EcleciaIndexerConfig) {\n super();\n\n // Validate required configuration\n validateUrl(config.rpcUrl, \"rpcUrl\");\n validatePositiveInteger(config.batchSize, \"batchSize\");\n\n // Validate optional genesis path if processing genesis\n if (config.genesisPath) {\n validateFilePath(config.genesisPath, \"genesisPath\");\n }\n\n // Validate health check port if provided\n if (config.healthCheckPort !== undefined) {\n validatePort(config.healthCheckPort, \"healthCheckPort\");\n }\n\n // Validate start height if provided\n if (config.startHeight !== undefined) {\n validatePositiveInteger(config.startHeight, \"startHeight\");\n }\n\n // Validate polling interval if provided\n if (config.pollingInterval !== undefined) {\n validatePositiveInteger(config.pollingInterval, \"pollingInterval\");\n }\n\n this.config = {\n ...defaultIndexerConfig,\n ...config,\n };\n\n // Initialize logger first so it can be used by queue error handler\n const {\n printf,\n } = winston.format;\n\n const eclesiaFormat = printf(({\n level, message, timestamp,\n }) => {\n return `${timestamp} [${level.toUpperCase()}]:\\t${message}`;\n });\n this.log = winston.createLogger({\n level: this.config.logLevel,\n defaultMeta: {\n service: \"Eclesia Indexer\",\n },\n transports: [\n new winston.transports.File({\n filename: \"error.log\",\n level: \"error\",\n }),\n new winston.transports.File({\n filename: \"combined.log\",\n }),\n new winston.transports.Console({\n format: winston.format.combine(winston.format.splat(),\n winston.format.timestamp(),\n eclesiaFormat,\n winston.format.colorize({\n all: true,\n })),\n }),\n ],\n });\n\n // Initialize block queue based on minimal or full indexing mode\n // Pass error handler that uses the logger\n const queueErrorHandler = (e: unknown) => {\n this.log.error(\"Error enqueueing block data: \" + e);\n };\n\n if (this.config.minimal) {\n // Minimal mode: only store block and block results\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse]>(this.config.batchSize, queueErrorHandler);\n }\n else {\n // Full mode: also store validator information\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>(this.config.batchSize, queueErrorHandler);\n }\n if (this.config.enablePrometheus) {\n this.prometheus = new IndexerMetrics();\n this.prometheusServer = Fastify({\n logger: false,\n });\n this.prometheusServer.get(\"/metrics\",\n async (_req, res) => {\n res.header(\"Content-Type\", this.prometheus!.registry.contentType);\n res.send(await this.prometheus!.getMetrics());\n },\n );\n this.prometheusServer.listen({\n port: this.config.prometheusPort,\n host: \"0.0.0.0\",\n },\n (err) => {\n if (err) {\n this.log.error(err);\n this.emit(\"fatal-error\", {\n error: err,\n message: \"Failed to start health check server\",\n });\n }\n });\n }\n this.fastify = Fastify({\n logger: false,\n });\n this.on(\"_unhandled\",\n (msg) => {\n if (msg.uuid) {\n this.log.verbose(\"Unhandled event: \" + msg.type);\n this.emit(\"uuid\",\n {\n status: true,\n uuid: msg.uuid,\n });\n }\n });\n this.fastify.get(\"/health\",\n async (_request, reply) => {\n const code = this.healthCheck.status == \"OK\"\n ? 200\n : 503;\n reply.code(code).send(this.healthCheck);\n });\n const healthPort = this.config.healthCheckPort\n ?? (process.env.HEALTH_CHECK_PORT ? parseInt(process.env.HEALTH_CHECK_PORT, 10) : 8080);\n this.fastify.listen({\n port: healthPort,\n host: \"0.0.0.0\",\n },\n (err) => {\n if (err) {\n this.log.error(err);\n this.emit(\"fatal-error\", {\n error: err,\n message: \"Failed to start health check server\",\n });\n }\n });\n }\n\n private setStatus(status: string) {\n this.healthCheck.status = status;\n }\n\n private blockListener = {\n next: (data: {\n header: {\n height: number\n }\n }) => {\n this.newBlockReceived(data.header.height);\n },\n };\n\n private isMinimal(_blockqueue: BlockQueue): _blockqueue is MinimalBlockQueue {\n if (this.config.minimal) {\n return true;\n }\n else {\n return false;\n }\n }\n\n public async connect() {\n try {\n if (this.client && this.tryToRecover) {\n this.log.verbose(\"Recover from error. Attempting to disconnect from RPC\");\n this.client.disconnect();\n this.blockClient.disconnect();\n this.log.verbose(\"Disconnected from RPC\");\n }\n this.client = await connectComet(this.config.rpcUrl);\n this.log.info(\"Connected to RPC for ad hoc queries\");\n\n this.blockClient = await connectComet(this.config.rpcUrl);\n this.log.info(\"Connected to RPC for block & validator info\");\n\n return true;\n }\n catch (error) {\n this.log.error(error);\n this.tryToRecover = true;\n return false;\n }\n }\n\n public async start() {\n if (this.blockQueue) {\n this.blockQueue.clear();\n this.log.verbose(\"Starting, clearing block queue\");\n }\n if (!this.initialized) {\n try {\n if (this.config.init) {\n await this.config.init();\n }\n }\n catch (e) {\n this.log.error(\"Failed to initialize indexer: \" + e);\n this.setStatus(\"FAILED\");\n throw e;\n }\n if (await this.config.shouldProcessGenesis()) {\n try {\n if (this.config.genesisPath) {\n await this.parseGenesis();\n }\n }\n catch (e) {\n this.log.error(\"Failed to parse genesis: \" + e);\n this.setStatus(\"FAILED\");\n throw e;\n }\n }\n this.initialized = true;\n }\n try {\n await this.connect();\n if (!this.config.usePolling && this.subscription) {\n this.subscription.removeListener(this.blockListener);\n this.subscription = null;\n this.log.verbose(\"Removed existing block listener and subscription\");\n }\n if (!this.config.usePolling) {\n this.subscription = this.client.subscribeNewBlock\n ? this.client.subscribeNewBlock()\n : null;\n }\n const status = await this.client.status();\n this.latestHeight = status.syncInfo.latestBlockHeight;\n this.log.info(\"Current chain height: \" + this.latestHeight);\n\n this.heightToProcess = await this.config.getNextHeight();\n if (this.config.usePolling) {\n this.pollForBlock();\n }\n else {\n if (this.subscription) {\n this.subscription.addListener(this.blockListener);\n }\n else {\n throw new Error(\"Could not subscribe to new blocks\");\n }\n }\n }\n catch (e) {\n this.log.error(\"Failed to set up block listening: \" + e);\n this.setStatus(\"FAILED\");\n throw e;\n }\n\n this.tryToRecover = false;\n this.fetcher().catch((e) => {\n this.setStatus(\"FAILED\");\n throw new Error(\"Error in fetching service: \" + e);\n });\n\n const hrTime = process.hrtime();\n let ms = hrTime[0] * 1000000 + hrTime[1] / 1000;\n while (this.blockQueue.size() > 0 && !this.tryToRecover) {\n // await the dequeued promise is essentially awaiting fetched data for that block\n try {\n if (this.tryToRecover) {\n throw new Error(\"Exiting processing loop. Attempting to recover indexer\");\n }\n // Index block inside a db transaction to ensure data consistency\n await this.config.beginTransaction();\n this.log.silly(\"Started db tx\");\n let height, timestamp;\n if (this.isMinimal(this.blockQueue)) {\n const timeoutPromise: ReturnType<typeof this.blockQueue.dequeue> = new Promise((resolve, reject) => {\n setTimeout(reject, QUEUE_DEQUEUE_TIMEOUT_MS, []);\n });\n const toProcess = await Promise.race([this.blockQueue.dequeue(), timeoutPromise]);\n this.log.silly(\"Retrieved block data\");\n if (!toProcess || !toProcess[0] || !toProcess[1]) {\n throw new Error(\"Could not fetch block\");\n }\n height = toProcess[0].block.header.height;\n timestamp = toRfc3339WithNanoseconds(toProcess[0].block.header.time);\n await this.processBlock(toProcess[0],\n toProcess[1]);\n }\n else {\n const timeoutPromise: ReturnType<typeof this.blockQueue.dequeue> = new Promise((resolve, reject) => {\n setTimeout(reject, QUEUE_DEQUEUE_TIMEOUT_MS, []);\n });\n const toProcess = await Promise.race([this.blockQueue.dequeue(), timeoutPromise]);\n this.log.silly(\"Retrieved block data\");\n if (!toProcess || !toProcess[0] || !toProcess[1] || !toProcess[2]) {\n throw new Error(\"Could not fetch block\");\n }\n\n this.log.silly(\"Decoded block\");\n height = toProcess[0].block.header.height;\n timestamp = toRfc3339WithNanoseconds(toProcess[0].block.header.time);\n await this.processBlock(toProcess[0],\n toProcess[1],\n QueryValidatorsResponse.decode(toProcess[2]).validators);\n }\n // Emit events to trigger periodic operations every 50, 100 and 1000 blocks\n if (height % PERIODIC_INTERVALS.LARGE == 0) {\n const hrTime = process.hrtime();\n const newms = hrTime[0] * 1000000 + hrTime[1] / 1000;\n const duration = newms - ms;\n ms = newms;\n const rate = 1000000000 / duration;\n this.log.info(\"Processing:\" + rate.toFixed(2) + \"blocks/sec\");\n await this.asyncEmit(\"periodic/1000\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n if (height % PERIODIC_INTERVALS.MEDIUM == 0) {\n await this.asyncEmit(\"periodic/100\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n if (height % PERIODIC_INTERVALS.SMALL == 0) {\n await this.asyncEmit(\"periodic/50\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n this.log.silly(\"Handled periodic events\");\n\n await this.config.endTransaction(true);\n\n this.log.silly(\"Committed db tx\");\n }\n catch (e) {\n this.log.error(\"\" + e);\n this.setStatus(\"FAILED\");\n try {\n await this.config.endTransaction(false);\n }\n catch (dbe) {\n this.log.error(\"Error ending transaction. Must be a DB error: \" + dbe);\n }\n this.tryToRecover = true;\n this.retryCount++;\n break;\n }\n this.retryCount = 0;\n this.setStatus(\"OK\");\n }\n if (this.retryCount < 3) {\n this.log.debug(\"Indexer retryCount: \" + this.retryCount);\n this.log.info(\"Indexer is restarting\");\n setTimeout(() => this.start(),\n this.retryCount * 5000);\n }\n else {\n this.log.info(\"Indexer failed too many times. Exiting.\");\n this.emit(\"fatal-error\", {\n error: new Error(\"Max retry attempts exceeded\"),\n message: \"Indexer failed too many times\",\n retryCount: this.retryCount,\n });\n }\n }\n\n public asyncEmit: EmitFunc<keyof WithHeightAndUUID<EventMap>> = async (\n type,\n event,\n ) => {\n event.uuid = uuidv4();\n\n /*\n * More than 1 listener can be registered for an event type\n * Fortunately these are all set up during module init() so we have a consistent count\n * so we can count responses to resolve when complete\n * values are irrelevant as promise resolution is only used for flow control\n */\n let listenerCount = this.handled.get(type);\n if (!listenerCount) {\n // Setting listenerCount to 1 (the unhandled listener)\n listenerCount = 1;\n }\n let listenersResponded = 0;\n const prom = new Promise<void>((resolve, reject) => {\n const returnFunc = (ev: UUIDEvent) => {\n if (ev.uuid == event.uuid) {\n if (ev.status) {\n listenersResponded++;\n if (listenersResponded == listenerCount) {\n // All listeners have done their thing so we can remove listener, resolve and continue execution\n this.off(\"uuid\",\n returnFunc);\n resolve();\n }\n }\n else {\n // At least 1 listener is reporting an error. Reject and handle exception at the original asyncEmit location\n reject(ev.error);\n }\n }\n };\n this.on(\"uuid\",\n returnFunc);\n });\n this.emit(type,\n event);\n\n return prom;\n };\n\n private async processBlock(block: BlockResponse, block_results: BlockResultsResponse | BlockResultsResponse38, validators?: Validator[]) {\n let processStart: [number, number] = [0, 0];\n if (this.config.logLevel == \"silly\") {\n processStart = process.hrtime();\n }\n const height = block.block.header.height;\n this.log.debug(\"Processing block: %d\",\n height);\n\n // Initialize height & timestamp to be used for this block-processing run\n const timestamp = toRfc3339WithNanoseconds(block.block.header.time);\n\n // Use & await asyncEmit to ensure db insertions in order\n\n /*\n * Emit block information to any interested modules.\n * Primarily the required block module listens to this\n */\n await this.asyncEmit(\"block\",\n {\n value: {\n block,\n block_results,\n },\n height,\n timestamp,\n });\n this.log.silly(\"Modules handled block event\");\n\n let beginBlockEvents: readonly Event[] | readonly Event38[];\n let endBlockEvents: readonly Event[] | readonly Event38[];\n if ((block_results as BlockResultsResponse38).finalizeBlockEvents) {\n beginBlockEvents = (block_results as BlockResultsResponse38).finalizeBlockEvents.filter(x => x.attributes.find(a => decodeAttr(a.key) == \"mode\" && decodeAttr(a.value) == \"begin_block\")) as readonly Event38[];\n endBlockEvents = (block_results as BlockResultsResponse38).finalizeBlockEvents.filter(x => x.attributes.find(a => decodeAttr(a.key) == \"mode\" && decodeAttr(a.value) == \"end_block\")) as readonly Event38[];\n }\n else {\n beginBlockEvents = (block_results as BlockResultsResponse).beginBlockEvents;\n endBlockEvents = (block_results as BlockResultsResponse).endBlockEvents;\n }\n // Deal with begin_block events first\n await this.asyncEmit(\"begin_block\",\n {\n value: {\n events: beginBlockEvents!,\n validators,\n },\n height,\n timestamp,\n });\n\n this.log.silly(\"Modules handled begin_block events\");\n\n // Then individual tx_events\n await this.asyncEmit(\"tx_events\",\n {\n value: block_results.results,\n height,\n timestamp,\n });\n this.log.silly(\"Modules handled tx events\");\n\n // Emit details and result for each tx msg separately\n for (let t = 0; t < block.block.txs.length; t++) {\n const tx = Tx.decode(block.block.txs[t]);\n\n const result = block_results.results[t].code;\n const txlog = block_results.results[t].log;\n\n if (result != 0) {\n // Tx failed. Ignore\n continue;\n }\n if (tx.body && tx.body.memo != \"\") {\n const txHash = createHash(\"sha256\").update(block.block.txs[t])\n .digest(\"hex\");\n await this.asyncEmit(\"tx_memo\",\n {\n value: {\n txHash,\n txBody: tx.body,\n },\n height,\n timestamp,\n });\n }\n // parsing log rather than using events directly in order to have msg_index available to filter appropriate events for each msg\n let events: Array<{\n msg_index?: number\n events: (Event | Event38)[]\n }> = txlog\n ? JSON.parse(txlog)\n : [];\n if (events.length == 0) {\n const eventsToAdd: typeof events = [];\n this.log.silly(\"No events found in tx log. Parsing events for msg_index\");\n for (let m = 0; m < block_results.results[t].events.length; m++) {\n if (block_results.results[t].events[m].attributes.find(a => decodeAttr(a.key) == \"msg_index\")) {\n const mi = decodeAttr(block_results.results[t].events[m].attributes.find(a => decodeAttr(a.key) == \"msg_index\")?.value ?? \"\");\n if (mi != \"\") {\n const miNum = parseInt(mi);\n let ev = eventsToAdd.find(x => x.msg_index == miNum);\n if (!ev) {\n ev = {\n msg_index: miNum,\n events: [block_results.results[t].events[m]],\n };\n eventsToAdd.push(ev);\n }\n else {\n ev.events.push(block_results.results[t].events[m] as Event);\n }\n }\n }\n }\n events = events.concat(eventsToAdd);\n }\n const msgs = tx.body?.messages;\n\n if (msgs) {\n for (let i = 0; i < msgs.length; i++) {\n this.log.silly(\"Indexer broadcasting msg for handling: \" + msgs[i].typeUrl);\n const msgevents\n = msgs.length > 1\n ? events.find(x => x.msg_index == i)?.events\n : events[0].events;\n await this.asyncEmit(msgs[i].typeUrl as never,\n {\n value: {\n tx: msgs[i].value as never,\n events: msgevents,\n } as never,\n height,\n timestamp,\n });\n if (msgs[i].typeUrl == \"/cosmos.authz.v1beta1.MsgExec\") {\n const authzMsgs = MsgExec.decode(msgs[i].value).msgs;\n if (authzMsgs) {\n for (let r = 0; r < authzMsgs.length; r++) {\n this.log.silly(\"Indexer broadcasting msg for handling: \" + authzMsgs[r].typeUrl);\n const authzMsgEvents = msgevents?.reduce((events, evt) => {\n if (evt.attributes.filter(x => decodeAttr(x.key) == \"authz_msg_index\" && decodeAttr(x.value) == \"\" + r).length > 0) {\n events.push(evt);\n }\n return events;\n },\n [] as (Event | Event38)[]);\n await this.asyncEmit(authzMsgs[r].typeUrl as never,\n {\n value: {\n tx: authzMsgs[r].value as never,\n events: authzMsgEvents,\n } as never,\n height,\n timestamp,\n });\n }\n }\n }\n }\n }\n }\n this.log.silly(\"Modules handled msg events\");\n\n // Then deal with end_block events\n await this.asyncEmit(\"end_block\",\n {\n value: endBlockEvents!,\n height,\n timestamp,\n });\n this.log.silly(\"Modules handled end_block events\");\n if (this.config.logLevel == \"silly\") {\n const processEnd = process.hrtime(processStart);\n const processTime = processEnd[0] * 1000 + processEnd[1] / 1000000;\n this.log.silly(\"Processed block %d in %d ms\",\n height,\n processTime.toFixed(2));\n }\n if (this.config.enablePrometheus) {\n this.prometheus!.updateBlockMetrics(height, this.latestHeight, this.blockQueue.size());\n }\n }\n\n private async fetcher() {\n for (let i = this.heightToProcess; i <= this.latestHeight; i++) {\n this.log.debug(\"Fetching: \" + i);\n if (this.tryToRecover) {\n this.log.verbose(\"Exiting fetcher loop. Attempting to recover indexer\");\n break;\n }\n try {\n if (this.isMinimal(this.blockQueue)) {\n const timeoutPromise: Promise<[BlockResponse, BlockResultsResponse]> = new Promise((resolve, reject) => {\n setTimeout(reject,\n RPC_TIMEOUT_MS,\n false);\n });\n const toIndex = Promise.race([Promise.all([this.blockClient.block(i) as Promise<BlockResponse>, this.blockClient.blockResults(i) as Promise<BlockResultsResponse>]), timeoutPromise]).catch((e) => {\n this.log.error(\"Error fetching block: \" + i + \" : \" + e);\n this.tryToRecover = true;\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse]>;\n this.blockQueue.enqueue(toIndex);\n }\n else {\n const timeoutPromise: Promise<[BlockResponse, BlockResultsResponse, Uint8Array]> = new Promise((resolve, reject) => {\n setTimeout(reject,\n RPC_TIMEOUT_MS,\n false);\n });\n const q = QueryValidatorsRequest.fromPartial({\n pagination: {\n limit: PAGINATION_LIMITS.VALIDATORS,\n },\n });\n const vals = QueryValidatorsRequest.encode(q).finish();\n const toIndex = Promise.race([\n Promise.all([\n this.blockClient.block(i) as Promise<BlockResponse>,\n this.blockClient.blockResults(i) as Promise<BlockResultsResponse>,\n this.callABCI(\"/cosmos.staking.v1beta1.Query/Validators\",\n vals,\n i,\n false),\n ]),\n timeoutPromise,\n ]).catch((e) => {\n this.log.error(\"Error fetching block: \" + i + \" : \" + e);\n this.tryToRecover = true;\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>;\n this.blockQueue.enqueue(toIndex);\n }\n await this.blockQueue.continue();\n if (this.tryToRecover) {\n this.retryCount++;\n throw new Error(\"RPC not responding\");\n }\n }\n catch (e) {\n this.log.error(e);\n break;\n }\n }\n if (!this.tryToRecover) {\n this.blockQueue.setSynced();\n this.log.info(\"Synced to latest height\");\n }\n }\n\n public async callABCI(path: string, data: Uint8Array, height?: number, adHoc: boolean = true): Promise<Uint8Array> {\n try {\n const abciq = await\n (adHoc\n ? this.client\n : this.blockClient).abciQuery({\n path,\n data,\n height: height,\n });\n if (abciq) {\n return abciq.value;\n }\n else {\n this.tryToRecover = true;\n this.setStatus(\"FAILED\");\n throw new Error(\"RPC not responding. Query at: \" + path);\n }\n }\n catch (_e) {\n this.tryToRecover = true;\n this.setStatus(\"FAILED\");\n this.retryCount++;\n throw new Error(\"RPC not responding. Query at: \" + path);\n }\n }\n\n private newBlockReceived(height: number): void {\n this.log.info(\"Received new block: %d\",\n height);\n if (height == this.latestHeight) {\n return;\n }\n // If we are synced, add to end of queue\n if (this.blockQueue.synced && !this.tryToRecover) {\n this.latestHeight = height;\n if (this.blockQueue.size() + 1 == this.config.batchSize) {\n this.log.error(\"Block queue is full. Cannot add new block\");\n this.tryToRecover = true;\n this.retryCount++;\n return;\n }\n try {\n if (this.isMinimal(this.blockQueue)) {\n this.blockQueue.enqueue(Promise.all([this.client.block(height) as Promise<BlockResponse>, this.client.blockResults(height) as Promise<BlockResultsResponse>]).catch((e) => {\n this.log.error(\"Error fetching block: \" + height + \" : \" + e);\n\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse]>);\n }\n else {\n const q = QueryValidatorsRequest.fromPartial({\n pagination: {\n limit: 1000n,\n },\n });\n const vals = QueryValidatorsRequest.encode(q).finish();\n this.blockQueue.enqueue(Promise.all([\n this.client.block(height) as Promise<BlockResponse>,\n this.client.blockResults(height) as Promise<BlockResultsResponse>,\n this.callABCI(\"/cosmos.staking.v1beta1.Query/Validators\",\n vals,\n height,\n false),\n ]).catch((e) => {\n this.log.error(\"Error fetching block: \" + height + \" : \" + e);\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>);\n }\n }\n catch (e) {\n this.log.error(\"\" + e);\n }\n }\n else {\n this.latestHeight = height;\n }\n }\n\n private async pollForBlock() {\n try {\n const status = await this.client.status();\n if (status.syncInfo.latestBlockHeight > this.latestHeight) {\n while (this.latestHeight < status.syncInfo.latestBlockHeight) {\n this.newBlockReceived(this.latestHeight + 1);\n }\n }\n setTimeout(() => {\n this.pollForBlock();\n },\n this.config.pollingInterval);\n }\n catch (e) {\n this.log.error(\"Error polling for new block: \" + e);\n this.tryToRecover = true;\n this.retryCount++;\n }\n }\n\n private readGenesis(): Parser.Parser {\n if (this.config.genesisPath) {\n return fs.createReadStream(this.config.genesisPath).pipe(Parser.parser());\n }\n else {\n throw new Error(\"Genesis path not set\");\n }\n }\n\n private async setArrayReader(path: string, processor: (chunk: unknown) => Promise<void>): Promise<boolean> {\n const readPromise = new Promise<boolean>((resolve, reject) => {\n try {\n const filters = path.split(\".\");\n const pickers = filters.map(filter => Pick.pick({\n filter,\n }));\n let counter = 0;\n let chunkCounter = 0;\n\n // Wrapper processor that handles transaction chunking\n const chunkProcessor = async (data: unknown) => {\n chunkCounter++;\n this.log.debug(`Processing genesis chunk ${chunkCounter}`);\n\n await processor(data);\n\n // Commit and restart transaction every 5 chunks (5000 entries)\n // This prevents timeout on large genesis files\n if (chunkCounter % 5 === 0) {\n this.log.debug(`Committing transaction after chunk ${chunkCounter}`);\n await this.config.endTransaction(true);\n await this.config.beginTransaction();\n }\n };\n\n chain([\n this.readGenesis(),\n ...pickers,\n StreamArray.streamArray(),\n Batch.batch({\n batchSize: GENESIS_BATCH_SIZE,\n }),\n chunkProcessor,\n ])\n .on(\"data\",\n (data) => {\n if (data && Array.isArray(data)) {\n counter = counter + data.length;\n }\n })\n .on(\"end\",\n () => {\n this.log.info(`Processed ${counter} entries in ${chunkCounter} chunks`);\n resolve(true);\n });\n }\n catch (_e) {\n this.log.verbose(\"Error in setArrayReader: \" + _e);\n reject();\n }\n });\n\n return readPromise;\n }\n\n private async setValueReader(path: string, processor: (chunk: unknown) => Promise<void>): Promise<boolean> {\n const readPromise = new Promise<boolean>((resolve, reject) => {\n try {\n const filters = path.split(\".\");\n const pickers = filters.map(filter => Pick.pick({\n filter,\n }));\n\n let counter = 0;\n chain([this.readGenesis(), ...pickers, StreamValues.streamValues(), processor])\n .on(\"data\",\n (_data) => {\n counter++;\n })\n .on(\"end\",\n () => {\n this.log.info(`Processed ${counter} entries`);\n resolve(true);\n });\n }\n catch (_e) {\n reject();\n }\n });\n\n return readPromise;\n }\n\n private async parseGenesis() {\n this.log.info(\"Parsing genesis\");\n await this.config.beginTransaction();\n try {\n this.log.info(\"Starting genesis import\");\n this.log.debug(\"Importing genesis file...\");\n\n for (const [key, _value] of this.handled) {\n if (key.startsWith(\"genesis/\")) {\n const genesisEntry = key.split(\"/\");\n\n this.log.verbose(\"Importing \" + key + \"...\");\n if (genesisEntry[1] == \"array\") {\n await this.setArrayReader(genesisEntry[2],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (data: any) => {\n await this.asyncEmit(key as never,\n {\n value: data.map((x: {\n value: never\n }) => x.value),\n } as never);\n return data;\n });\n }\n else {\n await this.setValueReader(genesisEntry[2],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (data: any) => {\n await this.asyncEmit(key as never,\n {\n value: data.value,\n } as never);\n return data;\n });\n }\n }\n }\n\n this.log.info(\"Importing gen TXs...\");\n\n await this.setArrayReader(\"app_state.genutil.gen_txs\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (data: any) => {\n for (let j = 0; j < data.length; j++) {\n const gentx = data[j].value;\n for (let i = 0; i < gentx.body.messages.length; i++) {\n const msg = gentx.body.messages[i];\n await this.asyncEmit((\"gentx\" + msg[\"@type\"]) as never,\n {\n value: msg,\n } as never);\n }\n }\n return data;\n });\n await this.config.endTransaction(true);\n\n this.log.info(\"Finished importing\");\n }\n catch (e) {\n try {\n await this.config.endTransaction(false);\n }\n catch (dbe) {\n this.log.error(\"Error ending transaction. Must be a DB error: \" + dbe);\n }\n this.log.error(\"Failed to import genesis\");\n throw e;\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WAAM,KAAK,UAAU,KACnB,EACE,OAAO,KAAK,KAAK,MAEX,EAAE,MAAM,EACf,CAAU;AACb,YAAO;MACP;QAGJ,OAAM,KAAK,eAAe,aAAa,IAErC,OAAO,SAAc;AACnB,WAAM,KAAK,UAAU,KACnB,EACE,OAAO,KAAK,OACb,CAAU;AACb,YAAO;MACP;;AAKV,QAAK,IAAI,KAAK,uBAAuB;AAErC,SAAM,KAAK,eAAe,6BAExB,OAAO,SAAc;AACnB,SAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;KACpC,MAAM,QAAQ,KAAK,GAAG;AACtB,UAAK,IAAI,IAAI,GAAG,IAAI,MAAM,KAAK,SAAS,QAAQ,KAAK;MACnD,MAAM,MAAM,MAAM,KAAK,SAAS;AAChC,YAAM,KAAK,UAAW,UAAU,IAAI,UAClC,EACE,OAAO,KACR,CAAU;;;AAGjB,WAAO;KACP;AACJ,SAAM,KAAK,OAAO,eAAe,KAAK;AAEtC,QAAK,IAAI,KAAK,qBAAqB;WAE9B,GAAG;AACR,OAAI;AACF,UAAM,KAAK,OAAO,eAAe,MAAM;YAElC,KAAK;AACV,SAAK,IAAI,MAAM,mDAAmD,IAAI;;AAExE,QAAK,IAAI,MAAM,2BAA2B;AAC1C,SAAM"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["uuidv4","timeoutPromise: ReturnType<typeof this.blockQueue.dequeue>","hrTime","processStart: [number, number]","beginBlockEvents: readonly Event[] | readonly Event38[]","endBlockEvents: readonly Event[] | readonly Event38[]","events: Array<{\n msg_index?: number\n events: (Event | Event38)[]\n }>","eventsToAdd: typeof events","events","timeoutPromise: Promise<[BlockResponse, BlockResultsResponse]>","timeoutPromise: Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>"],"sources":["../../src/indexer/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\n/* eslint-disable max-lines */\nimport {\n createHash,\n} from \"node:crypto\";\nimport * as fs from \"node:fs\";\n\nimport {\n BlockResponse, BlockResultsResponse, CometClient, connectComet, Event, toRfc3339WithNanoseconds,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n BlockResultsResponse as BlockResultsResponse38, Event as Event38,\n} from \"@cosmjs/tendermint-rpc/build/comet38/responses.js\";\nimport {\n MsgExec,\n} from \"cosmjs-types/cosmos/authz/v1beta1/tx.js\";\nimport {\n QueryValidatorsRequest,\n QueryValidatorsResponse,\n} from \"cosmjs-types/cosmos/staking/v1beta1/query.js\";\nimport {\n Validator,\n} from \"cosmjs-types/cosmos/staking/v1beta1/staking.js\";\nimport {\n Tx,\n} from \"cosmjs-types/cosmos/tx/v1beta1/tx.js\";\nimport Fastify, {\n FastifyInstance,\n} from \"fastify\";\nimport {\n chain,\n} from \"stream-chain\";\nimport Parser from \"stream-json\";\nimport Pick from \"stream-json/filters/Pick.js\";\nimport StreamArray from \"stream-json/streamers/StreamArray.js\";\nimport StreamValues from \"stream-json/streamers/StreamValues.js\";\nimport Batch from \"stream-json/utils/Batch.js\";\nimport {\n v4 as uuidv4,\n} from \"uuid\";\nimport * as winston from \"winston\";\n\nimport {\n DEFAULT_BATCH_SIZE, DEFAULT_HEALTH_CHECK_PORT, DEFAULT_POLLING_INTERVAL_MS, DEFAULT_START_HEIGHT,\n GENESIS_BATCH_SIZE, PAGINATION_LIMITS, PERIODIC_INTERVALS, QUEUE_DEQUEUE_TIMEOUT_MS, RPC_TIMEOUT_MS,\n} from \"../constants.js\";\nimport {\n EclesiaEmitter,\n} from \"../emitter/index.js\";\nimport {\n IndexerMetrics,\n} from \"../metrics/index.js\";\nimport {\n CircularBuffer,\n} from \"../promise-queue/index.js\";\nimport {\n BlockQueue, EcleciaIndexerConfig, EmitFunc, MinimalBlockQueue,\n UUIDEvent, WithHeightAndUUID,\n} from \"../types/index.js\";\nimport {\n decodeAttr,\n} from \"../utils/index.js\";\nimport {\n validateFilePath, validatePort, validatePositiveInteger, validateUrl,\n} from \"../validation/index.js\";\n\n/** Default configuration for the Eclesia indexer */\nexport const defaultIndexerConfig = {\n startHeight: DEFAULT_START_HEIGHT, // Start indexing from block 1\n batchSize: DEFAULT_BATCH_SIZE, // Process blocks in batches of 500\n modules: [], // No modules enabled by default\n getNextHeight: () => DEFAULT_START_HEIGHT, // Default height retrieval function\n logLevel: \"info\" as EcleciaIndexerConfig[\"logLevel\"], // Default log level\n usePolling: false, // Use WebSocket subscription by default\n pollingInterval: DEFAULT_POLLING_INTERVAL_MS, // Poll every 5 seconds when polling enabled\n shouldProcessGenesis: () => false, // Skip genesis processing by default\n minimal: true, // Use minimal indexing by default\n healthCheckPort: DEFAULT_HEALTH_CHECK_PORT, // Default health check port\n enablePrometheus: false, // Disable Prometheus metrics server by default\n prometheusPort: 9090, // Default Prometheus metrics server port\n init: () => Promise.resolve(), // No-op initialization function\n beginTransaction: () => Promise.resolve(), // No-op transaction begin function\n endTransaction: (_status: boolean) => Promise.resolve(), // No-op transaction end function\n};\n\n/**\n * Core blockchain indexer that connects to Tendermint RPC and processes blocks\n * Extends EclesiaEmitter to provide event-driven architecture for modules\n */\nexport class EcleciaIndexer extends EclesiaEmitter {\n /** Indexer configuration settings */\n public config: EcleciaIndexerConfig;\n\n /** Fastify HTTP server for health checks */\n private fastify: FastifyInstance;\n\n /** Prometheus HTTP server instance */\n private prometheusServer: FastifyInstance | null = null;\n\n /** Queue for managing block processing pipeline */\n private blockQueue: BlockQueue;\n\n /** Latest block height from the chain */\n private latestHeight!: number;\n\n /** Next block height to process */\n private heightToProcess!: number;\n\n /** Whether the indexer has been initialized */\n private initialized = false;\n\n /** Prometheus metrics server instance */\n public prometheus: IndexerMetrics | null = null;\n\n /** Number of retry attempts for error recovery */\n private retryCount = 0;\n\n /** CometBFT client for ad-hoc queries */\n public client!: CometClient;\n\n /** CometBFT client for block and validator queries */\n public blockClient!: CometClient;\n\n /** Winston logger instance */\n public log: winston.Logger;\n\n /** Flag indicating if indexer should attempt recovery */\n private tryToRecover: boolean = false;\n\n /** Health check status for monitoring */\n private healthCheck = {\n status: \"CONNECTING\",\n };\n\n /** WebSocket subscription for new block notifications */\n private subscription: ReturnType<CometClient[\"subscribeNewBlock\"]> | null = null;\n\n /**\n * Creates a new Eclesia indexer instance\n * @param config - Indexer configuration options\n */\n constructor(config: EcleciaIndexerConfig) {\n super();\n\n // Validate required configuration\n validateUrl(config.rpcUrl, \"rpcUrl\");\n validatePositiveInteger(config.batchSize, \"batchSize\");\n\n // Validate optional genesis path if processing genesis\n if (config.genesisPath) {\n validateFilePath(config.genesisPath, \"genesisPath\");\n }\n\n // Validate health check port if provided\n if (config.healthCheckPort !== undefined) {\n validatePort(config.healthCheckPort, \"healthCheckPort\");\n }\n\n // Validate start height if provided\n if (config.startHeight !== undefined) {\n validatePositiveInteger(config.startHeight, \"startHeight\");\n }\n\n // Validate polling interval if provided\n if (config.pollingInterval !== undefined) {\n validatePositiveInteger(config.pollingInterval, \"pollingInterval\");\n }\n\n this.config = {\n ...defaultIndexerConfig,\n ...config,\n };\n\n // Initialize logger first so it can be used by queue error handler\n const {\n printf,\n } = winston.format;\n\n const eclesiaFormat = printf(({\n level, message, timestamp,\n }) => {\n return `${timestamp} [${level.toUpperCase()}]:\\t${message}`;\n });\n this.log = winston.createLogger({\n level: this.config.logLevel,\n defaultMeta: {\n service: \"Eclesia Indexer\",\n },\n transports: [\n new winston.transports.File({\n filename: \"error.log\",\n level: \"error\",\n }),\n new winston.transports.File({\n filename: \"combined.log\",\n }),\n new winston.transports.Console({\n format: winston.format.combine(winston.format.splat(),\n winston.format.timestamp(),\n eclesiaFormat,\n winston.format.colorize({\n all: true,\n })),\n }),\n ],\n });\n\n // Initialize block queue based on minimal or full indexing mode\n // Pass error handler that uses the logger\n const queueErrorHandler = (e: unknown) => {\n this.prometheus?.recordError(\"block_queue\");\n this.log.error(\"Error enqueueing block data: \" + e);\n };\n\n if (this.config.minimal) {\n // Minimal mode: only store block and block results\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse]>(this.config.batchSize, queueErrorHandler);\n }\n else {\n // Full mode: also store validator information\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>(this.config.batchSize, queueErrorHandler);\n }\n if (this.config.enablePrometheus) {\n this.prometheus = new IndexerMetrics();\n this.prometheusServer = Fastify({\n logger: false,\n });\n this.prometheusServer.get(\"/metrics\",\n async (_req, res) => {\n res.header(\"Content-Type\", this.prometheus!.registry.contentType);\n res.send(await this.prometheus!.getMetrics());\n },\n );\n this.prometheusServer.listen({\n port: this.config.prometheusPort,\n host: \"0.0.0.0\",\n },\n (err) => {\n if (err) {\n this.log.error(err);\n this.prometheus?.recordError(\"metrics_server\");\n this.emit(\"fatal-error\", {\n error: err,\n message: \"Failed to start metrics server\",\n });\n }\n });\n }\n this.fastify = Fastify({\n logger: false,\n });\n this.on(\"_unhandled\",\n (msg) => {\n if (msg.uuid) {\n this.log.verbose(\"Unhandled event: \" + msg.type);\n this.emit(\"uuid\",\n {\n status: true,\n uuid: msg.uuid,\n });\n }\n });\n this.fastify.get(\"/health\",\n async (_request, reply) => {\n const code = this.healthCheck.status == \"OK\"\n ? 200\n : 503;\n reply.code(code).send(this.healthCheck);\n });\n const healthPort = this.config.healthCheckPort\n ?? (process.env.HEALTH_CHECK_PORT ? parseInt(process.env.HEALTH_CHECK_PORT, 10) : 8080);\n this.fastify.listen({\n port: healthPort,\n host: \"0.0.0.0\",\n },\n (err) => {\n if (err) {\n this.log.error(err);\n this.prometheus?.recordError(\"health_check_server\");\n this.emit(\"fatal-error\", {\n error: err,\n message: \"Failed to start health check server\",\n });\n }\n });\n }\n\n private setStatus(status: string) {\n this.healthCheck.status = status;\n }\n\n private blockListener = {\n next: (data: {\n header: {\n height: number\n }\n }) => {\n this.newBlockReceived(data.header.height);\n },\n };\n\n private isMinimal(_blockqueue: BlockQueue): _blockqueue is MinimalBlockQueue {\n if (this.config.minimal) {\n return true;\n }\n else {\n return false;\n }\n }\n\n public async connect() {\n try {\n if (this.client && this.tryToRecover) {\n this.log.verbose(\"Recover from error. Attempting to disconnect from RPC\");\n this.client.disconnect();\n this.blockClient.disconnect();\n this.log.verbose(\"Disconnected from RPC\");\n }\n this.client = await connectComet(this.config.rpcUrl);\n this.log.info(\"Connected to RPC for ad hoc queries\");\n\n this.blockClient = await connectComet(this.config.rpcUrl);\n this.log.info(\"Connected to RPC for block & validator info\");\n\n return true;\n }\n catch (error) {\n this.log.error(error);\n this.prometheus?.recordError(\"connect_rpc_error\");\n this.tryToRecover = true;\n return false;\n }\n }\n\n public async start() {\n if (this.blockQueue) {\n this.blockQueue.clear();\n this.log.verbose(\"Starting, clearing block queue\");\n }\n if (!this.initialized) {\n try {\n if (this.config.init) {\n await this.config.init();\n }\n }\n catch (e) {\n this.log.error(\"Failed to initialize indexer: \" + e);\n\n this.prometheus?.recordError(\"init_error\");\n this.setStatus(\"FAILED\");\n throw e;\n }\n if (await this.config.shouldProcessGenesis()) {\n try {\n if (this.config.genesisPath) {\n await this.parseGenesis();\n }\n }\n catch (e) {\n this.log.error(\"Failed to parse genesis: \" + e);\n\n this.prometheus?.recordError(\"genesis_error\");\n this.setStatus(\"FAILED\");\n throw e;\n }\n }\n this.initialized = true;\n }\n try {\n await this.connect();\n if (!this.config.usePolling && this.subscription) {\n this.subscription.removeListener(this.blockListener);\n this.subscription = null;\n this.log.verbose(\"Removed existing block listener and subscription\");\n }\n if (!this.config.usePolling) {\n this.subscription = this.client.subscribeNewBlock\n ? this.client.subscribeNewBlock()\n : null;\n }\n const status = await this.client.status();\n this.latestHeight = status.syncInfo.latestBlockHeight;\n this.log.info(\"Current chain height: \" + this.latestHeight);\n\n this.heightToProcess = await this.config.getNextHeight();\n if (this.config.usePolling) {\n this.pollForBlock();\n }\n else {\n if (this.subscription) {\n this.subscription.addListener(this.blockListener);\n }\n else {\n this.prometheus?.recordError(\"subscription_error\");\n throw new Error(\"Could not subscribe to new blocks\");\n }\n }\n }\n catch (e) {\n this.log.error(\"Failed to set up block listening: \" + e);\n this.prometheus?.recordError(\"block_listening_error\");\n this.setStatus(\"FAILED\");\n throw e;\n }\n\n this.tryToRecover = false;\n this.fetcher().catch((e) => {\n this.setStatus(\"FAILED\");\n\n this.prometheus?.recordError(\"fetching_error\");\n throw new Error(\"Error in fetching service: \" + e);\n });\n\n const hrTime = process.hrtime();\n let ms = hrTime[0] * 1000000 + hrTime[1] / 1000;\n while (this.blockQueue.size() > 0 && !this.tryToRecover) {\n if (this.config.enablePrometheus) {\n this.prometheus!.updateRetryCount(this.retryCount);\n }\n // await the dequeued promise is essentially awaiting fetched data for that block\n try {\n if (this.tryToRecover) {\n throw new Error(\"Exiting processing loop. Attempting to recover indexer\");\n }\n // Index block inside a db transaction to ensure data consistency\n await this.config.beginTransaction();\n this.log.silly(\"Started db tx\");\n let height, timestamp;\n if (this.isMinimal(this.blockQueue)) {\n const timeoutPromise: ReturnType<typeof this.blockQueue.dequeue> = new Promise((resolve, reject) => {\n setTimeout(reject, QUEUE_DEQUEUE_TIMEOUT_MS, []);\n });\n const toProcess = await Promise.race([this.blockQueue.dequeue(), timeoutPromise]);\n this.log.silly(\"Retrieved block data\");\n if (!toProcess || !toProcess[0] || !toProcess[1]) {\n this.prometheus?.recordError(\"rpc_error\");\n throw new Error(\"Could not fetch block\");\n }\n height = toProcess[0].block.header.height;\n timestamp = toRfc3339WithNanoseconds(toProcess[0].block.header.time);\n await this.processBlock(toProcess[0],\n toProcess[1]);\n }\n else {\n const timeoutPromise: ReturnType<typeof this.blockQueue.dequeue> = new Promise((resolve, reject) => {\n setTimeout(reject, QUEUE_DEQUEUE_TIMEOUT_MS, []);\n });\n const toProcess = await Promise.race([this.blockQueue.dequeue(), timeoutPromise]);\n this.log.silly(\"Retrieved block data\");\n if (!toProcess || !toProcess[0] || !toProcess[1] || !toProcess[2]) {\n this.prometheus?.recordError(\"rpc_error\");\n throw new Error(\"Could not fetch block\");\n }\n\n this.log.silly(\"Decoded block\");\n height = toProcess[0].block.header.height;\n timestamp = toRfc3339WithNanoseconds(toProcess[0].block.header.time);\n await this.processBlock(toProcess[0],\n toProcess[1],\n QueryValidatorsResponse.decode(toProcess[2]).validators);\n }\n // Emit events to trigger periodic operations every 50, 100 and 1000 blocks\n if (height % PERIODIC_INTERVALS.LARGE == 0) {\n const hrTime = process.hrtime();\n const newms = hrTime[0] * 1000000 + hrTime[1] / 1000;\n const duration = newms - ms;\n ms = newms;\n const rate = 1000000000 / duration;\n this.log.info(\"Processing:\" + rate.toFixed(2) + \"blocks/sec\");\n await this.asyncEmit(\"periodic/1000\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n if (height % PERIODIC_INTERVALS.MEDIUM == 0) {\n await this.asyncEmit(\"periodic/100\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n if (height % PERIODIC_INTERVALS.SMALL == 0) {\n await this.asyncEmit(\"periodic/50\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n this.log.silly(\"Handled periodic events\");\n\n await this.config.endTransaction(true);\n\n this.log.silly(\"Committed db tx\");\n }\n catch (e) {\n this.prometheus?.recordError(\"block_processing_error\");\n this.log.error(\"\" + e);\n this.setStatus(\"FAILED\");\n try {\n await this.config.endTransaction(false);\n }\n catch (dbe) {\n this.prometheus?.recordError(\"database\");\n this.log.error(\"Error ending transaction. Must be a DB error: \" + dbe);\n }\n this.tryToRecover = true;\n this.retryCount++;\n break;\n }\n this.retryCount = 0;\n this.setStatus(\"OK\");\n }\n if (this.retryCount < 3) {\n this.log.debug(\"Indexer retryCount: \" + this.retryCount);\n this.log.info(\"Indexer is restarting\");\n setTimeout(() => this.start(),\n this.retryCount * 5000);\n }\n else {\n this.log.info(\"Indexer failed too many times. Exiting.\");\n this.emit(\"fatal-error\", {\n error: new Error(\"Max retry attempts exceeded\"),\n message: \"Indexer failed too many times\",\n retryCount: this.retryCount,\n });\n }\n }\n\n public asyncEmit: EmitFunc<keyof WithHeightAndUUID<EventMap>> = async (\n type,\n event,\n ) => {\n event.uuid = uuidv4();\n\n /*\n * More than 1 listener can be registered for an event type\n * Fortunately these are all set up during module init() so we have a consistent count\n * so we can count responses to resolve when complete\n * values are irrelevant as promise resolution is only used for flow control\n */\n let listenerCount = this.handled.get(type);\n if (!listenerCount) {\n // Setting listenerCount to 1 (the unhandled listener)\n listenerCount = 1;\n }\n let listenersResponded = 0;\n const prom = new Promise<void>((resolve, reject) => {\n const returnFunc = (ev: UUIDEvent) => {\n if (ev.uuid == event.uuid) {\n if (ev.status) {\n listenersResponded++;\n if (listenersResponded == listenerCount) {\n // All listeners have done their thing so we can remove listener, resolve and continue execution\n this.off(\"uuid\",\n returnFunc);\n resolve();\n }\n }\n else {\n // At least 1 listener is reporting an error. Reject and handle exception at the original asyncEmit location\n reject(ev.error);\n }\n }\n };\n this.on(\"uuid\",\n returnFunc);\n });\n this.emit(type,\n event);\n\n return prom;\n };\n\n private async processBlock(block: BlockResponse, block_results: BlockResultsResponse | BlockResultsResponse38, validators?: Validator[]) {\n let processStart: [number, number] = [0, 0];\n if (this.config.logLevel == \"silly\") {\n processStart = process.hrtime();\n }\n let endTimer;\n if (this.config.enablePrometheus) {\n endTimer = this.prometheus!.timeBlockProcessing();\n }\n const height = block.block.header.height;\n this.log.debug(\"Processing block: %d\",\n height);\n\n // Initialize height & timestamp to be used for this block-processing run\n const timestamp = toRfc3339WithNanoseconds(block.block.header.time);\n\n // Use & await asyncEmit to ensure db insertions in order\n\n /*\n * Emit block information to any interested modules.\n * Primarily the required block module listens to this\n */\n await this.asyncEmit(\"block\",\n {\n value: {\n block,\n block_results,\n },\n height,\n timestamp,\n });\n this.log.silly(\"Modules handled block event\");\n\n let beginBlockEvents: readonly Event[] | readonly Event38[];\n let endBlockEvents: readonly Event[] | readonly Event38[];\n if ((block_results as BlockResultsResponse38).finalizeBlockEvents) {\n beginBlockEvents = (block_results as BlockResultsResponse38).finalizeBlockEvents.filter(x => x.attributes.find(a => decodeAttr(a.key) == \"mode\" && decodeAttr(a.value) == \"begin_block\")) as readonly Event38[];\n endBlockEvents = (block_results as BlockResultsResponse38).finalizeBlockEvents.filter(x => x.attributes.find(a => decodeAttr(a.key) == \"mode\" && decodeAttr(a.value) == \"end_block\")) as readonly Event38[];\n }\n else {\n beginBlockEvents = (block_results as BlockResultsResponse).beginBlockEvents;\n endBlockEvents = (block_results as BlockResultsResponse).endBlockEvents;\n }\n // Deal with begin_block events first\n await this.asyncEmit(\"begin_block\",\n {\n value: {\n events: beginBlockEvents!,\n validators,\n },\n height,\n timestamp,\n });\n\n this.log.silly(\"Modules handled begin_block events\");\n\n // Then individual tx_events\n await this.asyncEmit(\"tx_events\",\n {\n value: block_results.results,\n height,\n timestamp,\n });\n this.log.silly(\"Modules handled tx events\");\n\n // Emit details and result for each tx msg separately\n for (let t = 0; t < block.block.txs.length; t++) {\n const tx = Tx.decode(block.block.txs[t]);\n\n const result = block_results.results[t].code;\n const txlog = block_results.results[t].log;\n\n if (result != 0) {\n // Tx failed. Ignore\n continue;\n }\n if (tx.body && tx.body.memo != \"\") {\n const txHash = createHash(\"sha256\").update(block.block.txs[t])\n .digest(\"hex\");\n await this.asyncEmit(\"tx_memo\",\n {\n value: {\n txHash,\n txBody: tx.body,\n },\n height,\n timestamp,\n });\n }\n // parsing log rather than using events directly in order to have msg_index available to filter appropriate events for each msg\n let events: Array<{\n msg_index?: number\n events: (Event | Event38)[]\n }> = txlog\n ? JSON.parse(txlog)\n : [];\n if (events.length == 0) {\n const eventsToAdd: typeof events = [];\n this.log.silly(\"No events found in tx log. Parsing events for msg_index\");\n for (let m = 0; m < block_results.results[t].events.length; m++) {\n if (block_results.results[t].events[m].attributes.find(a => decodeAttr(a.key) == \"msg_index\")) {\n const mi = decodeAttr(block_results.results[t].events[m].attributes.find(a => decodeAttr(a.key) == \"msg_index\")?.value ?? \"\");\n if (mi != \"\") {\n const miNum = parseInt(mi);\n let ev = eventsToAdd.find(x => x.msg_index == miNum);\n if (!ev) {\n ev = {\n msg_index: miNum,\n events: [block_results.results[t].events[m]],\n };\n eventsToAdd.push(ev);\n }\n else {\n ev.events.push(block_results.results[t].events[m] as Event);\n }\n }\n }\n }\n events = events.concat(eventsToAdd);\n }\n const msgs = tx.body?.messages;\n\n if (msgs) {\n for (let i = 0; i < msgs.length; i++) {\n this.log.silly(\"Indexer broadcasting msg for handling: \" + msgs[i].typeUrl);\n const msgevents\n = msgs.length > 1\n ? events.find(x => x.msg_index == i)?.events\n : events[0].events;\n await this.asyncEmit(msgs[i].typeUrl as never,\n {\n value: {\n tx: msgs[i].value as never,\n events: msgevents,\n } as never,\n height,\n timestamp,\n });\n if (msgs[i].typeUrl == \"/cosmos.authz.v1beta1.MsgExec\") {\n const authzMsgs = MsgExec.decode(msgs[i].value).msgs;\n if (authzMsgs) {\n for (let r = 0; r < authzMsgs.length; r++) {\n this.log.silly(\"Indexer broadcasting msg for handling: \" + authzMsgs[r].typeUrl);\n const authzMsgEvents = msgevents?.reduce((events, evt) => {\n if (evt.attributes.filter(x => decodeAttr(x.key) == \"authz_msg_index\" && decodeAttr(x.value) == \"\" + r).length > 0) {\n events.push(evt);\n }\n return events;\n },\n [] as (Event | Event38)[]);\n await this.asyncEmit(authzMsgs[r].typeUrl as never,\n {\n value: {\n tx: authzMsgs[r].value as never,\n events: authzMsgEvents,\n } as never,\n height,\n timestamp,\n });\n }\n }\n }\n }\n }\n }\n this.log.silly(\"Modules handled msg events\");\n if (this.config.enablePrometheus) {\n this.prometheus!.recordTransactions(block.block.txs.length);\n }\n // Then deal with end_block events\n await this.asyncEmit(\"end_block\",\n {\n value: endBlockEvents!,\n height,\n timestamp,\n });\n this.log.silly(\"Modules handled end_block events\");\n if (this.config.logLevel == \"silly\") {\n const processEnd = process.hrtime(processStart);\n const processTime = processEnd[0] * 1000 + processEnd[1] / 1000000;\n this.log.silly(\"Processed block %d in %d ms\",\n height,\n processTime.toFixed(2));\n }\n\n if (this.config.enablePrometheus) {\n endTimer!();\n }\n if (this.config.enablePrometheus) {\n this.prometheus!.updateBlockMetrics(height, this.latestHeight, this.blockQueue.size());\n }\n }\n\n private async fetcher() {\n for (let i = this.heightToProcess; i <= this.latestHeight; i++) {\n this.log.debug(\"Fetching: \" + i);\n if (this.tryToRecover) {\n this.log.verbose(\"Exiting fetcher loop. Attempting to recover indexer\");\n break;\n }\n try {\n if (this.isMinimal(this.blockQueue)) {\n const timeoutPromise: Promise<[BlockResponse, BlockResultsResponse]> = new Promise((resolve, reject) => {\n setTimeout(reject,\n RPC_TIMEOUT_MS,\n false);\n });\n const toIndex = Promise.race([Promise.all([this.blockClient.block(i) as Promise<BlockResponse>, this.blockClient.blockResults(i) as Promise<BlockResultsResponse>]), timeoutPromise]).catch((e) => {\n this.log.error(\"Error fetching block: \" + i + \" : \" + e);\n this.tryToRecover = true;\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse]>;\n this.blockQueue.enqueue(toIndex);\n }\n else {\n const timeoutPromise: Promise<[BlockResponse, BlockResultsResponse, Uint8Array]> = new Promise((resolve, reject) => {\n setTimeout(reject,\n RPC_TIMEOUT_MS,\n false);\n });\n const q = QueryValidatorsRequest.fromPartial({\n pagination: {\n limit: PAGINATION_LIMITS.VALIDATORS,\n },\n });\n const vals = QueryValidatorsRequest.encode(q).finish();\n const toIndex = Promise.race([\n Promise.all([\n this.blockClient.block(i) as Promise<BlockResponse>,\n this.blockClient.blockResults(i) as Promise<BlockResultsResponse>,\n this.callABCI(\"/cosmos.staking.v1beta1.Query/Validators\",\n vals,\n i,\n false),\n ]),\n timeoutPromise,\n ]).catch((e) => {\n this.log.error(\"Error fetching block: \" + i + \" : \" + e);\n this.tryToRecover = true;\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>;\n this.blockQueue.enqueue(toIndex);\n }\n await this.blockQueue.continue();\n if (this.tryToRecover) {\n this.retryCount++;\n throw new Error(\"RPC not responding\");\n }\n }\n catch (e) {\n this.log.error(e);\n break;\n }\n }\n if (!this.tryToRecover) {\n this.blockQueue.setSynced();\n this.log.info(\"Synced to latest height\");\n }\n }\n\n public async callABCI(path: string, data: Uint8Array, height?: number, adHoc: boolean = true): Promise<Uint8Array> {\n try {\n const endTimer = this.prometheus?.timeRpcCall(path) ?? void 0;\n const abciq = await\n (adHoc\n ? this.client\n : this.blockClient).abciQuery({\n path,\n data,\n height: height,\n });\n endTimer?.();\n if (abciq) {\n return abciq.value;\n }\n else {\n this.tryToRecover = true;\n this.setStatus(\"FAILED\");\n this.prometheus?.recordError(\"abci_query_error\");\n throw new Error(\"RPC not responding. Query at: \" + path);\n }\n }\n catch (_e) {\n this.tryToRecover = true;\n this.setStatus(\"FAILED\");\n this.retryCount++;\n throw new Error(\"RPC not responding. Query at: \" + path);\n }\n }\n\n private newBlockReceived(height: number): void {\n this.log.info(\"Received new block: %d\",\n height);\n if (height == this.latestHeight) {\n return;\n }\n // If we are synced, add to end of queue\n if (this.blockQueue.synced && !this.tryToRecover) {\n this.latestHeight = height;\n if (this.blockQueue.size() + 1 == this.config.batchSize) {\n this.prometheus?.recordError(\"block_queue_full\");\n this.log.error(\"Block queue is full. Cannot add new block\");\n this.tryToRecover = true;\n this.retryCount++;\n return;\n }\n try {\n if (this.isMinimal(this.blockQueue)) {\n this.blockQueue.enqueue(Promise.all([this.client.block(height) as Promise<BlockResponse>, this.client.blockResults(height) as Promise<BlockResultsResponse>]).catch((e) => {\n this.log.error(\"Error fetching block: \" + height + \" : \" + e);\n\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse]>);\n }\n else {\n const q = QueryValidatorsRequest.fromPartial({\n pagination: {\n limit: 1000n,\n },\n });\n const vals = QueryValidatorsRequest.encode(q).finish();\n this.blockQueue.enqueue(Promise.all([\n this.client.block(height) as Promise<BlockResponse>,\n this.client.blockResults(height) as Promise<BlockResultsResponse>,\n this.callABCI(\"/cosmos.staking.v1beta1.Query/Validators\",\n vals,\n height,\n false),\n ]).catch((e) => {\n this.log.error(\"Error fetching block: \" + height + \" : \" + e);\n return Promise.resolve([]);\n }) as Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>);\n }\n }\n catch (e) {\n this.log.error(\"\" + e);\n }\n }\n else {\n this.latestHeight = height;\n }\n }\n\n private async pollForBlock() {\n try {\n const status = await this.client.status();\n if (status.syncInfo.latestBlockHeight > this.latestHeight) {\n while (this.latestHeight < status.syncInfo.latestBlockHeight) {\n this.newBlockReceived(this.latestHeight + 1);\n }\n }\n setTimeout(() => {\n this.pollForBlock();\n },\n this.config.pollingInterval);\n }\n catch (e) {\n this.log.error(\"Error polling for new block: \" + e);\n this.tryToRecover = true;\n this.retryCount++;\n }\n }\n\n private readGenesis(): Parser.Parser {\n if (this.config.genesisPath) {\n return fs.createReadStream(this.config.genesisPath).pipe(Parser.parser());\n }\n else {\n throw new Error(\"Genesis path not set\");\n }\n }\n\n private async setArrayReader(path: string, processor: (chunk: unknown) => Promise<void>): Promise<boolean> {\n const readPromise = new Promise<boolean>((resolve, reject) => {\n try {\n const filters = path.split(\".\");\n const pickers = filters.map(filter => Pick.pick({\n filter,\n }));\n let counter = 0;\n let chunkCounter = 0;\n\n // Wrapper processor that handles transaction chunking\n const chunkProcessor = async (data: unknown) => {\n chunkCounter++;\n this.log.debug(`Processing genesis chunk ${chunkCounter}`);\n\n await processor(data);\n\n // Commit and restart transaction every 5 chunks (5000 entries)\n // This prevents timeout on large genesis files\n if (chunkCounter % 5 === 0) {\n this.log.debug(`Committing transaction after chunk ${chunkCounter}`);\n await this.config.endTransaction(true);\n await this.config.beginTransaction();\n }\n };\n\n chain([\n this.readGenesis(),\n ...pickers,\n StreamArray.streamArray(),\n Batch.batch({\n batchSize: GENESIS_BATCH_SIZE,\n }),\n chunkProcessor,\n ])\n .on(\"data\",\n (data) => {\n if (data && Array.isArray(data)) {\n counter = counter + data.length;\n }\n })\n .on(\"end\",\n () => {\n this.log.info(`Processed ${counter} entries in ${chunkCounter} chunks`);\n resolve(true);\n });\n }\n catch (_e) {\n this.log.verbose(\"Error in setArrayReader: \" + _e);\n reject();\n }\n });\n\n return readPromise;\n }\n\n private async setValueReader(path: string, processor: (chunk: unknown) => Promise<void>): Promise<boolean> {\n const readPromise = new Promise<boolean>((resolve, reject) => {\n try {\n const filters = path.split(\".\");\n const pickers = filters.map(filter => Pick.pick({\n filter,\n }));\n\n let counter = 0;\n chain([this.readGenesis(), ...pickers, StreamValues.streamValues(), processor])\n .on(\"data\",\n (_data) => {\n counter++;\n })\n .on(\"end\",\n () => {\n this.log.info(`Processed ${counter} entries`);\n resolve(true);\n });\n }\n catch (_e) {\n reject();\n }\n });\n\n return readPromise;\n }\n\n private async parseGenesis() {\n this.log.info(\"Parsing genesis\");\n await this.config.beginTransaction();\n try {\n this.log.info(\"Starting genesis import\");\n this.log.debug(\"Importing genesis file...\");\n\n for (const [key, _value] of this.handled) {\n if (key.startsWith(\"genesis/\")) {\n const genesisEntry = key.split(\"/\");\n\n this.log.verbose(\"Importing \" + key + \"...\");\n if (genesisEntry[1] == \"array\") {\n await this.setArrayReader(genesisEntry[2],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (data: any) => {\n await this.asyncEmit(key as never,\n {\n value: data.map((x: {\n value: never\n }) => x.value),\n } as never);\n return data;\n });\n }\n else {\n await this.setValueReader(genesisEntry[2],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (data: any) => {\n await this.asyncEmit(key as never,\n {\n value: data.value,\n } as never);\n return data;\n });\n }\n }\n }\n\n this.log.info(\"Importing gen TXs...\");\n\n await this.setArrayReader(\"app_state.genutil.gen_txs\",\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async (data: any) => {\n for (let j = 0; j < data.length; j++) {\n const gentx = data[j].value;\n for (let i = 0; i < gentx.body.messages.length; i++) {\n const msg = gentx.body.messages[i];\n await this.asyncEmit((\"gentx\" + msg[\"@type\"]) as never,\n {\n value: msg,\n } as never);\n }\n }\n return data;\n });\n await this.config.endTransaction(true);\n\n this.log.info(\"Finished importing\");\n }\n catch (e) {\n try {\n await this.config.endTransaction(false);\n }\n catch (dbe) {\n this.prometheus?.recordError(\"database_error\");\n this.log.error(\"Error ending transaction. Must be a DB error: \" + dbe);\n }\n this.log.error(\"Failed to import genesis\");\n throw e;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAa,uBAAuB;CAClC,aAAa;CACb,WAAW;CACX,SAAS,EAAE;CACX,qBAAqB;CACrB,UAAU;CACV,YAAY;CACZ,iBAAiB;CACjB,4BAA4B;CAC5B,SAAS;CACT,iBAAiB;CACjB,kBAAkB;CAClB,gBAAgB;CAChB,YAAY,QAAQ,SAAS;CAC7B,wBAAwB,QAAQ,SAAS;CACzC,iBAAiB,YAAqB,QAAQ,SAAS;CACxD;;;;;AAMD,IAAa,iBAAb,cAAoC,eAAe;;;;;CAoDjD,YAAY,QAA8B;AACxC,SAAO;OA7CD,mBAA2C;OAY3C,cAAc;OAGf,aAAoC;OAGnC,aAAa;OAYb,eAAwB;OAGxB,cAAc,EACpB,QAAQ,cACT;OAGO,eAAoE;OA4JpE,gBAAgB,EACtB,OAAO,SAID;AACJ,QAAK,iBAAiB,KAAK,OAAO,OAAO;KAE5C;OAyOM,YAAyD,OAC9D,MACA,UACG;AACH,SAAM,OAAOA,IAAQ;GAQrB,IAAI,gBAAgB,KAAK,QAAQ,IAAI,KAAK;AAC1C,OAAI,CAAC,cAEH,iBAAgB;GAElB,IAAI,qBAAqB;GACzB,MAAM,OAAO,IAAI,SAAe,SAAS,WAAW;IAClD,MAAM,cAAc,OAAkB;AACpC,SAAI,GAAG,QAAQ,MAAM,KACnB,KAAI,GAAG,QAAQ;AACb;AACA,UAAI,sBAAsB,eAAe;AAEvC,YAAK,IAAI,QACP,WAAW;AACb,gBAAS;;WAKX,QAAO,GAAG,MAAM;;AAItB,SAAK,GAAG,QACN,WAAW;KACb;AACF,QAAK,KAAK,MACR,MAAM;AAER,UAAO;;AA7aP,cAAY,OAAO,QAAQ,SAAS;AACpC,0BAAwB,OAAO,WAAW,YAAY;AAGtD,MAAI,OAAO,YACT,kBAAiB,OA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,KAAK;KACpC,MAAM,QAAQ,KAAK,GAAG;AACtB,UAAK,IAAI,IAAI,GAAG,IAAI,MAAM,KAAK,SAAS,QAAQ,KAAK;MACnD,MAAM,MAAM,MAAM,KAAK,SAAS;AAChC,YAAM,KAAK,UAAW,UAAU,IAAI,UAClC,EACE,OAAO,KACR,CAAU;;;AAGjB,WAAO;KACP;AACJ,SAAM,KAAK,OAAO,eAAe,KAAK;AAEtC,QAAK,IAAI,KAAK,qBAAqB;WAE9B,GAAG;AACR,OAAI;AACF,UAAM,KAAK,OAAO,eAAe,MAAM;YAElC,KAAK;AACV,SAAK,YAAY,YAAY,iBAAiB;AAC9C,SAAK,IAAI,MAAM,mDAAmD,IAAI;;AAExE,QAAK,IAAI,MAAM,2BAA2B;AAC1C,SAAM"}
|
package/dist/metrics/index.cjs
CHANGED
|
@@ -133,6 +133,78 @@ var IndexerMetrics = class {
|
|
|
133
133
|
else if (type === "database") this.databaseErrors.inc();
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
|
+
* Records block processing duration
|
|
137
|
+
* @param durationSeconds - Duration in seconds
|
|
138
|
+
*/
|
|
139
|
+
recordBlockProcessing(durationSeconds) {
|
|
140
|
+
this.blockProcessingDuration.observe(durationSeconds);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Times a block processing operation
|
|
144
|
+
* @returns End timer function to call when operation completes
|
|
145
|
+
*/
|
|
146
|
+
timeBlockProcessing() {
|
|
147
|
+
return this.blockProcessingDuration.startTimer();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Records RPC call duration
|
|
151
|
+
* @param method - RPC method name
|
|
152
|
+
* @param durationSeconds - Duration in seconds
|
|
153
|
+
*/
|
|
154
|
+
recordRpcCall(method, durationSeconds) {
|
|
155
|
+
this.rpcCallDuration.observe({ method }, durationSeconds);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Times an RPC call operation
|
|
159
|
+
* @param method - RPC method name
|
|
160
|
+
* @returns End timer function to call when operation completes
|
|
161
|
+
*/
|
|
162
|
+
timeRpcCall(method) {
|
|
163
|
+
return this.rpcCallDuration.startTimer({ method });
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Records database query duration
|
|
167
|
+
* @param queryType - Type of query (select, insert, update, delete, etc.)
|
|
168
|
+
* @param durationSeconds - Duration in seconds
|
|
169
|
+
*/
|
|
170
|
+
recordDatabaseQuery(queryType, durationSeconds) {
|
|
171
|
+
this.databaseQueryDuration.observe({ query_type: queryType }, durationSeconds);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Times a database query operation
|
|
175
|
+
* @param queryType - Type of query (select, insert, update, delete, etc.)
|
|
176
|
+
* @returns End timer function to call when operation completes
|
|
177
|
+
*/
|
|
178
|
+
timeDatabaseQuery(queryType) {
|
|
179
|
+
return this.databaseQueryDuration.startTimer({ query_type: queryType });
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Updates the retry count gauge
|
|
183
|
+
* @param count - Current retry count
|
|
184
|
+
*/
|
|
185
|
+
updateRetryCount(count) {
|
|
186
|
+
this.retryCount.set(count);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Increments the retry count gauge by 1
|
|
190
|
+
*/
|
|
191
|
+
incrementRetryCount() {
|
|
192
|
+
this.retryCount.inc();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Resets the retry count gauge to 0
|
|
196
|
+
*/
|
|
197
|
+
resetRetryCount() {
|
|
198
|
+
this.retryCount.set(0);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Records transactions processed
|
|
202
|
+
* @param count - Number of transactions to record (defaults to 1)
|
|
203
|
+
*/
|
|
204
|
+
recordTransactions(count = 1) {
|
|
205
|
+
this.transactionsProcessed.inc(count);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
136
208
|
* Gets metrics in Prometheus format
|
|
137
209
|
* @returns Prometheus metrics string
|
|
138
210
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Registry","Counter","Gauge","Histogram"],"sources":["../../src/metrics/index.ts"],"sourcesContent":["/**\n * Prometheus metrics for monitoring indexer performance and health\n * Exposes metrics for blocks indexed, queue depth, errors, and processing times\n */\n\nimport {\n collectDefaultMetrics, Counter, Gauge, Histogram, Registry,\n} from \"prom-client\";\n\n/** Prometheus metrics registry */\nexport class IndexerMetrics {\n /** Prometheus registry instance */\n public readonly registry: Registry;\n\n /** Counter for total blocks indexed */\n public readonly blocksIndexed: Counter;\n\n /** Gauge for current block height */\n public readonly currentHeight: Gauge;\n\n /** Gauge for latest chain block height */\n public readonly latestHeight: Gauge;\n\n /** Gauge for blocks behind chain tip */\n public readonly blocksBehind: Gauge;\n\n /** Gauge for block queue depth */\n public readonly queueDepth: Gauge;\n\n /** Counter for total errors */\n public readonly errors: Counter;\n\n /** Counter for RPC errors */\n public readonly rpcErrors: Counter;\n\n /** Counter for database errors */\n public readonly databaseErrors: Counter;\n\n /** Histogram for block processing duration */\n public readonly blockProcessingDuration: Histogram;\n\n /** Histogram for RPC call duration */\n public readonly rpcCallDuration: Histogram;\n\n /** Histogram for database query duration */\n public readonly databaseQueryDuration: Histogram;\n\n /** Gauge for retry count */\n public readonly retryCount: Gauge;\n\n /** Counter for total transactions processed */\n public readonly transactionsProcessed: Counter;\n\n constructor() {\n this.registry = new Registry();\n\n // Collect default Node.js metrics (memory, CPU, etc.)\n collectDefaultMetrics({\n register: this.registry,\n });\n\n // Block indexing metrics\n this.blocksIndexed = new Counter({\n name: \"indexer_blocks_indexed_total\",\n help: \"Total number of blocks indexed\",\n registers: [this.registry],\n });\n\n this.currentHeight = new Gauge({\n name: \"indexer_current_height\",\n help: \"Current block height being processed\",\n registers: [this.registry],\n });\n\n this.latestHeight = new Gauge({\n name: \"indexer_latest_chain_height\",\n help: \"Latest block height on the chain\",\n registers: [this.registry],\n });\n\n this.blocksBehind = new Gauge({\n name: \"indexer_blocks_behind\",\n help: \"Number of blocks behind chain tip\",\n registers: [this.registry],\n });\n\n this.queueDepth = new Gauge({\n name: \"indexer_queue_depth\",\n help: \"Current depth of block processing queue\",\n registers: [this.registry],\n });\n\n // Error metrics\n this.errors = new Counter({\n name: \"indexer_errors_total\",\n help: \"Total number of indexer errors\",\n labelNames: [\"type\"],\n registers: [this.registry],\n });\n\n this.rpcErrors = new Counter({\n name: \"indexer_rpc_errors_total\",\n help: \"Total number of RPC errors\",\n registers: [this.registry],\n });\n\n this.databaseErrors = new Counter({\n name: \"indexer_database_errors_total\",\n help: \"Total number of database errors\",\n registers: [this.registry],\n });\n\n // Performance metrics\n this.blockProcessingDuration = new Histogram({\n name: \"indexer_block_processing_duration_seconds\",\n help: \"Time spent processing a single block\",\n buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2, 5],\n registers: [this.registry],\n });\n\n this.rpcCallDuration = new Histogram({\n name: \"indexer_rpc_call_duration_seconds\",\n help: \"Duration of RPC calls\",\n buckets: [0.01, 0.05, 0.1, 0.5, 1, 2, 5, 10],\n labelNames: [\"method\"],\n registers: [this.registry],\n });\n\n this.databaseQueryDuration = new Histogram({\n name: \"indexer_database_query_duration_seconds\",\n help: \"Duration of database queries\",\n buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1],\n labelNames: [\"query_type\"],\n registers: [this.registry],\n });\n\n // Operational metrics\n this.retryCount = new Gauge({\n name: \"indexer_retry_count\",\n help: \"Current number of retry attempts\",\n registers: [this.registry],\n });\n\n this.transactionsProcessed = new Counter({\n name: \"indexer_transactions_processed_total\",\n help: \"Total number of transactions processed\",\n registers: [this.registry],\n });\n }\n\n /**\n * Updates block indexing metrics\n * @param currentHeight - Current height being processed\n * @param latestHeight - Latest height on chain\n * @param queueSize - Current queue depth\n */\n updateBlockMetrics(currentHeight: number, latestHeight: number, queueSize: number) {\n this.blocksIndexed.inc();\n this.currentHeight.set(currentHeight);\n this.latestHeight.set(latestHeight);\n this.blocksBehind.set(latestHeight - currentHeight);\n this.queueDepth.set(queueSize);\n }\n\n /**\n * Records an error occurrence\n * @param type - Error type (rpc, database, processing, etc.)\n */\n recordError(type: string) {\n this.errors.inc({\n type,\n });\n\n if (type === \"rpc\") {\n this.rpcErrors.inc();\n }\n else if (type === \"database\") {\n this.databaseErrors.inc();\n }\n }\n\n /**\n * Gets metrics in Prometheus format\n * @returns Prometheus metrics string\n */\n async getMetrics(): Promise<string> {\n return this.registry.metrics();\n }\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,iBAAb,MAA4B;CA2C1B,cAAc;AACZ,OAAK,WAAW,IAAIA,sBAAU;AAG9B,yCAAsB,EACpB,UAAU,KAAK,UAChB,CAAC;AAGF,OAAK,gBAAgB,IAAIC,oBAAQ;GAC/B,MAAM;GACN,MAAM;GACN,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAEF,OAAK,gBAAgB,IAAIC,kBAAM;GAC7B,MAAM;GACN,MAAM;GACN,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAEF,OAAK,eAAe,IAAIA,kBAAM;GAC5B,MAAM;GACN,MAAM;GACN,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAEF,OAAK,eAAe,IAAIA,kBAAM;GAC5B,MAAM;GACN,MAAM;GACN,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAEF,OAAK,aAAa,IAAIA,kBAAM;GAC1B,MAAM;GACN,MAAM;GACN,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAGF,OAAK,SAAS,IAAID,oBAAQ;GACxB,MAAM;GACN,MAAM;GACN,YAAY,CAAC,OAAO;GACpB,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAEF,OAAK,YAAY,IAAIA,oBAAQ;GAC3B,MAAM;GACN,MAAM;GACN,WAAW,CAAC,KAAK,SAAS;GAC3B,CAAC;AAEF,OAAK,iBAAiB,IAAIA,oBAAQ;GAChC,MAAM;GACN,MAAM;GACN,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Histogram"],"sources":["../../src/metrics/index.ts"],"sourcesContent":["/**\n * Prometheus metrics for monitoring indexer performance and health\n * Exposes metrics for blocks indexed, queue depth, errors, and processing times\n */\n\nimport {\n collectDefaultMetrics, Counter, Gauge, Histogram, Registry,\n} from \"prom-client\";\n\n/** Prometheus metrics registry */\nexport class IndexerMetrics {\n /** Prometheus registry instance */\n public readonly registry: Registry;\n\n /** Counter for total blocks indexed */\n public readonly blocksIndexed: Counter;\n\n /** Gauge for current block height */\n public readonly currentHeight: Gauge;\n\n /** Gauge for latest chain block height */\n public readonly latestHeight: Gauge;\n\n /** Gauge for blocks behind chain tip */\n public readonly blocksBehind: Gauge;\n\n /** Gauge for block queue depth */\n public readonly queueDepth: Gauge;\n\n /** Counter for total errors */\n public readonly errors: Counter;\n\n /** Counter for RPC errors */\n public readonly rpcErrors: Counter;\n\n /** Counter for database errors */\n public readonly databaseErrors: Counter;\n\n /** Histogram for block processing duration */\n public readonly blockProcessingDuration: Histogram;\n\n /** Histogram for RPC call duration */\n public readonly rpcCallDuration: Histogram;\n\n /** Histogram for database query duration */\n public readonly databaseQueryDuration: Histogram;\n\n /** Gauge for retry count */\n public readonly retryCount: Gauge;\n\n /** Counter for total transactions processed */\n public readonly transactionsProcessed: Counter;\n\n constructor() {\n this.registry = new Registry();\n\n // Collect default Node.js metrics (memory, CPU, etc.)\n collectDefaultMetrics({\n register: this.registry,\n });\n\n // Block indexing metrics\n this.blocksIndexed = new Counter({\n name: \"indexer_blocks_indexed_total\",\n help: \"Total number of blocks indexed\",\n registers: [this.registry],\n });\n\n this.currentHeight = new Gauge({\n name: \"indexer_current_height\",\n help: \"Current block height being processed\",\n registers: [this.registry],\n });\n\n this.latestHeight = new Gauge({\n name: \"indexer_latest_chain_height\",\n help: \"Latest block height on the chain\",\n registers: [this.registry],\n });\n\n this.blocksBehind = new Gauge({\n name: \"indexer_blocks_behind\",\n help: \"Number of blocks behind chain tip\",\n registers: [this.registry],\n });\n\n this.queueDepth = new Gauge({\n name: \"indexer_queue_depth\",\n help: \"Current depth of block processing queue\",\n registers: [this.registry],\n });\n\n // Error metrics\n this.errors = new Counter({\n name: \"indexer_errors_total\",\n help: \"Total number of indexer errors\",\n labelNames: [\"type\"],\n registers: [this.registry],\n });\n\n this.rpcErrors = new Counter({\n name: \"indexer_rpc_errors_total\",\n help: \"Total number of RPC errors\",\n registers: [this.registry],\n });\n\n this.databaseErrors = new Counter({\n name: \"indexer_database_errors_total\",\n help: \"Total number of database errors\",\n registers: [this.registry],\n });\n\n // Performance metrics\n this.blockProcessingDuration = new Histogram({\n name: \"indexer_block_processing_duration_seconds\",\n help: \"Time spent processing a single block\",\n buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2, 5],\n registers: [this.registry],\n });\n\n this.rpcCallDuration = new Histogram({\n name: \"indexer_rpc_call_duration_seconds\",\n help: \"Duration of RPC calls\",\n buckets: [0.01, 0.05, 0.1, 0.5, 1, 2, 5, 10],\n labelNames: [\"method\"],\n registers: [this.registry],\n });\n\n this.databaseQueryDuration = new Histogram({\n name: \"indexer_database_query_duration_seconds\",\n help: \"Duration of database queries\",\n buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1],\n labelNames: [\"query_type\"],\n registers: [this.registry],\n });\n\n // Operational metrics\n this.retryCount = new Gauge({\n name: \"indexer_retry_count\",\n help: \"Current number of retry attempts\",\n registers: [this.registry],\n });\n\n this.transactionsProcessed = new Counter({\n name: \"indexer_transactions_processed_total\",\n help: \"Total number of transactions processed\",\n registers: [this.registry],\n });\n }\n\n /**\n * Updates block indexing metrics\n * @param currentHeight - Current height being processed\n * @param latestHeight - Latest height on chain\n * @param queueSize - Current queue depth\n */\n updateBlockMetrics(currentHeight: number, latestHeight: number, queueSize: number) {\n this.blocksIndexed.inc();\n this.currentHeight.set(currentHeight);\n this.latestHeight.set(latestHeight);\n this.blocksBehind.set(latestHeight - currentHeight);\n this.queueDepth.set(queueSize);\n }\n\n /**\n * Records an error occurrence\n * @param type - Error type (rpc, database, processing, etc.)\n */\n recordError(type: string) {\n this.errors.inc({\n type,\n });\n\n if (type === \"rpc\") {\n this.rpcErrors.inc();\n }\n else if (type === \"database\") {\n this.databaseErrors.inc();\n }\n }\n\n /**\n * Records block processing duration\n * @param durationSeconds - Duration in seconds\n */\n recordBlockProcessing(durationSeconds: number) {\n this.blockProcessingDuration.observe(durationSeconds);\n }\n\n /**\n * Times a block processing operation\n * @returns End timer function to call when operation completes\n */\n timeBlockProcessing() {\n return this.blockProcessingDuration.startTimer();\n }\n\n /**\n * Records RPC call duration\n * @param method - RPC method name\n * @param durationSeconds - Duration in seconds\n */\n recordRpcCall(method: string, durationSeconds: number) {\n this.rpcCallDuration.observe({\n method,\n }, durationSeconds);\n }\n\n /**\n * Times an RPC call operation\n * @param method - RPC method name\n * @returns End timer function to call when operation completes\n */\n timeRpcCall(method: string) {\n return this.rpcCallDuration.startTimer({\n method,\n });\n }\n\n /**\n * Records database query duration\n * @param queryType - Type of query (select, insert, update, delete, etc.)\n * @param durationSeconds - Duration in seconds\n */\n recordDatabaseQuery(queryType: string, durationSeconds: number) {\n this.databaseQueryDuration.observe({\n query_type: queryType,\n }, durationSeconds);\n }\n\n /**\n * Times a database query operation\n * @param queryType - Type of query (select, insert, update, delete, etc.)\n * @returns End timer function to call when operation completes\n */\n timeDatabaseQuery(queryType: string) {\n return this.databaseQueryDuration.startTimer({\n query_type: queryType,\n });\n }\n\n /**\n * Updates the retry count gauge\n * @param count - Current retry count\n */\n updateRetryCount(count: number) {\n this.retryCount.set(count);\n }\n\n /**\n * Increments the retry count gauge by 1\n */\n incrementRetryCount() {\n this.retryCount.inc();\n }\n\n /**\n * Resets the retry count gauge to 0\n */\n resetRetryCount() {\n this.retryCount.set(0);\n }\n\n /**\n * Records transactions processed\n * @param count - Number of transactions to record (defaults to 1)\n */\n recordTransactions(count: number = 1) {\n this.transactionsProcessed.inc(count);\n }\n\n /**\n * Gets metrics in Prometheus format\n * @returns Prometheus metrics string\n */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EAAE,gBAAgB;;;;;;;CAQrB,kBAAkB,WAAmB;AACnC,SAAO,KAAK,sBAAsB,WAAW,EAC3C,YAAY,WACb,CAAC;;;;;;CAOJ,iBAAiB,OAAe;AAC9B,OAAK,WAAW,IAAI,MAAM;;;;;CAM5B,sBAAsB;AACpB,OAAK,WAAW,KAAK;;;;;CAMvB,kBAAkB;AAChB,OAAK,WAAW,IAAI,EAAE;;;;;;CAOxB,mBAAmB,QAAgB,GAAG;AACpC,OAAK,sBAAsB,IAAI,MAAM;;;;;;CAOvC,MAAM,aAA8B;AAClC,SAAO,KAAK,SAAS,SAAS"}
|
package/dist/metrics/index.d.cts
CHANGED
|
@@ -45,6 +45,58 @@ declare class IndexerMetrics {
|
|
|
45
45
|
* @param type - Error type (rpc, database, processing, etc.)
|
|
46
46
|
*/
|
|
47
47
|
recordError(type: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Records block processing duration
|
|
50
|
+
* @param durationSeconds - Duration in seconds
|
|
51
|
+
*/
|
|
52
|
+
recordBlockProcessing(durationSeconds: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Times a block processing operation
|
|
55
|
+
* @returns End timer function to call when operation completes
|
|
56
|
+
*/
|
|
57
|
+
timeBlockProcessing(): (labels?: Partial<Record<string, string | number>> | undefined) => number;
|
|
58
|
+
/**
|
|
59
|
+
* Records RPC call duration
|
|
60
|
+
* @param method - RPC method name
|
|
61
|
+
* @param durationSeconds - Duration in seconds
|
|
62
|
+
*/
|
|
63
|
+
recordRpcCall(method: string, durationSeconds: number): void;
|
|
64
|
+
/**
|
|
65
|
+
* Times an RPC call operation
|
|
66
|
+
* @param method - RPC method name
|
|
67
|
+
* @returns End timer function to call when operation completes
|
|
68
|
+
*/
|
|
69
|
+
timeRpcCall(method: string): (labels?: Partial<Record<string, string | number>> | undefined) => number;
|
|
70
|
+
/**
|
|
71
|
+
* Records database query duration
|
|
72
|
+
* @param queryType - Type of query (select, insert, update, delete, etc.)
|
|
73
|
+
* @param durationSeconds - Duration in seconds
|
|
74
|
+
*/
|
|
75
|
+
recordDatabaseQuery(queryType: string, durationSeconds: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* Times a database query operation
|
|
78
|
+
* @param queryType - Type of query (select, insert, update, delete, etc.)
|
|
79
|
+
* @returns End timer function to call when operation completes
|
|
80
|
+
*/
|
|
81
|
+
timeDatabaseQuery(queryType: string): (labels?: Partial<Record<string, string | number>> | undefined) => number;
|
|
82
|
+
/**
|
|
83
|
+
* Updates the retry count gauge
|
|
84
|
+
* @param count - Current retry count
|
|
85
|
+
*/
|
|
86
|
+
updateRetryCount(count: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* Increments the retry count gauge by 1
|
|
89
|
+
*/
|
|
90
|
+
incrementRetryCount(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Resets the retry count gauge to 0
|
|
93
|
+
*/
|
|
94
|
+
resetRetryCount(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Records transactions processed
|
|
97
|
+
* @param count - Number of transactions to record (defaults to 1)
|
|
98
|
+
*/
|
|
99
|
+
recordTransactions(count?: number): void;
|
|
48
100
|
/**
|
|
49
101
|
* Gets metrics in Prometheus format
|
|
50
102
|
* @returns Prometheus metrics string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/metrics/index.ts"],"sourcesContent":[],"mappings":";;;;;AAeiC,cALpB,cAAA,CAKoB;;WAMD,QAAA,EATJ,QASI;;WAMF,aAAA,EAZG,OAYH;;WAMD,aAAA,EAfI,KAeJ;;WAMc,YAAA,EAlBX,KAkBW;;WAMF,YAAA,EArBT,KAqBS;;WAMA,UAAA,EAxBX,KAwBW;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/metrics/index.ts"],"sourcesContent":[],"mappings":";;;;;AAeiC,cALpB,cAAA,CAKoB;;WAMD,QAAA,EATJ,QASI;;WAMF,aAAA,EAZG,OAYH;;WAMD,aAAA,EAfI,KAeJ;;WAMc,YAAA,EAlBX,KAkBW;;WAMF,YAAA,EArBT,KAqBS;;WAMA,UAAA,EAxBX,KAwBW;;WA8IpB,MAAA,EAnKK,OAmKL;;WAoBO,SAAA,EApLC,OAoLD;;WAsBS,cAAA,EAvMH,OAuMG;;EAwCR,SAAA,uBAAA,EA5Oc,SA4Od;;4BAzOM;;kCAGM;;uBAGX;;kCAGW;;;;;;;;;;;;;;;;;;;;;;;mCA8IpB,QAAA;;;;;;;;;;;;yCAoBO,QAAA;;;;;;;;;;;;kDAsBS,QAAA;;;;;;;;;;;;;;;;;;;;;;;gBAwCf"}
|