make references compile
This commit is contained in:
parent
469b55fa9a
commit
009fdbe2cf
@ -1122,7 +1122,7 @@ impl Web3ProxyApp {
|
|||||||
/// proxy request with up to 3 tries.
|
/// proxy request with up to 3 tries.
|
||||||
async fn proxy_request(
|
async fn proxy_request(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
request: JsonRpcRequest,
|
mut request: JsonRpcRequest,
|
||||||
authorization: Arc<Authorization>,
|
authorization: Arc<Authorization>,
|
||||||
head_block_num: Option<U64>,
|
head_block_num: Option<U64>,
|
||||||
) -> (StatusCode, JsonRpcForwardedResponse, Vec<Arc<Web3Rpc>>) {
|
) -> (StatusCode, JsonRpcForwardedResponse, Vec<Arc<Web3Rpc>>) {
|
||||||
@ -1136,16 +1136,15 @@ impl Web3ProxyApp {
|
|||||||
|
|
||||||
let response_id = request.id;
|
let response_id = request.id;
|
||||||
|
|
||||||
|
// TODO: trace log request.params before we send them to _proxy_request_with_caching which might modify them
|
||||||
|
|
||||||
let mut tries = 3;
|
let mut tries = 3;
|
||||||
let mut code;
|
let mut last_code_and_response = None;
|
||||||
let mut response;
|
|
||||||
while tries > 0 {
|
while tries > 0 {
|
||||||
// TODO: make sure this doesn't retry jsonrpc errors
|
let (code, response_data) = match self
|
||||||
let response_data;
|
|
||||||
(code, response_data) = match self
|
|
||||||
._proxy_request_with_caching(
|
._proxy_request_with_caching(
|
||||||
&request.method,
|
&request.method,
|
||||||
request.params,
|
&mut request.params,
|
||||||
head_block_num,
|
head_block_num,
|
||||||
&request_metadata,
|
&request_metadata,
|
||||||
)
|
)
|
||||||
@ -1155,7 +1154,7 @@ impl Web3ProxyApp {
|
|||||||
Err(err) => err.as_response_parts(),
|
Err(err) => err.as_response_parts(),
|
||||||
};
|
};
|
||||||
|
|
||||||
response = JsonRpcForwardedResponse::from_response_data(response_data, response_id);
|
last_code_and_response = Some((code, response_data));
|
||||||
|
|
||||||
if code == StatusCode::OK {
|
if code == StatusCode::OK {
|
||||||
break;
|
break;
|
||||||
@ -1163,11 +1162,14 @@ impl Web3ProxyApp {
|
|||||||
|
|
||||||
// TODO: emit a stat?
|
// TODO: emit a stat?
|
||||||
// TODO: only log params in development
|
// TODO: only log params in development
|
||||||
warn!(method=%request.method, params=?request.params, ?response, "request failed");
|
warn!(method=%request.method, params=?request.params, response=?last_code_and_response, "request failed");
|
||||||
|
|
||||||
tries -= 1;
|
tries -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = response.expect("we definitely looped at least once");
|
let (code, response) = last_code_and_response.expect("there should always be a response");
|
||||||
|
|
||||||
|
let response = JsonRpcForwardedResponse::from_response_data(response, response_id);
|
||||||
|
|
||||||
// TODO: this serializes twice :/
|
// TODO: this serializes twice :/
|
||||||
request_metadata.add_response(ResponseOrBytes::Response(&response));
|
request_metadata.add_response(ResponseOrBytes::Response(&response));
|
||||||
@ -1182,7 +1184,7 @@ impl Web3ProxyApp {
|
|||||||
async fn _proxy_request_with_caching(
|
async fn _proxy_request_with_caching(
|
||||||
self: &Arc<Self>,
|
self: &Arc<Self>,
|
||||||
method: &str,
|
method: &str,
|
||||||
mut params: serde_json::Value,
|
params: &mut serde_json::Value,
|
||||||
head_block_num: Option<U64>,
|
head_block_num: Option<U64>,
|
||||||
request_metadata: &Arc<RequestMetadata>,
|
request_metadata: &Arc<RequestMetadata>,
|
||||||
) -> Web3ProxyResult<JsonRpcResponseEnum<Arc<RawValue>>> {
|
) -> Web3ProxyResult<JsonRpcResponseEnum<Arc<RawValue>>> {
|
||||||
@ -1297,7 +1299,7 @@ impl Web3ProxyApp {
|
|||||||
let x = bundler_4337_rpcs
|
let x = bundler_4337_rpcs
|
||||||
.try_proxy_connection::<_, Box<RawValue>>(
|
.try_proxy_connection::<_, Box<RawValue>>(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
Some(request_metadata),
|
Some(request_metadata),
|
||||||
Some(Duration::from_secs(30)),
|
Some(Duration::from_secs(30)),
|
||||||
None,
|
None,
|
||||||
@ -1338,7 +1340,7 @@ impl Web3ProxyApp {
|
|||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.try_proxy_connection::<_, U256>(
|
.try_proxy_connection::<_, U256>(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
Some(request_metadata),
|
Some(request_metadata),
|
||||||
Some(Duration::from_secs(30)),
|
Some(Duration::from_secs(30)),
|
||||||
None,
|
None,
|
||||||
@ -1371,7 +1373,7 @@ impl Web3ProxyApp {
|
|||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.try_proxy_connection::<_, Box<RawValue>>(
|
.try_proxy_connection::<_, Box<RawValue>>(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
Some(request_metadata),
|
Some(request_metadata),
|
||||||
Some(Duration::from_secs(30)),
|
Some(Duration::from_secs(30)),
|
||||||
None,
|
None,
|
||||||
@ -1395,7 +1397,7 @@ impl Web3ProxyApp {
|
|||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.try_proxy_connection::<_, Box<RawValue>>(
|
.try_proxy_connection::<_, Box<RawValue>>(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
Some(request_metadata),
|
Some(request_metadata),
|
||||||
Some(Duration::from_secs(30)),
|
Some(Duration::from_secs(30)),
|
||||||
Some(&U64::one()),
|
Some(&U64::one()),
|
||||||
@ -1421,7 +1423,7 @@ impl Web3ProxyApp {
|
|||||||
self
|
self
|
||||||
.try_send_protected(
|
.try_send_protected(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
request_metadata,
|
request_metadata,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1611,7 +1613,7 @@ impl Web3ProxyApp {
|
|||||||
let cache_key: Option<JsonRpcQueryCacheKey> = match block_needed(
|
let cache_key: Option<JsonRpcQueryCacheKey> = match block_needed(
|
||||||
&authorization,
|
&authorization,
|
||||||
method,
|
method,
|
||||||
&mut params,
|
params,
|
||||||
head_block_num,
|
head_block_num,
|
||||||
&self.balanced_rpcs,
|
&self.balanced_rpcs,
|
||||||
)
|
)
|
||||||
@ -1621,7 +1623,7 @@ impl Web3ProxyApp {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
false,
|
false,
|
||||||
)),
|
)),
|
||||||
BlockNeeded::CacheNever => None,
|
BlockNeeded::CacheNever => None,
|
||||||
@ -1650,7 +1652,7 @@ impl Web3ProxyApp {
|
|||||||
Some(request_block),
|
Some(request_block),
|
||||||
None,
|
None,
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
cache_errors,
|
cache_errors,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -1691,7 +1693,7 @@ impl Web3ProxyApp {
|
|||||||
Some(from_block),
|
Some(from_block),
|
||||||
Some(to_block),
|
Some(to_block),
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
cache_errors,
|
cache_errors,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -1711,11 +1713,11 @@ impl Web3ProxyApp {
|
|||||||
.jsonrpc_response_cache
|
.jsonrpc_response_cache
|
||||||
.try_get_with::<_, Web3ProxyError>(cache_key.hash(), async {
|
.try_get_with::<_, Web3ProxyError>(cache_key.hash(), async {
|
||||||
let response_data = timeout(
|
let response_data = timeout(
|
||||||
max_wait + Duration::from_millis(10),
|
max_wait + Duration::from_millis(100),
|
||||||
self.balanced_rpcs
|
self.balanced_rpcs
|
||||||
.try_proxy_connection::<_, Arc<RawValue>>(
|
.try_proxy_connection::<_, Arc<RawValue>>(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
Some(request_metadata),
|
Some(request_metadata),
|
||||||
Some(max_wait),
|
Some(max_wait),
|
||||||
from_block_num.as_ref(),
|
from_block_num.as_ref(),
|
||||||
@ -1741,7 +1743,7 @@ impl Web3ProxyApp {
|
|||||||
self.balanced_rpcs
|
self.balanced_rpcs
|
||||||
.try_proxy_connection::<_, Arc<RawValue>>(
|
.try_proxy_connection::<_, Arc<RawValue>>(
|
||||||
method,
|
method,
|
||||||
¶ms,
|
params,
|
||||||
Some(request_metadata),
|
Some(request_metadata),
|
||||||
Some(max_wait),
|
Some(max_wait),
|
||||||
None,
|
None,
|
||||||
|
@ -250,17 +250,6 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::Database(err) => {
|
|
||||||
error!("database err={:#?}", err);
|
|
||||||
(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
JsonRpcErrorData {
|
|
||||||
message: "database error!".into(),
|
|
||||||
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16().into(),
|
|
||||||
data: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::Contract(err) => {
|
Self::Contract(err) => {
|
||||||
warn!("Contract Error: {:#?}", err);
|
warn!("Contract Error: {:#?}", err);
|
||||||
(
|
(
|
||||||
@ -272,6 +261,17 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Self::Database(err) => {
|
||||||
|
error!("database err={:#?}", err);
|
||||||
|
(
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
JsonRpcErrorData {
|
||||||
|
message: "database error!".into(),
|
||||||
|
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16().into(),
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::Decimal(err) => {
|
Self::Decimal(err) => {
|
||||||
debug!("Decimal Error: {:#?}", err);
|
debug!("Decimal Error: {:#?}", err);
|
||||||
(
|
(
|
||||||
@ -283,18 +283,9 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::SiweVerification(err) => {
|
|
||||||
trace!("Siwe Verification err={:#?}", err,);
|
|
||||||
(
|
|
||||||
StatusCode::UNAUTHORIZED,
|
|
||||||
JsonRpcErrorData {
|
|
||||||
message: format!("siwe verification error: {:#?}", err).into(),
|
|
||||||
code: StatusCode::UNAUTHORIZED.as_u16().into(),
|
|
||||||
data: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::EthersHttpClient(err) => {
|
Self::EthersHttpClient(err) => {
|
||||||
|
todo!("how should we handle this error? needs to try into jsonrpcerrordata");
|
||||||
|
|
||||||
warn!("EthersHttpClientError err={:#?}", err);
|
warn!("EthersHttpClientError err={:#?}", err);
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
@ -306,6 +297,8 @@ impl Web3ProxyError {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::EthersProvider(err) => {
|
Self::EthersProvider(err) => {
|
||||||
|
todo!("how should we handle this error? needs to try into jsonrpcerrordata");
|
||||||
|
|
||||||
warn!("EthersProviderError err={:#?}", err);
|
warn!("EthersProviderError err={:#?}", err);
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
@ -317,6 +310,8 @@ impl Web3ProxyError {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::EthersWsClient(err) => {
|
Self::EthersWsClient(err) => {
|
||||||
|
todo!("how should we handle this error? needs to try into jsonrpcerrordata");
|
||||||
|
|
||||||
warn!("EthersWsClientError err={:#?}", err);
|
warn!("EthersWsClientError err={:#?}", err);
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
@ -372,6 +367,17 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Self::HeaderToString(err) => {
|
||||||
|
// trace!(?err, "HeaderToString");
|
||||||
|
(
|
||||||
|
StatusCode::BAD_REQUEST,
|
||||||
|
JsonRpcErrorData {
|
||||||
|
message: err.to_string().into(),
|
||||||
|
code: StatusCode::BAD_REQUEST.as_u16().into(),
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::HttpUri(err) => {
|
Self::HttpUri(err) => {
|
||||||
trace!("HttpUri {:#?}", err);
|
trace!("HttpUri {:#?}", err);
|
||||||
(
|
(
|
||||||
@ -489,29 +495,6 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Self::RedisDeadpool(err) => {
|
|
||||||
error!("redis deadpool err={:#?}", err);
|
|
||||||
(
|
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
JsonRpcErrorData {
|
|
||||||
// TODO: is it safe to expose our io error strings?
|
|
||||||
message: err.to_string().into(),
|
|
||||||
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16().into(),
|
|
||||||
data: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::UnknownReferralCode => {
|
|
||||||
trace!("UnknownReferralCode");
|
|
||||||
(
|
|
||||||
StatusCode::UNAUTHORIZED,
|
|
||||||
JsonRpcErrorData {
|
|
||||||
message: "invalid referral code".into(),
|
|
||||||
code: StatusCode::UNAUTHORIZED.as_u16().into(),
|
|
||||||
data: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::InvalidReferer => {
|
Self::InvalidReferer => {
|
||||||
trace!("InvalidReferer");
|
trace!("InvalidReferer");
|
||||||
(
|
(
|
||||||
@ -794,7 +777,7 @@ impl Web3ProxyError {
|
|||||||
(
|
(
|
||||||
StatusCode::PAYMENT_REQUIRED,
|
StatusCode::PAYMENT_REQUIRED,
|
||||||
JsonRpcErrorData {
|
JsonRpcErrorData {
|
||||||
message: "Payment is required and user is not premium".into(),
|
message: "Payment is required to activate premium".into(),
|
||||||
code: StatusCode::PAYMENT_REQUIRED.as_u16().into(),
|
code: StatusCode::PAYMENT_REQUIRED.as_u16().into(),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
@ -843,6 +826,18 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Self::RedisDeadpool(err) => {
|
||||||
|
error!("redis deadpool err={:#?}", err);
|
||||||
|
(
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
JsonRpcErrorData {
|
||||||
|
// TODO: is it safe to expose our io error strings?
|
||||||
|
message: err.to_string().into(),
|
||||||
|
code: StatusCode::INTERNAL_SERVER_ERROR.as_u16().into(),
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::RefererRequired => {
|
Self::RefererRequired => {
|
||||||
trace!("referer required");
|
trace!("referer required");
|
||||||
(
|
(
|
||||||
@ -899,6 +894,17 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Self::SiweVerification(err) => {
|
||||||
|
trace!("Siwe Verification err={:#?}", err,);
|
||||||
|
(
|
||||||
|
StatusCode::UNAUTHORIZED,
|
||||||
|
JsonRpcErrorData {
|
||||||
|
message: format!("siwe verification error: {:#?}", err).into(),
|
||||||
|
code: StatusCode::UNAUTHORIZED.as_u16().into(),
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::StatusCode(status_code, err_msg, err) => {
|
Self::StatusCode(status_code, err_msg, err) => {
|
||||||
// different status codes should get different error levels. 500s should warn. 400s should stat
|
// different status codes should get different error levels. 500s should warn. 400s should stat
|
||||||
let code = status_code.as_u16();
|
let code = status_code.as_u16();
|
||||||
@ -926,17 +932,6 @@ impl Web3ProxyError {
|
|||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Self::HeaderToString(err) => {
|
|
||||||
// trace!(?err, "HeaderToString");
|
|
||||||
(
|
|
||||||
StatusCode::BAD_REQUEST,
|
|
||||||
JsonRpcErrorData {
|
|
||||||
message: err.to_string().into(),
|
|
||||||
code: StatusCode::BAD_REQUEST.as_u16().into(),
|
|
||||||
data: None,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Self::UlidDecode(err) => {
|
Self::UlidDecode(err) => {
|
||||||
// trace!(?err, "UlidDecodeError");
|
// trace!(?err, "UlidDecodeError");
|
||||||
(
|
(
|
||||||
@ -959,7 +954,6 @@ impl Web3ProxyError {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// TODO: stat?
|
|
||||||
Self::UnknownKey => (
|
Self::UnknownKey => (
|
||||||
StatusCode::UNAUTHORIZED,
|
StatusCode::UNAUTHORIZED,
|
||||||
JsonRpcErrorData {
|
JsonRpcErrorData {
|
||||||
@ -968,13 +962,24 @@ impl Web3ProxyError {
|
|||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Self::UnknownReferralCode => {
|
||||||
|
trace!("UnknownReferralCode");
|
||||||
|
(
|
||||||
|
StatusCode::UNAUTHORIZED,
|
||||||
|
JsonRpcErrorData {
|
||||||
|
message: "invalid referral code".into(),
|
||||||
|
code: StatusCode::UNAUTHORIZED.as_u16().into(),
|
||||||
|
data: None,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Self::UserAgentRequired => {
|
Self::UserAgentRequired => {
|
||||||
trace!("UserAgentRequired");
|
trace!("UserAgentRequired");
|
||||||
(
|
(
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::UNAUTHORIZED,
|
||||||
JsonRpcErrorData {
|
JsonRpcErrorData {
|
||||||
message: "User agent required".into(),
|
message: "User agent required".into(),
|
||||||
code: StatusCode::BAD_REQUEST.as_u16().into(),
|
code: StatusCode::UNAUTHORIZED.as_u16().into(),
|
||||||
data: None,
|
data: None,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use crate::errors::{Web3ProxyError, Web3ProxyResult};
|
|
||||||
use crate::response_cache::JsonRpcResponseEnum;
|
use crate::response_cache::JsonRpcResponseEnum;
|
||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use ethers::prelude::ProviderError;
|
|
||||||
use serde::de::{self, Deserializer, MapAccess, SeqAccess, Visitor};
|
use serde::de::{self, Deserializer, MapAccess, SeqAccess, Visitor};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
@ -10,7 +8,7 @@ use std::borrow::Cow;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub trait JsonRpcParams = Clone + fmt::Debug + serde::Serialize + Send + Sync + 'static;
|
pub trait JsonRpcParams = fmt::Debug + serde::Serialize + Send + Sync + 'static;
|
||||||
pub trait JsonRpcResultData = serde::Serialize + serde::de::DeserializeOwned + fmt::Debug + Send;
|
pub trait JsonRpcResultData = serde::Serialize + serde::de::DeserializeOwned + fmt::Debug + Send;
|
||||||
|
|
||||||
// TODO: &str here instead of String should save a lot of allocations
|
// TODO: &str here instead of String should save a lot of allocations
|
||||||
|
Loading…
Reference in New Issue
Block a user