import { IndexerMetrics } from "../metrics/index.mjs"; import { EclesiaIndexerConfig, EmitFunc, WithHeightAndUUID } from "../types/index.mjs"; import { EclesiaEmitter } from "../emitter/index.mjs"; import { CometClient } from "@cosmjs/tendermint-rpc"; import * as winston from "winston"; //#region src/indexer/index.d.ts /** Default configuration for the Eclesia indexer */ declare const defaultIndexerConfig: { startHeight: number; batchSize: number; modules: never[]; getNextHeight: () => number; logLevel: EclesiaIndexerConfig["logLevel"]; usePolling: boolean; pollingInterval: number; shouldProcessGenesis: () => boolean; minimal: boolean; enableHealthcheck: boolean; healthCheckPort: number; enablePrometheus: boolean; prometheusPort: number; init: () => Promise; beginTransaction: () => Promise; endTransaction: (_status: boolean) => Promise; }; /** * Core blockchain indexer that connects to Tendermint RPC and processes blocks * Extends EclesiaEmitter to provide event-driven architecture for modules */ declare class EclesiaIndexer extends EclesiaEmitter { /** Indexer configuration settings */ config: EclesiaIndexerConfig; /** Fastify HTTP server for health checks */ private fastify; /** Prometheus HTTP server instance */ private prometheusServer; /** Indicates if the indexer has started */ private started; /** Queue for managing block processing pipeline */ private blockQueue; /** Latest block height from the chain */ private latestHeight; /** Next block height to process */ heightToProcess: number; /** Whether the indexer has been initialized */ private initialized; /** Prometheus metrics server instance */ prometheus: IndexerMetrics | null; /** Number of retry attempts for error recovery */ private retryCount; /** CometBFT client for ad-hoc queries */ client: CometClient; /** CometBFT client for block and validator queries */ blockClient: CometClient; /** Winston logger instance */ log: winston.Logger; /** Flag indicating if indexer should attempt recovery */ private tryToRecover; /** Health check status for monitoring */ private healthCheck; /** WebSocket subscription for new block notifications */ private subscription; /** Timeout handler for block reception */ private blockTimeout; /** Timer for the next poll in polling mode */ private pollTimer; /** Bumped on every (re)start and stop so a polling chain from a previous run exits */ private pollGeneration; /** Bumped on every start() so callbacks left over from a previous run cannot trigger recovery in this one */ private runGeneration; /** * Rejecters of waits parked in waitForBlockData(). Each entry is removed as soon as its block * arrives, so a healthy run keeps this empty instead of accumulating one entry per block. */ private blockWaiters; /** Pending restart timer */ private retryTimer; /** Resolves when the indexer has stopped for good: stop() was called, endHeight was reached, or it gave up */ private stopped; private resolveStopped; /** Next height the fetcher will request; advances as fetches are enqueued */ private nextFetchHeight; /** Whether a fetcher loop is active, and for which run */ private fetcherRunning; private fetcherGeneration; private fetcherToken; /** Height of the block whose processing failed most recently, and how many times in a row */ private lastFailedHeight; private sameHeightFailures; /** * Creates a new Eclesia indexer instance * @param config - Indexer configuration options */ constructor(config: EclesiaIndexerConfig); private setStatus; /** * Marks the current run for recovery and wakes the main loop if it is parked waiting for a * block. Callbacks left over from a previous run pass their generation and are ignored. */ private requestRecovery; /** Rejects every wait parked in waitForBlockData() */ private wakeBlockWaiters; /** * Refuses to index a chain other than the configured one. An RPC pool that mixes networks, or * a wrong URL, would otherwise write a different chain's blocks into the database. */ private assertChainId; /** Counts consecutive processing failures per block height */ private noteBlockFailure; /** True once one block has failed maxFailuresPerBlock times in a row */ private isStuck; /** * Waits for the next dequeued block but wakes early when recovery or stop is requested, so a * loop parked on an empty queue never waits for a block that will not come. */ private waitForBlockData; /** (Re)arms the idle check that runs when no block has been announced for a while */ private armIdleCheck; /** * Runs when no block has been announced for IDLE_CHECK_INTERVAL_MS. A chain that has stopped * producing blocks (halt, upgrade, slow chain) is not an error: the indexer reports WAITING and * checks again later. Recovery is requested only when the chain has moved on without us, which * means the subscription is dead, or when the RPC cannot be reached at all. */ private checkLiveness; /** * Builds the listener for one run's block subscription. It carries the generation it was * created for, so when a restart disconnects the previous client and that subscription * completes, the completion is attributed to the finished run and ignored instead of * poisoning the run that is starting. */ private makeBlockListener; /** Listener attached to the current block subscription */ private blockListener; private isMinimal; connect(): Promise; /** * Opens one CometBFT client with its own timeout. If the timeout wins, the client * that may still arrive is disconnected so a slow RPC never leaks a socket. */ private connectWithTimeout; private initialize; /** * Stops the indexer and releases everything that would keep the process alive: * the block subscription, polling and inactivity timers, both RPC clients and the * health and metrics servers. Safe to call more than once. */ stop(): Promise; private clearBlockQueue; private setupBlockListening; /** * Resolves once the indexer has stopped for good: stop() was called, endHeight was reached, or * a fatal-error was emitted. Restarts with backoff do not resolve it. Use it to keep a caller * waiting for the whole run rather than for the first loop exit. */ whenStopped(): Promise; start(): Promise; /** * Emits an event and waits for its handlers. Handlers run one after another in registration * order: they share one database connection and one transaction, so interleaving them at * await points would let two handlers read and write the same rows in an unpredictable order, * and a failure in one would leave the others mid-flight while the block is rolled back. The * first rejection propagates and stops the remaining handlers. */ asyncEmit: EmitFunc>; private processBlock; /** * Fetches every height from nextFetchHeight up to latestHeight, waiting for queue space * before each fetch. Serves the initial catch-up and live blocks alike: a new announcement * only moves latestHeight and starts this loop if it is not already running, so bursts and * skipped announcements are handled by the same code and the queue can never overflow. */ private fetcher; /** * Runs an ABCI query. A transport failure (RPC down, timeout, empty reply) requests a recovery. * A reply with a non-zero code is the chain answering "no" (pruned height, unknown path, bad * key): it is thrown as an RPCError with the code and log, and no recovery is requested for * ad-hoc queries, so modules can catch it. Block-pipeline queries reject into the fetcher, * which requests recovery itself. */ callABCI(path: string, data: Uint8Array, height?: number, adHoc?: boolean): Promise; /** * Fetches the complete validator set at a height, following pagination, and returns it * re-encoded as a single QueryValidatorsResponse so the block queue payload keeps its shape. * Chains with more validators than one page (1000) were silently truncated before. */ private fetchValidatorSet; private newBlockReceived; /** Starts a single polling chain, retiring any chain left over from a previous run */ private startPolling; private stopPolling; private pollForBlock; private readGenesis; private setArrayReader; private setValueReader; private parseGenesis; } /** @deprecated Misspelling kept for compatibility, use EclesiaIndexer. Removed in 3.0. */ declare const EcleciaIndexer: typeof EclesiaIndexer; /** @deprecated Misspelling kept for compatibility, use EclesiaIndexer. Removed in 3.0. */ type EcleciaIndexer = EclesiaIndexer; //#endregion export { EcleciaIndexer, EclesiaIndexer, defaultIndexerConfig }; //# sourceMappingURL=index.d.mts.map