fix: cp-7.57.0 Initialize feature flags from state#21168
Merged
mcmire merged 4 commits intoOct 15, 2025
Conversation
0ee7360 introduced a change such that when the app is cold-started and Engine is initialized, RemoteFeatureFlagController is no longer instructed to reuse feature flags from a previous start, but rather, it will fetch them all over again. This change was made so that by simply listening to `RemoteFeatureFlagController:stateChange`, the RPC failover mode in NetworkController could be easily enabled or disabled. In hindsign, this changed increased the start time of the app, negatively impacting performance. This is particularly noticeable on low-end devices where the app is frequently killed and restarted automatically due to out-of-memory issues. Also, changing the behavior of `RemoteFeatureFlagController:stateChange` in the way described above is admittedly strange. To address this, this PR once again initializes RemoteFeatureFlagController from persisted state. As for NetworkController, it now correctly asks for the RemoteFeatureFlagController state once it is initialized and uses it to switch the RPC failover mode.
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
NicolasMassart
previously approved these changes
Oct 15, 2025
NicolasMassart
left a comment
Contributor
There was a problem hiding this comment.
Happy to re-approve once changes made
|
sethkfman
approved these changes
Oct 15, 2025
sethkfman
left a comment
Contributor
There was a problem hiding this comment.
LGTM - providing sign-off for platform
NicolasMassart
approved these changes
Oct 15, 2025
This was
linked to
issues
Oct 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
0ee7360 introduced a change such that when the app is cold-started and Engine is initialized, RemoteFeatureFlagController is no longer instructed to reuse feature flags from a previous start, but rather, it will fetch them all over again. This change was made so that by simply listening to
RemoteFeatureFlagController:stateChange, the RPC failover mode in NetworkController could be easily enabled or disabled.In hindsight, this changed increased the start time of the app, negatively impacting performance. This is particularly noticeable on low-end devices where the app is frequently killed and restarted automatically due to out-of-memory issues. Also, changing the behavior of
RemoteFeatureFlagController:stateChangein the way described above is admittedly strange.To address this, this PR once again initializes RemoteFeatureFlagController from persisted state. As for NetworkController, it now correctly asks for the RemoteFeatureFlagController state once it is initialized and uses it to switch the RPC failover mode.
Changelog
CHANGELOG entry: Don't re-fetch feature flags on app restart, but rely on persistence instead
Related issues
(N/A)
Manual testing steps
QUICKNODE_environment variables to.js.env. Ask me for what they should be.yarn setup:expo, runyarn watch:clean.node_modules/@metamask/network-controller/dist/rpc-service/rpc-service.cjs, look forasync function _RpcService_processRequestand make these changes:async function _RpcService_processRequest(fetchOptions) { let response; try { return await __classPrivateFieldGet(this, _RpcService_policy, "f").execute(async () => { + console.log('[REQUEST]', this.endpointUrl.toString(), 'with', fetchOptions); + if ( + this.endpointUrl.toString().includes("linea-mainnet.infura.io") || + this.endpointUrl.toString().includes("mainnet.era.zksync.io") + ) { + console.log('[RESPONSE]', this.endpointUrl.toString(), '=> 502'); + throw new controller_utils_1.HttpError(502); + } response = await __classPrivateFieldGet(this, _RpcService_fetch, "f").call(this, this.endpointUrl, fetchOptions); + console.log('[RESPONSE]', this.endpointUrl.toString(), '=>', response.status); if (!response.ok) { throw new controller_utils_1.HttpError(response.status); } return await response.json(); }); }app/core/Engine/controllers/network-controller-init.ts, look fornew NetworkController, and make these changes:return { ...commonOptions, policyOptions: { maxRetries, - maxConsecutiveFailures: (maxRetries + 1) * 7, + maxConsecutiveFailures: (maxRetries + 1) * 4, }, }; }, additionalDefaultNetworks, }; const networkController = new NetworkController(networkControllerOptions);[REQUEST] https://linea-mainnet.infura.io/v3/<api key>...with a line under this is[RESPONSE] https://linea-mainnet.infura.io/v3/<api key> => 502.[REQUEST] https://<name>.linea-mainnet.quiknode.pro/<api-key>. This is an indicator that the RPC failover logic is still working.Screenshots/Recordings
(N/A)
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Initialize
RemoteFeatureFlagControllerfrom persisted state and toggleNetworkControllerRPC failover based onwalletFrameworkRpcFailoverEnabledat init and on updates, with new tests.RemoteFeatureFlagControllerwith persistedstate.toggleRpcFailoverhelper and subscribe toRemoteFeatureFlagController:stateChangeusing selectorstate.remoteFeatureFlags.walletFrameworkRpcFailoverEnabled.walletFrameworkRpcFailoverEnabled.app/core/Engine/Engine.test.ts):ClientConfigApiServiceandNetworkControllermethods.Written by Cursor Bugbot for commit df7f8ed. This will update automatically on new commits. Configure here.