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 dashmap::DashMap;
|
||||||
use ethers::prelude::{Block, TxHash};
|
use ethers::prelude::{Block, TxHash};
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::fmt;
|
||||||
use std::sync::atomic::{self, AtomicU64};
|
use std::sync::atomic::{self, AtomicU64};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
@ -21,7 +22,6 @@ pub enum SyncStatus {
|
|||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct BlockWatcher {
|
pub struct BlockWatcher {
|
||||||
sender: BlockWatcherSender,
|
sender: BlockWatcherSender,
|
||||||
/// this Mutex is locked over awaits, so we want an async lock
|
/// this Mutex is locked over awaits, so we want an async lock
|
||||||
@ -30,6 +30,13 @@ pub struct BlockWatcher {
|
|||||||
head_block_number: AtomicU64,
|
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 {
|
impl BlockWatcher {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let (sender, receiver) = mpsc::unbounded_channel();
|
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 governor::clock::{Clock, QuantaClock};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::{mpsc, watch, RwLock};
|
use tokio::sync::{mpsc, watch, RwLock};
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use tracing::{instrument, warn};
|
use tracing::warn;
|
||||||
use warp::Filter;
|
use warp::Filter;
|
||||||
|
|
||||||
// use crate::types::{BlockMap, ConnectionsMap, RpcRateLimiterMap};
|
// use crate::types::{BlockMap, ConnectionsMap, RpcRateLimiterMap};
|
||||||
@ -26,7 +27,6 @@ static APP_USER_AGENT: &str = concat!(
|
|||||||
|
|
||||||
/// The application
|
/// The application
|
||||||
// TODO: this debug impl is way too verbose. make something smaller
|
// TODO: this debug impl is way too verbose. make something smaller
|
||||||
#[derive(Debug)]
|
|
||||||
struct Web3ProxyApp {
|
struct Web3ProxyApp {
|
||||||
/// clock used for rate limiting
|
/// clock used for rate limiting
|
||||||
/// TODO: use tokio's clock (will require a different ratelimiting crate)
|
/// TODO: use tokio's clock (will require a different ratelimiting crate)
|
||||||
@ -42,8 +42,14 @@ struct Web3ProxyApp {
|
|||||||
private_rpcs_ratelimiter_lock: RwLock<()>,
|
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 {
|
impl Web3ProxyApp {
|
||||||
#[instrument]
|
|
||||||
async fn try_new(
|
async fn try_new(
|
||||||
allowed_lag: u64,
|
allowed_lag: u64,
|
||||||
balanced_rpc_tiers: Vec<Vec<(&str, u32)>>,
|
balanced_rpc_tiers: Vec<Vec<(&str, u32)>>,
|
||||||
@ -149,7 +155,6 @@ impl Web3ProxyApp {
|
|||||||
|
|
||||||
/// send the request to the approriate RPCs
|
/// send the request to the approriate RPCs
|
||||||
/// TODO: dry this up
|
/// TODO: dry this up
|
||||||
#[instrument]
|
|
||||||
async fn proxy_web3_rpc(
|
async fn proxy_web3_rpc(
|
||||||
self: Arc<Web3ProxyApp>,
|
self: Arc<Web3ProxyApp>,
|
||||||
json_body: serde_json::Value,
|
json_body: serde_json::Value,
|
||||||
@ -331,7 +336,6 @@ impl Web3ProxyApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
|
||||||
async fn try_send_requests(
|
async fn try_send_requests(
|
||||||
&self,
|
&self,
|
||||||
rpc_servers: Vec<String>,
|
rpc_servers: Vec<String>,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use ethers::prelude::{BlockNumber, Middleware};
|
use ethers::prelude::{BlockNumber, Middleware};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use std::fmt;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{cmp::Ordering, sync::Arc};
|
use std::{cmp::Ordering, sync::Arc};
|
||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
@ -10,12 +11,19 @@ use tracing::{info, warn};
|
|||||||
use crate::block_watcher::BlockWatcherSender;
|
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
|
// 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 {
|
pub enum Web3Provider {
|
||||||
Http(ethers::providers::Provider<ethers::providers::Http>),
|
Http(ethers::providers::Provider<ethers::providers::Http>),
|
||||||
Ws(ethers::providers::Provider<ethers::providers::Ws>),
|
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
|
/// Forward functions to the inner ethers::providers::Provider
|
||||||
impl Web3Provider {
|
impl Web3Provider {
|
||||||
/// Send a web3 request
|
/// Send a web3 request
|
||||||
|
@ -8,6 +8,7 @@ use governor::NotUntil;
|
|||||||
use governor::RateLimiter;
|
use governor::RateLimiter;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tracing::{info, instrument};
|
use tracing::{info, instrument};
|
||||||
@ -23,7 +24,6 @@ type Web3RateLimiterMap = DashMap<String, Web3RateLimiter>;
|
|||||||
pub type Web3ConnectionMap = DashMap<String, Web3Connection>;
|
pub type Web3ConnectionMap = DashMap<String, Web3Connection>;
|
||||||
|
|
||||||
/// Load balance to the rpc
|
/// Load balance to the rpc
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Web3ProviderTier {
|
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: 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
|
/// TODO: we probably want a better lock
|
||||||
@ -33,6 +33,13 @@ pub struct Web3ProviderTier {
|
|||||||
ratelimiters: Web3RateLimiterMap,
|
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 {
|
impl Web3ProviderTier {
|
||||||
pub async fn try_new(
|
pub async fn try_new(
|
||||||
servers: Vec<(&str, u32)>,
|
servers: Vec<(&str, u32)>,
|
||||||
|
Loading…
Reference in New Issue
Block a user