@eclesia/indexer-engine 2.14.5 → 2.16.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 (121) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +20 -15
  2. package/dist/_virtual/rolldown_runtime.mjs +10 -30
  3. package/dist/constants.cjs +31 -2
  4. package/dist/constants.cjs.map +1 -1
  5. package/dist/constants.d.cts +27 -3
  6. package/dist/constants.d.cts.map +1 -1
  7. package/dist/constants.d.mts +27 -3
  8. package/dist/constants.d.mts.map +1 -1
  9. package/dist/constants.mjs +27 -3
  10. package/dist/constants.mjs.map +1 -1
  11. package/dist/emitter/index.cjs +25 -7
  12. package/dist/emitter/index.cjs.map +1 -1
  13. package/dist/emitter/index.d.cts +8 -1
  14. package/dist/emitter/index.d.cts.map +1 -1
  15. package/dist/emitter/index.d.mts +8 -1
  16. package/dist/emitter/index.d.mts.map +1 -1
  17. package/dist/emitter/index.mjs +25 -7
  18. package/dist/emitter/index.mjs.map +1 -1
  19. package/dist/index.cjs +6 -0
  20. package/dist/index.d.cts +3 -3
  21. package/dist/index.d.mts +3 -3
  22. package/dist/index.mjs +3 -3
  23. package/dist/indexer/index.cjs +498 -225
  24. package/dist/indexer/index.cjs.map +1 -1
  25. package/dist/indexer/index.d.cts +111 -7
  26. package/dist/indexer/index.d.cts.map +1 -1
  27. package/dist/indexer/index.d.mts +111 -7
  28. package/dist/indexer/index.d.mts.map +1 -1
  29. package/dist/indexer/index.mjs +496 -224
  30. package/dist/indexer/index.mjs.map +1 -1
  31. package/dist/metrics/index.cjs +14 -0
  32. package/dist/metrics/index.cjs.map +1 -1
  33. package/dist/metrics/index.d.cts +7 -0
  34. package/dist/metrics/index.d.cts.map +1 -1
  35. package/dist/metrics/index.d.mts +7 -0
  36. package/dist/metrics/index.d.mts.map +1 -1
  37. package/dist/metrics/index.mjs +14 -0
  38. package/dist/metrics/index.mjs.map +1 -1
  39. package/dist/mocks/index.cjs +3 -1
  40. package/dist/mocks/index.cjs.map +1 -1
  41. package/dist/mocks/index.d.cts +2 -2
  42. package/dist/mocks/index.d.mts +2 -2
  43. package/dist/mocks/index.mjs +4 -2
  44. package/dist/mocks/index.mjs.map +1 -1
  45. package/dist/mocks/rpc-client.cjs +185 -20
  46. package/dist/mocks/rpc-client.cjs.map +1 -1
  47. package/dist/mocks/rpc-client.d.cts +26 -10
  48. package/dist/mocks/rpc-client.d.cts.map +1 -1
  49. package/dist/mocks/rpc-client.d.mts +26 -10
  50. package/dist/mocks/rpc-client.d.mts.map +1 -1
  51. package/dist/mocks/rpc-client.mjs +184 -22
  52. package/dist/mocks/rpc-client.mjs.map +1 -1
  53. package/dist/promise-queue/index.cjs +10 -4
  54. package/dist/promise-queue/index.cjs.map +1 -1
  55. package/dist/promise-queue/index.d.cts +1 -4
  56. package/dist/promise-queue/index.d.cts.map +1 -1
  57. package/dist/promise-queue/index.d.mts +1 -4
  58. package/dist/promise-queue/index.d.mts.map +1 -1
  59. package/dist/promise-queue/index.mjs +10 -4
  60. package/dist/promise-queue/index.mjs.map +1 -1
  61. package/dist/types/index.cjs.map +1 -1
  62. package/dist/types/index.d.cts +28 -5
  63. package/dist/types/index.d.cts.map +1 -1
  64. package/dist/types/index.d.mts +28 -5
  65. package/dist/types/index.d.mts.map +1 -1
  66. package/dist/types/index.mjs.map +1 -1
  67. package/dist/utils/index.cjs +6 -1
  68. package/dist/utils/index.cjs.map +1 -1
  69. package/dist/utils/index.d.cts +3 -2
  70. package/dist/utils/index.d.mts +3 -2
  71. package/dist/utils/index.mjs +7 -2
  72. package/dist/utils/index.mjs.map +1 -1
  73. package/dist/utils/text.cjs +31 -0
  74. package/dist/utils/text.cjs.map +1 -1
  75. package/dist/utils/text.d.cts +24 -1
  76. package/dist/utils/text.d.cts.map +1 -1
  77. package/dist/utils/text.d.mts +24 -1
  78. package/dist/utils/text.d.mts.map +1 -1
  79. package/dist/utils/text.mjs +30 -1
  80. package/dist/utils/text.mjs.map +1 -1
  81. package/dist/utils/timeout.cjs +32 -0
  82. package/dist/utils/timeout.cjs.map +1 -0
  83. package/dist/utils/timeout.d.cts +18 -0
  84. package/dist/utils/timeout.d.cts.map +1 -0
  85. package/dist/utils/timeout.d.mts +18 -0
  86. package/dist/utils/timeout.d.mts.map +1 -0
  87. package/dist/utils/timeout.mjs +30 -0
  88. package/dist/utils/timeout.mjs.map +1 -0
  89. package/package.json +28 -27
  90. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.cjs +0 -32
  91. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.cjs.map +0 -1
  92. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.mjs +0 -29
  93. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/ascii.mjs.map +0 -1
  94. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.cjs +0 -67
  95. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.cjs.map +0 -1
  96. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.mjs +0 -64
  97. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/base64.mjs.map +0 -1
  98. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.cjs +0 -80
  99. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.cjs.map +0 -1
  100. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.mjs +0 -77
  101. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/bech32.mjs.map +0 -1
  102. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.cjs +0 -33
  103. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.cjs.map +0 -1
  104. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.mjs +0 -30
  105. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/hex.mjs.map +0 -1
  106. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.cjs +0 -106
  107. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.cjs.map +0 -1
  108. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.mjs +0 -103
  109. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/index.mjs.map +0 -1
  110. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.cjs +0 -52
  111. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.cjs.map +0 -1
  112. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.mjs +0 -49
  113. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/rfc3339.mjs.map +0 -1
  114. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.cjs +0 -31
  115. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.cjs.map +0 -1
  116. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.mjs +0 -28
  117. package/dist/node_modules/.pnpm/@cosmjs_encoding@0.36.0/node_modules/@cosmjs/encoding/build/utf8.mjs.map +0 -1
  118. package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.cjs +0 -98
  119. package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.cjs.map +0 -1
  120. package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.mjs +0 -95
  121. package/dist/node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.mjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { IndexerMetrics } from "../metrics/index.mjs";
