Skip to content

Commit

Permalink
feat: sessionId and hardcoded provider
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Feb 10, 2025
1 parent 193138b commit cc62f59
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/handlers/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct RpcQueryParams {
pub project_id: String,
/// Optional provider ID for the exact provider request
pub provider_id: Option<String>,
pub session_id: Option<String>,

// 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
Expand Down
47 changes: 47 additions & 0 deletions src/handlers/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,53 @@ pub async fn rpc_call(
body: Bytes,
) -> Result<Response, RpcError> {
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() {
Expand Down
1 change: 1 addition & 0 deletions src/handlers/wallet/get_calls_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand Down

0 comments on commit cc62f59

Please sign in to comment.