Skip to content

Commit 3c80d85

Browse files
authored
feat: sessionId and hardcoded provider (#947)
* feat: sessionId and hardcoded provider * chore: switch to Quicknode * chore: switch to Lava for Base and Arb * chore: fmt
1 parent 5cbd1b9 commit 3c80d85

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/handlers/identity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ async fn lookup_identity_rpc(
317317
// ENS registry contract is only deployed on mainnet
318318
chain_id: ETHEREUM_MAINNET.to_owned(),
319319
provider_id: None,
320+
session_id: None,
320321
source: Some(crate::analytics::MessageSource::Identity),
321322
sdk_info,
322323
},

src/handlers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub struct RpcQueryParams {
4747
pub project_id: String,
4848
/// Optional provider ID for the exact provider request
4949
pub provider_id: Option<String>,
50+
pub session_id: Option<String>,
5051

5152
// TODO remove this param, as it can be set by actual rpc users but it shouldn't be
5253
/// Optional "source" field to indicate an internal request

src/handlers/proxy.rs

+47
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,53 @@ pub async fn rpc_call(
6767
body: Bytes,
6868
) -> Result<Response, RpcError> {
6969
let chain_id = query_params.chain_id.clone();
70+
71+
if query_params.session_id.is_some() {
72+
let provider_id = match chain_id.as_str() {
73+
"eip155:10" => Some("quicknode"), // Optimism
74+
"eip155:8453" => Some("lava"), // Base
75+
"eip155:42161" => Some("lava"), // Arbitrum One
76+
_ => {
77+
debug!(
78+
"Requested sessionId for chain {chain_id} but no hardcoded provider was configured"
79+
);
80+
None
81+
}
82+
};
83+
84+
if let Some(provider_id) = provider_id {
85+
let provider = state
86+
.providers
87+
.get_rpc_provider_by_provider_id(provider_id)
88+
.ok_or_else(|| RpcError::UnsupportedProvider(provider_id.to_owned()))?;
89+
let response = rpc_provider_call(
90+
state.clone(),
91+
addr,
92+
query_params.clone(),
93+
headers.clone(),
94+
body.clone(),
95+
provider.clone(),
96+
)
97+
.await;
98+
99+
match response {
100+
Ok(response) if !response.status().is_server_error() => {
101+
return Ok(response);
102+
}
103+
e => {
104+
// Not recording metric since this is a hardcoded provider
105+
// state
106+
// .metrics
107+
// .add_rpc_call_retries(0, chain_id.clone());
108+
debug!(
109+
"Provider (via sessionId) '{}' returned an error {e:?}, trying the next provider",
110+
provider.provider_kind()
111+
);
112+
}
113+
}
114+
}
115+
}
116+
70117
// Exact provider proxy request for testing suite
71118
// This request is allowed only for the RPC_PROXY_TESTING_PROJECT_ID
72119
let providers = match query_params.provider_id.clone() {

src/handlers/wallet/get_calls_status.rs

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ async fn handler_internal(
133133
chain_id: chain_id.into(),
134134
project_id,
135135
provider_id: None,
136+
session_id: None,
136137
source: Some(MessageSource::WalletGetCallsStatus),
137138
sdk_info: query.sdk_info.clone(),
138139
},

0 commit comments

Comments
 (0)