Skip to content

feat!: Use RemoteFeatureFlagController for isRpcFailoverEnabled#9013

Merged
FrederikBolding merged 6 commits into
mainfrom
fb/use-feature-flags-in-network-controller
Jun 5, 2026
Merged

feat!: Use RemoteFeatureFlagController for isRpcFailoverEnabled#9013
FrederikBolding merged 6 commits into
mainfrom
fb/use-feature-flags-in-network-controller

Conversation

@FrederikBolding
Copy link
Copy Markdown
Member

@FrederikBolding FrederikBolding commented Jun 5, 2026

Explanation

This PR enables use of the RemoteFeatureFlagController to automatically determine the state of isRpcFailoverEnabled. Thus, the constructor argument has been removed and a init function has been introduced.

References

https://consensyssoftware.atlassian.net/browse/WPC-1053

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

High Risk
Breaking API and required init/messenger setup; mis-wiring leaves failover off or stale, and failover changes affect live RPC routing for configured endpoints.

Overview
Breaking change: NetworkController no longer accepts isRpcFailoverEnabled in the constructor. RPC failover is driven by RemoteFeatureFlagController via the walletFrameworkRpcFailoverEnabled flag.

Consumers must wire RemoteFeatureFlagController:getState and RemoteFeatureFlagController:stateChange on the network controller messenger, call init() after construction to apply the initial flag, and drop any manual isRpcFailoverEnabled option. The controller subscribes to remote flag updates and toggles failover through the existing #updateRpcFailoverEnabled path (same behavior as enableRpcFailover / disableRpcFailover).

Adds @metamask/remote-feature-flag-controller, getIsRpcFailoverEnabled in selectors.ts, dependency graph/README updates, and test helpers that mock the remote flag and call init() in withController.

Reviewed by Cursor Bugbot for commit 5ffe1c5. Bugbot is set up for automated code reviews on this repo. Configure here.

describe('disableRpcFailover', () => {
describe('if the controller was initialized with isRpcFailoverEnabled = true', () => {
it('calls disableRpcFailover on only the network clients whose RPC endpoints have configured failover URLs', async () => {
const originalCreateAutoManagedNetworkClient =
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spy needed to be applied earlier to ensure it caught the first call to createAutoManagedNetworkClient

@FrederikBolding FrederikBolding marked this pull request as ready for review June 5, 2026 11:01
@FrederikBolding FrederikBolding requested review from a team as code owners June 5, 2026 11:01
@FrederikBolding FrederikBolding changed the title feat: Use RemoteFeatureFlagController for isRpcFailoverEnabled feat!: Use RemoteFeatureFlagController for isRpcFailoverEnabled Jun 5, 2026
Comment thread packages/network-controller/tests/helpers.ts
Comment thread packages/network-controller/src/NetworkController.ts
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ffe1c5. Configure here.

*/
init(): void {
const state = this.messenger.call('RemoteFeatureFlagController:getState');
this.#updateRpcFailoverEnabled(getIsRpcFailoverEnabled(state));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init eagerly builds all clients

Medium Severity

init routes through #updateRpcFailoverEnabled, which populates the auto-managed network client registry whenever the remote failover flag is true. The old constructor only stored the boolean and deferred client creation until the network was first used, so startup can now create every network client early when the flag is on.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 5ffe1c5. Configure here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done at init time anyways via initializeProvider in both clients. Should not matter.

@FrederikBolding FrederikBolding requested a review from Mrtenz June 5, 2026 11:33
);

this.messenger.subscribe(
// eslint-disable-next-line no-restricted-syntax
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the restricted syntax here? 🤔

Copy link
Copy Markdown
Member Author

@FrederikBolding FrederikBolding Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a special rule for stateChanged / stateChange. But not many controllers have exported types for it yet, so I can't really use the new format here.

@FrederikBolding FrederikBolding added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit e307c45 Jun 5, 2026
370 checks passed
@FrederikBolding FrederikBolding deleted the fb/use-feature-flags-in-network-controller branch June 5, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants