-
-
Notifications
You must be signed in to change notification settings - Fork 256
Ensure networksMetadata never references old network client IDs
#7047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
befa4e1 to
6933895
Compare
networksMetadata always reflects available networksnetworksMetadata never references old network client IDs
6933895 to
e5a0e22
Compare
In debugging a long-standing issue where SelectedNetworkController sometimes requests invalid network client IDs from NetworkController, one bug was discovered in NetworkController. Namely, when a network is removed, its data is removed from `networkConfigurationsByChainId`, but not `networksMetadata`. This commit fixes `removeNetwork` to do this, and ensures that when the controller is initialized, if `networksMetadata` contains invalid network client IDs, they are removed.
e5a0e22 to
d80de28
Compare
|
|
||
| const getRootMessenger = (): RootMessenger => { | ||
| return new Messenger({ namespace: MOCK_ANY_NAMESPACE }); | ||
| const rootMessenger = new Messenger< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the tests for GasFeeController instantiate a real NetworkController, we also need to make sure that we register ErrorReportingService:captureException, as NetworkController may call it during initialization if the initial state is incoherent. These changes should have been here all along, but they have not been needed so far. The reason they are needed now is that in some tests, the initial NetworkController state sets networksMetadata for networks that aren't present in networkConfigurationsByChainId. We could make the initial state more accurate, but it doesn't really matter here, we just need to register ErrorReportingService:captureException with a dummy handler.
| btoa, | ||
| }), | ||
| }); | ||
| it('corrects an invalid selectedNetworkClientId to the default RPC endpoint of the first chain, logging this fact', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two tests were combined into one for simplicity.
| }), | ||
| '0x2': buildCustomNetworkConfiguration({ chainId: '0x2' }), | ||
| '0x3': buildCustomNetworkConfiguration({ chainId: '0x3' }), | ||
| it('removes invalid network client IDs from networksMetadata, logging this fact', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new test.
| }, | ||
| networksMetadata: { | ||
| mainnet: { | ||
| [TESTNET.networkType]: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the NetworkController tests used initial state which is now invalid, so they were corrected.
Explanation
In debugging a long-standing issue where SelectedNetworkController sometimes requests invalid network client IDs from NetworkController, one bug was discovered in NetworkController. Namely, when a network is removed, its data is removed from
networkConfigurationsByChainId, but notnetworksMetadata. This commit fixesremoveNetworkto do this, and ensures that when the controller is initialized, ifnetworksMetadatacontains invalid network client IDs, they are removed.References
Fixes https://consensyssoftware.atlassian.net/browse/WPC-151.
Checklist
Note
Cleans
networksMetadataof invalid network client IDs on initialization and when removing networks, with tests and changelog updates.correctInitialStateremoves invalid network client IDs fromnetworksMetadataand logs viaErrorReportingService:captureException.removeNetworknow deletesnetworksMetadatafor all RPC endpoints in the removed configuration.selectedNetworkClientId, metadata cleanup, and error logging intests/NetworkController.test.ts.ErrorReportingService:captureExceptionand expose handler injection (tests/helpers.ts).GasFeeController.test.tsto register and delegateErrorReportingService:captureExceptionin messenger setup.packages/network-controller/CHANGELOG.mdunder Unreleased → Fixed to document metadata cleanup behavior.Written by Cursor Bugbot for commit deeb2e2. This will update automatically on new commits. Configure here.