Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
cca8f81
Extend createServicePolicy to support live network status
mcmire Nov 14, 2025
6a3cff1
Fix tests
mcmire Nov 15, 2025
c08f398
Add more tests
mcmire Nov 17, 2025
5e0e3e1
No need for getLastInnerFailureReason
mcmire Nov 17, 2025
e2eba7a
Fix an issue with onAvailable
mcmire Nov 17, 2025
246b2b5
Reduce the diff
mcmire Nov 17, 2025
199bb79
Fix tests
mcmire Nov 17, 2025
ff6d832
Use a quasi-enum for the availability status
mcmire Nov 17, 2025
fa66813
Fix test
mcmire Nov 17, 2025
9d090e9
Revamp NetworkController RPC endpoint events
mcmire Nov 14, 2025
0da865b
Remove this comment
mcmire Nov 17, 2025
b3909af
Add 'degraded' status
mcmire Nov 17, 2025
6b628d7
Use similar terminology as in createServicePolicy
mcmire Nov 17, 2025
4a3985a
Merge branch 'update-create-service-policy' into update-network-contr…
mcmire Nov 17, 2025
2d38446
Adjust createServicePolicy as well
mcmire Nov 17, 2025
3d8da80
Adjust createServicePolicy as well
mcmire Nov 17, 2025
7860897
Merge branch 'update-create-service-policy' into update-network-contr…
mcmire Nov 18, 2025
f67839a
Update some of the terminology
mcmire Nov 18, 2025
110cb0b
Update more of the terminology
mcmire Nov 18, 2025
b16597a
RpcEndpointUnvailable -> RpcEndpointUnavailable
mcmire Nov 18, 2025
dabf9bd
Keep network statuses up to date as requests are made
mcmire Nov 17, 2025
137c3d7
Merge branch 'main' into update-network-controller-rpc-endpoint-events
mcmire Nov 19, 2025
cb498e3
Address Cursor comment
mcmire Nov 19, 2025
cdd8491
Make the RPC endpoint event tests more realistic, and address Cursor …
mcmire Nov 19, 2025
73017d1
Reword JSDoc for events, remove endpointUrl from chainUnavailable event
mcmire Nov 20, 2025
7de4def
Merge branch 'main' into update-network-controller-rpc-endpoint-events
mcmire Nov 20, 2025
026ce00
Use the primaryEndpointUrl from the Cockatiel event in the messenger …
mcmire Nov 20, 2025
aa4df24
Remove console.log's
mcmire Nov 21, 2025
e02f3ae
Tweak JSDoc for NetworkStatus
mcmire Nov 21, 2025
e3eb8ec
Merge branch 'update-network-controller-rpc-endpoint-events' into upd…
mcmire Nov 21, 2025
0e13332
Merge branch 'main' into update-network-controller-rpc-endpoint-events
mcmire Nov 21, 2025
41ab331
Merge branch 'update-network-controller-rpc-endpoint-events' into upd…
mcmire Nov 21, 2025
c09fdaf
Fix changelog
mcmire Nov 21, 2025
74d9d0f
Remove RpcService.getLastInnerFailureReason, use lastError directly
mcmire Nov 21, 2025
bbbfa9c
Remove redundant tag in log
mcmire Nov 21, 2025
4f9d84b
data -> context
mcmire Nov 21, 2025
1862024
Remove unused utility type
mcmire Nov 21, 2025
2f29875
Tweak log statement
mcmire Nov 21, 2025
827696f
Tweak comment
mcmire Nov 21, 2025
72de1d6
Revert log change
mcmire Nov 21, 2025
0f55384
Add comment for why we are ignoring 'isolated'
mcmire Nov 21, 2025
067a807
refactor(network-controller): improve RPC service chain configuration
cryptodev-2s Nov 25, 2025
4b57f32
refactor(network-controller): replace magic number with calculated co…
cryptodev-2s Nov 25, 2025
056703f
test(network-controller): rollback test description change
cryptodev-2s Nov 25, 2025
321ff7c
Group RPC endpoint event tests by failover enabled/disabled
cryptodev-2s Nov 25, 2025
7b9c736
docs: add JSDoc for getError helper in createNetworkClient
cryptodev-2s Nov 25, 2025
2c35648
refactor: remove primaryEndpointUrl from chain-level RPC events
cryptodev-2s Nov 25, 2025
30a9486
docs: clarify event payload changes in network-controller changelog
cryptodev-2s Nov 26, 2025
4e7a37a
fix: add undefined check for error in onServiceBreak handler
cryptodev-2s Nov 26, 2025
61bdbbc
refactor: improve type safety for getError function
cryptodev-2s Nov 26, 2025
9fea617
fix: prevent race condition in onBreak chain status check
cryptodev-2s Nov 26, 2025
e4459ee
revert: remove previousStatus check that introduced race condition
cryptodev-2s Nov 26, 2025
c59898d
test: fix test to properly verify degraded then recover scenario
cryptodev-2s Nov 26, 2025
bcc840f
Remove primaryEndpointUrl from onBreak, onDegraded, and onAvailable e…
cryptodev-2s Nov 26, 2025
3918d08
Remove endpointUrl from chain-level RPC events
cryptodev-2s Nov 26, 2025
916a0e2
Fix typo: correct tertiary endpoint URL in test
cryptodev-2s Nov 26, 2025
47a5270
Merge branch 'update-network-controller-rpc-endpoint-events' into upd…
cryptodev-2s Nov 27, 2025
4b56af2
Merge branch 'main' into update-network-status-live
cryptodev-2s Nov 27, 2025
c0070c8
docs: add changelog entry for automatic network status updates
cryptodev-2s Nov 27, 2025
e623211
test: improve test descriptions for clarity
cryptodev-2s Nov 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/network-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
- For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
- Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
- Automatically update network status metadata when chain-level RPC events are published ([#7186](https://github.com/MetaMask/core/pull/7186))
- `NetworkController` now automatically subscribes to `NetworkController:rpcEndpointChainUnavailable`, `NetworkController:rpcEndpointChainDegraded`, and `NetworkController:rpcEndpointChainAvailable` events and updates the corresponding network's status metadata in state when these events are published.
- This enables real-time network status updates without requiring explicit `lookupNetwork` calls, providing more accurate and timely network availability information.

## [26.0.0]

Expand Down
62 changes: 46 additions & 16 deletions packages/network-controller/src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,31 @@ export class NetworkController extends BaseController<
`${this.name}:updateNetwork`,
this.updateNetwork.bind(this),
);

this.messenger.subscribe(
`${this.name}:rpcEndpointChainUnavailable`,
({ networkClientId }) => {
this.#updateMetadataForNetwork(networkClientId, {
networkStatus: NetworkStatus.Unavailable,
});
},
);
this.messenger.subscribe(
`${this.name}:rpcEndpointChainDegraded`,
({ networkClientId }) => {
this.#updateMetadataForNetwork(networkClientId, {
networkStatus: NetworkStatus.Degraded,
});
},
);
this.messenger.subscribe(
`${this.name}:rpcEndpointChainAvailable`,
({ networkClientId }) => {
this.#updateMetadataForNetwork(networkClientId, {
networkStatus: NetworkStatus.Available,
});
},
);
}

