@lido-nestjs/execution 1.11.1 → 1.13.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.
- package/dist/common/networks.d.ts +2 -0
- package/dist/common/networks.js +16 -1
- package/dist/ethers/debug-trace-block-by-hash.d.ts +4 -0
- package/dist/ethers/debug-trace-block-by-hash.js +13 -0
- package/dist/events/index.d.ts +43 -0
- package/dist/index.d.ts +1 -0
- package/dist/interfaces/debug-traces.d.ts +27 -0
- package/dist/provider/extended-json-rpc-batch-provider.d.ts +12 -0
- package/dist/provider/extended-json-rpc-batch-provider.js +40 -12
- package/dist/provider/simple-fallback-json-rpc-batch-provider.d.ts +11 -0
- package/dist/provider/simple-fallback-json-rpc-batch-provider.js +40 -1
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Network } from '@ethersproject/networks';
|
|
2
2
|
import { Networkish } from '../interfaces/networkish';
|
|
3
|
+
import { ConnectionInfo } from '@ethersproject/web';
|
|
3
4
|
export declare const networksEqual: (networkA: Network, networkB: Network) => boolean;
|
|
4
5
|
export declare const getNetworkChain: (networkish: Networkish) => number;
|
|
5
6
|
export declare const networksChainsEqual: (networkA: Network, networkB: Networkish) => boolean;
|
|
7
|
+
export declare const getConnectionFQDN: (connectionInfo: ConnectionInfo | string) => string;
|
package/dist/common/networks.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
const IP_V4_REGEX = new RegExp(/^(?<domain>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(?<port>\d+))?/i);
|
|
6
|
+
const DOMAIN_REGEX = new RegExp(/^(?<protocol>https?:\/\/)(?=(?<fqdn>[^:/]+))(?:(?<service>www|ww\d|cdn|ftp|mail|pop\d?|ns\d?|git)\.)?(?:(?<subdomain>[^:/]+)\.)*(?<domain>[^:/]+\.[a-z0-9]+)(?::(?<port>\d+))?(?<path>\/[^?]*)?(?:\?(?<query>[^#]*))?(?:#(?<hash>.*))?/i);
|
|
5
7
|
const networksEqual = (networkA, networkB) => {
|
|
6
8
|
return (networkA.name === networkB.name &&
|
|
7
9
|
networkA.chainId === networkB.chainId &&
|
|
@@ -11,8 +13,21 @@ const networksEqual = (networkA, networkB) => {
|
|
|
11
13
|
const getNetworkChain = (networkish) => typeof networkish === 'object' && networkish != null
|
|
12
14
|
? networkish.chainId
|
|
13
15
|
: networkish;
|
|
14
|
-
const networksChainsEqual = (networkA, networkB) => networkA.chainId === getNetworkChain(networkB);
|
|
16
|
+
const networksChainsEqual = (networkA, networkB) => networkA.chainId === getNetworkChain(networkB);
|
|
17
|
+
const getConnectionFQDN = (connectionInfo) => {
|
|
18
|
+
var _a, _b, _c, _d;
|
|
19
|
+
const urlLike = typeof connectionInfo === 'string' ? connectionInfo : connectionInfo.url;
|
|
20
|
+
const ipGroups = (_a = urlLike.match(IP_V4_REGEX)) === null || _a === void 0 ? void 0 : _a.groups;
|
|
21
|
+
if (ipGroups) {
|
|
22
|
+
/* istanbul ignore next */
|
|
23
|
+
return (_b = ipGroups.domain) !== null && _b !== void 0 ? _b : '';
|
|
24
|
+
}
|
|
25
|
+
const groups = (_c = urlLike.match(DOMAIN_REGEX)) === null || _c === void 0 ? void 0 : _c.groups;
|
|
26
|
+
/* istanbul ignore next */
|
|
27
|
+
return (_d = groups === null || groups === void 0 ? void 0 : groups.fqdn) !== null && _d !== void 0 ? _d : '';
|
|
28
|
+
};
|
|
15
29
|
|
|
30
|
+
exports.getConnectionFQDN = getConnectionFQDN;
|
|
16
31
|
exports.getNetworkChain = getNetworkChain;
|
|
17
32
|
exports.networksChainsEqual = networksChainsEqual;
|
|
18
33
|
exports.networksEqual = networksEqual;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExtendedJsonRpcBatchProvider } from '../provider/extended-json-rpc-batch-provider';
|
|
2
|
+
import { SimpleFallbackJsonRpcBatchProvider } from '../provider/simple-fallback-json-rpc-batch-provider';
|
|
3
|
+
import { TraceConfig, TraceResult } from '../interfaces/debug-traces';
|
|
4
|
+
export declare function getDebugTraceBlockByHash(this: ExtendedJsonRpcBatchProvider | SimpleFallbackJsonRpcBatchProvider, blockHash: string, traceConfig: Partial<TraceConfig>): Promise<TraceResult[]>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
async function getDebugTraceBlockByHash(blockHash, traceConfig) {
|
|
6
|
+
await this.getNetwork();
|
|
7
|
+
return (await this.perform('getDebugTraceBlockByHash', {
|
|
8
|
+
blockHash,
|
|
9
|
+
traceConfig,
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.getDebugTraceBlockByHash = getDebugTraceBlockByHash;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SimpleFallbackJsonRpcBatchProvider } from '../provider/simple-fallback-json-rpc-batch-provider';
|
|
2
|
+
import { AllProvidersFailedError } from '../error';
|
|
3
|
+
import { ExtendedJsonRpcBatchProvider, JsonRpcRequest, JsonRpcResponse } from '../provider/extended-json-rpc-batch-provider';
|
|
4
|
+
export declare type FallbackProviderRequestFailedAllEvent = {
|
|
5
|
+
action: 'fallback-provider:request:failed:all';
|
|
6
|
+
provider: SimpleFallbackJsonRpcBatchProvider;
|
|
7
|
+
error: AllProvidersFailedError;
|
|
8
|
+
};
|
|
9
|
+
export declare type FallbackProviderRequestNonRetryableErrorEvent = {
|
|
10
|
+
action: 'fallback-provider:request:non-retryable-error';
|
|
11
|
+
provider: SimpleFallbackJsonRpcBatchProvider;
|
|
12
|
+
error: Error | unknown;
|
|
13
|
+
};
|
|
14
|
+
export declare type FallbackProviderRequestEvent = {
|
|
15
|
+
action: 'fallback-provider:request';
|
|
16
|
+
provider: SimpleFallbackJsonRpcBatchProvider;
|
|
17
|
+
activeFallbackProviderIndex: number;
|
|
18
|
+
fallbackProvidersCount: number;
|
|
19
|
+
domain: string;
|
|
20
|
+
retryAttempt: number;
|
|
21
|
+
};
|
|
22
|
+
export declare type ProviderResponseBatchedErrorEvent = {
|
|
23
|
+
action: 'provider:response-batched:error';
|
|
24
|
+
error: Error;
|
|
25
|
+
request: JsonRpcRequest[];
|
|
26
|
+
provider: ExtendedJsonRpcBatchProvider;
|
|
27
|
+
domain: string;
|
|
28
|
+
};
|
|
29
|
+
export declare type ProviderResponseBatchedEvent = {
|
|
30
|
+
action: 'provider:response-batched';
|
|
31
|
+
request: JsonRpcRequest[];
|
|
32
|
+
response: JsonRpcResponse[] | JsonRpcResponse;
|
|
33
|
+
provider: ExtendedJsonRpcBatchProvider;
|
|
34
|
+
domain: string;
|
|
35
|
+
};
|
|
36
|
+
export declare type ProviderRequestBatchedEvent = {
|
|
37
|
+
action: 'provider:request-batched';
|
|
38
|
+
request: JsonRpcRequest[];
|
|
39
|
+
provider: ExtendedJsonRpcBatchProvider;
|
|
40
|
+
domain: string;
|
|
41
|
+
};
|
|
42
|
+
export declare type ProviderEvents = ProviderRequestBatchedEvent | ProviderResponseBatchedEvent | ProviderResponseBatchedErrorEvent;
|
|
43
|
+
export declare type FallbackProviderEvents = ProviderEvents | FallbackProviderRequestEvent | FallbackProviderRequestNonRetryableErrorEvent | FallbackProviderRequestFailedAllEvent;
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare type CallType = 'CALL' | 'DELEGATECALL' | 'STATICCALL';
|
|
2
|
+
export declare type TraceResultItem = {
|
|
3
|
+
from: string;
|
|
4
|
+
gas: string;
|
|
5
|
+
gasUsed: string;
|
|
6
|
+
to: string;
|
|
7
|
+
input: string;
|
|
8
|
+
type: string;
|
|
9
|
+
value?: string;
|
|
10
|
+
calls?: TraceResultItem[];
|
|
11
|
+
};
|
|
12
|
+
export declare type TraceResult = {
|
|
13
|
+
txHash?: string;
|
|
14
|
+
result: TraceResultItem;
|
|
15
|
+
};
|
|
16
|
+
export declare type TraceResponse = {
|
|
17
|
+
id: number;
|
|
18
|
+
jsonrpc: string;
|
|
19
|
+
result: TraceResult[];
|
|
20
|
+
};
|
|
21
|
+
export declare type TraceConfig = {
|
|
22
|
+
tracer: string;
|
|
23
|
+
disableStorage: boolean;
|
|
24
|
+
disableStack: boolean;
|
|
25
|
+
enableMemory: boolean;
|
|
26
|
+
enableReturnData: boolean;
|
|
27
|
+
};
|
|
@@ -10,6 +10,13 @@ import { BlockTag } from '../ethers/block-tag';
|
|
|
10
10
|
import { TransactionRequest } from '@ethersproject/abstract-provider/src.ts/index';
|
|
11
11
|
import { MiddlewareCallback, MiddlewareService } from '@lido-nestjs/middleware';
|
|
12
12
|
import { FeeHistory } from '../ethers/fee-history';
|
|
13
|
+
import { TraceConfig, TraceResult } from '../interfaces/debug-traces';
|
|
14
|
+
import { ProviderEvents } from '../events';
|
|
15
|
+
export interface ExtendedJsonRpcBatchProviderEventEmitter extends NodeJS.EventEmitter {
|
|
16
|
+
on(eventName: 'rpc', listener: (event: ProviderEvents) => void): this;
|
|
17
|
+
once(eventName: 'rpc', listener: (event: ProviderEvents) => void): this;
|
|
18
|
+
addListener(eventName: 'rpc', listener: (event: ProviderEvents) => void): this;
|
|
19
|
+
}
|
|
13
20
|
export interface RequestPolicy {
|
|
14
21
|
jsonRpcMaxBatchSize: number;
|
|
15
22
|
maxConcurrentRequests: number;
|
|
@@ -66,14 +73,19 @@ export declare class ExtendedJsonRpcBatchProvider extends JsonRpcProvider {
|
|
|
66
73
|
protected _concurrencyLimiter: LimitFunction;
|
|
67
74
|
protected _tickCounter: number;
|
|
68
75
|
protected _fetchMiddlewareService: MiddlewareService<Promise<any>>;
|
|
76
|
+
protected _domain: string;
|
|
77
|
+
protected _eventEmitter: ExtendedJsonRpcBatchProviderEventEmitter;
|
|
69
78
|
constructor(url: ConnectionInfo | string, network?: Networkish, requestPolicy?: RequestPolicy, fetchMiddlewares?: MiddlewareCallback<Promise<any>>[]);
|
|
70
79
|
static _formatter: Formatter | null;
|
|
71
80
|
static getFormatter(): Formatter;
|
|
72
81
|
protected _batchAggregatorTick(): void;
|
|
73
82
|
protected _startBatchAggregator(): void;
|
|
74
83
|
getFeeHistory(blockCount: number, newestBlock?: string | null | number, rewardPercentiles?: number[]): Promise<FeeHistory>;
|
|
84
|
+
getDebugTraceBlockByHash(blockHash: string, traceConfig: TraceConfig): Promise<TraceResult[]>;
|
|
75
85
|
prepareRequest(method: string, params: any): [string, Array<any>];
|
|
76
86
|
use(callback: MiddlewareCallback<Promise<any>>): void;
|
|
87
|
+
get domain(): string;
|
|
88
|
+
get eventEmitter(): ExtendedJsonRpcBatchProviderEventEmitter;
|
|
77
89
|
send(method: string, params: Array<unknown>): Promise<unknown>;
|
|
78
90
|
detectNetwork(): Promise<Network>;
|
|
79
91
|
protected fetchJson(connection: string | ConnectionInfo, json?: string, processFunc?: (value: any, response: FetchJsonResponse) => any): Promise<any>;
|
|
@@ -14,6 +14,9 @@ var formatterWithEip1898 = require('../ethers/formatter-with-eip1898.js');
|
|
|
14
14
|
var middleware = require('@lido-nestjs/middleware');
|
|
15
15
|
var feeHistory = require('../ethers/fee-history.js');
|
|
16
16
|
var errorCodes = require('../error/codes/error-codes.js');
|
|
17
|
+
var debugTraceBlockByHash = require('../ethers/debug-trace-block-by-hash.js');
|
|
18
|
+
var networks = require('../common/networks.js');
|
|
19
|
+
var events = require('events');
|
|
17
20
|
|
|
18
21
|
exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extends providers.JsonRpcProvider {
|
|
19
22
|
constructor(url, network, requestPolicy, fetchMiddlewares = []) {
|
|
@@ -21,6 +24,8 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
|
|
|
21
24
|
this._batchAggregator = null;
|
|
22
25
|
this._queue = new queue.Queue();
|
|
23
26
|
this._tickCounter = 0;
|
|
27
|
+
this._eventEmitter = new events.EventEmitter();
|
|
28
|
+
this._domain = networks.getConnectionFQDN(url);
|
|
24
29
|
this._requestPolicy = requestPolicy !== null && requestPolicy !== void 0 ? requestPolicy : {
|
|
25
30
|
jsonRpcMaxBatchSize: 200,
|
|
26
31
|
maxConcurrentRequests: 5,
|
|
@@ -46,24 +51,29 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
|
|
|
46
51
|
// if queue size is less then 'jsonRpcMaxBatchSize' - dequeue remaining elements
|
|
47
52
|
const batch = this._queue.dequeueMultiple(this._requestPolicy.jsonRpcMaxBatchSize);
|
|
48
53
|
const batchRequest = batch.map((intent) => intent.request);
|
|
49
|
-
|
|
50
|
-
action: '
|
|
54
|
+
const event = {
|
|
55
|
+
action: 'provider:request-batched',
|
|
51
56
|
request: properties.deepCopy(batchRequest),
|
|
52
57
|
provider: this,
|
|
53
|
-
|
|
58
|
+
domain: this._domain,
|
|
59
|
+
};
|
|
60
|
+
this._eventEmitter.emit('rpc', event);
|
|
54
61
|
this._concurrencyLimiter(() => {
|
|
55
62
|
return this._fetchMiddlewareService.go(() => this.fetchJson(this.connection, JSON.stringify(batchRequest)), {
|
|
56
63
|
provider: this,
|
|
64
|
+
domain: this._domain,
|
|
57
65
|
});
|
|
58
66
|
})
|
|
59
67
|
.then((batchResult) => {
|
|
60
68
|
var _a;
|
|
61
|
-
|
|
62
|
-
action: 'response',
|
|
69
|
+
const event = {
|
|
70
|
+
action: 'provider:response-batched',
|
|
63
71
|
request: properties.deepCopy(batchRequest),
|
|
64
72
|
response: properties.deepCopy(batchResult),
|
|
65
73
|
provider: this,
|
|
66
|
-
|
|
74
|
+
domain: this._domain,
|
|
75
|
+
};
|
|
76
|
+
this._eventEmitter.emit('rpc', event);
|
|
67
77
|
if (!Array.isArray(batchResult)) {
|
|
68
78
|
const errMessage = 'Unexpected batch result.';
|
|
69
79
|
const jsonRpcErrorMessage = (_a = batchResult.error) === null || _a === void 0 ? void 0 : _a.message;
|
|
@@ -100,24 +110,28 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
|
|
|
100
110
|
}
|
|
101
111
|
});
|
|
102
112
|
}, (error) => {
|
|
103
|
-
|
|
104
|
-
action: 'response',
|
|
113
|
+
const event = {
|
|
114
|
+
action: 'provider:response-batched:error',
|
|
105
115
|
error: error,
|
|
106
116
|
request: properties.deepCopy(batchRequest),
|
|
107
117
|
provider: this,
|
|
108
|
-
|
|
118
|
+
domain: this._domain,
|
|
119
|
+
};
|
|
120
|
+
this._eventEmitter.emit('rpc', event);
|
|
109
121
|
batch.forEach((inflightRequest) => {
|
|
110
122
|
inflightRequest.reject(error);
|
|
111
123
|
});
|
|
112
124
|
})
|
|
113
125
|
.catch((error) => {
|
|
114
126
|
// catch errors happening in the 'then' callback
|
|
115
|
-
|
|
116
|
-
action: 'response',
|
|
127
|
+
const event = {
|
|
128
|
+
action: 'provider:response-batched:error',
|
|
117
129
|
error: error,
|
|
118
130
|
request: properties.deepCopy(batchRequest),
|
|
119
131
|
provider: this,
|
|
120
|
-
|
|
132
|
+
domain: this._domain,
|
|
133
|
+
};
|
|
134
|
+
this._eventEmitter.emit('rpc', event);
|
|
121
135
|
batch.forEach((inflightRequest) => {
|
|
122
136
|
inflightRequest.reject(error);
|
|
123
137
|
});
|
|
@@ -140,6 +154,9 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
|
|
|
140
154
|
async getFeeHistory(blockCount, newestBlock, rewardPercentiles) {
|
|
141
155
|
return feeHistory.getFeeHistory.call(this, blockCount, newestBlock, rewardPercentiles);
|
|
142
156
|
}
|
|
157
|
+
async getDebugTraceBlockByHash(blockHash, traceConfig) {
|
|
158
|
+
return debugTraceBlockByHash.getDebugTraceBlockByHash.call(this, blockHash, traceConfig);
|
|
159
|
+
}
|
|
143
160
|
prepareRequest(method, params) {
|
|
144
161
|
switch (method) {
|
|
145
162
|
case 'getFeeHistory':
|
|
@@ -147,6 +164,11 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
|
|
|
147
164
|
'eth_feeHistory',
|
|
148
165
|
[params.blockCount, params.newestBlock, params.rewardPercentiles],
|
|
149
166
|
];
|
|
167
|
+
case 'getDebugTraceBlockByHash':
|
|
168
|
+
return [
|
|
169
|
+
'debug_traceBlockByHash',
|
|
170
|
+
[params.blockHash, params.traceConfig],
|
|
171
|
+
];
|
|
150
172
|
default:
|
|
151
173
|
return super.prepareRequest(method, params);
|
|
152
174
|
}
|
|
@@ -154,6 +176,12 @@ exports.ExtendedJsonRpcBatchProvider = class ExtendedJsonRpcBatchProvider extend
|
|
|
154
176
|
use(callback) {
|
|
155
177
|
this._fetchMiddlewareService.use(callback);
|
|
156
178
|
}
|
|
179
|
+
get domain() {
|
|
180
|
+
return this._domain;
|
|
181
|
+
}
|
|
182
|
+
get eventEmitter() {
|
|
183
|
+
return this._eventEmitter;
|
|
184
|
+
}
|
|
157
185
|
send(method, params) {
|
|
158
186
|
const request = {
|
|
159
187
|
method: method,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { BaseProvider, Formatter } from '@ethersproject/providers';
|
|
2
3
|
import { CallOverrides as CallOverridesSource } from '@ethersproject/contracts';
|
|
3
4
|
import { SimpleFallbackProviderConfig } from '../interfaces/simple-fallback-provider-config';
|
|
@@ -10,6 +11,8 @@ import { Deferrable } from '@ethersproject/properties';
|
|
|
10
11
|
import { TransactionRequest } from '@ethersproject/abstract-provider/src.ts/index';
|
|
11
12
|
import { EventType, Listener } from '@ethersproject/abstract-provider';
|
|
12
13
|
import { FeeHistory } from '../ethers/fee-history';
|
|
14
|
+
import { TraceConfig, TraceResult } from '../interfaces/debug-traces';
|
|
15
|
+
import { FallbackProviderEvents } from '../events';
|
|
13
16
|
/**
|
|
14
17
|
* EIP-1898 support
|
|
15
18
|
* https://eips.ethereum.org/EIPS/eip-1898
|
|
@@ -26,6 +29,11 @@ declare module '@ethersproject/providers' {
|
|
|
26
29
|
blockTag?: BlockTag;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
32
|
+
export interface SimpleFallbackJsonRpcBatchProviderEventEmitter extends NodeJS.EventEmitter {
|
|
33
|
+
on(eventName: 'rpc', listener: (event: FallbackProviderEvents) => void): this;
|
|
34
|
+
once(eventName: 'rpc', listener: (event: FallbackProviderEvents) => void): this;
|
|
35
|
+
addListener(eventName: 'rpc', listener: (event: FallbackProviderEvents) => void): this;
|
|
36
|
+
}
|
|
29
37
|
export declare class SimpleFallbackJsonRpcBatchProvider extends BaseProvider {
|
|
30
38
|
protected config: SimpleFallbackProviderConfig;
|
|
31
39
|
protected logger: LoggerService;
|
|
@@ -35,11 +43,13 @@ export declare class SimpleFallbackJsonRpcBatchProvider extends BaseProvider {
|
|
|
35
43
|
protected resetTimer: ReturnType<typeof setTimeout> | null;
|
|
36
44
|
protected lastPerformError: Error | null | unknown;
|
|
37
45
|
protected lastError: Error | null | unknown;
|
|
46
|
+
protected _eventEmitter: SimpleFallbackJsonRpcBatchProviderEventEmitter;
|
|
38
47
|
constructor(config: SimpleFallbackProviderConfig, logger: LoggerService);
|
|
39
48
|
static _formatter: Formatter | null;
|
|
40
49
|
static getFormatter(): Formatter;
|
|
41
50
|
on(eventName: EventType, listener: Listener): this;
|
|
42
51
|
getFeeHistory(blockCount: number, newestBlock?: string | null | number, rewardPercentiles?: number[]): Promise<FeeHistory>;
|
|
52
|
+
getDebugTraceBlockByHash(blockHash: string, traceConfig: Partial<TraceConfig>): Promise<TraceResult[]>;
|
|
43
53
|
protected get provider(): FallbackProvider;
|
|
44
54
|
protected switchToNextProvider(): void;
|
|
45
55
|
protected isNonRetryableError(error: Error | unknown): boolean;
|
|
@@ -50,4 +60,5 @@ export declare class SimpleFallbackJsonRpcBatchProvider extends BaseProvider {
|
|
|
50
60
|
protected resetFallbacks(): void;
|
|
51
61
|
protected networksEqual(networkA: Network, networkB: Network): boolean;
|
|
52
62
|
get activeProviderIndex(): number;
|
|
63
|
+
get eventEmitter(): SimpleFallbackJsonRpcBatchProviderEventEmitter;
|
|
53
64
|
}
|
|
@@ -13,6 +13,8 @@ var noNewBlocksWhilePolling_error = require('../error/no-new-blocks-while-pollin
|
|
|
13
13
|
var errors = require('../common/errors.js');
|
|
14
14
|
var allProvidersFailed_error = require('../error/all-providers-failed.error.js');
|
|
15
15
|
var feeHistory = require('../ethers/fee-history.js');
|
|
16
|
+
var debugTraceBlockByHash = require('../ethers/debug-trace-block-by-hash.js');
|
|
17
|
+
var events = require('events');
|
|
16
18
|
|
|
17
19
|
exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchProvider extends providers.BaseProvider {
|
|
18
20
|
constructor(config, logger) {
|
|
@@ -22,6 +24,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
22
24
|
// it is crucial not to mix these two errors
|
|
23
25
|
this.lastPerformError = null; // last error for 'perform' operations, is batch-oriented
|
|
24
26
|
this.lastError = null; // last error for whole provider
|
|
27
|
+
this._eventEmitter = new events.EventEmitter();
|
|
25
28
|
this.config = Object.assign({ maxRetries: 3, minBackoffMs: 500, maxBackoffMs: 5000, logRetries: true, resetIntervalMs: 10000, maxTimeWithoutNewBlocksMs: 60000 }, config);
|
|
26
29
|
this.logger = logger;
|
|
27
30
|
const conns = config.urls.filter((url) => {
|
|
@@ -39,6 +42,10 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
39
42
|
this.fallbackProviders = conns.map((conn, index) => {
|
|
40
43
|
var _a;
|
|
41
44
|
const provider = new extendedJsonRpcBatchProvider.ExtendedJsonRpcBatchProvider(conn, undefined, config.requestPolicy, (_a = config.fetchMiddlewares) !== null && _a !== void 0 ? _a : []);
|
|
45
|
+
// re-emitting events from fallback-providers
|
|
46
|
+
provider.eventEmitter.on('rpc', (event) => {
|
|
47
|
+
this._eventEmitter.emit('rpc', event);
|
|
48
|
+
});
|
|
42
49
|
return {
|
|
43
50
|
network: null,
|
|
44
51
|
provider,
|
|
@@ -76,6 +83,9 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
76
83
|
async getFeeHistory(blockCount, newestBlock, rewardPercentiles) {
|
|
77
84
|
return feeHistory.getFeeHistory.call(this, blockCount, newestBlock, rewardPercentiles);
|
|
78
85
|
}
|
|
86
|
+
async getDebugTraceBlockByHash(blockHash, traceConfig) {
|
|
87
|
+
return debugTraceBlockByHash.getDebugTraceBlockByHash.call(this, blockHash, traceConfig);
|
|
88
|
+
}
|
|
79
89
|
get provider() {
|
|
80
90
|
if (this.activeFallbackProviderIndex > this.fallbackProviders.length - 1) {
|
|
81
91
|
this.activeFallbackProviderIndex = 0;
|
|
@@ -118,15 +128,35 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
118
128
|
// maximum number of switching is limited to total fallback provider count
|
|
119
129
|
while (attempt < this.fallbackProviders.length) {
|
|
120
130
|
try {
|
|
131
|
+
let performRetryAttempt = 0;
|
|
121
132
|
attempt++;
|
|
122
133
|
// awaiting is extremely important here
|
|
123
134
|
// without it, the error will not be caught in current try-catch scope
|
|
124
|
-
return await retry(() =>
|
|
135
|
+
return await retry(() => {
|
|
136
|
+
const provider = this.provider;
|
|
137
|
+
const event = {
|
|
138
|
+
action: 'fallback-provider:request',
|
|
139
|
+
provider: this,
|
|
140
|
+
activeFallbackProviderIndex: this.activeFallbackProviderIndex,
|
|
141
|
+
fallbackProvidersCount: this.fallbackProviders.length,
|
|
142
|
+
domain: provider.provider.domain,
|
|
143
|
+
retryAttempt: performRetryAttempt,
|
|
144
|
+
};
|
|
145
|
+
this._eventEmitter.emit('rpc', event);
|
|
146
|
+
performRetryAttempt++;
|
|
147
|
+
return provider.provider.perform(method, params);
|
|
148
|
+
});
|
|
125
149
|
}
|
|
126
150
|
catch (e) {
|
|
127
151
|
this.lastError = e;
|
|
128
152
|
// checking that error should not be retried on another provider
|
|
129
153
|
if (this.isNonRetryableError(e)) {
|
|
154
|
+
const event = {
|
|
155
|
+
action: 'fallback-provider:request:non-retryable-error',
|
|
156
|
+
provider: this,
|
|
157
|
+
error: e,
|
|
158
|
+
};
|
|
159
|
+
this._eventEmitter.emit('rpc', event);
|
|
130
160
|
throw e;
|
|
131
161
|
}
|
|
132
162
|
this.logger.error('Error while doing ETH1 RPC request. Will try to switch to another provider');
|
|
@@ -144,6 +174,12 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
144
174
|
}
|
|
145
175
|
const allProvidersFailedError = new allProvidersFailed_error.AllProvidersFailedError('All attempts to do ETH1 RPC request failed');
|
|
146
176
|
allProvidersFailedError.cause = this.lastError;
|
|
177
|
+
const event = {
|
|
178
|
+
action: 'fallback-provider:request:failed:all',
|
|
179
|
+
provider: this,
|
|
180
|
+
error: allProvidersFailedError,
|
|
181
|
+
};
|
|
182
|
+
this._eventEmitter.emit('rpc', event);
|
|
147
183
|
throw allProvidersFailedError;
|
|
148
184
|
}
|
|
149
185
|
async detectNetwork() {
|
|
@@ -223,6 +259,9 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
223
259
|
get activeProviderIndex() {
|
|
224
260
|
return this.activeFallbackProviderIndex;
|
|
225
261
|
}
|
|
262
|
+
get eventEmitter() {
|
|
263
|
+
return this._eventEmitter;
|
|
264
|
+
}
|
|
226
265
|
};
|
|
227
266
|
exports.SimpleFallbackJsonRpcBatchProvider._formatter = null;
|
|
228
267
|
exports.SimpleFallbackJsonRpcBatchProvider = tslib.__decorate([
|