@metamask-previews/network-controller 22.2.1-preview-ac664446 → 22.2.1-preview-ea165590

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/CHANGELOG.md CHANGED
@@ -7,11 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Implement circuit breaker pattern when retrying requests to Infura and custom RPC endpoints ([#5290](https://github.com/MetaMask/core/pull/5290))
13
+ - If the network is perceived to be down after 5 attempts, further retries will be paused for 30 seconds
14
+ - "Down" means the following:
15
+ - A failure to reach the network (exact error depending on platform / HTTP client)
16
+ - The request responds with a non-JSON-parseable or non-JSON-RPC-compatible body
17
+ - The request returns a non-200 response
18
+ - Use exponential backoff / jitter when retrying requests to Infura and custom RPC endpoints ([#5290](https://github.com/MetaMask/core/pull/5290))
19
+ - As requests are retried, the delay between retries will increase exponentially (using random variance to prevent bursts)
20
+
21
+ ### Changed
22
+
23
+ - **BREAKING:** `NetworkController` constructor now takes two required options, `fetch` and `btoa` ([#5290](https://github.com/MetaMask/core/pull/5290))
24
+ - These are passed along to functions that create the JSON-RPC middleware
25
+ - Synchronize retry logic and error handling behavior between Infura and custom RPC endpoints ([#5290](https://github.com/MetaMask/core/pull/5290))
26
+ - A request to a custom endpoint that returns a 418 response will no longer return a JSON-RPC response with the error "Request is being rate limited"
27
+ - A request to a custom endpoint that returns a 429 response now returns a JSON-RPC response with the error "Request is being rate limited"
28
+ - A request to a custom endpoint that throws an "ECONNRESET" error will now be retried up to 5 times
29
+ - A request to a Infura endpoint that fails more than 5 times in a row will now respond with a JSON-RPC error that encompasses the failure instead of hiding it as "InfuraProvider - cannot complete request. All retries exhausted"
30
+ - A request to a Infura endpoint that returns a non-retriable, non-2xx response will now respond with a JSON-RPC error that has the underling message "Non-200 status code: '\<code\>'" rather than including the raw response from the endpoint
31
+ - A request to a custom endpoint that fails with a retriable error more than 5 times in a row will now respond with a JSON-RPC error that encompasses the failure instead of returning an empty response
32
+ - A "retriable error" is now regarded as the following:
33
+ - A failure to reach the network (exact error depending on platform / HTTP client)
34
+ - The request responds with a non-JSON-parseable or non-JSON-RPC-compatible body
35
+ - The request returns a 503 or 504 response
36
+ - Bump dependencies to support usage of RPC services internally for network requests ([#5290](https://github.com/MetaMask/core/pull/5290))
37
+ - Bump `@metamask/eth-json-rpc-infura` to `^10.1.0`
38
+ - Bump `@metamask/eth-json-rpc-middleware` to `^15.1.0`
39
+
10
40
  ## [22.2.1]
11
41
 
12
42
  ### Changed
13
43
 
14
- - Bump `@metamask/base-controller` from `^7.1.1` to `^8.0.0` [#5305](https://github.com/MetaMask/core/pull/5305))
44
+ - Bump `@metamask/base-controller` from `^7.1.1` to `^8.0.0` ([#5305](https://github.com/MetaMask/core/pull/5305))
15
45
 
16
46
  ## [22.2.0]
17
47
 
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_refreshNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
39
+ var _NetworkController_instances, _NetworkController_ethQuery, _NetworkController_infuraProjectId, _NetworkController_previouslySelectedNetworkClientId, _NetworkController_providerProxy, _NetworkController_blockTrackerProxy, _NetworkController_autoManagedNetworkClientRegistry, _NetworkController_autoManagedNetworkClient, _NetworkController_log, _NetworkController_fetch, _NetworkController_btoa, _NetworkController_networkConfigurationsByNetworkClientId, _NetworkController_refreshNetwork, _NetworkController_getLatestBlock, _NetworkController_determineEIP1559Compatibility, _NetworkController_validateNetworkFields, _NetworkController_determineNetworkConfigurationToPersist, _NetworkController_registerNetworkClientsAsNeeded, _NetworkController_unregisterNetworkClientsAsNeeded, _NetworkController_updateNetworkConfigurations, _NetworkController_ensureAutoManagedNetworkClientRegistryPopulated, _NetworkController_createAutoManagedNetworkClientRegistry, _NetworkController_applyNetworkSelection;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.NetworkController = exports.selectAvailableNetworkClientIds = exports.getAvailableNetworkClientIds = exports.selectNetworkConfigurations = exports.getNetworkConfigurations = exports.getDefaultNetworkControllerState = exports.knownKeysOf = exports.RpcEndpointType = void 0;
42
42
  const base_controller_1 = require("@metamask/base-controller");
@@ -286,7 +286,7 @@ function buildNetworkConfigurationsByNetworkClientId(networkConfigurationsByChai
286
286
  * Controller that creates and manages an Ethereum network provider.
287
287
  */
288
288
  class NetworkController extends base_controller_1.BaseController {
289
- constructor({ messenger, state, infuraProjectId, log, }) {
289
+ constructor({ messenger, state, infuraProjectId, log, fetch: givenFetch, btoa: givenBtoa, }) {
290
290
  const initialState = { ...getDefaultNetworkControllerState(), ...state };
291
291
  validateNetworkControllerState(initialState);
292
292
  if (!infuraProjectId || typeof infuraProjectId !== 'string') {
@@ -320,9 +320,13 @@ class NetworkController extends base_controller_1.BaseController {
320
320
  _NetworkController_autoManagedNetworkClientRegistry.set(this, void 0);
321
321
  _NetworkController_autoManagedNetworkClient.set(this, void 0);
322
322
  _NetworkController_log.set(this, void 0);
323
+ _NetworkController_fetch.set(this, void 0);
324
+ _NetworkController_btoa.set(this, void 0);
323
325
  _NetworkController_networkConfigurationsByNetworkClientId.set(this, void 0);
324
326
  __classPrivateFieldSet(this, _NetworkController_infuraProjectId, infuraProjectId, "f");
325
327
  __classPrivateFieldSet(this, _NetworkController_log, log, "f");
328
+ __classPrivateFieldSet(this, _NetworkController_fetch, givenFetch, "f");
329
+ __classPrivateFieldSet(this, _NetworkController_btoa, givenBtoa, "f");
326
330
  __classPrivateFieldSet(this, _NetworkController_previouslySelectedNetworkClientId, this.state.selectedNetworkClientId, "f");
327
331
  __classPrivateFieldSet(this, _NetworkController_networkConfigurationsByNetworkClientId, buildNetworkConfigurationsByNetworkClientId(this.state.networkConfigurationsByChainId), "f");
328
332
  this.messagingSystem.registerActionHandler(
@@ -1103,7 +1107,7 @@ class NetworkController extends base_controller_1.BaseController {
1103
1107
  }
1104
1108
  }
1105
1109
  exports.NetworkController = NetworkController;
1106
- _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId = new WeakMap(), _NetworkController_previouslySelectedNetworkClientId = new WeakMap(), _NetworkController_providerProxy = new WeakMap(), _NetworkController_blockTrackerProxy = new WeakMap(), _NetworkController_autoManagedNetworkClientRegistry = new WeakMap(), _NetworkController_autoManagedNetworkClient = new WeakMap(), _NetworkController_log = new WeakMap(), _NetworkController_networkConfigurationsByNetworkClientId = new WeakMap(), _NetworkController_instances = new WeakSet(), _NetworkController_refreshNetwork =
1110
+ _NetworkController_ethQuery = new WeakMap(), _NetworkController_infuraProjectId = new WeakMap(), _NetworkController_previouslySelectedNetworkClientId = new WeakMap(), _NetworkController_providerProxy = new WeakMap(), _NetworkController_blockTrackerProxy = new WeakMap(), _NetworkController_autoManagedNetworkClientRegistry = new WeakMap(), _NetworkController_autoManagedNetworkClient = new WeakMap(), _NetworkController_log = new WeakMap(), _NetworkController_fetch = new WeakMap(), _NetworkController_btoa = new WeakMap(), _NetworkController_networkConfigurationsByNetworkClientId = new WeakMap(), _NetworkController_instances = new WeakSet(), _NetworkController_refreshNetwork =
1107
1111
  /**
1108
1112
  * Executes a series of steps to switch the network:
1109
1113
  *
@@ -1313,19 +1317,27 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1313
1317
  for (const addedRpcEndpoint of addedRpcEndpoints) {
1314
1318
  if (addedRpcEndpoint.type === RpcEndpointType.Infura) {
1315
1319
  autoManagedNetworkClientRegistry[types_1.NetworkClientType.Infura][addedRpcEndpoint.networkClientId] = (0, create_auto_managed_network_client_1.createAutoManagedNetworkClient)({
1316
- type: types_1.NetworkClientType.Infura,
1317
- chainId: networkFields.chainId,
1318
- network: addedRpcEndpoint.networkClientId,
1319
- infuraProjectId: __classPrivateFieldGet(this, _NetworkController_infuraProjectId, "f"),
1320
- ticker: networkFields.nativeCurrency,
1320
+ networkClientConfiguration: {
1321
+ type: types_1.NetworkClientType.Infura,
1322
+ chainId: networkFields.chainId,
1323
+ network: addedRpcEndpoint.networkClientId,
1324
+ infuraProjectId: __classPrivateFieldGet(this, _NetworkController_infuraProjectId, "f"),
1325
+ ticker: networkFields.nativeCurrency,
1326
+ },
1327
+ fetch: __classPrivateFieldGet(this, _NetworkController_fetch, "f"),
1328
+ btoa: __classPrivateFieldGet(this, _NetworkController_btoa, "f"),
1321
1329
  });
1322
1330
  }
1323
1331
  else {
1324
1332
  autoManagedNetworkClientRegistry[types_1.NetworkClientType.Custom][addedRpcEndpoint.networkClientId] = (0, create_auto_managed_network_client_1.createAutoManagedNetworkClient)({
1325
- type: types_1.NetworkClientType.Custom,
1326
- chainId: networkFields.chainId,
1327
- rpcUrl: addedRpcEndpoint.url,
1328
- ticker: networkFields.nativeCurrency,
1333
+ networkClientConfiguration: {
1334
+ type: types_1.NetworkClientType.Custom,
1335
+ chainId: networkFields.chainId,
1336
+ rpcUrl: addedRpcEndpoint.url,
1337
+ ticker: networkFields.nativeCurrency,
1338
+ },
1339
+ fetch: __classPrivateFieldGet(this, _NetworkController_fetch, "f"),
1340
+ btoa: __classPrivateFieldGet(this, _NetworkController_btoa, "f"),
1329
1341
  });
1330
1342
  }
1331
1343
  }
@@ -1373,21 +1385,29 @@ async function _NetworkController_determineEIP1559Compatibility(networkClientId)
1373
1385
  return [
1374
1386
  rpcEndpoint.networkClientId,
1375
1387
  (0, create_auto_managed_network_client_1.createAutoManagedNetworkClient)({
1376
- type: types_1.NetworkClientType.Infura,
1377
- network: infuraNetworkName,
1378
- infuraProjectId: __classPrivateFieldGet(this, _NetworkController_infuraProjectId, "f"),
1379
- chainId: networkConfiguration.chainId,
1380
- ticker: networkConfiguration.nativeCurrency,
1388
+ networkClientConfiguration: {
1389
+ type: types_1.NetworkClientType.Infura,
1390
+ network: infuraNetworkName,
1391
+ infuraProjectId: __classPrivateFieldGet(this, _NetworkController_infuraProjectId, "f"),
1392
+ chainId: networkConfiguration.chainId,
1393
+ ticker: networkConfiguration.nativeCurrency,
1394
+ },
1395
+ fetch: __classPrivateFieldGet(this, _NetworkController_fetch, "f"),
1396
+ btoa: __classPrivateFieldGet(this, _NetworkController_btoa, "f"),
1381
1397
  }),
1382
1398
  ];
1383
1399
  }
1384
1400
  return [
1385
1401
  rpcEndpoint.networkClientId,
1386
1402
  (0, create_auto_managed_network_client_1.createAutoManagedNetworkClient)({
1387
- type: types_1.NetworkClientType.Custom,
1388
- chainId: networkConfiguration.chainId,
1389
- rpcUrl: rpcEndpoint.url,
1390
- ticker: networkConfiguration.nativeCurrency,
1403
+ networkClientConfiguration: {
1404
+ type: types_1.NetworkClientType.Custom,
1405
+ chainId: networkConfiguration.chainId,
1406
+ rpcUrl: rpcEndpoint.url,
1407
+ ticker: networkConfiguration.nativeCurrency,
1408
+ },
1409
+ fetch: __classPrivateFieldGet(this, _NetworkController_fetch, "f"),
1410
+ btoa: __classPrivateFieldGet(this, _NetworkController_btoa, "f"),
1391
1411
  }),
1392
1412
  ];
1393
1413
  });