@lido-nestjs/execution 1.2.0 → 1.3.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.
|
@@ -26,6 +26,7 @@ export declare class SimpleFallbackJsonRpcBatchProvider extends BaseProvider {
|
|
|
26
26
|
protected fallbackProviders: [FallbackProvider];
|
|
27
27
|
protected activeFallbackProviderIndex: number;
|
|
28
28
|
protected detectNetworkFirstRun: boolean;
|
|
29
|
+
protected resetTimer: ReturnType<typeof setTimeout> | null;
|
|
29
30
|
constructor(config: SimpleFallbackProviderConfig, logger: LoggerService);
|
|
30
31
|
static _formatter: Formatter | null;
|
|
31
32
|
static getFormatter(): Formatter;
|
|
@@ -35,5 +36,6 @@ export declare class SimpleFallbackJsonRpcBatchProvider extends BaseProvider {
|
|
|
35
36
|
[name: string]: unknown;
|
|
36
37
|
}): Promise<unknown>;
|
|
37
38
|
detectNetwork(): Promise<Network>;
|
|
39
|
+
protected resetFallbacks(): void;
|
|
38
40
|
protected networksEqual(networkA: Network, networkB: Network): boolean;
|
|
39
41
|
}
|
|
@@ -14,6 +14,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
14
14
|
constructor(config, logger) {
|
|
15
15
|
super(config.network);
|
|
16
16
|
this.detectNetworkFirstRun = true;
|
|
17
|
+
this.resetTimer = null;
|
|
17
18
|
this.config = Object.assign({ maxRetries: 3, minBackoffMs: 500, maxBackoffMs: 5000, logRetries: true }, config);
|
|
18
19
|
this.logger = logger;
|
|
19
20
|
const conns = config.urls.filter((url) => {
|
|
@@ -35,6 +36,7 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
35
36
|
network: null,
|
|
36
37
|
provider,
|
|
37
38
|
index,
|
|
39
|
+
unreachable: false,
|
|
38
40
|
};
|
|
39
41
|
});
|
|
40
42
|
this.activeFallbackProviderIndex = 0;
|
|
@@ -96,13 +98,17 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
96
98
|
throw new Error('All attempts to do ETH1 RPC request failed');
|
|
97
99
|
}
|
|
98
100
|
async detectNetwork() {
|
|
99
|
-
const results = await Promise.allSettled(this.fallbackProviders
|
|
100
|
-
|
|
101
|
+
const results = await Promise.allSettled(this.fallbackProviders
|
|
102
|
+
.filter((c) => !c.unreachable)
|
|
103
|
+
.map((c) => c.provider.getNetwork()));
|
|
104
|
+
results.forEach((result, index) => {
|
|
101
105
|
if (result.status === 'fulfilled') {
|
|
102
|
-
this.fallbackProviders[
|
|
106
|
+
this.fallbackProviders[index].network = result.value;
|
|
107
|
+
this.fallbackProviders[index].unreachable = false;
|
|
103
108
|
}
|
|
104
109
|
else {
|
|
105
|
-
this.fallbackProviders[
|
|
110
|
+
this.fallbackProviders[index].network = null;
|
|
111
|
+
this.fallbackProviders[index].unreachable = true;
|
|
106
112
|
}
|
|
107
113
|
});
|
|
108
114
|
let previousNetwork = null;
|
|
@@ -139,8 +145,26 @@ exports.SimpleFallbackJsonRpcBatchProvider = class SimpleFallbackJsonRpcBatchPro
|
|
|
139
145
|
if (this.detectNetworkFirstRun) {
|
|
140
146
|
this.detectNetworkFirstRun = false;
|
|
141
147
|
}
|
|
148
|
+
if (this.resetTimer) {
|
|
149
|
+
clearTimeout(this.resetTimer);
|
|
150
|
+
}
|
|
151
|
+
this.resetTimer = setTimeout(() => {
|
|
152
|
+
this.resetFallbacks();
|
|
153
|
+
}, this.config.resetIntervalMs || 10000);
|
|
142
154
|
return previousNetwork;
|
|
143
155
|
}
|
|
156
|
+
resetFallbacks() {
|
|
157
|
+
if (this.resetTimer) {
|
|
158
|
+
clearTimeout(this.resetTimer);
|
|
159
|
+
}
|
|
160
|
+
this.fallbackProviders.forEach((fallbackProvider, index) => {
|
|
161
|
+
var _a;
|
|
162
|
+
if (!((_a = this.fallbackProviders[index].network) === null || _a === void 0 ? void 0 : _a.chainId)) {
|
|
163
|
+
this.fallbackProviders[index].unreachable = false;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
this.activeFallbackProviderIndex = 0;
|
|
167
|
+
}
|
|
144
168
|
networksEqual(networkA, networkB) {
|
|
145
169
|
return networks.networksEqual(networkA, networkB);
|
|
146
170
|
}
|