@lido-nestjs/execution 1.17.0 → 1.18.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.
@@ -166,8 +166,10 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
166
166
  ]);
167
167
  }
168
168
  async perform(method, params) {
169
+ var _a, _b;
169
170
  const retry = retrier.retrier(this.logger, this.config.maxRetries, this.config.minBackoffMs, this.config.maxBackoffMs, this.config.logRetries, (e) => this.isNonRetryableError(e));
170
171
  let attempt = 0;
172
+ (_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, this.formatLog(`RPC call: ${method}`));
171
173
  // will perform maximum `this.config.maxRetries` retries for fetching data with single provider
172
174
  // after failure will switch to next provider
173
175
  // maximum number of switching is limited to total fallback provider count
@@ -176,7 +178,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
176
178
  let performRetryAttempt = 0;
177
179
  attempt++;
178
180
  // Log which provider we're attempting to use
179
- this.logger.log(this.formatLog(`Attempting request (attempt ${attempt}/${this.fallbackProviders.length})`, this.activeFallbackProviderIndex));
181
+ this.logger.log(this.formatLog(`Attempting ${method} (attempt ${attempt}/${this.fallbackProviders.length})`, this.activeFallbackProviderIndex));
180
182
  // awaiting is extremely important here
181
183
  // without it, the error will not be caught in current try-catch scope
182
184
  const result = await retry(() => {
@@ -199,7 +201,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
199
201
  return performPromise;
200
202
  });
201
203
  // Log successful request
202
- this.logger.log(this.formatLog(`Request successful after ${performRetryAttempt} retry attempt(s)`, this.activeFallbackProviderIndex));
204
+ this.logger.log(this.formatLog(`${method} successful after ${performRetryAttempt} retry attempt(s)`, this.activeFallbackProviderIndex));
203
205
  return result;
204
206
  }
205
207
  catch (e) {
@@ -214,18 +216,18 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
214
216
  this._eventEmitter.emit('rpc', event);
215
217
  // Log context (label + provider index) synchronously before error object
216
218
  // to ensure proper ordering in async logging systems
217
- this.logger.error(this.formatLog(`Non-retryable error occurred`, this.activeFallbackProviderIndex));
219
+ this.logger.error(this.formatLog(`${method} non-retryable error occurred`, this.activeFallbackProviderIndex));
218
220
  this.logger.error(e);
219
221
  throw e;
220
222
  }
221
223
  // Log context (label + provider index) synchronously before error object
222
224
  // to ensure proper ordering in async logging systems
223
225
  if (e instanceof requestTimeout_error.RequestTimeoutError) {
224
- this.logger.error(this.formatLog(`Request timeout after ${e.timeoutMs}ms. Will switch to next provider.`, this.activeFallbackProviderIndex));
226
+ this.logger.error(this.formatLog(`${method} timeout after ${e.timeoutMs}ms. Will switch to next provider.`, this.activeFallbackProviderIndex));
225
227
  this.logger.error(e);
226
228
  }
227
229
  else {
228
- this.logger.error(this.formatLog(`Error occurred. Will switch to next provider.`, this.activeFallbackProviderIndex));
230
+ this.logger.error(this.formatLog(`${method} error occurred. Will switch to next provider.`, this.activeFallbackProviderIndex));
229
231
  this.logger.error(e);
230
232
  }
231
233
  // This check is needed to avoid multiple `switchToNextProvider` calls when doing one JSON-RPC batch.
@@ -239,7 +241,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
239
241
  }
240
242
  }
241
243
  }
242
- const allProvidersFailedError = new allProvidersFailed_error.AllProvidersFailedError('All attempts to do ETH1 RPC request failed');
244
+ const allProvidersFailedError = new allProvidersFailed_error.AllProvidersFailedError(`All attempts to do ETH1 RPC request failed for ${method}`);
243
245
  allProvidersFailedError.cause = this.lastError;
244
246
  const event = {
245
247
  action: 'fallback-provider:request:failed:all',
@@ -351,19 +353,29 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
351
353
  try {
352
354
  // Uses perform() which handles fallback switching automatically
353
355
  const receipt = await this.getTransactionReceipt(txHash);
354
- if (receipt && receipt.confirmations >= confirmations) {
355
- const elapsedMs = Date.now() - startTime;
356
- this.logger.log(this.formatLog(`Transaction ${txHash} confirmed after ${pollCount} polls (${elapsedMs}ms, ${receipt.confirmations} confirmations)`));
357
- return { receipt, pollCount, elapsedMs };
356
+ if (!receipt) {
357
+ // Transaction pending in mempool, not yet included in a block
358
+ lastError = null;
359
+ await sleep.sleep(pollInterval);
360
+ continue;
358
361
  }
359
- lastError = null;
362
+ if (receipt.confirmations < confirmations) {
363
+ // Transaction mined but waiting for more confirmations
364
+ lastError = null;
365
+ await sleep.sleep(pollInterval);
366
+ continue;
367
+ }
368
+ // Transaction confirmed with enough confirmations
369
+ const elapsedMs = Date.now() - startTime;
370
+ this.logger.log(this.formatLog(`Transaction ${txHash} confirmed after ${pollCount} polls (${elapsedMs}ms, ${receipt.confirmations} confirmations)`));
371
+ return { receipt, pollCount, elapsedMs };
360
372
  }
361
373
  catch (error) {
362
374
  // All providers failed - log and retry until timeout
363
375
  lastError = error;
364
376
  this.logger.warn(this.formatLog(`waitForTransactionWithFallback poll #${pollCount} failed for ${txHash}: ${error}`));
377
+ await sleep.sleep(pollInterval);
365
378
  }
366
- await sleep.sleep(pollInterval);
367
379
  }
368
380
  const elapsedMs = Date.now() - startTime;
369
381
  const errorContext = lastError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lido-nestjs/execution",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",