wow. it was slow because it was all the debug formatter
This commit is contained in:
parent
d1da66194e
commit
bf03729f9b
@ -2,6 +2,7 @@
|
||||
use dashmap::DashMap;
|
||||
use ethers::prelude::{Block, TxHash};
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{self, AtomicU64};
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
@ -21,7 +22,6 @@ pub enum SyncStatus {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BlockWatcher {
|
||||
sender: BlockWatcherSender,
|
||||
/// this Mutex is locked over awaits, so we want an async lock
|
||||
@ -30,6 +30,13 @@ pub struct BlockWatcher {
|
||||
head_block_number: AtomicU64,
|
||||
}
|
||||
|
||||
impl fmt::Debug for BlockWatcher {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// TODO: the default formatter takes forever to write. this is too quiet though
|
||||
write!(f, "BlockWatcher(...)")
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockWatcher {
|
||||
pub fn new() -> Self {
|
||||
let (sender, receiver) = mpsc::unbounded_channel();
|
||||
|
14
src/main.rs
14
src/main.rs
@ -6,11 +6,12 @@ use futures::future;
|
||||
use governor::clock::{Clock, QuantaClock};
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::{mpsc, watch, RwLock};
|
||||
use tokio::time::sleep;
|
||||
use tracing::{instrument, warn};
|
||||
use tracing::warn;
|
||||
use warp::Filter;
|
||||
|
||||
// use crate::types::{BlockMap, ConnectionsMap, RpcRateLimiterMap};
|
||||
@ -26,7 +27,6 @@ static APP_USER_AGENT: &str = concat!(
|
||||
|
||||
/// The application
|
||||
// TODO: this debug impl is way too verbose. make something smaller
|
||||
#[derive(Debug)]
|
||||
struct Web3ProxyApp {
|
||||
/// clock used for rate limiting
|
||||
/// TODO: use tokio's clock (will require a different ratelimiting crate)
|
||||
@ -42,8 +42,14 @@ struct Web3ProxyApp {
|
||||
private_rpcs_ratelimiter_lock: RwLock<()>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Web3ProxyApp {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// TODO: the default formatter takes forever to write. this is too quiet though
|
||||
write!(f, "Web3ProxyApp(...)")
|
||||
}
|
||||
}
|
||||
|
||||
impl Web3ProxyApp {
|
||||
#[instrument]
|
||||
async fn try_new(
|
||||
allowed_lag: u64,
|
||||
balanced_rpc_tiers: Vec<Vec<(&str, u32)>>,
|
||||
@ -149,7 +155,6 @@ impl Web3ProxyApp {
|
||||
|
||||
/// send the request to the approriate RPCs
|
||||
/// TODO: dry this up
|
||||
#[instrument]
|
||||
async fn proxy_web3_rpc(
|
||||
self: Arc<Web3ProxyApp>,
|
||||
json_body: serde_json::Value,
|
||||
@ -331,7 +336,6 @@ impl Web3ProxyApp {
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
async fn try_send_requests(
|
||||
&self,
|
||||
rpc_servers: Vec<String>,
|
||||
|
@ -2,6 +2,7 @@
|
||||
use derive_more::From;
|
||||
use ethers::prelude::{BlockNumber, Middleware};
|
||||
use futures::StreamExt;
|
||||
use std::fmt;
|
||||
use std::time::Duration;
|
||||
use std::{cmp::Ordering, sync::Arc};
|
||||
use tokio::time::interval;
|
||||
@ -10,12 +11,19 @@ use tracing::{info, warn};
|
||||
use crate::block_watcher::BlockWatcherSender;
|
||||
|
||||
// TODO: instead of an enum, I tried to use Box<dyn Provider>, but hit https://github.com/gakonst/ethers-rs/issues/592
|
||||
#[derive(From, Debug)]
|
||||
#[derive(From)]
|
||||
pub enum Web3Provider {
|
||||
Http(ethers::providers::Provider<ethers::providers::Http>),
|
||||
Ws(ethers::providers::Provider<ethers::providers::Ws>),
|
||||
}
|
||||
|
||||
impl fmt::Debug for Web3Provider {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// TODO: the default formatter takes forever to write. this is too quiet though
|
||||
write!(f, "Web3Provider(...)")
|
||||
}
|
||||
}
|
||||
|
||||
/// Forward functions to the inner ethers::providers::Provider
|
||||
impl Web3Provider {
|
||||
/// Send a web3 request
|
||||
|
@ -8,6 +8,7 @@ use governor::NotUntil;
|
||||
use governor::RateLimiter;
|
||||
use std::cmp;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::num::NonZeroU32;
|
||||
use std::sync::Arc;
|
||||
use tracing::{info, instrument};
|
||||
@ -23,7 +24,6 @@ type Web3RateLimiterMap = DashMap<String, Web3RateLimiter>;
|
||||
pub type Web3ConnectionMap = DashMap<String, Web3Connection>;
|
||||
|
||||
/// Load balance to the rpc
|
||||
#[derive(Debug)]
|
||||
pub struct Web3ProviderTier {
|
||||
/// TODO: what type for the rpc? Vec<String> isn't great. i think we want this to be the key for the provider and not the provider itself
|
||||
/// TODO: we probably want a better lock
|
||||
@ -33,6 +33,13 @@ pub struct Web3ProviderTier {
|
||||
ratelimiters: Web3RateLimiterMap,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Web3ProviderTier {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// TODO: the default formatter takes forever to write. this is too quiet though
|
||||
write!(f, "Web3ProviderTier")
|
||||
}
|
||||
}
|
||||
|
||||
impl Web3ProviderTier {
|
||||
pub async fn try_new(
|
||||
servers: Vec<(&str, u32)>,
|
||||
|
Loading…
Reference in New Issue
Block a user