@eclesia/indexer-engine 2.8.2 → 2.9.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.
Files changed (57) hide show
  1. package/dist/emitter/index.cjs +8 -0
  2. package/dist/emitter/index.cjs.map +1 -1
  3. package/dist/emitter/index.d.cts +12 -0
  4. package/dist/emitter/index.d.cts.map +1 -1
  5. package/dist/emitter/index.d.ts +12 -0
  6. package/dist/emitter/index.d.ts.map +1 -1
  7. package/dist/emitter/index.js +8 -0
  8. package/dist/emitter/index.js.map +1 -1
  9. package/dist/indexer/index.cjs +11 -2
  10. package/dist/indexer/index.cjs.map +1 -1
  11. package/dist/indexer/index.d.cts +23 -1
  12. package/dist/indexer/index.d.cts.map +1 -1
  13. package/dist/indexer/index.d.ts +23 -1
  14. package/dist/indexer/index.d.ts.map +1 -1
  15. package/dist/indexer/index.js +11 -2
  16. package/dist/indexer/index.js.map +1 -1
  17. package/dist/promise-queue/index.cjs +12 -1
  18. package/dist/promise-queue/index.cjs.map +1 -1
  19. package/dist/promise-queue/index.d.cts +26 -0
  20. package/dist/promise-queue/index.d.cts.map +1 -1
  21. package/dist/promise-queue/index.d.ts +26 -0
  22. package/dist/promise-queue/index.d.ts.map +1 -1
  23. package/dist/promise-queue/index.js +12 -1
  24. package/dist/promise-queue/index.js.map +1 -1
  25. package/dist/types/index.cjs.map +1 -1
  26. package/dist/types/index.d.cts +8 -1
  27. package/dist/types/index.d.cts.map +1 -1
  28. package/dist/types/index.d.ts +8 -1
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/index.js.map +1 -1
  31. package/dist/utils/bech32.cjs +17 -0
  32. package/dist/utils/bech32.cjs.map +1 -1
  33. package/dist/utils/bech32.d.cts +17 -0
  34. package/dist/utils/bech32.d.cts.map +1 -1
  35. package/dist/utils/bech32.d.ts +17 -0
  36. package/dist/utils/bech32.d.ts.map +1 -1
  37. package/dist/utils/bech32.js +17 -0
  38. package/dist/utils/bech32.js.map +1 -1
  39. package/dist/utils/bigint.cjs +6 -0
  40. package/dist/utils/bigint.cjs.map +1 -1
  41. package/dist/utils/bigint.d.cts +6 -0
  42. package/dist/utils/bigint.d.cts.map +1 -1
  43. package/dist/utils/bigint.d.ts +6 -0
  44. package/dist/utils/bigint.d.ts.map +1 -1
  45. package/dist/utils/bigint.js +6 -0
  46. package/dist/utils/bigint.js.map +1 -1
  47. package/dist/utils/index.cjs.map +1 -1
  48. package/dist/utils/index.js.map +1 -1
  49. package/dist/utils/text.cjs +6 -0
  50. package/dist/utils/text.cjs.map +1 -1
  51. package/dist/utils/text.d.cts +6 -0
  52. package/dist/utils/text.d.cts.map +1 -1
  53. package/dist/utils/text.d.ts +6 -0
  54. package/dist/utils/text.d.ts.map +1 -1
  55. package/dist/utils/text.js +6 -0
  56. package/dist/utils/text.js.map +1 -1
  57. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["uuidv4","hrTime","processStart: [number, number]","events: Array<{\n msg_index?: number\n events: Event[]\n }>","events","timeoutPromise: Promise<[BlockResponse, BlockResultsResponse]>","timeoutPromise: Promise<[BlockResponse, BlockResultsResponse, Uint8Array]>"],"sources":["../../src/indexer/index.ts"],"sourcesContent":["/* eslint-disable max-lines */\nimport {\n createHash,\n} from \"node:crypto\";\nimport * as fs from \"node:fs\";\n\nimport {\n BlockResponse, BlockResultsResponse, CometClient, toRfc3339WithNanoseconds,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n connectComet,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n Event,\n} from \"@cosmjs/tendermint-rpc\";\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 EclesiaEmitter,\n} from \"../emitter/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\";\n\nexport const defaultIndexerConfig = {\n startHeight: 1,\n batchSize: 500,\n modules: [],\n getNextHeight: () => 1,\n logLevel: \"info\" as EcleciaIndexerConfig[\"logLevel\"],\n usePolling: false,\n pollingInterval: 5000,\n processGenesis: false,\n minimal: true,\n init: () => Promise.resolve(),\n beginTransaction: () => Promise.resolve(),\n endTransaction: (_status: boolean) => Promise.resolve(),\n};\n\nexport class EcleciaIndexer extends EclesiaEmitter {\n private config: EcleciaIndexerConfig;\n\n private fastify: FastifyInstance;\n\n private blockQueue: BlockQueue;\n\n private latestHeight!: number;\n\n private heightToProcess!: number;\n\n private initialized = false;\n\n private retryCount = 0;\n\n public client!: CometClient;\n\n public blockClient!: CometClient;\n\n public log: winston.Logger;\n\n private tryToRecover: boolean = false;\n\n private healthCheck = {\n status: \"CONNECTING\",\n };\n\n private subscription: ReturnType<CometClient[\"subscribeNewBlock\"]> | null = null;\n\n constructor(config: EcleciaIndexerConfig) {\n super();\n this.config = {\n ...defaultIndexerConfig,\n ...config,\n };\n if (this.config.minimal) {\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse]>(this.config.batchSize);\n }\n else {\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>(this.config.batchSize);\n }\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 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 this.fastify.listen({\n port: 80,\n host: \"0.0.0.0\",\n },\n (err) => {\n if (err) {\n this.log.error(err);\n process.exit(1);\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 (this.config.processGenesis) {\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 this.subscription = this.client.subscribeNewBlock\n ? this.client.subscribeNewBlock()\n : null;\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 toProcess = await this.blockQueue.dequeue();\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 toProcess = await this.blockQueue.dequeue();\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 % 1000 == 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 % 100 == 0) {\n await this.asyncEmit(\"periodic/100\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n if (height % 50 == 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 process.exit(1);\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, 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 this.log.silly(\"Started db tx\");\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 // Deal with begin_block events first\n await this.asyncEmit(\"begin_block\",\n {\n value: {\n events: block_results.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 const events: Array<{\n msg_index?: number\n events: Event[]\n }> = txlog\n ? JSON.parse(txlog)\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[]);\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: block_results.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\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 20000,\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 20000,\n false);\n });\n const q = QueryValidatorsRequest.fromPartial({\n pagination: {\n limit: 1000n,\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 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\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 chain([\n this.readGenesis(),\n ...pickers,\n StreamArray.streamArray(),\n Batch.batch({\n batchSize: 1000,\n }),\n processor,\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`);\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;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0DA,MAAa,uBAAuB;CAClC,aAAa;CACb,WAAW;CACX,SAAS,EAAE;CACX,qBAAqB;CACrB,UAAU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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","hrTime","processStart: [number, number]","events: Array<{\n msg_index?: number\n events: Event[]\n }>","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, toRfc3339WithNanoseconds,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n connectComet,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n Event,\n} from \"@cosmjs/tendermint-rpc\";\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 EclesiaEmitter,\n} from \"../emitter/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\";\n\n/** Default configuration for the Eclesia indexer */\nexport const defaultIndexerConfig = {\n startHeight: 1, // Start indexing from block 1\n batchSize: 500, // Process blocks in batches of 500\n modules: [], // No modules enabled by default\n getNextHeight: () => 1, // Default height retrieval function\n logLevel: \"info\" as EcleciaIndexerConfig[\"logLevel\"], // Default log level\n usePolling: false, // Use WebSocket subscription by default\n pollingInterval: 5000, // Poll every 5 seconds when polling enabled\n shouldProcessGenesis: () => false, // Skip genesis processing by default\n minimal: true, // Use minimal indexing by default\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 /** 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 /** 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 this.config = {\n ...defaultIndexerConfig,\n ...config,\n };\n\n // Initialize block queue based on minimal or full indexing mode\n if (this.config.minimal) {\n // Minimal mode: only store block and block results\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse]>(this.config.batchSize);\n }\n else {\n // Full mode: also store validator information\n this.blockQueue = new CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>(this.config.batchSize);\n }\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 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 this.fastify.listen({\n port: 80,\n host: \"0.0.0.0\",\n },\n (err) => {\n if (err) {\n this.log.error(err);\n process.exit(1);\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 this.subscription = this.client.subscribeNewBlock\n ? this.client.subscribeNewBlock()\n : null;\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 toProcess = await this.blockQueue.dequeue();\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 toProcess = await this.blockQueue.dequeue();\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 % 1000 == 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 % 100 == 0) {\n await this.asyncEmit(\"periodic/100\",\n {\n value: null,\n height,\n timestamp,\n });\n }\n if (height % 50 == 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 process.exit(1);\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, 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 this.log.silly(\"Started db tx\");\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 // Deal with begin_block events first\n await this.asyncEmit(\"begin_block\",\n {\n value: {\n events: block_results.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 const events: Array<{\n msg_index?: number\n events: Event[]\n }> = txlog\n ? JSON.parse(txlog)\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[]);\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: block_results.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\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 20000,\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 20000,\n false);\n });\n const q = QueryValidatorsRequest.fromPartial({\n pagination: {\n limit: 1000n,\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 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\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 chain([\n this.readGenesis(),\n ...pickers,\n StreamArray.streamArray(),\n Batch.batch({\n batchSize: 1000,\n }),\n processor,\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`);\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;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4DA,MAAa,uBAAuB;CAClC,aAAa;CACb,WAAW;CACX,SAAS,EAAE;CACX,qBAAqB;CACrB,UAAU;CACV,YAAY;CACZ,iBAAiB;CACjB,4BAA4B;CAC5B,SAAS;CACT,YAAY,QAAQ,SAAS;CAC7B,wBAAwB,QAAQ,SAAS;CACzC,iBAAiB,YAAqB,QAAQ,SAAS;CACxD;;;;;AAMD,IAAa,iBAAb,cAAoC,eAAe;;;;;CA8CjD,YAAY,QAA8B;AACxC,SAAO;OA9BD,cAAc;OAGd,aAAa;OAYb,eAAwB;OAGxB,cAAc,EACpB,QAAQ,cACT;OAGO,eAAoE;OA2FpE,gBAAgB,EACtB,OAAO,SAID;AACJ,QAAK,iBAAiB,KAAK,OAAO,OAAO;KAE5C;OA6MM,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;;AAlVP,OAAK,SAAS;GACZ,GAAG;GACH,GAAG;GACJ;AAGD,MAAI,KAAK,OAAO,QAEd,MAAK,aAAa,IAAI,eAAsD,KAAK,OAAO,UAAU;MAIlG,MAAK,aAAa,IAAI,eAAkE,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I,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,5 +1,11 @@
1
1
 
2
2
  //#region src/promise-queue/index.ts
3
+ /**
4
+ * Implements an "infinite" FIFO queue of fixed size using promises
5
+ * - await `continue()` before enqueing items to ensure fixed size (resolves when space available)
6
+ * - await `dequeue()` to pop an item (resolves when next item is available)
7
+ * - size() is always at minimum 1 item which is the promise for the next enqueued item
8
+ */
3
9
  var PromiseQueue = class {
4
10
  constructor(batchSize) {
5
11
  this.synced = false;
@@ -56,6 +62,11 @@ var PromiseQueue = class {
56
62
  return this.items.length;
57
63
  }
58
64
  };
65
+ /**
66
+ * Circular buffer implementation using promises for efficient memory usage
67
+ * Reuses array slots in a circular fashion to maintain constant memory footprint
68
+ * Used by the indexer for managing block processing queues
69
+ */
59
70
  var CircularBuffer = class {
60
71
  constructor(batchSize) {
61
72
  this.count = 0;
@@ -99,7 +110,7 @@ var CircularBuffer = class {
99
110
  this.next++;
100
111
  this.count--;
101
112
  if (this.next >= this.batchSize) this.next = 0;
102
- if (this.count < this.batchSize) this.batcher(true);
113
+ if (this.count <= this.batchSize) this.batcher(true);
103
114
  return item;
104
115
  }
105
116
  clear() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":["/*\n *This implements an \"infinite\" FIFO queue of fixed size.\n *await `continue()` before enqueing items to ensure fixed size (as it only resolves when space available)\n *await `dequeue()` to pop an item as it will only resolve if the next item is available\n *size() is always at minimum 1 item which is the promise that will resolve to the next item whenever it is enqueued\n */\n\nexport class PromiseQueue<T> {\n private items: Array<Promise<T>>;\n\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n private batcher!: (val: boolean) => void;\n\n public synced = false;\n\n private batchSize: number;\n\n private continuePromise: Promise<boolean>;\n\n constructor(batchSize: number) {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.batchSize = batchSize;\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items.push(nextVal);\n if (this.size() > this.batchSize) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n clear() {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n dequeue() {\n const item = this.items.shift();\n if (this.size() <= this.batchSize) {\n this.batcher(true);\n }\n\n return item as Promise<T>;\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.items.length == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.items.length;\n }\n}\n\nexport class CircularBuffer<T> {\n private items: Array<Promise<T>>;\n\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n private count: number = 0;\n\n private next: number = 0;\n\n private batcher!: (val: boolean) => void;\n\n public synced = false;\n\n private batchSize: number;\n\n private continuePromise: Promise<boolean>;\n\n private nextAvail: number = 0;\n\n constructor(batchSize: number) {\n if (batchSize <= 1) {\n throw new Error(\"Batch size must be greater than 1\");\n }\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(batchSize);\n this.batchSize = batchSize;\n this.items[this.nextAvail] = nextVal;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items[this.nextAvail] = nextVal;\n this.count++;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n if (this.nextAvail == this.next) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n dequeue() {\n const item = this.items[this.next];\n this.next++;\n this.count--;\n if (this.next >= this.batchSize) {\n this.next = 0;\n }\n if (this.count < this.batchSize) {\n this.batcher(true);\n }\n return item;\n }\n\n clear() {\n this.next = 0;\n this.nextAvail = 0;\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(this.batchSize);\n this.items[this.nextAvail] = nextVal;\n this.synced = false;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.count == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.count;\n }\n}\n"],"mappings":";;AAOA,IAAa,eAAb,MAA6B;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B,WAAW;AACT,SAAO,KAAK;;CAGd,YAAY;AACV,OAAK,SAAS;;CAGhB,UAAU;AACR,MAAI,KAAK,SAAS,EAChB,QAAO;MAGP,QAAO;;CAIX,OAAO;AACL,SAAO,KAAK"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":["/**\n * Implements an \"infinite\" FIFO queue of fixed size using promises\n * - await `continue()` before enqueing items to ensure fixed size (resolves when space available)\n * - await `dequeue()` to pop an item (resolves when next item is available)\n * - size() is always at minimum 1 item which is the promise for the next enqueued item\n */\nexport class PromiseQueue<T> {\n /** Array of promises representing queued items */\n private items: Array<Promise<T>>;\n\n /** Function to resolve the next enqueued promise */\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n /** Function to resolve the continue promise when space is available */\n private batcher!: (val: boolean) => void;\n\n /** Flag indicating if the queue is synced with the data source */\n public synced = false;\n\n /** Maximum number of items to keep in the queue */\n private batchSize: number;\n\n /** Promise that resolves when it's safe to enqueue more items */\n private continuePromise: Promise<boolean>;\n\n constructor(batchSize: number) {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.batchSize = batchSize;\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items.push(nextVal);\n if (this.size() > this.batchSize) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n clear() {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n dequeue() {\n const item = this.items.shift();\n if (this.size() <= this.batchSize) {\n this.batcher(true);\n }\n\n return item as Promise<T>;\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.items.length == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.items.length;\n }\n}\n\n/**\n * Circular buffer implementation using promises for efficient memory usage\n * Reuses array slots in a circular fashion to maintain constant memory footprint\n * Used by the indexer for managing block processing queues\n */\nexport class CircularBuffer<T> {\n /** Fixed-size array of promises representing buffered items */\n private items: Array<Promise<T>>;\n\n /** Function to resolve the next enqueued promise */\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n /** Current number of items in the buffer */\n private count: number = 0;\n\n /** Index of the next item to dequeue */\n private next: number = 0;\n\n /** Function to resolve the continue promise when space is available */\n private batcher!: (val: boolean) => void;\n\n /** Flag indicating if the buffer is synced with the data source */\n public synced = false;\n\n /** Maximum number of items the buffer can hold */\n private batchSize: number;\n\n /** Promise that resolves when it's safe to enqueue more items */\n private continuePromise: Promise<boolean>;\n\n /** Index of the next available slot for enqueueing */\n private nextAvail: number = 0;\n\n constructor(batchSize: number) {\n if (batchSize <= 1) {\n throw new Error(\"Batch size must be greater than 1\");\n }\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(batchSize);\n this.batchSize = batchSize;\n this.items[this.nextAvail] = nextVal;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items[this.nextAvail] = nextVal;\n this.count++;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n if (this.nextAvail == this.next) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n dequeue() {\n const item = this.items[this.next];\n this.next++;\n this.count--;\n if (this.next >= this.batchSize) {\n this.next = 0;\n }\n if (this.count <= this.batchSize) {\n this.batcher(true);\n }\n return item;\n }\n\n clear() {\n this.next = 0;\n this.nextAvail = 0;\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(this.batchSize);\n this.items[this.nextAvail] = nextVal;\n this.synced = false;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.count == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.count;\n }\n}\n"],"mappings":";;;;;;;;AAMA,IAAa,eAAb,MAA6B;CAmB3B,YAAY,WAAmB;OARxB,SAAS;EASd,MAAM,UAAU,IAAI,SAAY,SAAS,YAAY;AACnD,QAAK,WAAW;IAChB;AACF,OAAK,YAAY;AACjB,OAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,QAAK,UAAU;IACf;AACF,OAAK,QAAQ,KAAK;AAClB,OAAK,QAAQ,CAAC,QAAQ;;CAGxB,QAAQ,MAA0B;AAChC,MAAI;AACF,QAAK,SAAS,KAAK;GACnB,MAAM,UAAU,IAAI,SAAY,SAAS,YAAY;AACnD,SAAK,WAAW;KAChB;AACF,QAAK,MAAM,KAAK,QAAQ;AACxB,OAAI,KAAK,MAAM,GAAG,KAAK,UACrB,MAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,SAAK,UAAU;KACf;WAGC,GAAG;AACR,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AAGnB,OAAI,KAAK,aAAa,KAAK,KACzB,MAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,SAAK,UAAU;KACf;WAGC,GAAG;AACR,WAAQ,MAAM,6BAA6B,EAAE;;;CAIjD,UAAU;EACR,MAAM,OAAO,KAAK,MAAM,KAAK;AAC7B,OAAK;AACL,OAAK;AACL,MAAI,KAAK,QAAQ,KAAK,UACpB,MAAK,OAAO;AAEd,MAAI,KAAK,SAAS,KAAK,UACrB,MAAK,QAAQ,KAAK;AAEpB,SAAO;;CAGT,QAAQ;AACN,OAAK,OAAO;AACZ,OAAK,YAAY;EACjB,MAAM,UAAU,IAAI,SAAY,SAAS,YAAY;AACnD,QAAK,WAAW;IAChB;AACF,OAAK,QAAQ,IAAI,MAAkB,KAAK,UAAU;AAClD,OAAK,MAAM,KAAK,aAAa;AAC7B,OAAK,SAAS;AACd,OAAK,QAAQ;AACb,OAAK;AACL,MAAI,KAAK,aAAa,KAAK,UACzB,MAAK,YAAY;AAGnB,OAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,QAAK,UAAU;IACf;AACF,OAAK,QAAQ,KAAK;;CAGpB,WAAW;AACT,SAAO,KAAK;;CAGd,YAAY;AACV,OAAK,SAAS;;CAGhB,UAAU;AACR,MAAI,KAAK,SAAS,EAChB,QAAO;MAGP,QAAO;;CAIX,OAAO;AACL,SAAO,KAAK"}
@@ -1,10 +1,22 @@
1
1
  //#region src/promise-queue/index.d.ts
2
+ /**
3
+ * Implements an "infinite" FIFO queue of fixed size using promises
4
+ * - await `continue()` before enqueing items to ensure fixed size (resolves when space available)
5
+ * - await `dequeue()` to pop an item (resolves when next item is available)
6
+ * - size() is always at minimum 1 item which is the promise for the next enqueued item
7
+ */
2
8
  declare class PromiseQueue<T> {
9
+ /** Array of promises representing queued items */
3
10
  private items;
11
+ /** Function to resolve the next enqueued promise */
4
12
  private enqueuer;
13
+ /** Function to resolve the continue promise when space is available */
5
14
  private batcher;
15
+ /** Flag indicating if the queue is synced with the data source */
6
16
  synced: boolean;
17
+ /** Maximum number of items to keep in the queue */
7
18
  private batchSize;
19
+ /** Promise that resolves when it's safe to enqueue more items */
8
20
  private continuePromise;
9
21
  constructor(batchSize: number);
10
22
  enqueue(item: T | PromiseLike<T>): void;
@@ -15,15 +27,29 @@ declare class PromiseQueue<T> {
15
27
  isEmpty(): boolean;
16
28
  size(): number;
17
29
  }
30
+ /**
31
+ * Circular buffer implementation using promises for efficient memory usage
32
+ * Reuses array slots in a circular fashion to maintain constant memory footprint
33
+ * Used by the indexer for managing block processing queues
34
+ */
18
35
  declare class CircularBuffer<T> {
36
+ /** Fixed-size array of promises representing buffered items */
19
37
  private items;
38
+ /** Function to resolve the next enqueued promise */
20
39
  private enqueuer;
40
+ /** Current number of items in the buffer */
21
41
  private count;
42
+ /** Index of the next item to dequeue */
22
43
  private next;
44
+ /** Function to resolve the continue promise when space is available */
23
45
  private batcher;
46
+ /** Flag indicating if the buffer is synced with the data source */
24
47
  synced: boolean;
48
+ /** Maximum number of items the buffer can hold */
25
49
  private batchSize;
50
+ /** Promise that resolves when it's safe to enqueue more items */
26
51
  private continuePromise;
52
+ /** Index of the next available slot for enqueueing */
27
53
  private nextAvail;
28
54
  constructor(batchSize: number);
29
55
  enqueue(item: T | PromiseLike<T>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":[],"mappings":";cAOa;EAAA,QAAA,KAAA;EAAY,QAAA,QAAA;UAyBT,OAAA;QAAgB,EAAA,OAAA;UAAZ,SAAA;UAmCO,eAAA;aAAR,CAAA,SAAA,EAAA,MAAA;SAGT,CAAA,IAAA,EAtCM,CAsCN,GAtCU,WAsCV,CAtCsB,CAsCtB,CAAA,CAAA,EAAA,IAAA;EAAA,KAAA,CAAA,CAAA,EAAA,IAAA;EAsBG,OAAA,CAAA,CAAA,EAzBM,OAyBQ,CAzBA,CAyBA,CAAA;EAAA,QAAA,CAAA,CAAA,EAtBjB,OAsBiB,CAAA,OAAA,CAAA;WAyCX,CAAA,CAAA,EAAA,IAAA;SAAgB,CAAA,CAAA,EAAA,OAAA;MAAZ,CAAA,CAAA,EAAA,MAAA;;AAwBX,cAjEI,cAiEJ,CAAA,CAAA,CAAA,CAAA;UAkCC,KAAA;EAAA,QAAA,QAAA;;;;;;;;;gBA1DM,IAAI,YAAY;aAwBvB,QAAA;;cAkCC"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;;AAkE2B,cAlEd,YAkEc,CAAA,CAAA,CAAA,CAAA;;UAGjB,KAAA;EAAA;EA2BG,QAAA,QAAA;EAAc;UAkDX,OAAA;;QAAI,EAAA,OAAA;;UAwBX,SAAA;;EAkCC,QAAA,eAAA;;gBA7KM,IAAI,YAAY;;aAmCb,QAAQ;cAGjB;;;;;;;;;;cA2BG;;;;;;;;;;;;;;;;;;;;gBAkDG,IAAI,YAAY;aAwBvB,QAAA;;cAkCC"}
@@ -1,10 +1,22 @@
1
1
  //#region src/promise-queue/index.d.ts
2
+ /**
3
+ * Implements an "infinite" FIFO queue of fixed size using promises
4
+ * - await `continue()` before enqueing items to ensure fixed size (resolves when space available)
5
+ * - await `dequeue()` to pop an item (resolves when next item is available)
6
+ * - size() is always at minimum 1 item which is the promise for the next enqueued item
7
+ */
2
8
  declare class PromiseQueue<T> {
9
+ /** Array of promises representing queued items */
3
10
  private items;
11
+ /** Function to resolve the next enqueued promise */
4
12
  private enqueuer;
13
+ /** Function to resolve the continue promise when space is available */
5
14
  private batcher;
15
+ /** Flag indicating if the queue is synced with the data source */
6
16
  synced: boolean;
17
+ /** Maximum number of items to keep in the queue */
7
18
  private batchSize;
19
+ /** Promise that resolves when it's safe to enqueue more items */
8
20
  private continuePromise;
9
21
  constructor(batchSize: number);
10
22
  enqueue(item: T | PromiseLike<T>): void;
@@ -15,15 +27,29 @@ declare class PromiseQueue<T> {
15
27
  isEmpty(): boolean;
16
28
  size(): number;
17
29
  }
30
+ /**
31
+ * Circular buffer implementation using promises for efficient memory usage
32
+ * Reuses array slots in a circular fashion to maintain constant memory footprint
33
+ * Used by the indexer for managing block processing queues
34
+ */
18
35
  declare class CircularBuffer<T> {
36
+ /** Fixed-size array of promises representing buffered items */
19
37
  private items;
38
+ /** Function to resolve the next enqueued promise */
20
39
  private enqueuer;
40
+ /** Current number of items in the buffer */
21
41
  private count;
42
+ /** Index of the next item to dequeue */
22
43
  private next;
44
+ /** Function to resolve the continue promise when space is available */
23
45
  private batcher;
46
+ /** Flag indicating if the buffer is synced with the data source */
24
47
  synced: boolean;
48
+ /** Maximum number of items the buffer can hold */
25
49
  private batchSize;
50
+ /** Promise that resolves when it's safe to enqueue more items */
26
51
  private continuePromise;
52
+ /** Index of the next available slot for enqueueing */
27
53
  private nextAvail;
28
54
  constructor(batchSize: number);
29
55
  enqueue(item: T | PromiseLike<T>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":[],"mappings":";cAOa;EAAA,QAAA,KAAA;EAAY,QAAA,QAAA;UAyBT,OAAA;QAAgB,EAAA,OAAA;UAAZ,SAAA;UAmCO,eAAA;aAAR,CAAA,SAAA,EAAA,MAAA;SAGT,CAAA,IAAA,EAtCM,CAsCN,GAtCU,WAsCV,CAtCsB,CAsCtB,CAAA,CAAA,EAAA,IAAA;EAAA,KAAA,CAAA,CAAA,EAAA,IAAA;EAsBG,OAAA,CAAA,CAAA,EAzBM,OAyBQ,CAzBA,CAyBA,CAAA;EAAA,QAAA,CAAA,CAAA,EAtBjB,OAsBiB,CAAA,OAAA,CAAA;WAyCX,CAAA,CAAA,EAAA,IAAA;SAAgB,CAAA,CAAA,EAAA,OAAA;MAAZ,CAAA,CAAA,EAAA,MAAA;;AAwBX,cAjEI,cAiEJ,CAAA,CAAA,CAAA,CAAA;UAkCC,KAAA;EAAA,QAAA,QAAA;;;;;;;;;gBA1DM,IAAI,YAAY;aAwBvB,QAAA;;cAkCC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;;AAkE2B,cAlEd,YAkEc,CAAA,CAAA,CAAA,CAAA;;UAGjB,KAAA;EAAA;EA2BG,QAAA,QAAA;EAAc;UAkDX,OAAA;;QAAI,EAAA,OAAA;;UAwBX,SAAA;;EAkCC,QAAA,eAAA;;gBA7KM,IAAI,YAAY;;aAmCb,QAAQ;cAGjB;;;;;;;;;;cA2BG;;;;;;;;;;;;;;;;;;;;gBAkDG,IAAI,YAAY;aAwBvB,QAAA;;cAkCC"}
@@ -1,4 +1,10 @@
1
1
  //#region src/promise-queue/index.ts
2
+ /**
3
+ * Implements an "infinite" FIFO queue of fixed size using promises
4
+ * - await `continue()` before enqueing items to ensure fixed size (resolves when space available)
5
+ * - await `dequeue()` to pop an item (resolves when next item is available)
6
+ * - size() is always at minimum 1 item which is the promise for the next enqueued item
7
+ */
2
8
  var PromiseQueue = class {
3
9
  constructor(batchSize) {
4
10
  this.synced = false;
@@ -55,6 +61,11 @@ var PromiseQueue = class {
55
61
  return this.items.length;
56
62
  }
57
63
  };
64
+ /**
65
+ * Circular buffer implementation using promises for efficient memory usage
66
+ * Reuses array slots in a circular fashion to maintain constant memory footprint
67
+ * Used by the indexer for managing block processing queues
68
+ */
58
69
  var CircularBuffer = class {
59
70
  constructor(batchSize) {
60
71
  this.count = 0;
@@ -98,7 +109,7 @@ var CircularBuffer = class {
98
109
  this.next++;
99
110
  this.count--;
100
111
  if (this.next >= this.batchSize) this.next = 0;
101
- if (this.count < this.batchSize) this.batcher(true);
112
+ if (this.count <= this.batchSize) this.batcher(true);
102
113
  return item;
103
114
  }
104
115
  clear() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":["/*\n *This implements an \"infinite\" FIFO queue of fixed size.\n *await `continue()` before enqueing items to ensure fixed size (as it only resolves when space available)\n *await `dequeue()` to pop an item as it will only resolve if the next item is available\n *size() is always at minimum 1 item which is the promise that will resolve to the next item whenever it is enqueued\n */\n\nexport class PromiseQueue<T> {\n private items: Array<Promise<T>>;\n\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n private batcher!: (val: boolean) => void;\n\n public synced = false;\n\n private batchSize: number;\n\n private continuePromise: Promise<boolean>;\n\n constructor(batchSize: number) {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.batchSize = batchSize;\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items.push(nextVal);\n if (this.size() > this.batchSize) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n clear() {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n dequeue() {\n const item = this.items.shift();\n if (this.size() <= this.batchSize) {\n this.batcher(true);\n }\n\n return item as Promise<T>;\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.items.length == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.items.length;\n }\n}\n\nexport class CircularBuffer<T> {\n private items: Array<Promise<T>>;\n\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n private count: number = 0;\n\n private next: number = 0;\n\n private batcher!: (val: boolean) => void;\n\n public synced = false;\n\n private batchSize: number;\n\n private continuePromise: Promise<boolean>;\n\n private nextAvail: number = 0;\n\n constructor(batchSize: number) {\n if (batchSize <= 1) {\n throw new Error(\"Batch size must be greater than 1\");\n }\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(batchSize);\n this.batchSize = batchSize;\n this.items[this.nextAvail] = nextVal;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items[this.nextAvail] = nextVal;\n this.count++;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n if (this.nextAvail == this.next) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n dequeue() {\n const item = this.items[this.next];\n this.next++;\n this.count--;\n if (this.next >= this.batchSize) {\n this.next = 0;\n }\n if (this.count < this.batchSize) {\n this.batcher(true);\n }\n return item;\n }\n\n clear() {\n this.next = 0;\n this.nextAvail = 0;\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(this.batchSize);\n this.items[this.nextAvail] = nextVal;\n this.synced = false;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.count == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.count;\n }\n}\n"],"mappings":";AAOA,I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AAQ,KAAK;;CAGpB,WAAW;AACT,SAAO,KAAK;;CAGd,YAAY;AACV,OAAK,SAAS;;CAGhB,UAAU;AACR,MAAI,KAAK,SAAS,EAChB,QAAO;MAGP,QAAO;;CAIX,OAAO;AACL,SAAO,KAAK"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/promise-queue/index.ts"],"sourcesContent":["/**\n * Implements an \"infinite\" FIFO queue of fixed size using promises\n * - await `continue()` before enqueing items to ensure fixed size (resolves when space available)\n * - await `dequeue()` to pop an item (resolves when next item is available)\n * - size() is always at minimum 1 item which is the promise for the next enqueued item\n */\nexport class PromiseQueue<T> {\n /** Array of promises representing queued items */\n private items: Array<Promise<T>>;\n\n /** Function to resolve the next enqueued promise */\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n /** Function to resolve the continue promise when space is available */\n private batcher!: (val: boolean) => void;\n\n /** Flag indicating if the queue is synced with the data source */\n public synced = false;\n\n /** Maximum number of items to keep in the queue */\n private batchSize: number;\n\n /** Promise that resolves when it's safe to enqueue more items */\n private continuePromise: Promise<boolean>;\n\n constructor(batchSize: number) {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.batchSize = batchSize;\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items.push(nextVal);\n if (this.size() > this.batchSize) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n clear() {\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n this.items = [nextVal];\n }\n\n dequeue() {\n const item = this.items.shift();\n if (this.size() <= this.batchSize) {\n this.batcher(true);\n }\n\n return item as Promise<T>;\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.items.length == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.items.length;\n }\n}\n\n/**\n * Circular buffer implementation using promises for efficient memory usage\n * Reuses array slots in a circular fashion to maintain constant memory footprint\n * Used by the indexer for managing block processing queues\n */\nexport class CircularBuffer<T> {\n /** Fixed-size array of promises representing buffered items */\n private items: Array<Promise<T>>;\n\n /** Function to resolve the next enqueued promise */\n private enqueuer!: (val: T | PromiseLike<T>) => void;\n\n /** Current number of items in the buffer */\n private count: number = 0;\n\n /** Index of the next item to dequeue */\n private next: number = 0;\n\n /** Function to resolve the continue promise when space is available */\n private batcher!: (val: boolean) => void;\n\n /** Flag indicating if the buffer is synced with the data source */\n public synced = false;\n\n /** Maximum number of items the buffer can hold */\n private batchSize: number;\n\n /** Promise that resolves when it's safe to enqueue more items */\n private continuePromise: Promise<boolean>;\n\n /** Index of the next available slot for enqueueing */\n private nextAvail: number = 0;\n\n constructor(batchSize: number) {\n if (batchSize <= 1) {\n throw new Error(\"Batch size must be greater than 1\");\n }\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(batchSize);\n this.batchSize = batchSize;\n this.items[this.nextAvail] = nextVal;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n enqueue(item: T | PromiseLike<T>) {\n try {\n this.enqueuer(item);\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items[this.nextAvail] = nextVal;\n this.count++;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n if (this.nextAvail == this.next) {\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n }\n }\n catch (e) {\n console.error(\"Enqueing rejected data: \" + e);\n }\n }\n\n dequeue() {\n const item = this.items[this.next];\n this.next++;\n this.count--;\n if (this.next >= this.batchSize) {\n this.next = 0;\n }\n if (this.count <= this.batchSize) {\n this.batcher(true);\n }\n return item;\n }\n\n clear() {\n this.next = 0;\n this.nextAvail = 0;\n const nextVal = new Promise<T>((resolve, _reject) => {\n this.enqueuer = resolve;\n });\n this.items = new Array<Promise<T>>(this.batchSize);\n this.items[this.nextAvail] = nextVal;\n this.synced = false;\n this.count = 1;\n this.nextAvail++;\n if (this.nextAvail >= this.batchSize) {\n this.nextAvail = 0;\n }\n\n this.continuePromise = new Promise<boolean>((resolve, _reject) => {\n this.batcher = resolve;\n });\n this.batcher(true);\n }\n\n continue() {\n return this.continuePromise;\n }\n\n setSynced() {\n this.synced = true;\n }\n\n isEmpty() {\n if (this.count == 0) {\n return true;\n }\n else {\n return false;\n }\n }\n\n size() {\n return this.count;\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAa,eAAb,MAA6B;CAmB3B,YAAY,WAAmB;OARxB,SAAS;EASd,MAAM,UAAU,IAAI,SAAY,SAAS,YAAY;AACnD,QAAK,WAAW;IAChB;AACF,OAAK,YAAY;AACjB,OAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,QAAK,UAAU;IACf;AACF,OAAK,QAAQ,KAAK;AAClB,OAAK,QAAQ,CAAC,QAAQ;;CAGxB,QAAQ,MAA0B;AAChC,MAAI;AACF,QAAK,SAAS,KAAK;GACnB,MAAM,UAAU,IAAI,SAAY,SAAS,YAAY;AACnD,SAAK,WAAW;KAChB;AACF,QAAK,MAAM,KAAK,QAAQ;AACxB,OAAI,KAAK,MAAM,GAAG,KAAK,UACrB,MAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,SAAK,UAAU;KACf;WA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B,MAAK,YAAY;AAGnB,OAAI,KAAK,aAAa,KAAK,KACzB,MAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,SAAK,UAAU;KACf;WAGC,GAAG;AACR,WAAQ,MAAM,6BAA6B,EAAE;;;CAIjD,UAAU;EACR,MAAM,OAAO,KAAK,MAAM,KAAK;AAC7B,OAAK;AACL,OAAK;AACL,MAAI,KAAK,QAAQ,KAAK,UACpB,MAAK,OAAO;AAEd,MAAI,KAAK,SAAS,KAAK,UACrB,MAAK,QAAQ,KAAK;AAEpB,SAAO;;CAGT,QAAQ;AACN,OAAK,OAAO;AACZ,OAAK,YAAY;EACjB,MAAM,UAAU,IAAI,SAAY,SAAS,YAAY;AACnD,QAAK,WAAW;IAChB;AACF,OAAK,QAAQ,IAAI,MAAkB,KAAK,UAAU;AAClD,OAAK,MAAM,KAAK,aAAa;AAC7B,OAAK,SAAS;AACd,OAAK,QAAQ;AACb,OAAK;AACL,MAAI,KAAK,aAAa,KAAK,UACzB,MAAK,YAAY;AAGnB,OAAK,kBAAkB,IAAI,SAAkB,SAAS,YAAY;AAChE,QAAK,UAAU;IACf;AACF,OAAK,QAAQ,KAAK;;CAGpB,WAAW;AACT,SAAO,KAAK;;CAGd,YAAY;AACV,OAAK,SAAS;;CAGhB,UAAU;AACR,MAAI,KAAK,SAAS,EAChB,QAAO;MAGP,QAAO;;CAIX,OAAO;AACL,SAAO,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["import {\n BlockResponse, BlockResultsResponse,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n Event,\n} from \"@cosmjs/tendermint-rpc/build/comet38/responses\";\nimport {\n Validator,\n} from \"cosmjs-types/cosmos/staking/v1beta1/staking\";\nimport {\n TxBody,\n} from \"cosmjs-types/cosmos/tx/v1beta1/tx\";\n\nimport {\n EcleciaIndexer,\n} from \"../indexer\";\nimport {\n CircularBuffer,\n} from \"../promise-queue\";\n\nexport type EcleciaIndexerConfig = {\n startHeight?: number\n endHeight?: number\n batchSize: number\n modules: string[]\n getNextHeight: () => number | PromiseLike<number>\n logLevel: \"error\" | \"warn\" | \"info\" | \"http\" | \"verbose\" | \"debug\" | \"silly\"\n rpcUrl: string\n processGenesis?: boolean\n genesisPath?: string\n usePolling?: boolean\n pollingInterval?: number\n minimal?: boolean\n init?: () => Promise<void>\n beginTransaction: () => Promise<void>\n endTransaction: (status: boolean) => Promise<void>\n};\n\nexport type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;\nexport type MinimalBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse]>;\nexport type BlockQueue = FullBlockQueue | MinimalBlockQueue;\nexport type WithHeightAndUUID<T> = {\n [K in keyof T]: T[K] & {\n uuid?: string\n height?: number\n timestamp?: string\n };\n};\nexport type EmitFunc<K extends keyof WithHeightAndUUID<EventMap>> = (\n t: K,\n e: WithHeightAndUUID<EventMap>[K]\n) => Promise<void | void[]>;\n\nexport type LogEvent = {\n type: \"log\" | \"info\" | \"warning\" | \"error\" | \"verbose\" | \"transient\"\n message: string\n};\nexport type UUIDEvent = {\n uuid: string\n error?: string\n status: boolean\n};\nexport type Events = {\n log: LogEvent\n uuid: UUIDEvent\n begin_block: {\n value: {\n events: BlockResultsResponse[\"beginBlockEvents\"]\n validators: Validator[] | undefined\n }\n }\n\n block: {\n value: {\n block: BlockResponse\n block_results: BlockResultsResponse\n }\n }\n end_block: {\n value: BlockResultsResponse[\"endBlockEvents\"]\n }\n tx_events: {\n value: BlockResultsResponse[\"results\"]\n }\n tx_memo: {\n value: {\n txHash: string\n txBody: TxBody\n }\n }\n _unhandled: {\n type: string\n event: unknown\n }\n \"periodic/50\": {\n value: null\n }\n \"periodic/100\": {\n value: null\n }\n \"periodic/1000\": {\n value: null\n }\n};\nexport type TxResult<T> = {\n tx: T\n events: Event[]\n};\n\nexport interface IndexingModule {\n indexer: EcleciaIndexer\n name: string\n depends: string[]\n provides: string[]\n setup: () => Promise<void>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n init: (...args: any[]) => void\n}\n"],"mappings":""}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/types/index.ts"],"sourcesContent":["/* eslint-disable @stylistic/no-multi-spaces */\nimport {\n BlockResponse, BlockResultsResponse,\n} from \"@cosmjs/tendermint-rpc\";\nimport {\n Event,\n} from \"@cosmjs/tendermint-rpc/build/comet38/responses\";\nimport {\n Validator,\n} from \"cosmjs-types/cosmos/staking/v1beta1/staking\";\nimport {\n TxBody,\n} from \"cosmjs-types/cosmos/tx/v1beta1/tx\";\n\nimport {\n EcleciaIndexer,\n} from \"../indexer\";\nimport {\n CircularBuffer,\n} from \"../promise-queue\";\n\n/** Configuration interface for the Eclesia indexer */\nexport type EcleciaIndexerConfig = {\n startHeight?: number // Block height to start indexing from\n endHeight?: number // Block height to stop indexing at (optional)\n batchSize: number // Number of blocks to process in parallel\n modules: string[] // List of module names to enable\n getNextHeight: () => number | PromiseLike<number> // Function to determine next block to process\n logLevel: \"error\" | \"warn\" | \"info\" | \"http\" | \"verbose\" | \"debug\" | \"silly\" // Logging verbosity level\n rpcUrl: string // Tendermint RPC endpoint URL\n shouldProcessGenesis: () => Promise<boolean> // Whether to process genesis state\n genesisPath?: string // Path to genesis file\n usePolling?: boolean // Use polling instead of WebSocket subscription\n pollingInterval?: number // Interval between polls in milliseconds\n minimal?: boolean // Use minimal indexing mode (blocks only)\n init?: () => Promise<void> // Custom initialization function\n beginTransaction: () => Promise<void> // Function to begin database transaction\n endTransaction: (status: boolean) => Promise<void> // Function to end database transaction\n};\n\n/** Queue for full indexing mode with validator data */\nexport type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;\n\n/** Queue for minimal indexing mode without validator data */\nexport type MinimalBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse]>;\n\n/** Union type for block queues */\nexport type BlockQueue = FullBlockQueue | MinimalBlockQueue;\n\n/** Utility type to add height, timestamp, and UUID to event types */\nexport type WithHeightAndUUID<T> = {\n [K in keyof T]: T[K] & {\n uuid?: string // Unique identifier for event tracking\n height?: number // Block height when event occurred\n timestamp?: string // Block timestamp when event occurred\n };\n};\n\n/** Function signature for emitting events asynchronously */\nexport type EmitFunc<K extends keyof WithHeightAndUUID<EventMap>> = (\n t: K,\n e: WithHeightAndUUID<EventMap>[K]\n) => Promise<void | void[]>;\n\nexport type LogEvent = {\n type: \"log\" | \"info\" | \"warning\" | \"error\" | \"verbose\" | \"transient\"\n message: string\n};\nexport type UUIDEvent = {\n uuid: string\n error?: string\n status: boolean\n};\nexport type Events = {\n log: LogEvent\n uuid: UUIDEvent\n begin_block: {\n value: {\n events: BlockResultsResponse[\"beginBlockEvents\"]\n validators: Validator[] | undefined\n }\n }\n\n block: {\n value: {\n block: BlockResponse\n block_results: BlockResultsResponse\n }\n }\n end_block: {\n value: BlockResultsResponse[\"endBlockEvents\"]\n }\n tx_events: {\n value: BlockResultsResponse[\"results\"]\n }\n tx_memo: {\n value: {\n txHash: string\n txBody: TxBody\n }\n }\n _unhandled: {\n type: string\n event: unknown\n }\n \"periodic/50\": {\n value: null\n }\n \"periodic/100\": {\n value: null\n }\n \"periodic/1000\": {\n value: null\n }\n};\nexport type TxResult<T> = {\n tx: T\n events: Event[]\n};\n\n/** Interface that all indexing modules must implement */\nexport interface IndexingModule {\n indexer: EcleciaIndexer // Reference to the main indexer instance\n name: string // Unique module name\n depends: string[] // Array of module names this module depends on\n provides: string[] // Array of capabilities this module provides\n setup: () => Promise<void> // Async setup function for database schema initialization\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n init: (...args: any[]) => void // Initialization function called by the indexer\n}\n"],"mappings":""}
@@ -9,6 +9,7 @@ import { TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
9
9
  declare namespace index_d_exports {
10
10
  export { BlockQueue, EcleciaIndexerConfig, EmitFunc, Events, FullBlockQueue, IndexingModule, LogEvent, MinimalBlockQueue, TxResult, UUIDEvent, WithHeightAndUUID };
11
11
  }
12
+ /** Configuration interface for the Eclesia indexer */
12
13
  type EcleciaIndexerConfig = {
13
14
  startHeight?: number;
14
15
  endHeight?: number;
@@ -17,7 +18,7 @@ type EcleciaIndexerConfig = {
17
18
  getNextHeight: () => number | PromiseLike<number>;
18
19
  logLevel: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
19
20
  rpcUrl: string;
20
- processGenesis?: boolean;
21
+ shouldProcessGenesis: () => Promise<boolean>;
21
22
  genesisPath?: string;
22
23
  usePolling?: boolean;
23
24
  pollingInterval?: number;
@@ -26,14 +27,19 @@ type EcleciaIndexerConfig = {
26
27
  beginTransaction: () => Promise<void>;
27
28
  endTransaction: (status: boolean) => Promise<void>;
28
29
  };
30
+ /** Queue for full indexing mode with validator data */
29
31
  type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;
32
+ /** Queue for minimal indexing mode without validator data */
30
33
  type MinimalBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse]>;
34
+ /** Union type for block queues */
31
35
  type BlockQueue = FullBlockQueue | MinimalBlockQueue;
36
+ /** Utility type to add height, timestamp, and UUID to event types */
32
37
  type WithHeightAndUUID<T> = { [K in keyof T]: T[K] & {
33
38
  uuid?: string;
34
39
  height?: number;
35
40
  timestamp?: string;
36
41
  } };
42
+ /** Function signature for emitting events asynchronously */
37
43
  type EmitFunc<K extends keyof WithHeightAndUUID<EventMap>> = (t: K, e: WithHeightAndUUID<EventMap>[K]) => Promise<void | void[]>;
38
44
  type LogEvent = {
39
45
  type: "log" | "info" | "warning" | "error" | "verbose" | "transient";
@@ -89,6 +95,7 @@ type TxResult<T> = {
89
95
  tx: T;
90
96
  events: Event[];
91
97
  };
98
+ /** Interface that all indexing modules must implement */
92
99
  interface IndexingModule {
93
100
  indexer: EcleciaIndexer;
94
101
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources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AAA;IACI,KAAA,EAAA,IAAA;EAAK,CAAA;EAIE,cAAA,EAAA;IAAc,KAAA,EAAA,IAAA;;iBAKhB,EAAA;IAAO,KAAA,EAAA,IAAA;;;KAXV;MACN;UACI;;;UAIO,cAAA;WACN;;;;eAII"}
@@ -9,6 +9,7 @@ import { TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx";
9
9
  declare namespace index_d_exports {
10
10
  export { BlockQueue, EcleciaIndexerConfig, EmitFunc, Events, FullBlockQueue, IndexingModule, LogEvent, MinimalBlockQueue, TxResult, UUIDEvent, WithHeightAndUUID };
11
11
  }
12
+ /** Configuration interface for the Eclesia indexer */
12
13
  type EcleciaIndexerConfig = {
13
14
  startHeight?: number;
14
15
  endHeight?: number;
@@ -17,7 +18,7 @@ type EcleciaIndexerConfig = {
17
18
  getNextHeight: () => number | PromiseLike<number>;
18
19
  logLevel: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
19
20
  rpcUrl: string;
20
- processGenesis?: boolean;
21
+ shouldProcessGenesis: () => Promise<boolean>;
21
22
  genesisPath?: string;
22
23
  usePolling?: boolean;
23
24
  pollingInterval?: number;
@@ -26,14 +27,19 @@ type EcleciaIndexerConfig = {
26
27
  beginTransaction: () => Promise<void>;
27
28
  endTransaction: (status: boolean) => Promise<void>;
28
29
  };
30
+ /** Queue for full indexing mode with validator data */
29
31
  type FullBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse, Uint8Array]>;
32
+ /** Queue for minimal indexing mode without validator data */
30
33
  type MinimalBlockQueue = CircularBuffer<[BlockResponse, BlockResultsResponse]>;
34
+ /** Union type for block queues */
31
35
  type BlockQueue = FullBlockQueue | MinimalBlockQueue;
36
+ /** Utility type to add height, timestamp, and UUID to event types */
32
37
  type WithHeightAndUUID<T> = { [K in keyof T]: T[K] & {
33
38
  uuid?: string;
34
39
  height?: number;
35
40
  timestamp?: string;
36
41
  } };
42
+ /** Function signature for emitting events asynchronously */
37
43
  type EmitFunc<K extends keyof WithHeightAndUUID<EventMap>> = (t: K, e: WithHeightAndUUID<EventMap>[K]) => Promise<void | void[]>;
38
44
  type LogEvent = {
39
45
  type: "log" | "info" | "warning" | "error" | "verbose" | "transient";
@@ -89,6 +95,7 @@ type TxResult<T> = {
89
95
  tx: T;
90
96
  events: Event[];
91
97
  };
98
+ /** Interface that all indexing modules must implement */
92
99
  interface IndexingModule {
93
100
  indexer: EcleciaIndexer;
94
101
  name: string;