1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/app/scripts/migrations
Elliot Winkler ed3cc404f2
NetworkController: Split network into networkId and networkStatus (#17556)
The `network` store of the network controller crams two types of data
into one place. It roughly tracks whether we have enough information to
make requests to the network and whether the network is capable of
receiving requests, but it also stores the ID of the network (as
obtained via `net_version`).

Generally we shouldn't be using the network ID for anything, as it has
been completely replaced by chain ID, which all custom RPC endpoints
have been required to support for over a year now. However, as the
network ID is used in various places within the extension codebase,
removing it entirely would be a non-trivial effort. So, minimally, this
commit splits `network` into two stores: `networkId` and
`networkStatus`. But it also expands the concept of network status.

Previously, the network was in one of two states: "loading" and
"not-loading". But now it can be in one of four states:

- `available`: The network is able to receive and respond to requests.
- `unavailable`: The network is not able to receive and respond to
  requests for unknown reasons.
- `blocked`: The network is actively blocking requests based on the
  user's geolocation. (This is specific to Infura.)
- `unknown`: We don't know whether the network can receive and respond
  to requests, either because we haven't checked or we tried to check
  and were unsuccessful.

This commit also changes how the network status is determined —
specifically, how many requests are used to determine that status, when
they occur, and whether they are awaited. Previously, the network
controller would make 2 to 3 requests during the course of running
`lookupNetwork`.

* First, if it was an Infura network, it would make a request for
  `eth_blockNumber` to determine whether Infura was blocking requests or
  not, then emit an appropriate event. This operation was not awaited.
* Then, regardless of the network, it would fetch the network ID via
  `net_version`. This operation was awaited.
* Finally, regardless of the network, it would fetch the latest block
  via `eth_getBlockByNumber`, then use the result to determine whether
  the network supported EIP-1559. This operation was awaited.

Now:

* One fewer request is made, specifically `eth_blockNumber`, as we don't
  need to make an extra request to determine whether Infura is blocking
  requests; we can reuse `eth_getBlockByNumber`;
* All requests are awaited, which makes `lookupNetwork` run fully
  in-band instead of partially out-of-band; and
* Both requests for `net_version` and `eth_getBlockByNumber` are
  performed in parallel to make `lookupNetwork` run slightly faster.
2023-03-30 16:49:12 -06:00
..
002.js
003.js
004.js
005.js
006.js
007.js
008.js
009.js
010.js
011.js
012.js
013.js
014.js
015.js
016.js
017.js
018.js
019.js
020.js
021.js
021.test.js
022.js
022.test.js
023.js
023.test.js
024.js
024.test.js
025.js
025.test.js
026.js
026.test.js
027.js
027.test.js
028.js
028.test.js
029.js
029.test.js
030.js
030.test.js
031.js
031.test.js
032.js
033.js
033.test.js
034.js
034.test.js
035.js
035.test.js
036.js
036.test.js
037.js
037.test.js
038.js
038.test.js
039.js
039.test.js
040.js
040.test.js
041.js
041.test.js
042.js
042.test.js
043.js
043.test.js
044.js
044.test.js
045.js
045.test.js
046.js
046.test.js
047.js
047.test.js
048.js
048.test.js
049.js
049.test.js
050.js
050.test.js
051.js
051.test.js
052.js
052.test.js
053.js
053.test.js
054.js
054.test.js
055.js
055.test.js
056.js
056.test.js
057.js
057.test.js
058.js
058.test.js
059.js
059.test.js
060.js
060.test.js
061.js
061.test.js
062.js
062.test.js
063.js
063.test.js
064.js
064.test.js
065.js
065.test.js
066.js
066.test.js
067.js
067.test.js
068.js
068.test.js
069.js
069.test.js
070.js
070.test.js
071.js
071.test.js
072.js
072.test.js
073.js
073.test.js
074.js
074.test.js
075.js
075.test.js
076.js
076.test.js
077.js
077.test.js
078.test.js
078.ts
079.js
079.test.js
080.js
080.test.js
081.test.js
081.ts
082.test.js
082.ts
083.test.js NetworkController: Split network into networkId and networkStatus (#17556) 2023-03-30 16:49:12 -06:00
083.ts NetworkController: Split network into networkId and networkStatus (#17556) 2023-03-30 16:49:12 -06:00
fail-tx.js
index.js NetworkController: Split network into networkId and networkStatus (#17556) 2023-03-30 16:49:12 -06:00
migrations.test.js
template.test.js
template.ts