@metamask/network-controller 23.4.0 → 23.5.1
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 +30 -1
- package/dist/NetworkController.cjs +26 -9
- package/dist/NetworkController.cjs.map +1 -1
- package/dist/NetworkController.d.cts +10 -1
- package/dist/NetworkController.d.cts.map +1 -1
- package/dist/NetworkController.d.mts +10 -1
- package/dist/NetworkController.d.mts.map +1 -1
- package/dist/NetworkController.mjs +26 -9
- package/dist/NetworkController.mjs.map +1 -1
- package/dist/rpc-service/rpc-service.cjs +36 -46
- package/dist/rpc-service/rpc-service.cjs.map +1 -1
- package/dist/rpc-service/rpc-service.d.cts.map +1 -1
- package/dist/rpc-service/rpc-service.d.mts.map +1 -1
- package/dist/rpc-service/rpc-service.mjs +37 -47
- package/dist/rpc-service/rpc-service.mjs.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [23.5.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Block tracker errors will no longer be wrapped under "PollingBlockTracker - encountered an error while attempting to update latest block" ([#5860](https://github.com/MetaMask/core/pull/5860))
|
|
15
|
+
- Bump dependencies ([#5867](https://github.com/MetaMask/core/pull/5867), [#5860](https://github.com/MetaMask/core/pull/5860))
|
|
16
|
+
- Bump `@metamask/eth-block-tracker` to `^12.0.1`
|
|
17
|
+
- Bump `@metamask/eth-json-rpc-infura` to `^10.2.0`
|
|
18
|
+
- Bump `@metamask/eth-json-rpc-middleware` to `^17.0.1`
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Rather than throwing an error, NetworkController now corrects an invalid initial `selectedNetworkClientId` to point to the default RPC endpoint of the first network sorted by chain ID ([#5851](https://github.com/MetaMask/core/pull/5851))
|
|
23
|
+
- Fix the block tracker so that it will now reject if an error is thrown while making the request instead of hanging ([#5860](https://github.com/MetaMask/core/pull/5860))
|
|
24
|
+
|
|
25
|
+
## [23.5.0]
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- Remove obsolete `eth_getBlockByNumber` error handling for load balancer errors ([#5808](https://github.com/MetaMask/core/pull/5808))
|
|
30
|
+
- Bump `@metamask/controller-utils` to `^11.9.0` ([#5812](https://github.com/MetaMask/core/pull/5812))
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- Improved handling of HTTP status codes to prevent unnecessary circuit breaker triggers ([#5798](https://github.com/MetaMask/core/pull/5798), [#5809](https://github.com/MetaMask/core/pull/5809))
|
|
35
|
+
- HTTP 4XX responses (e.g. rate limit errors) will no longer trigger the circuit breaker policy.
|
|
36
|
+
|
|
10
37
|
## [23.4.0]
|
|
11
38
|
|
|
12
39
|
### Added
|
|
@@ -839,7 +866,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
839
866
|
|
|
840
867
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
841
868
|
|
|
842
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.
|
|
869
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.5.1...HEAD
|
|
870
|
+
[23.5.1]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.5.0...@metamask/network-controller@23.5.1
|
|
871
|
+
[23.5.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.4.0...@metamask/network-controller@23.5.0
|
|
843
872
|
[23.4.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.3.0...@metamask/network-controller@23.4.0
|
|
844
873
|
[23.3.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.2.0...@metamask/network-controller@23.3.0
|
|
845
874
|
[23.2.0]: https://github.com/MetaMask/core/compare/@metamask/network-controller@23.1.0...@metamask/network-controller@23.2.0
|
|
@@ -46,6 +46,7 @@ const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
|
46
46
|
const swappable_obj_proxy_1 = require("@metamask/swappable-obj-proxy");
|
|
47
47
|
const utils_1 = require("@metamask/utils");
|
|
48
48
|
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
49
|
+
const immer_1 = require("immer");
|
|
49
50
|
const lodash_1 = require("lodash");
|
|
50
51
|
const reselect_1 = require("reselect");
|
|
51
52
|
const URI = __importStar(require("uri-js"));
|
|
@@ -300,7 +301,7 @@ function deriveInfuraNetworkNameFromRpcEndpointUrl(rpcEndpointUrl) {
|
|
|
300
301
|
* @param state - The NetworkController state to verify.
|
|
301
302
|
* @throws if the state is invalid in some way.
|
|
302
303
|
*/
|
|
303
|
-
function
|
|
304
|
+
function validateInitialState(state) {
|
|
304
305
|
const networkConfigurationEntries = Object.entries(state.networkConfigurationsByChainId);
|
|
305
306
|
const networkClientIds = getAvailableNetworkClientIds(getNetworkConfigurations(state));
|
|
306
307
|
if (networkConfigurationEntries.length === 0) {
|
|
@@ -324,12 +325,27 @@ function validateNetworkControllerState(state) {
|
|
|
324
325
|
if ([...new Set(networkClientIds)].length < networkClientIds.length) {
|
|
325
326
|
throw new Error('NetworkController state has invalid `networkConfigurationsByChainId`: Every RPC endpoint across all network configurations must have a unique `networkClientId`');
|
|
326
327
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Checks that the given initial NetworkController state is internally
|
|
331
|
+
* consistent similar to `validateInitialState`, but if an anomaly is detected,
|
|
332
|
+
* it does its best to correct the state and logs an error to Sentry.
|
|
333
|
+
*
|
|
334
|
+
* @param state - The NetworkController state to verify.
|
|
335
|
+
* @param messenger - The NetworkController messenger.
|
|
336
|
+
* @returns The corrected state.
|
|
337
|
+
*/
|
|
338
|
+
function correctInitialState(state, messenger) {
|
|
339
|
+
const networkConfigurationsSortedByChainId = getNetworkConfigurations(state).sort((a, b) => a.chainId.localeCompare(b.chainId));
|
|
340
|
+
const networkClientIds = getAvailableNetworkClientIds(networkConfigurationsSortedByChainId);
|
|
341
|
+
return (0, immer_1.produce)(state, (newState) => {
|
|
342
|
+
if (!networkClientIds.includes(state.selectedNetworkClientId)) {
|
|
343
|
+
const firstNetworkConfiguration = networkConfigurationsSortedByChainId[0];
|
|
344
|
+
const newSelectedNetworkClientId = firstNetworkConfiguration.rpcEndpoints[firstNetworkConfiguration.defaultRpcEndpointIndex].networkClientId;
|
|
345
|
+
messenger.call('ErrorReportingService:captureException', new Error(`\`selectedNetworkClientId\` '${state.selectedNetworkClientId}' does not refer to an RPC endpoint within a network configuration; correcting to '${newSelectedNetworkClientId}'`));
|
|
346
|
+
newState.selectedNetworkClientId = newSelectedNetworkClientId;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
333
349
|
}
|
|
334
350
|
/**
|
|
335
351
|
* Transforms a map of chain ID to network configuration to a map of network
|
|
@@ -361,7 +377,8 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
361
377
|
...getDefaultNetworkControllerState(additionalDefaultNetworks),
|
|
362
378
|
...state,
|
|
363
379
|
};
|
|
364
|
-
|
|
380
|
+
validateInitialState(initialState);
|
|
381
|
+
const correctedInitialState = correctInitialState(initialState, messenger);
|
|
365
382
|
if (!infuraProjectId || typeof infuraProjectId !== 'string') {
|
|
366
383
|
throw new Error('Invalid Infura project ID');
|
|
367
384
|
}
|
|
@@ -382,7 +399,7 @@ class NetworkController extends base_controller_1.BaseController {
|
|
|
382
399
|
},
|
|
383
400
|
},
|
|
384
401
|
messenger,
|
|
385
|
-
state:
|
|
402
|
+
state: correctedInitialState,
|
|
386
403
|
});
|
|
387
404
|
_NetworkController_instances.add(this);
|
|
388
405
|
_NetworkController_ethQuery.set(this, void 0);
|