2022-08-24 03:11:49 +03:00
|
|
|
use super::connection::Web3Connection;
|
|
|
|
use super::provider::Web3Provider;
|
2022-11-25 03:45:13 +03:00
|
|
|
use crate::frontend::authorization::{AuthorizatioType, Authorization};
|
2022-09-20 09:56:24 +03:00
|
|
|
use crate::metered::{JsonRpcErrorCount, ProviderErrorCount};
|
2022-09-23 08:22:33 +03:00
|
|
|
use anyhow::Context;
|
2022-09-24 05:47:44 +03:00
|
|
|
use chrono::Utc;
|
2022-11-01 21:54:39 +03:00
|
|
|
use entities::revert_log;
|
2022-09-24 05:47:44 +03:00
|
|
|
use entities::sea_orm_active_enums::Method;
|
2022-09-21 07:48:21 +03:00
|
|
|
use ethers::providers::{HttpClientError, ProviderError, WsClientError};
|
2022-09-24 10:35:56 +03:00
|
|
|
use ethers::types::{Address, Bytes};
|
2022-12-06 01:38:54 +03:00
|
|
|
use log::{debug, error, trace, warn, Level};
|
2022-09-09 06:53:16 +03:00
|
|
|
use metered::metered;
|
|
|
|
use metered::HitCount;
|
|
|
|
use metered::ResponseTime;
|
|
|
|
use metered::Throughput;
|
2022-11-14 21:24:52 +03:00
|
|
|
use migration::sea_orm::{self, ActiveEnum, ActiveModelTrait};
|
2022-09-24 05:47:44 +03:00
|
|
|
use serde_json::json;
|
2022-08-24 03:11:49 +03:00
|
|
|
use std::fmt;
|
2022-09-23 00:03:37 +03:00
|
|
|
use std::sync::atomic::{self, AtomicBool, Ordering};
|
2022-08-24 03:14:49 +03:00
|
|
|
use std::sync::Arc;
|
2022-11-12 09:11:58 +03:00
|
|
|
use thread_fast_rng::rand::Rng;
|
2022-08-30 23:01:42 +03:00
|
|
|
use tokio::time::{sleep, Duration, Instant};
|
2022-08-24 03:11:49 +03:00
|
|
|
|
2022-08-30 23:01:42 +03:00
|
|
|
#[derive(Debug)]
|
2022-08-24 03:14:49 +03:00
|
|
|
pub enum OpenRequestResult {
|
2022-08-24 03:59:05 +03:00
|
|
|
Handle(OpenRequestHandle),
|
|
|
|
/// Unable to start a request. Retry at the given time.
|
2022-08-24 03:11:49 +03:00
|
|
|
RetryAt(Instant),
|
2022-11-25 10:41:53 +03:00
|
|
|
/// Unable to start a request because the server is not synced
|
2022-12-06 00:13:36 +03:00
|
|
|
NotReady,
|
2022-08-24 03:11:49 +03:00
|
|
|
}
|
|
|
|
|
2022-08-24 03:59:05 +03:00
|
|
|
/// Make RPC requests through this handle and drop it when you are done.
|
2022-08-30 23:01:42 +03:00
|
|
|
#[derive(Debug)]
|
2022-09-09 06:53:16 +03:00
|
|
|
pub struct OpenRequestHandle {
|
2022-11-08 22:58:11 +03:00
|
|
|
authorization: Arc<Authorization>,
|
2022-09-23 00:03:37 +03:00
|
|
|
conn: Arc<Web3Connection>,
|
2022-09-20 09:00:27 +03:00
|
|
|
// TODO: this is the same metrics on the conn. use a reference?
|
2022-09-09 06:53:16 +03:00
|
|
|
metrics: Arc<OpenRequestHandleMetrics>,
|
2022-09-23 00:03:37 +03:00
|
|
|
used: AtomicBool,
|
2022-09-09 06:53:16 +03:00
|
|
|
}
|
2022-08-24 03:11:49 +03:00
|
|
|
|
2022-09-23 01:34:43 +03:00
|
|
|
/// Depending on the context, RPC errors can require different handling.
|
2022-09-21 07:48:21 +03:00
|
|
|
pub enum RequestErrorHandler {
|
2022-11-25 03:45:13 +03:00
|
|
|
/// Log at the trace level. Use when errors are expected.
|
|
|
|
TraceLevel,
|
2022-09-23 01:15:56 +03:00
|
|
|
/// Log at the debug level. Use when errors are expected.
|
2022-09-21 07:48:21 +03:00
|
|
|
DebugLevel,
|
2022-09-23 01:15:56 +03:00
|
|
|
/// Log at the error level. Use when errors are bad.
|
2022-09-21 07:48:21 +03:00
|
|
|
ErrorLevel,
|
2022-09-23 01:15:56 +03:00
|
|
|
/// Log at the warn level. Use when errors do not cause problems.
|
2022-09-21 07:48:21 +03:00
|
|
|
WarnLevel,
|
2022-11-25 03:45:13 +03:00
|
|
|
/// Potentially save the revert. Users can tune how often this happens
|
|
|
|
SaveReverts,
|
2022-09-21 07:48:21 +03:00
|
|
|
}
|
|
|
|
|
2022-09-24 10:04:11 +03:00
|
|
|
// TODO: second param could be skipped since we don't need it here
|
2022-09-24 05:47:44 +03:00
|
|
|
#[derive(serde::Deserialize, serde::Serialize)]
|
2022-09-24 10:04:11 +03:00
|
|
|
struct EthCallParams((EthCallFirstParams, Option<serde_json::Value>));
|
|
|
|
|
|
|
|
#[derive(serde::Deserialize, serde::Serialize)]
|
|
|
|
struct EthCallFirstParams {
|
2022-09-24 10:35:56 +03:00
|
|
|
to: Address,
|
|
|
|
data: Option<Bytes>,
|
2022-09-24 05:47:44 +03:00
|
|
|
}
|
|
|
|
|
2022-09-21 07:48:21 +03:00
|
|
|
impl From<Level> for RequestErrorHandler {
|
|
|
|
fn from(level: Level) -> Self {
|
|
|
|
match level {
|
2022-11-25 03:45:13 +03:00
|
|
|
Level::Trace => RequestErrorHandler::TraceLevel,
|
2022-11-12 11:24:32 +03:00
|
|
|
Level::Debug => RequestErrorHandler::DebugLevel,
|
|
|
|
Level::Error => RequestErrorHandler::ErrorLevel,
|
|
|
|
Level::Warn => RequestErrorHandler::WarnLevel,
|
2022-09-23 01:15:56 +03:00
|
|
|
_ => unimplemented!("unexpected tracing Level"),
|
2022-09-21 07:48:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-08 22:58:11 +03:00
|
|
|
impl Authorization {
|
2022-09-23 01:34:43 +03:00
|
|
|
/// Save a RPC call that return "execution reverted" to the database.
|
2022-09-24 10:35:56 +03:00
|
|
|
async fn save_revert(
|
|
|
|
self: Arc<Self>,
|
|
|
|
method: Method,
|
|
|
|
params: EthCallFirstParams,
|
|
|
|
) -> anyhow::Result<()> {
|
2022-11-10 02:58:07 +03:00
|
|
|
let rpc_key_id = match self.checks.rpc_key_id {
|
|
|
|
Some(rpc_key_id) => rpc_key_id.into(),
|
|
|
|
None => {
|
2022-11-12 11:24:32 +03:00
|
|
|
// // trace!(?self, "cannot save revert without rpc_key_id");
|
2022-11-10 02:58:07 +03:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-08 22:58:11 +03:00
|
|
|
let db_conn = self.db_conn.as_ref().context("no database connection")?;
|
|
|
|
|
|
|
|
// TODO: should the database set the timestamp?
|
|
|
|
// we intentionally use "now" and not the time the request started
|
|
|
|
// why? because we aggregate stats and setting one in the past could cause confusion
|
|
|
|
let timestamp = Utc::now();
|
|
|
|
let to: Vec<u8> = params
|
|
|
|
.to
|
|
|
|
.as_bytes()
|
|
|
|
.try_into()
|
|
|
|
.expect("address should always convert to a Vec<u8>");
|
|
|
|
let call_data = params.data.map(|x| format!("{}", x));
|
|
|
|
|
|
|
|
let rl = revert_log::ActiveModel {
|
2022-11-10 02:58:07 +03:00
|
|
|
rpc_key_id: sea_orm::Set(rpc_key_id),
|
2022-11-08 22:58:11 +03:00
|
|
|
method: sea_orm::Set(method),
|
|
|
|
to: sea_orm::Set(to),
|
|
|
|
call_data: sea_orm::Set(call_data),
|
|
|
|
timestamp: sea_orm::Set(timestamp),
|
|
|
|
..Default::default()
|
|
|
|
};
|
2022-09-24 05:47:44 +03:00
|
|
|
|
2022-11-08 22:58:11 +03:00
|
|
|
let rl = rl
|
|
|
|
.save(db_conn)
|
|
|
|
.await
|
|
|
|
.context("Failed saving new revert log")?;
|
2022-09-23 08:22:33 +03:00
|
|
|
|
2022-11-08 22:58:11 +03:00
|
|
|
// TODO: what log level?
|
|
|
|
// TODO: better format
|
2022-11-16 10:19:56 +03:00
|
|
|
trace!("revert_log: {:?}", rl);
|
2022-09-24 05:47:44 +03:00
|
|
|
|
|
|
|
// TODO: return something useful
|
|
|
|
Ok(())
|
2022-09-23 00:51:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 06:53:16 +03:00
|
|
|
#[metered(registry = OpenRequestHandleMetrics, visibility = pub)]
|
2022-08-24 03:14:49 +03:00
|
|
|
impl OpenRequestHandle {
|
2022-11-08 22:58:11 +03:00
|
|
|
pub fn new(authorization: Arc<Authorization>, conn: Arc<Web3Connection>) -> Self {
|
2022-09-20 09:00:27 +03:00
|
|
|
// TODO: take request_id as an argument?
|
2022-09-06 23:12:45 +03:00
|
|
|
// TODO: attach a unique id to this? customer requests have one, but not internal queries
|
2022-08-24 03:11:49 +03:00
|
|
|
// TODO: what ordering?!
|
2022-09-09 06:53:16 +03:00
|
|
|
// TODO: should we be using metered, or not? i think not because we want stats for each handle
|
|
|
|
// TODO: these should maybe be sent to an influxdb instance?
|
2022-09-20 09:00:27 +03:00
|
|
|
conn.active_requests.fetch_add(1, atomic::Ordering::Relaxed);
|
2022-08-24 03:11:49 +03:00
|
|
|
|
2022-09-06 23:12:45 +03:00
|
|
|
// TODO: handle overflows?
|
|
|
|
// TODO: what ordering?
|
2022-11-25 03:45:13 +03:00
|
|
|
match authorization.as_ref().authorization_type {
|
|
|
|
AuthorizatioType::Frontend => {
|
|
|
|
conn.frontend_requests
|
|
|
|
.fetch_add(1, atomic::Ordering::Relaxed);
|
|
|
|
}
|
|
|
|
AuthorizatioType::Internal => {
|
|
|
|
conn.internal_requests
|
|
|
|
.fetch_add(1, atomic::Ordering::Relaxed);
|
|
|
|
}
|
|
|
|
}
|
2022-09-09 06:53:16 +03:00
|
|
|
|
|
|
|
let metrics = conn.open_request_handle_metrics.clone();
|
2022-09-23 00:03:37 +03:00
|
|
|
let used = false.into();
|
2022-09-06 23:12:45 +03:00
|
|
|
|
2022-09-23 00:03:37 +03:00
|
|
|
Self {
|
2022-11-08 22:58:11 +03:00
|
|
|
authorization,
|
2022-09-23 00:03:37 +03:00
|
|
|
conn,
|
|
|
|
metrics,
|
|
|
|
used,
|
|
|
|
}
|
2022-08-24 03:11:49 +03:00
|
|
|
}
|
|
|
|
|
2022-09-23 01:34:43 +03:00
|
|
|
#[inline]
|
2022-08-24 03:11:49 +03:00
|
|
|
pub fn clone_connection(&self) -> Arc<Web3Connection> {
|
2022-09-23 00:03:37 +03:00
|
|
|
self.conn.clone()
|
2022-08-24 03:11:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Send a web3 request
|
|
|
|
/// By having the request method here, we ensure that the rate limiter was called and connection counts were properly incremented
|
2022-09-10 03:12:14 +03:00
|
|
|
/// TODO: we no longer take self because metered doesn't like that
|
2022-09-14 07:27:18 +03:00
|
|
|
/// TODO: ErrorCount includes too many types of errors, such as transaction reverts
|
2022-09-20 09:56:24 +03:00
|
|
|
#[measure([JsonRpcErrorCount, HitCount, ProviderErrorCount, ResponseTime, Throughput])]
|
2022-09-24 05:47:44 +03:00
|
|
|
pub async fn request<P, R>(
|
2022-08-24 03:11:49 +03:00
|
|
|
&self,
|
|
|
|
method: &str,
|
2022-09-24 05:47:44 +03:00
|
|
|
params: &P,
|
2022-09-21 07:48:21 +03:00
|
|
|
error_handler: RequestErrorHandler,
|
2022-09-20 09:00:27 +03:00
|
|
|
) -> Result<R, ProviderError>
|
2022-08-24 03:11:49 +03:00
|
|
|
where
|
2022-09-23 00:51:52 +03:00
|
|
|
// TODO: not sure about this type. would be better to not need clones, but measure and spawns combine to need it
|
2022-09-24 05:47:44 +03:00
|
|
|
P: Clone + fmt::Debug + serde::Serialize + Send + Sync + 'static,
|
2022-08-24 03:11:49 +03:00
|
|
|
R: serde::Serialize + serde::de::DeserializeOwned + fmt::Debug,
|
|
|
|
{
|
2022-09-23 00:03:37 +03:00
|
|
|
// ensure this function only runs once
|
|
|
|
if self.used.swap(true, Ordering::Release) {
|
|
|
|
unimplemented!("a request handle should only be used once");
|
|
|
|
}
|
2022-09-20 09:00:27 +03:00
|
|
|
|
2022-09-23 00:51:52 +03:00
|
|
|
// TODO: use tracing spans
|
2022-08-30 23:01:42 +03:00
|
|
|
// TODO: requests from customers have request ids, but we should add
|
2022-08-24 03:11:49 +03:00
|
|
|
// TODO: including params in this is way too verbose
|
2022-11-08 22:58:11 +03:00
|
|
|
// the authorization field is already on a parent span
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!(rpc=%self.conn, %method, "request");
|
2022-08-24 03:11:49 +03:00
|
|
|
|
|
|
|
let mut provider = None;
|
2022-12-06 00:13:36 +03:00
|
|
|
let mut logged = false;
|
2022-08-24 03:11:49 +03:00
|
|
|
while provider.is_none() {
|
2022-12-06 00:13:36 +03:00
|
|
|
let ready_provider = self
|
|
|
|
.conn
|
|
|
|
.provider_state
|
|
|
|
.read()
|
|
|
|
.await
|
|
|
|
// TODO: hard code true, or take a bool in the `new` function?
|
|
|
|
.provider(true)
|
|
|
|
.await
|
|
|
|
.cloned();
|
|
|
|
|
|
|
|
match ready_provider {
|
2022-08-30 23:01:42 +03:00
|
|
|
None => {
|
2022-12-06 00:13:36 +03:00
|
|
|
if !logged {
|
|
|
|
logged = true;
|
|
|
|
warn!("no provider for {}!", self.conn);
|
|
|
|
}
|
|
|
|
|
2022-08-30 23:01:42 +03:00
|
|
|
// TODO: how should this work? a reconnect should be in progress. but maybe force one now?
|
2022-09-23 00:51:52 +03:00
|
|
|
// TODO: sleep how long? subscribe to something instead? maybe use a watch handle?
|
|
|
|
// TODO: this is going to be way too verbose!
|
2022-08-30 23:01:42 +03:00
|
|
|
sleep(Duration::from_millis(100)).await
|
|
|
|
}
|
2022-12-06 00:13:36 +03:00
|
|
|
Some(x) => provider = Some(x),
|
2022-08-24 03:11:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-06 00:13:36 +03:00
|
|
|
let provider = provider.expect("provider was checked already");
|
|
|
|
|
|
|
|
// trace!("got provider for {:?}", self);
|
2022-09-21 07:48:21 +03:00
|
|
|
|
2022-09-23 00:51:52 +03:00
|
|
|
// TODO: really sucks that we have to clone here
|
2022-12-06 00:13:36 +03:00
|
|
|
let response = match &*provider {
|
2022-11-23 01:45:22 +03:00
|
|
|
Web3Provider::Mock => unimplemented!(),
|
2022-09-23 01:14:24 +03:00
|
|
|
Web3Provider::Http(provider) => provider.request(method, params).await,
|
|
|
|
Web3Provider::Ws(provider) => provider.request(method, params).await,
|
2022-08-24 03:11:49 +03:00
|
|
|
};
|
|
|
|
|
2022-12-06 00:13:36 +03:00
|
|
|
// trace!("got response for {:?}: {:?}", self, response);
|
|
|
|
|
2022-09-10 03:12:14 +03:00
|
|
|
if let Err(err) = &response {
|
2022-09-23 01:42:44 +03:00
|
|
|
// only save reverts for some types of calls
|
|
|
|
// TODO: do something special for eth_sendRawTransaction too
|
2022-09-24 10:04:11 +03:00
|
|
|
let error_handler = if let RequestErrorHandler::SaveReverts = error_handler {
|
2022-11-26 07:57:25 +03:00
|
|
|
// TODO: should all these be Trace or Debug or a mix?
|
2022-09-24 10:04:11 +03:00
|
|
|
if !["eth_call", "eth_estimateGas"].contains(&method) {
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!(%method, "skipping save on revert");
|
2022-11-26 07:57:25 +03:00
|
|
|
RequestErrorHandler::TraceLevel
|
2022-11-08 22:58:11 +03:00
|
|
|
} else if self.authorization.db_conn.is_some() {
|
|
|
|
let log_revert_chance = self.authorization.checks.log_revert_chance;
|
|
|
|
|
|
|
|
if log_revert_chance == 0.0 {
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!(%method, "no chance. skipping save on revert");
|
2022-11-26 07:57:25 +03:00
|
|
|
RequestErrorHandler::TraceLevel
|
2022-11-08 22:58:11 +03:00
|
|
|
} else if log_revert_chance == 1.0 {
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!(%method, "gaurenteed chance. SAVING on revert");
|
2022-11-08 22:58:11 +03:00
|
|
|
error_handler
|
2022-11-12 09:11:58 +03:00
|
|
|
} else if thread_fast_rng::thread_fast_rng().gen_range(0.0f64..=1.0)
|
|
|
|
< log_revert_chance
|
|
|
|
{
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!(%method, "missed chance. skipping save on revert");
|
2022-11-26 07:57:25 +03:00
|
|
|
RequestErrorHandler::TraceLevel
|
2022-09-24 10:04:11 +03:00
|
|
|
} else {
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!("Saving on revert");
|
2022-11-08 22:58:11 +03:00
|
|
|
// TODO: is always logging at debug level fine?
|
|
|
|
error_handler
|
2022-09-24 10:04:11 +03:00
|
|
|
}
|
2022-09-23 01:42:44 +03:00
|
|
|
} else {
|
2022-11-12 11:24:32 +03:00
|
|
|
// trace!(%method, "no database. skipping save on revert");
|
2022-11-26 07:57:25 +03:00
|
|
|
RequestErrorHandler::TraceLevel
|
2022-09-21 07:48:21 +03:00
|
|
|
}
|
2022-09-23 01:42:44 +03:00
|
|
|
} else {
|
|
|
|
error_handler
|
|
|
|
};
|
|
|
|
|
2022-10-12 00:31:34 +03:00
|
|
|
// check for "execution reverted" here
|
|
|
|
let is_revert = if let ProviderError::JsonRpcClientError(err) = err {
|
|
|
|
// Http and Ws errors are very similar, but different types
|
2022-12-06 00:13:36 +03:00
|
|
|
let msg = match &*provider {
|
2022-11-23 01:45:22 +03:00
|
|
|
Web3Provider::Mock => unimplemented!(),
|
2022-10-12 00:31:34 +03:00
|
|
|
Web3Provider::Http(_) => {
|
|
|
|
if let Some(HttpClientError::JsonRpcError(err)) =
|
|
|
|
err.downcast_ref::<HttpClientError>()
|
|
|
|
{
|
|
|
|
Some(&err.message)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Web3Provider::Ws(_) => {
|
|
|
|
if let Some(WsClientError::JsonRpcError(err)) =
|
|
|
|
err.downcast_ref::<WsClientError>()
|
|
|
|
{
|
|
|
|
Some(&err.message)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(msg) = msg {
|
|
|
|
msg.starts_with("execution reverted")
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
2022-10-10 07:15:07 +03:00
|
|
|
|
2022-11-25 03:45:13 +03:00
|
|
|
// TODO: think more about the method and param logs. those can be sensitive information
|
2022-09-23 01:42:44 +03:00
|
|
|
match error_handler {
|
2022-09-21 07:48:21 +03:00
|
|
|
RequestErrorHandler::DebugLevel => {
|
2022-10-12 00:31:34 +03:00
|
|
|
// TODO: think about this revert check more. sometimes we might want reverts logged so this needs a flag
|
|
|
|
if !is_revert {
|
2022-11-14 21:24:52 +03:00
|
|
|
debug!(
|
|
|
|
"bad response from {}! method={} params={:?} err={:?}",
|
|
|
|
self.conn, method, params, err
|
|
|
|
);
|
2022-10-12 00:31:34 +03:00
|
|
|
}
|
2022-09-21 07:48:21 +03:00
|
|
|
}
|
2022-11-25 03:45:13 +03:00
|
|
|
RequestErrorHandler::TraceLevel => {
|
|
|
|
trace!(
|
|
|
|
"bad response from {}! method={} params={:?} err={:?}",
|
|
|
|
self.conn,
|
|
|
|
method,
|
|
|
|
params,
|
|
|
|
err
|
|
|
|
);
|
|
|
|
}
|
2022-09-23 01:42:44 +03:00
|
|
|
RequestErrorHandler::ErrorLevel => {
|
2022-11-25 03:45:13 +03:00
|
|
|
// TODO: include params if not running in release mode
|
2022-11-14 21:24:52 +03:00
|
|
|
error!(
|
2022-11-25 03:45:13 +03:00
|
|
|
"bad response from {}! method={} err={:?}",
|
|
|
|
self.conn, method, err
|
2022-11-14 21:24:52 +03:00
|
|
|
);
|
2022-09-23 01:42:44 +03:00
|
|
|
}
|
2022-09-21 07:48:21 +03:00
|
|
|
RequestErrorHandler::WarnLevel => {
|
2022-11-25 03:45:13 +03:00
|
|
|
// TODO: include params if not running in release mode
|
2022-11-14 21:24:52 +03:00
|
|
|
warn!(
|
2022-11-25 03:45:13 +03:00
|
|
|
"bad response from {}! method={} err={:?}",
|
|
|
|
self.conn, method, err
|
2022-11-14 21:24:52 +03:00
|
|
|
);
|
2022-09-21 07:48:21 +03:00
|
|
|
}
|
2022-09-24 10:04:11 +03:00
|
|
|
RequestErrorHandler::SaveReverts => {
|
2022-11-25 03:45:13 +03:00
|
|
|
trace!(
|
|
|
|
"bad response from {}! method={} params={:?} err={:?}",
|
|
|
|
self.conn,
|
|
|
|
method,
|
|
|
|
params,
|
|
|
|
err
|
|
|
|
);
|
|
|
|
|
2022-10-12 00:31:34 +03:00
|
|
|
// TODO: do not unwrap! (doesn't matter much since we check method as a string above)
|
|
|
|
let method: Method = Method::try_from_value(&method.to_string()).unwrap();
|
|
|
|
|
|
|
|
// TODO: DO NOT UNWRAP! But also figure out the best way to keep returning ProviderErrors here
|
|
|
|
let params: EthCallParams = serde_json::from_value(json!(params))
|
|
|
|
.context("parsing params to EthCallParams")
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// spawn saving to the database so we don't slow down the request
|
2022-11-08 22:58:11 +03:00
|
|
|
let f = self.authorization.clone().save_revert(method, params.0 .0);
|
2022-10-12 00:31:34 +03:00
|
|
|
|
|
|
|
tokio::spawn(f);
|
2022-09-21 07:48:21 +03:00
|
|
|
}
|
2022-09-14 07:27:18 +03:00
|
|
|
}
|
2022-09-10 03:12:14 +03:00
|
|
|
} else {
|
2022-09-21 07:48:21 +03:00
|
|
|
// TODO: i think ethers already has trace logging (and does it much more fancy)
|
2022-09-10 03:58:33 +03:00
|
|
|
// TODO: opt-in response inspection to log reverts with their request. put into redis or what?
|
2022-11-12 11:24:32 +03:00
|
|
|
// // trace!(rpc=%self.conn, %method, ?response);
|
|
|
|
// trace!(%method, rpc=%self.conn, "response");
|
2022-09-10 03:12:14 +03:00
|
|
|
}
|
|
|
|
|
2022-08-24 03:11:49 +03:00
|
|
|
response
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 03:14:49 +03:00
|
|
|
impl Drop for OpenRequestHandle {
|
2022-08-24 03:11:49 +03:00
|
|
|
fn drop(&mut self) {
|
2022-09-23 00:03:37 +03:00
|
|
|
self.conn
|
|
|
|
.active_requests
|
|
|
|
.fetch_sub(1, atomic::Ordering::AcqRel);
|
2022-08-24 03:11:49 +03:00
|
|
|
}
|
|
|
|
}
|