Skip to content

Commit 81a987c

Browse files
committed
refactor: remove primaryEndpointUrl from chain-level RPC events
Remove primaryEndpointUrl field from NetworkController chain-level events: - NetworkController:rpcEndpointChainUnavailable - NetworkController:rpcEndpointChainDegraded - NetworkController:rpcEndpointChainAvailable Chain-level events are designed to represent the overall status of an endpoint chain, not individual endpoints. The primaryEndpointUrl field is redundant since consumers can derive endpoint information from the networkClientId using getNetworkClientById() or getNetworkConfigurationByNetworkClientId(). Individual endpoint events (rpcEndpointUnavailable, rpcEndpointDegraded, rpcEndpointRetried) retain the primaryEndpointUrl field, as it's useful for comparing endpointUrl to primaryEndpointUrl to determine whether the affected endpoint is a primary or a failover. Updated event type definitions, event publishing logic, test assertions, and changelog to reflect these changes.
1 parent 7b9c736 commit 81a987c

File tree

4 files changed

+6
-20
lines changed

4 files changed

+6
-20
lines changed

packages/network-controller/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
- **BREAKING:** Split up and update payload data for `NetworkController:rpcEndpointDegraded` and `NetworkController:rpcEndpointUnavailable` ([#7166](https://github.com/MetaMask/core/pull/7166))
1818
- `NetworkController:rpcEndpointDegraded` and `NetworkController:rpcEndpointUnavailable` still exist and retain the same behavior as before.
19-
- New events are `NetworkController:rpcEndpointChainDegraded` and `NetworkController:rpcEndpointChainUnavailable`, and are designed to represent an entire chain of endpoints. They are also guaranteed to not be published multiple times in a row. In particular, `NetworkController:rpcEndpointUnavailable` is published only after trying all of the endpoints for a chain and when the underlying circuit for the last endpoint breaks, not as each primary's or failover's circuit breaks.
20-
- The event payloads for all events have been changed as well: `failoverEndpointUrl` has been renamed to `endpointUrl`, and `endpointUrl` has been renamed to `primaryEndpointUrl`. In addition, `networkClientId` has been added to the payload.
19+
- New events are `NetworkController:rpcEndpointChainDegraded` and `NetworkController:rpcEndpointChainUnavailable`, and are designed to represent an entire chain of endpoints. They are also guaranteed to not be published multiple times in a row. In particular, `NetworkController:rpcEndpointChainUnavailable` is published only after trying all of the endpoints for a chain and when the underlying circuit for the last endpoint breaks, not as each primary's or failover's circuit breaks.
20+
- The event payloads have been changed:
21+
- For individual endpoint events (`NetworkController:rpcEndpointUnavailable`, `NetworkController:rpcEndpointDegraded`): `failoverEndpointUrl` has been renamed to `endpointUrl`, and `endpointUrl` has been renamed to `primaryEndpointUrl`. In addition, `networkClientId` has been added to the payload.
22+
- For chain-level events (`NetworkController:rpcEndpointChainUnavailable`, `NetworkController:rpcEndpointChainDegraded`, `NetworkController:rpcEndpointChainAvailable`): These include `chainId`, `networkClientId`, and event-specific fields (e.g., `error`, `endpointUrl`) but do not include `primaryEndpointUrl`. Consumers can derive endpoint information from the `networkClientId` using `NetworkController:getNetworkClientById` or `NetworkController:getNetworkConfigurationByNetworkClientId`.
2123
- **BREAKING:** Rename and update payload data for `NetworkController:rpcEndpointRequestRetried` ([#7166](https://github.com/MetaMask/core/pull/7166))
2224
- This event is now called `NetworkController:rpcEndpointRetried`.
2325
- The event payload has been changed as well: `failoverEndpointUrl` has been removed, and `primaryEndpointUrl` has been added. In addition, `networkClientId` and `attempt` have been added to the payload.

packages/network-controller/src/NetworkController.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ export type NetworkControllerNetworkRemovedEvent = {
455455
* @param payload.error - The last error produced by the last failover in the
456456
* endpoint chain.
457457
* @param payload.networkClientId - The target network's client ID.
458-
* @param payload.primaryEndpointUrl - The endpoint chain's primary URL.
459458
*/
460459
export type NetworkControllerRpcEndpointChainUnavailableEvent = {
461460
type: 'NetworkController:rpcEndpointChainUnavailable';
@@ -464,7 +463,6 @@ export type NetworkControllerRpcEndpointChainUnavailableEvent = {
464463
chainId: Hex;
465464
error: unknown;
466465
networkClientId: NetworkClientId;
467-
primaryEndpointUrl: string;
468466
},
469467
];
470468
};
@@ -519,7 +517,6 @@ export type NetworkControllerRpcEndpointUnavailableEvent = {
519517
* @param payload.error - The last error produced by the endpoint (or
520518
* `undefined` if the request was slow).
521519
* @param payload.networkClientId - The target network's client ID.
522-
* @param payload.primaryEndpointUrl - The endpoint chain's primary URL.
523520
*/
524521
export type NetworkControllerRpcEndpointChainDegradedEvent = {
525522
type: 'NetworkController:rpcEndpointChainDegraded';
@@ -529,7 +526,6 @@ export type NetworkControllerRpcEndpointChainDegradedEvent = {
529526
endpointUrl: string;
530527
error: unknown;
531528
networkClientId: NetworkClientId;
532-
primaryEndpointUrl: string;
533529
},
534530
];
535531
};
@@ -584,7 +580,6 @@ export type NetworkControllerRpcEndpointDegradedEvent = {
584580
* @param payload.endpointUrl - The URL of the endpoint which meets either of
585581
* the above conditions.
586582
* @param payload.networkClientId - The target network's client ID.
587-
* @param payload.primaryEndpointUrl - The endpoint chain's primary URL.
588583
*/
589584
export type NetworkControllerRpcEndpointChainAvailableEvent = {
590585
type: 'NetworkController:rpcEndpointChainAvailable';
@@ -593,7 +588,6 @@ export type NetworkControllerRpcEndpointChainAvailableEvent = {
593588
chainId: Hex;
594589
endpointUrl: string;
595590
networkClientId: NetworkClientId;
596-
primaryEndpointUrl: string;
597591
},
598592
];
599593
};

packages/network-controller/src/create-network-client-tests/rpc-endpoint-events.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('createNetworkClient - RPC endpoint events', () => {
8484
},
8585
}),
8686
},
87-
async ({ makeRpcCall, clock, chainId, rpcUrl }) => {
87+
async ({ makeRpcCall, clock, chainId }) => {
8888
messenger.subscribe(
8989
'NetworkController:rpcEndpointRetried',
9090
() => {
@@ -127,7 +127,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
127127
chainId,
128128
error: expectedUnavailableError,
129129
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
130-
primaryEndpointUrl: rpcUrl,
131130
});
132131
},
133132
);
@@ -363,7 +362,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
363362
endpointUrl: rpcUrl,
364363
error: expectedDegradedError,
365364
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
366-
primaryEndpointUrl: rpcUrl,
367365
});
368366
},
369367
);
@@ -480,7 +478,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
480478
endpointUrl: rpcUrl,
481479
error: expectedDegradedError,
482480
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
483-
primaryEndpointUrl: rpcUrl,
484481
});
485482
},
486483
);
@@ -829,7 +826,7 @@ describe('createNetworkClient - RPC endpoint events', () => {
829826
},
830827
}),
831828
},
832-
async ({ makeRpcCall, clock, chainId, rpcUrl }) => {
829+
async ({ makeRpcCall, clock, chainId }) => {
833830
messenger.subscribe(
834831
'NetworkController:rpcEndpointRetried',
835832
() => {
@@ -860,7 +857,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
860857
chainId,
861858
endpointUrl: failoverEndpointUrl,
862859
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
863-
primaryEndpointUrl: rpcUrl,
864860
});
865861
},
866862
);
@@ -951,7 +947,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
951947
endpointUrl: rpcUrl,
952948
error: expectedDegradedError,
953949
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
954-
primaryEndpointUrl: rpcUrl,
955950
});
956951
},
957952
);
@@ -1028,7 +1023,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
10281023
endpointUrl: rpcUrl,
10291024
error: undefined,
10301025
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
1031-
primaryEndpointUrl: rpcUrl,
10321026
});
10331027
},
10341028
);
@@ -1265,7 +1259,6 @@ describe('createNetworkClient - RPC endpoint events', () => {
12651259
chainId,
12661260
endpointUrl: rpcUrl,
12671261
networkClientId: 'AAAA-AAAA-AAAA-AAAA',
1268-
primaryEndpointUrl: rpcUrl,
12691262
});
12701263
},
12711264
);

packages/network-controller/src/create-network-client.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ function createRpcServiceChain({
261261
messenger.publish('NetworkController:rpcEndpointChainUnavailable', {
262262
chainId: configuration.chainId,
263263
networkClientId: id,
264-
primaryEndpointUrl: primaryEndpointUrlFromEvent,
265264
error,
266265
});
267266
},
@@ -294,7 +293,6 @@ function createRpcServiceChain({
294293
messenger.publish('NetworkController:rpcEndpointChainDegraded', {
295294
chainId: configuration.chainId,
296295
networkClientId: id,
297-
primaryEndpointUrl: primaryEndpointUrlFromEvent,
298296
endpointUrl,
299297
error,
300298
});
@@ -323,7 +321,6 @@ function createRpcServiceChain({
323321
messenger.publish('NetworkController:rpcEndpointChainAvailable', {
324322
chainId: configuration.chainId,
325323
networkClientId: id,
326-
primaryEndpointUrl: primaryEndpointUrlFromEvent,
327324
endpointUrl,
328325
});
329326
},

0 commit comments

Comments
 (0)