more tracing and error handling
This commit is contained in:
parent
6f7783d260
commit
0d1e629567
@ -297,54 +297,6 @@ impl JsonRpcForwardedResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: delete this. its on JsonRpcErrorData
|
|
||||||
pub fn from_ethers_error(e: ProviderError, id: Box<RawValue>) -> Web3ProxyResult<Self> {
|
|
||||||
// TODO: move turning ClientError into json to a helper function?
|
|
||||||
let code;
|
|
||||||
let message: String;
|
|
||||||
let data;
|
|
||||||
|
|
||||||
match e {
|
|
||||||
ProviderError::JsonRpcClientError(err) => {
|
|
||||||
if let Some(err) = err.as_error_response() {
|
|
||||||
code = err.code;
|
|
||||||
message = err.message.clone();
|
|
||||||
data = err.data.clone();
|
|
||||||
} else if let Some(err) = err.as_serde_error() {
|
|
||||||
// this is not an rpc error. keep it as an error
|
|
||||||
// TODO: ankr gives us "rate limited" but ethers fails to parse because it tries to require id even though its optional
|
|
||||||
return Err(Web3ProxyError::BadResponse(
|
|
||||||
format!("parse error: {}", err).into(),
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
return Err(anyhow::anyhow!("unexpected ethers error! {:?}", err).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
e => return Err(e.into()),
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
jsonrpc: "2.0",
|
|
||||||
id,
|
|
||||||
result: None,
|
|
||||||
error: Some(JsonRpcErrorData {
|
|
||||||
code,
|
|
||||||
message: message.into(),
|
|
||||||
data,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn try_from_response_result(
|
|
||||||
result: Result<Arc<RawValue>, ProviderError>,
|
|
||||||
id: Box<RawValue>,
|
|
||||||
) -> Web3ProxyResult<Self> {
|
|
||||||
match result {
|
|
||||||
Ok(response) => Ok(Self::from_raw_response(response, id)),
|
|
||||||
Err(e) => Self::from_ethers_error(e, id),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_response_data(data: JsonRpcResponseEnum<Arc<RawValue>>, id: Box<RawValue>) -> Self {
|
pub fn from_response_data(data: JsonRpcResponseEnum<Arc<RawValue>>, id: Box<RawValue>) -> Self {
|
||||||
match data {
|
match data {
|
||||||
JsonRpcResponseEnum::Result { value, .. } => Self::from_raw_response(value, id),
|
JsonRpcResponseEnum::Result { value, .. } => Self::from_raw_response(value, id),
|
||||||
|
@ -251,7 +251,7 @@ impl ConsensusWeb3Rpcs {
|
|||||||
if let Some(min_block_needed) = min_block_needed {
|
if let Some(min_block_needed) = min_block_needed {
|
||||||
if !self.has_block_data(rpc, min_block_needed) {
|
if !self.has_block_data(rpc, min_block_needed) {
|
||||||
trace!(
|
trace!(
|
||||||
"{} is missing min_block_needed ({}). skipping",
|
"{} is missing min_block_needed ({}). will not work now",
|
||||||
rpc,
|
rpc,
|
||||||
min_block_needed,
|
min_block_needed,
|
||||||
);
|
);
|
||||||
@ -262,7 +262,7 @@ impl ConsensusWeb3Rpcs {
|
|||||||
if let Some(max_block_needed) = max_block_needed {
|
if let Some(max_block_needed) = max_block_needed {
|
||||||
if !self.has_block_data(rpc, max_block_needed) {
|
if !self.has_block_data(rpc, max_block_needed) {
|
||||||
trace!(
|
trace!(
|
||||||
"{} is missing max_block_needed ({}). skipping",
|
"{} is missing max_block_needed ({}). will not work now",
|
||||||
rpc,
|
rpc,
|
||||||
max_block_needed,
|
max_block_needed,
|
||||||
);
|
);
|
||||||
@ -273,7 +273,7 @@ impl ConsensusWeb3Rpcs {
|
|||||||
// TODO: this might be a big perf hit. benchmark
|
// TODO: this might be a big perf hit. benchmark
|
||||||
if let Some(x) = rpc.hard_limit_until.as_ref() {
|
if let Some(x) = rpc.hard_limit_until.as_ref() {
|
||||||
if *x.borrow() > Instant::now() {
|
if *x.borrow() > Instant::now() {
|
||||||
trace!("{} is rate limited. skipping", rpc,);
|
trace!("{} is rate limited. will not work now", rpc,);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -786,7 +786,7 @@ impl ConsensusFinder {
|
|||||||
|
|
||||||
if num_known < web3_rpcs.min_synced_rpcs {
|
if num_known < web3_rpcs.min_synced_rpcs {
|
||||||
// this keeps us from serving requests when the proxy first starts
|
// this keeps us from serving requests when the proxy first starts
|
||||||
trace!("not enough servers known");
|
info!(min_synced_rpcs=%web3_rpcs.min_synced_rpcs, "not enough servers known");
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,7 +887,7 @@ impl Web3Rpcs {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Track stats
|
/// Make a request with stat tracking.
|
||||||
pub async fn request_with_metadata<P: JsonRpcParams, R: JsonRpcResultData>(
|
pub async fn request_with_metadata<P: JsonRpcParams, R: JsonRpcResultData>(
|
||||||
&self,
|
&self,
|
||||||
method: &str,
|
method: &str,
|
||||||
|
@ -263,12 +263,12 @@ impl OpenRequestHandle {
|
|||||||
// check for "execution reverted" here
|
// check for "execution reverted" here
|
||||||
// TODO: move this info a function on ResponseErrorType
|
// TODO: move this info a function on ResponseErrorType
|
||||||
let response_type = if let ProviderError::JsonRpcClientError(err) = err {
|
let response_type = if let ProviderError::JsonRpcClientError(err) = err {
|
||||||
// Http and Ws errors are very similar, but different types
|
// JsonRpc and Application errors get rolled into the JsonRpcClientError
|
||||||
let msg = err.as_error_response().map(|x| x.message.clone());
|
let msg = err.as_error_response().map(|x| x.message.clone());
|
||||||
|
|
||||||
trace!("error message: {:?}", msg);
|
|
||||||
|
|
||||||
if let Some(msg) = msg {
|
if let Some(msg) = msg {
|
||||||
|
trace!(%msg, "jsonrpc error message");
|
||||||
|
|
||||||
if msg.starts_with("execution reverted") {
|
if msg.starts_with("execution reverted") {
|
||||||
trace!("revert from {}", self.rpc);
|
trace!("revert from {}", self.rpc);
|
||||||
ResponseTypes::Revert
|
ResponseTypes::Revert
|
||||||
@ -316,42 +316,59 @@ impl OpenRequestHandle {
|
|||||||
RequestErrorHandler::DebugLevel => {
|
RequestErrorHandler::DebugLevel => {
|
||||||
// TODO: think about this revert check more. sometimes we might want reverts logged so this needs a flag
|
// TODO: think about this revert check more. sometimes we might want reverts logged so this needs a flag
|
||||||
if matches!(response_type, ResponseTypes::Revert) {
|
if matches!(response_type, ResponseTypes::Revert) {
|
||||||
|
trace!(
|
||||||
|
rpc=%self.rpc,
|
||||||
|
%method,
|
||||||
|
?params,
|
||||||
|
?err,
|
||||||
|
"revert",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
debug!(
|
debug!(
|
||||||
"bad response from {}! method={} params={:?} err={:?}",
|
rpc=%self.rpc,
|
||||||
self.rpc, method, params, err
|
%method,
|
||||||
|
?params,
|
||||||
|
?err,
|
||||||
|
"bad response",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RequestErrorHandler::TraceLevel => {
|
RequestErrorHandler::TraceLevel => {
|
||||||
trace!(
|
trace!(
|
||||||
"bad response from {}! method={} params={:?} err={:?}",
|
rpc=%self.rpc,
|
||||||
self.rpc,
|
%method,
|
||||||
method,
|
?params,
|
||||||
params,
|
?err,
|
||||||
err
|
"bad response",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
RequestErrorHandler::ErrorLevel => {
|
RequestErrorHandler::ErrorLevel => {
|
||||||
// TODO: include params if not running in release mode
|
// TODO: only include params if not running in release mode
|
||||||
error!(
|
error!(
|
||||||
"bad response from {}! method={} err={:?}",
|
rpc=%self.rpc,
|
||||||
self.rpc, method, err
|
%method,
|
||||||
|
?params,
|
||||||
|
?err,
|
||||||
|
"bad response",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
RequestErrorHandler::WarnLevel => {
|
RequestErrorHandler::WarnLevel => {
|
||||||
// TODO: include params if not running in release mode
|
// TODO: only include params if not running in release mode
|
||||||
warn!(
|
warn!(
|
||||||
"bad response from {}! method={} err={:?}",
|
rpc=%self.rpc,
|
||||||
self.rpc, method, err
|
%method,
|
||||||
|
?params,
|
||||||
|
?err,
|
||||||
|
"bad response",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
RequestErrorHandler::Save => {
|
RequestErrorHandler::Save => {
|
||||||
trace!(
|
trace!(
|
||||||
"bad response from {}! method={} params={:?} err={:?}",
|
rpc=%self.rpc,
|
||||||
self.rpc,
|
%method,
|
||||||
method,
|
?params,
|
||||||
params,
|
?err,
|
||||||
err
|
"bad response",
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: do not unwrap! (doesn't matter much since we check method as a string above)
|
// TODO: do not unwrap! (doesn't matter much since we check method as a string above)
|
||||||
|
Loading…
Reference in New Issue
Block a user