Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sessionId and hardcoded provider #947

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("quicknode"), // Optimism
"eip155:8453" => Some("quicknode"), // Base
"eip155:42161" => Some("quicknode"), // Arbitrum One
chris13524 marked this conversation as resolved.
Show resolved Hide resolved
_ => {
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
Loading