From cc62f59d126502752c0d77e52e62aa5e04159fbb Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Mon, 10 Feb 2025 11:10:58 -0500 Subject: [PATCH] feat: sessionId and hardcoded provider --- src/handlers/identity.rs | 1 + src/handlers/mod.rs | 1 + src/handlers/proxy.rs | 47 +++++++++++++++++++++++++ src/handlers/wallet/get_calls_status.rs | 1 + 4 files changed, 50 insertions(+) diff --git a/src/handlers/identity.rs b/src/handlers/identity.rs index 205ee9f67..05882e77e 100644 --- a/src/handlers/identity.rs +++ b/src/handlers/identity.rs @@ -317,6 +317,7 @@ async fn lookup_identity_rpc( // ENS registry contract is only deployed on mainnet chain_id: ETHEREUM_MAINNET.to_owned(), provider_id: None, + session_id: None, source: Some(crate::analytics::MessageSource::Identity), sdk_info, }, diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 42846a429..2e5ed9870 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -47,6 +47,7 @@ pub struct RpcQueryParams { pub project_id: String, /// Optional provider ID for the exact provider request pub provider_id: Option, + pub session_id: Option, // TODO remove this param, as it can be set by actual rpc users but it shouldn't be /// Optional "source" field to indicate an internal request diff --git a/src/handlers/proxy.rs b/src/handlers/proxy.rs index a89cafe86..e27cd28e0 100644 --- a/src/handlers/proxy.rs +++ b/src/handlers/proxy.rs @@ -67,6 +67,53 @@ pub async fn rpc_call( body: Bytes, ) -> Result { let chain_id = query_params.chain_id.clone(); + + if query_params.session_id.is_some() { + let provider_id = match chain_id.as_str() { + "eip155:10" => Some("infura"), // Optimism + "eip155:8453" => Some("infura"), // Base + "eip155:42161" => Some("infura"), // Arbitrum One + _ => { + debug!( + "Requested sessionId for chain {chain_id} but no hardcoded provider was configured" + ); + None + } + }; + + if let Some(provider_id) = provider_id { + let provider = state + .providers + .get_rpc_provider_by_provider_id(provider_id) + .ok_or_else(|| RpcError::UnsupportedProvider(provider_id.to_owned()))?; + let response = rpc_provider_call( + state.clone(), + addr, + query_params.clone(), + headers.clone(), + body.clone(), + provider.clone(), + ) + .await; + + match response { + Ok(response) if !response.status().is_server_error() => { + return Ok(response); + } + e => { + // Not recording metric since this is a hardcoded provider + // state + // .metrics + // .add_rpc_call_retries(0, chain_id.clone()); + debug!( + "Provider (via sessionId) '{}' returned an error {e:?}, trying the next provider", + provider.provider_kind() + ); + } + } + } + } + // Exact provider proxy request for testing suite // This request is allowed only for the RPC_PROXY_TESTING_PROJECT_ID let providers = match query_params.provider_id.clone() { diff --git a/src/handlers/wallet/get_calls_status.rs b/src/handlers/wallet/get_calls_status.rs index 95811b5f8..48ba044aa 100644 --- a/src/handlers/wallet/get_calls_status.rs +++ b/src/handlers/wallet/get_calls_status.rs @@ -133,6 +133,7 @@ async fn handler_internal( chain_id: chain_id.into(), project_id, provider_id: None, + session_id: None, source: Some(MessageSource::WalletGetCallsStatus), sdk_info: query.sdk_info.clone(), },