2
- import { EcleciaIndexerConfig, EmitFunc, WithHeightAndUUID } from "../types/index.mjs";
2
+ import { EclesiaIndexerConfig, EmitFunc, WithHeightAndUUID } from "../types/index.mjs";
3
3
  import { EclesiaEmitter } from "../emitter/index.mjs";
4
4
  import { CometClient } from "@cosmjs/tendermint-rpc";
5
5
  import * as winston from "winston";
@@ -11,7 +11,7 @@ declare const defaultIndexerConfig: {
11
11
  batchSize: number;
12
12
  modules: never[];
13
13
  getNextHeight: () => number;
14
- logLevel: EcleciaIndexerConfig["logLevel"];
14
+ logLevel: EclesiaIndexerConfig["logLevel"];
15
15
  usePolling: boolean;
16
16
  pollingInterval: number;
17
17
  shouldProcessGenesis: () => boolean;
@@ -28,9 +28,9 @@ declare const defaultIndexerConfig: {
28
28
  * Core blockchain indexer that connects to Tendermint RPC and processes blocks
29
29
  * Extends EclesiaEmitter to provide event-driven architecture for modules
30
30
  */
31
- declare class EcleciaIndexer extends EclesiaEmitter {
31
+ declare class EclesiaIndexer extends EclesiaEmitter {
32
32
  /** Indexer configuration settings */
33
- config: EcleciaIndexerConfig;
33
+ config: EclesiaIndexerConfig;
34
34
  /** Fastify HTTP server for health checks */
35
35
  private fastify;
36
36
  /** Prometheus HTTP server instance */
@@ -63,31 +63,135 @@ declare class EcleciaIndexer extends EclesiaEmitter {
63
63
  private subscription;
64
64
  /** Timeout handler for block reception */
65
65
  private blockTimeout;
66
+ /** Timer for the next poll in polling mode */
67
+ private pollTimer;
68
+ /** Bumped on every (re)start and stop so a polling chain from a previous run exits */
69
+ private pollGeneration;
70
+ /** Bumped on every start() so callbacks left over from a previous run cannot trigger recovery in this one */
71
+ private runGeneration;
72
+ /**
73
+ * Rejecters of waits parked in waitForBlockData(). Each entry is removed as soon as its block
74
+ * arrives, so a healthy run keeps this empty instead of accumulating one entry per block.
75
+ */
76
+ private blockWaiters;
77
+ /** Pending restart timer */
78
+ private retryTimer;
79
+ /** Resolves when the indexer has stopped for good: stop() was called, endHeight was reached, or it gave up */
80
+ private stopped;
81
+ private resolveStopped;
82
+ /** Next height the fetcher will request; advances as fetches are enqueued */
83
+ private nextFetchHeight;
84
+ /** Whether a fetcher loop is active, and for which run */
85
+ private fetcherRunning;
86
+ private fetcherGeneration;
87
+ private fetcherToken;
88
+ /** Height of the block whose processing failed most recently, and how many times in a row */
89
+ private lastFailedHeight;
90
+ private sameHeightFailures;
66
91
  /**
67
92
  * Creates a new Eclesia indexer instance
68
93
  * @param config - Indexer configuration options
69
94
  */
70
- constructor(config: EcleciaIndexerConfig);
95
+ constructor(config: EclesiaIndexerConfig);
71
96
  private setStatus;
97
+ /**
98
+ * Marks the current run for recovery and wakes the main loop if it is parked waiting for a
99
+ * block. Callbacks left over from a previous run pass their generation and are ignored.
100
+ */
101
+ private requestRecovery;
102
+ /** Rejects every wait parked in waitForBlockData() */
103
+ private wakeBlockWaiters;
104
+ /**
105
+ * Refuses to index a chain other than the configured one. An RPC pool that mixes networks, or
106
+ * a wrong URL, would otherwise write a different chain's blocks into the database.
107
+ */
108
+ private assertChainId;
109
+ /** Counts consecutive processing failures per block height */
110
+ private noteBlockFailure;
111
+ /** True once one block has failed maxFailuresPerBlock times in a row */
112
+ private isStuck;
113
+ /**
114
+ * Waits for the next dequeued block but wakes early when recovery or stop is requested, so a
115
+ * loop parked on an empty queue never waits for a block that will not come.
116
+ */
117
+ private waitForBlockData;
118
+ /** (Re)arms the idle check that runs when no block has been announced for a while */
119
+ private armIdleCheck;
120
+ /**
121
+ * Runs when no block has been announced for IDLE_CHECK_INTERVAL_MS. A chain that has stopped
122
+ * producing blocks (halt, upgrade, slow chain) is not an error: the indexer reports WAITING and
123
+ * checks again later. Recovery is requested only when the chain has moved on without us, which
124
+ * means the subscription is dead, or when the RPC cannot be reached at all.
125
+ */
126
+ private checkLiveness;
72
127
  private blockListener;
73
128
  private isMinimal;
74
129
  connect(): Promise<boolean>;
130
+ /**
131
+ * Opens one CometBFT client with its own timeout. If the timeout wins, the client
132
+ * that may still arrive is disconnected so a slow RPC never leaks a socket.
133
+ */
134
+ private connectWithTimeout;
75
135
  private initialize;
76
- stop(): void;
136
+ /**
137
+ * Stops the indexer and releases everything that would keep the process alive:
138
+ * the block subscription, polling and inactivity timers, both RPC clients and the
139
+ * health and metrics servers. Safe to call more than once.
140
+ */
141
+ stop(): Promise<void>;
77
142
  private clearBlockQueue;
78
143
  private setupBlockListening;
144
+ /**
145
+ * Resolves once the indexer has stopped for good: stop() was called, endHeight was reached, or
146
+ * a fatal-error was emitted. Restarts with backoff do not resolve it. Use it to keep a caller
147
+ * waiting for the whole run rather than for the first loop exit.
148
+ */
149
+ whenStopped(): Promise<void>;
79
150
  start(): Promise<void>;
151
+ /**
152
+ * Emits an event and waits for its handlers. Handlers run one after another in registration
153
+ * order: they share one database connection and one transaction, so interleaving them at
154
+ * await points would let two handlers read and write the same rows in an unpredictable order,
155
+ * and a failure in one would leave the others mid-flight while the block is rolled back. The
156
+ * first rejection propagates and stops the remaining handlers.
157
+ */
80
158
  asyncEmit: EmitFunc<keyof WithHeightAndUUID<EventMap>>;
81
159
  private processBlock;
160
+ /**
161
+ * Fetches every height from nextFetchHeight up to latestHeight, waiting for queue space
162
+ * before each fetch. Serves the initial catch-up and live blocks alike: a new announcement
163
+ * only moves latestHeight and starts this loop if it is not already running, so bursts and
164
+ * skipped announcements are handled by the same code and the queue can never overflow.
165
+ */
82
166
  private fetcher;
167
+ /**
168
+ * Runs an ABCI query. A transport failure (RPC down, timeout, empty reply) requests a recovery.
169
+ * A reply with a non-zero code is the chain answering "no" (pruned height, unknown path, bad
170
+ * key): it is thrown as an RPCError with the code and log, and no recovery is requested for
171
+ * ad-hoc queries, so modules can catch it. Block-pipeline queries reject into the fetcher,
172
+ * which requests recovery itself.
173
+ */
83
174
  callABCI(path: string, data: Uint8Array, height?: number, adHoc?: boolean): Promise<Uint8Array>;
175
+ /**
176
+ * Fetches the complete validator set at a height, following pagination, and returns it
177
+ * re-encoded as a single QueryValidatorsResponse so the block queue payload keeps its shape.
178
+ * Chains with more validators than one page (1000) were silently truncated before.
179
+ */
180
+ private fetchValidatorSet;
84
181
  private newBlockReceived;
182
+ /** Starts a single polling chain, retiring any chain left over from a previous run */
183
+ private startPolling;
184
+ private stopPolling;
85
185
  private pollForBlock;
86
186
  private readGenesis;
87
187
  private setArrayReader;
88
188
  private setValueReader;
89
189
  private parseGenesis;
90
190
  }
191
+ /** @deprecated Misspelling kept for compatibility, use EclesiaIndexer. Removed in 3.0. */
192
+ declare const EcleciaIndexer: typeof EclesiaIndexer;
193
+ /** @deprecated Misspelling kept for compatibility, use EclesiaIndexer. Removed in 3.0. */
194
+ type EcleciaIndexer = EclesiaIndexer;
91
195
  //#endregion
92
- export { EcleciaIndexer, defaultIndexerConfig };
196
+ export { EcleciaIndexer, EclesiaIndexer, defaultIndexerConfig };
93
197
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/indexer/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAuEa;EAAA,WAAA,EAAA,MAAA;EAKS,SAAA,EAAA,MAAA;;;EAWa,QAAA,EAXb,oBAWa,CAAA,UAAA,CAAA;EAAA,UAAA,EAAA,OAAA;EAOtB,eAAA,EAAe,MAAA;EAEX,oBAAA,EAAA,GAAA,GAAA,OAAA;EAwBI,OAAA,EAAA,OAAA;EAMH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