@lido-nestjs/execution 1.20.0 → 1.21.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.
@@ -75,7 +75,8 @@ export declare class ExtendedJsonRpcBatchProvider extends JsonRpcProvider {
75
75
  protected _fetchMiddlewareService: MiddlewareService<Promise<any>>;
76
76
  protected _domain: string;
77
77
  protected _eventEmitter: ExtendedJsonRpcBatchProviderEventEmitter;
78
- constructor(url: ConnectionInfo | string, network?: Networkish, requestPolicy?: RequestPolicy, fetchMiddlewares?: MiddlewareCallback<Promise<any>>[]);
78
+ protected _requestTimeoutMs?: number;
79
+ constructor(url: ConnectionInfo | string, network?: Networkish, requestPolicy?: RequestPolicy, fetchMiddlewares?: MiddlewareCallback<Promise<any>>[], requestTimeoutMs?: number);
79
80
  static _formatter: Formatter | null;
80
81
  static getFormatter(): Formatter;
81
82
  protected _batchAggregatorTick(): void;
@@ -15,14 +15,16 @@ var errorCodes = require('../error/codes/error-codes.js');
15
15
  var debugTraceBlockByHash = require('../ethers/debug-trace-block-by-hash.js');
16
16
  var networks = require('../common/networks.js');
17
17
  var sanitizeError = require('../common/sanitize-error.js');
18
+ var requestTimeout_error = require('../error/request-timeout.error.js');
18
19
  var lazyEventEmitter = require('../common/lazy-event-emitter.js');
19
20
 
20
21
  exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extends providers.JsonRpcProvider {
21
- constructor(url, network, requestPolicy, fetchMiddlewares = []) {
22
+ constructor(url, network, requestPolicy, fetchMiddlewares = [], requestTimeoutMs) {
22
23
  super(url, network);
23
24
  this._batchAggregator = null;
24
25
  this._queue = new queue.Queue();
25
26
  this._tickCounter = 0;
27
+ this._requestTimeoutMs = requestTimeoutMs;
26
28
  this._eventEmitter = new lazyEventEmitter.LazyEventEmitter();
27
29
  this._domain = networks.getConnectionFQDN(url);
28
30
  this._requestPolicy = requestPolicy !== null && requestPolicy !== void 0 ? requestPolicy : {
@@ -189,12 +191,22 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
189
191
  };
190
192
  const currentRequest = {
191
193
  request,
192
- reject: null,
193
194
  resolve: null,
195
+ reject: null,
194
196
  };
197
+ let timerId;
195
198
  const promise = new Promise((resolve, reject) => {
196
199
  currentRequest.resolve = resolve;
197
200
  currentRequest.reject = reject;
201
+ if (this._requestTimeoutMs) {
202
+ const timeoutMs = this._requestTimeoutMs;
203
+ timerId = setTimeout(() => {
204
+ reject(new requestTimeout_error.RequestTimeoutError(`Request timeout after ${timeoutMs}ms`, timeoutMs));
205
+ }, timeoutMs);
206
+ }
207
+ }).finally(() => {
208
+ if (timerId)
209
+ clearTimeout(timerId);
198
210
  });
199
211
  this._queue.enqueue(currentRequest);
200
212
  this._startBatchAggregator();
@@ -220,5 +232,5 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
220
232
  exports.ExtendedJsonRpcBatchProvider._formatter = null;
221
233
  exports.ExtendedJsonRpcBatchProvider = tslib.__decorate([
222
234
  common.Injectable(),
223
- tslib.__metadata("design:paramtypes", [Object, Object, Object, Array])
235
+ tslib.__metadata("design:paramtypes", [Object, Object, Object, Array, Number])
224
236
  ], exports.ExtendedJsonRpcBatchProvider);
@@ -55,7 +55,6 @@ export declare class SimpleFallbackJsonRpcBatchProvider extends BaseProvider {
55
55
  protected get provider(): FallbackProvider;
56
56
  protected switchToNextProvider(): void;
57
57
  protected isNonRetryableError(error: Error | unknown): boolean;
58
- protected withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T>;
59
58
  perform(method: string, params: {
60
59
  [name: string]: unknown;
61
60
  }): Promise<unknown>;
@@ -46,7 +46,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
46
46
  }
47
47
  this.fallbackProviders = conns.map((conn, index) => {
48
48
  var _a;
49
- const provider = new extendedJsonRpcBatchProvider.ExtendedJsonRpcBatchProvider(conn, undefined, config.requestPolicy, (_a = config.fetchMiddlewares) !== null && _a !== void 0 ? _a : []);
49
+ const provider = new extendedJsonRpcBatchProvider.ExtendedJsonRpcBatchProvider(conn, undefined, config.requestPolicy, (_a = config.fetchMiddlewares) !== null && _a !== void 0 ? _a : [], config.requestTimeoutMs);
50
50
  return {
51
51
  network: null,
52
52
  provider,
@@ -152,16 +152,6 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
152
152
  errors.isErrorHasCode(error) &&
153
153
  errors.nonRetryableErrors.includes(error.code));
154
154
  }
155
- withTimeout(promise, timeoutMs) {
156
- return Promise.race([
157
- promise,
158
- new Promise((_, reject) => {
159
- setTimeout(() => {
160
- reject(new requestTimeout_error.RequestTimeoutError(`Request timeout after ${timeoutMs}ms`, timeoutMs));
161
- }, timeoutMs);
162
- }),
163
- ]);
164
- }
165
155
  async perform(method, params) {
166
156
  var _a, _b;
167
157
  const retry = retrier.retrier(this.logger, this.config.maxRetries, this.config.minBackoffMs, this.config.maxBackoffMs, this.config.logRetries, (e) => this.isNonRetryableError(e));
@@ -189,12 +179,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
189
179
  retryAttempt: performRetryAttempt,
190
180
  }));
191
181
  performRetryAttempt++;
192
- const performPromise = provider.provider.perform(method, params);
193
- // Apply timeout if configured
194
- if (this.config.requestTimeoutMs) {
195
- return this.withTimeout(performPromise, this.config.requestTimeoutMs);
196
- }
197
- return performPromise;
182
+ return provider.provider.perform(method, params);
198
183
  });
199
184
  // Log successful request
200
185
  this.logger.log(this.formatLog(`${method} successful after ${performRetryAttempt} retry attempt(s)`, this.activeFallbackProviderIndex));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lido-nestjs/execution",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",