feat(ymax-planner): Fallback RPC endpoint support#12624
Conversation
gibson042
left a comment
There was a problem hiding this comment.
I absolutely do not want to be in the business of maintaining this collection of parallel client-utils infrastructure. If changes are worth making, they're worth making in the source package.
| /** | ||
| * Parts of the network config fetched from the chain | ||
| * can be overriden using env vars starting from | ||
| * `OVERRIDE_` | ||
| */ | ||
| const overrideNetworkConfigFromEnvironmentVariables = ( | ||
| { chainName, rpcAddrs }: MinimalNetworkConfig, | ||
| { env }: { env: NodeJS.ProcessEnv }, | ||
| ) => { | ||
| if (env.OVERRIDE_RPC_ADDRESS) rpcAddrs[0] = env.OVERRIDE_RPC_ADDRESS; | ||
| if (env.FALLBACK_RPC_ADDRESS) rpcAddrs.push(env.FALLBACK_RPC_ADDRESS); | ||
|
|
||
| return { | ||
| chainName, | ||
| rpcAddrs, | ||
| websocketUrl: env.OVERRIDE_WEBSOCKET_URL || rpcAddrs.find(Boolean)!, | ||
| }; | ||
| }; |
There was a problem hiding this comment.
This seems like it will interact poorly with AGORIC_NET. I think I'd rather expand that to support e.g. "$fqdn1,…,$chainId".
| return makeVstorageKitFromVstorage({ vstorage, networkConfig }); | ||
| }; | ||
|
|
||
| const makeVstoragetWrapper = ( |
| import makeSmartWalletKit from './wrappers/smart-wallet.ts'; | ||
| import makeSigningSmartWalletKit from './wrappers/signing-smart-wallet.ts'; |
There was a problem hiding this comment.
This name reüse makes it super hard to keep track of what's going on, and will even hinder following likes in client-utils.
| try { | ||
| if (fallbackVstorage) await verifyStatus({ now }, priorityRpcAddress); | ||
|
|
||
| curr = await vstorage.readStorageMeta(path, { | ||
| height: config?.height, | ||
| kind: config?.kind, | ||
| }); | ||
| } catch (err) { | ||
| if (fallbackVstorage) { |
There was a problem hiding this comment.
Too much redundancy; too much forward maintenance burden.
| await null; | ||
|
|
||
| try { | ||
| if (fallbackVstorage) await verifyStatus({ now }, priorityRpcAddress); |
| await null; | ||
|
|
||
| try { | ||
| if (fallbackClient) await verifyStatus({ now }, priorityRpcAddress); |
There was a problem hiding this comment.
Why should the tx signer care whether or not the receiving RPC node is catching up?
There was a problem hiding this comment.
Why should the tx signer care whether or not the receiving RPC node is catching up?
It's likely/possible the signed message will be using an out of sync seq num if the RPC is behind.
mhofman
left a comment
There was a problem hiding this comment.
I haven't fully reviewed but I was hoping there would be a way to more directly hook into the startgate client to avoid patching on top of it.
| client.broadcastTx = broadcastTx; | ||
| client.sign = sign; | ||
| client.signAndBroadcast = signAndBroadcast; |
There was a problem hiding this comment.
I think we may need to override signAndBroadcastSync too for completeness ?
There was a problem hiding this comment.
But really I'm worried this is "patching on top" and that all the other StargateClient methods wouldn't end up using the fallback.
closes: #XXXX
refs: #XXXX
Description
Adds fallback RPC support to the ymax planner service. When a primary RPC node is unavailable or falling behind, requests automatically fail over to a configured fallback node
Key changes:
src/main.ts: AddsoverrideNetworkConfigFromEnvironmentVariablesto supportOVERRIDE_RPC_ADDRESS,FALLBACK_RPC_ADDRESS, andOVERRIDE_WEBSOCKET_URLenv vars. SwitchesmakeSmartWalletKitandmakeSigningSmartWalletKitimports from@agoric/client-utilsto local wrappers that are fallback-awaresrc/wrappers/stargate-client.ts(new): WrapsSigningStargateClientso thatbroadcastTx,sign, andsignAndBroadcasteach verify the primary node's health before calling it, falling back to the secondary node on failuresrc/wrappers/vstorage-kit.ts(new): Wraps vstorage'sreadStorageandreadStorageMetawith the same primary/fallback patternsrc/wrappers/smart-wallet.ts(new): Thin adapter that constructs aSmartWalletKitusing the fallback-aware vstorage kitsrc/wrappers/signing-smart-wallet.ts(new): Thin adapter that constructs aSigningSmartWalletKitusing the fallback-aware stargate clientsrc/wrappers/utils.ts(new):verifyStatushelper that hits the RPC /status endpoint with a 5-second cache TTL, rejecting if the node is catching upSecurity Considerations
No new authorities are introduced. The fallback RPC address is configured via a server-side environment variable
FALLBACK_RPC_ADDRESS, not user input. The status check usesAbortSignal.timeoutto prevent hanging requests. Trust boundaries remain the same — both primary and fallback nodes are expected to be trusted RPC endpoints configured by the operatorScaling Considerations
Each RPC call now incurs an additional
/statushealth check against the primary node, cached for 5 seconds (roughly one block interval). This adds one lightweight HTTP request per ~5 seconds under load. When a fallback client is configured, an additionalSigningStargateClientandVStorageconnection are maintained, doubling the connection footprint to RPC nodesDocumentation Considerations
N/A
Testing Considerations
N/A
Upgrade Considerations
This is an additive change to the ymax planner service. Existing deployments without the new environment variables will behave identically to before — no fallback client is created unless
FALLBACK_RPC_ADDRESSis set. To adopt, operators set the env vars and redeploy; no data migration or on-chain changes required