feat(network-controller): force RPC failover via remote flag#9175
feat(network-controller): force RPC failover via remote flag#9175cryptodev-2s wants to merge 36 commits into
Conversation
Thread isRpcFailoverForced through createNetworkClient, createRpcServiceChain, and createAutoManagedNetworkClient. When the force flag is on for an Infura endpoint that has failover URLs, the endpoint chain is built from failovers only, bypassing Infura entirely.
… param Add a disableRpcFailoverForced reconstruction test mirroring the sibling, and add the missing isRpcFailoverForced JSDoc tags.
…e-enabled flag Subscribe to RemoteFeatureFlagController state changes and read the forced failover flag on init, reconstructing affected network clients. Add public enableRpcFailoverForced/disableRpcFailoverForced methods and their messenger action types. Update existing tests for the new createAutoManagedNetworkClient argument and the new auto-managed client methods.
Export NetworkControllerEnableRpcFailoverForcedAction and NetworkControllerDisableRpcFailoverForcedAction, and update the init JSDoc to mention both failover flags.
…form prefix Rename the remote flag key from wallet-framework-rpc-failover-force-enabled to core-platform-rpc-failover-force-enabled to match the team's new name.
a049dda to
0bd5566
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
54126df to
0bd5566
Compare
Resolve create-network-client.ts by keeping main's URL-based isInfura (#9125) plus the forced-failover branch. Resolve NetworkController.test.ts by dropping the stale megaeth-testnet expectation that main replaced with megaeth-testnet-v2.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Drop the NetworkController enableRpcFailoverForced/disableRpcFailoverForced methods, their messenger actions, and exports. Forced failover is driven entirely by the remote feature flag; nothing calls these imperatively.
…eForcedRpcFailover
…loverMode Replace the boolean walletFrameworkRpcFailoverEnabled and the forced flag with a single corePlatformRpcFailoverMode flag (disabled/enabled/forced). The selectors derive both isRpcFailoverEnabled and isRpcFailoverForced from it, defaulting to disabled. NetworkController no longer reads walletFrameworkRpcFailoverEnabled.
| #isRpcFailoverEnabled = false; | ||
|
|
||
| #isRpcFailoverForced = false; |
There was a problem hiding this comment.
Instead of having two booleans, let's bring the state directly into the controller. Then we can simplify to one RemoteFeatureFlagController:stateChange subscription too
There was a problem hiding this comment.
Done in e690b24. The controller now tracks a single #rpcFailoverMode field with one RemoteFeatureFlagController:stateChange subscription via getRpcFailoverMode, and the createAutoManagedNetworkClient call sites derive the enabled/forced booleans from the mode.
| }); | ||
|
|
||
| this.#isRpcFailoverEnabled = newIsRpcFailoverEnabled; | ||
| } |
There was a problem hiding this comment.
Since we are making a breaking change we can remove enableRpcFailover and disableRpcFailover on NetworkController
There was a problem hiding this comment.
Yes I am planning to do this in a follow up PR
There was a problem hiding this comment.
Finally made part of this pr to close #9175 (comment)
…controller Replace the two #isRpcFailover* booleans and their two RemoteFeatureFlagController subscriptions with a single #rpcFailoverMode field, one subscription via getRpcFailoverMode, and one #updateRpcFailover method. The createAutoManagedNetworkClient call sites derive the enabled/forced booleans from the mode inline.
…lover Remove the imperative enableRpcFailover/disableRpcFailover methods, their messenger actions, and exported types. RPC failover is driven entirely by the corePlatformRpcFailoverMode remote feature flag.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
| isRpcFailoverEnabled?: boolean; | ||
| isRpcFailoverForced?: boolean; |
There was a problem hiding this comment.
| isRpcFailoverEnabled?: boolean; | |
| isRpcFailoverForced?: boolean; | |
| rpcFailoverMode?: RpcFailoverMode; |
There shouldn't be that many instances to update
There was a problem hiding this comment.
Done in 268e479. buildRootMessenger, withController, and withNetworkClient all take a single rpcFailoverMode option now.
| isRpcFailoverEnabled: boolean; | ||
| isRpcFailoverForced: boolean; |
There was a problem hiding this comment.
| isRpcFailoverEnabled: boolean; | |
| isRpcFailoverForced: boolean; | |
| rpcFailoverMode: RpcFailoverMode; |
There was a problem hiding this comment.
Done in 268e479. createNetworkClient, createRpcServiceChain, and getAvailableEndpoints all take a single rpcFailoverMode now and switch on it.
| const enableForcedRpcFailover = (): void => { | ||
| isRpcFailoverForced = true; | ||
| destroy(); | ||
| networkClient = undefined; | ||
| }; |
There was a problem hiding this comment.
Maybe we only need a single setRpcFailoverMode?
There was a problem hiding this comment.
Agreed, done in 268e479. The auto managed client exposes one setRpcFailoverMode and the four enable/disable methods are gone.
|
|
||
| * @param callback - Called with each network client that has failover URLs. | ||
| */ | ||
| #forEachNetworkClientWithFailover( |
There was a problem hiding this comment.
I guess this can be moved into updateRpcFailover instead of being a separate callback function now
There was a problem hiding this comment.
Yep, inlined in 268e479. updateRpcFailover walks the registry directly and calls setRpcFailoverMode on each client that has failover URLs.
Replace the isRpcFailoverEnabled/isRpcFailoverForced booleans throughout with the single RpcFailoverMode. createNetworkClient/createRpcServiceChain and createAutoManagedNetworkClient take a rpcFailoverMode, the auto-managed client exposes one setRpcFailoverMode, and #updateRpcFailover applies it directly.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Explanation
RPC failover is now controlled by a single remote feature flag,
corePlatformRpcFailoverMode, a string with three values:disabled: failover URLs are ignored. Traffic stays on the primary endpoint (Infura only).enabled: traffic diverts to the configured failover URLs when the primary endpoint is unavailable. This is the existing automatic failover behavior.forced: Infura endpoints that have failover URLs route all traffic (including block tracker polling) to those failover URLs, bypassing Infura entirely. Infura endpoints without failover URLs stay on Infura, and custom endpoints are unaffected.The value defaults to
disabledwhen the flag is absent or unrecognized.forcedis the emergency kill switch: if the automatic failover logic itself ever misbehaves, it deterministically takes Infura out of the path.BREAKING: the controller no longer reads
walletFrameworkRpcFailoverEnabled(theenabledmode replaces it), and the imperativeNetworkController.enableRpcFailover/disableRpcFailovermethods and their messenger actions are removed. Failover is driven entirely by the remote flag. Internally the controller tracks a singleRpcFailoverModeapplied through oneRemoteFeatureFlagController:stateChangesubscription.Note:
corePlatformRpcFailoverModeis a server side contract, delivered camelCase by the ClientConfigAPI. The oldwalletFrameworkRpcFailoverEnabledflag stays in LaunchDarkly for already shipped clients.References
Checklist
Note
High Risk
Breaking public API and remote-flag contract changes alter how all wallet RPC traffic is routed for Infura networks, including an emergency bypass path; misconfiguration could cut clients off from Infura or route everything to failovers unexpectedly.
Overview
BREAKING: RPC failover is now controlled only by the remote string flag
corePlatformRpcFailoverMode(disabled|enabled|forced), replacingwalletFrameworkRpcFailoverEnabledand the imperativeenableRpcFailover/disableRpcFailoverAPIs (including messenger actions and exported action types).NetworkControllertracksRpcFailoverMode, applies it oninit()andRemoteFeatureFlagController:stateChange, and propagates it viasetRpcFailoverModeon auto-managed clients with failover URLs.createNetworkClientbuilds the RPC chain through newgetAvailableEndpointslogic:enabledkeeps Infura primary plus failover fallbacks;forcedsends all Infura traffic (including block polling) to failover URLs when configured, bypassing Infura; custom primaries are unchanged.Tests and helpers switch from
isRpcFailoverEnabledtorpcFailoverMode, with coverage for forced routing and selector defaults.Reviewed by Cursor Bugbot for commit 50e82f0. Bugbot is set up for automated code reviews on this repo. Configure here.