/**
Expand Down Expand Up @@ -1846,11 +1871,11 @@ export class NetworkController extends BaseController<
async #lookupGivenNetwork(networkClientId: NetworkClientId) {
const { networkStatus, isEIP1559Compatible } =
await this.#determineNetworkMetadata(networkClientId);
this.#updateMetadataForNetwork(
networkClientId,

this.#updateMetadataForNetwork(networkClientId, {
networkStatus,
isEIP1559Compatible,
);
});
}

/**
Expand Down Expand Up @@ -1925,11 +1950,10 @@ export class NetworkController extends BaseController<
}
}

this.#updateMetadataForNetwork(
this.state.selectedNetworkClientId,
this.#updateMetadataForNetwork(this.state.selectedNetworkClientId, {
networkStatus,
isEIP1559Compatible,
);
});

if (isInfura) {
if (networkStatus === NetworkStatus.Available) {
Expand All @@ -1949,14 +1973,17 @@ export class NetworkController extends BaseController<
* Updates the metadata for the given network in state.
*
* @param networkClientId - The associated network client ID.
* @param networkStatus - The network status to store in state.
* @param isEIP1559Compatible - The EIP-1559 compatibility status to
* @param metadata - The metadata to store in state.
* @param metadata.networkStatus - The network status to store in state.
* @param metadata.isEIP1559Compatible - The EIP-1559 compatibility status to
* store in state.
*/
#updateMetadataForNetwork(
networkClientId: NetworkClientId,
networkStatus: NetworkStatus,
isEIP1559Compatible: boolean | undefined,
metadata: {
networkStatus: NetworkStatus;
isEIP1559Compatible?: boolean | undefined;
},
) {
this.update((state) => {
if (state.networksMetadata[networkClientId] === undefined) {
Expand All @@ -1965,12 +1992,15 @@ export class NetworkController extends BaseController<
EIPS: {},
};
}
const meta = state.networksMetadata[networkClientId];
meta.status = networkStatus;
if (isEIP1559Compatible === undefined) {
delete meta.EIPS[1559];
} else {
meta.EIPS[1559] = isEIP1559Compatible;
const newMetadata = state.networksMetadata[networkClientId];
newMetadata.status = metadata.networkStatus;

if ('isEIP1559Compatible' in metadata) {
if (metadata.isEIP1559Compatible === undefined) {
delete newMetadata.EIPS[1559];
} else {
newMetadata.EIPS[1559] = metadata.isEIP1559Compatible;
}
}
});
}
Expand Down
28 changes: 18 additions & 10 deletions packages/network-controller/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
/**
* Represents the availability state of the currently selected network.
* Represents the availability status of an RPC endpoint. (Regrettably, the
* name of this type is a misnomer.)
*
* The availability status is set both automatically (as requests are made) and
* manually (when `lookupNetwork` is called).
*/
export enum NetworkStatus {
/**
* The network may or may not be able to receive requests, but either no
* attempt has been made to determine this, or an attempt was made but was
* unsuccessful.
* Either the availability status of the RPC endpoint has not been determined,
* or request that `lookupNetwork` performed returned an unknown error.
*/
Unknown = 'unknown',
/**
* The network is able to receive and respond to requests.
* The RPC endpoint is consistently returning successful (2xx) responses.
*/
Available = 'available',
/**
* The network was unable to receive and respond to requests for unknown
* reasons.
* Either the last request to the RPC endpoint was either too slow, or the
* endpoint is consistently returning errors and the number of retries has
* been reached.
*/
Degraded = 'degraded',
/**
* The RPC endpoint is consistently returning enough 5xx errors that requests
* have been paused.
*/
Unavailable = 'unavailable',
/**
* The network is not only unavailable, but is also inaccessible for the user
* specifically based on their location. This state only applies to Infura
* networks.
* The RPC endpoint is inaccessible for the user based on their location. This
* status only applies to Infura networks.
*/
Blocked = 'blocked',
}
Expand Down
Loading
Loading