dont subscribe to blocks on private rpcs

This commit is contained in:
Bryan Stitt 2022-05-12 01:36:37 +00:00
parent 71ab993574
commit 927ec60183
4 changed files with 35 additions and 13 deletions

View File

@ -6,3 +6,20 @@
url = "ws://127.0.0.1:8546" url = "ws://127.0.0.1:8546"
soft_limit = 200_000 soft_limit = 200_000
[private_rpcs]
[private_rpcs.eden]
url = "https://api.edennetwork.io/v1/"
soft_limit = 1_805
[private_rpcs.eden_beta]
url = "https://api.edennetwork.io/v1/beta"
soft_limit = 5_861
[private_rpcs.ethermine]
url = "https://rpc.ethermine.org"
soft_limit = 5_861
[private_rpcs.flashbots]
url = "https://rpc.flashbots.net"
soft_limit = 7074

View File

@ -85,6 +85,7 @@ impl Web3ProxyApp {
balanced_rpc_tier, balanced_rpc_tier,
Some(http_client.clone()), Some(http_client.clone()),
&clock, &clock,
true,
) )
})) }))
.await .await
@ -103,6 +104,7 @@ impl Web3ProxyApp {
private_rpcs, private_rpcs,
Some(http_client), Some(http_client),
&clock, &clock,
false,
) )
.await?, .await?,
) )

View File

@ -65,6 +65,7 @@ impl Web3Connections {
servers: Vec<Web3ConnectionConfig>, servers: Vec<Web3ConnectionConfig>,
http_client: Option<reqwest::Client>, http_client: Option<reqwest::Client>,
clock: &QuantaClock, clock: &QuantaClock,
subscribe_heads: bool,
) -> anyhow::Result<Arc<Self>> { ) -> anyhow::Result<Arc<Self>> {
let mut connections = vec![]; let mut connections = vec![];
@ -85,19 +86,21 @@ impl Web3Connections {
synced_connections: RwLock::new(SyncedConnections::new(num_connections)), synced_connections: RwLock::new(SyncedConnections::new(num_connections)),
}); });
for connection in connections.inner.iter() { if subscribe_heads {
// subscribe to new heads in a spawned future for connection in connections.inner.iter() {
// TODO: channel instead. then we can have one future with write access to a left-right? // subscribe to new heads in a spawned future
let connection = Arc::clone(connection); // TODO: channel instead. then we can have one future with write access to a left-right?
let connections = connections.clone(); let connection = Arc::clone(connection);
tokio::spawn(async move { let connections = connections.clone();
let url = connection.url().to_string(); tokio::spawn(async move {
let url = connection.url().to_string();
// TODO: instead of passing Some(connections), pass Some(channel_sender). Then listen on the receiver below to keep local heads up-to-date // TODO: instead of passing Some(connections), pass Some(channel_sender). Then listen on the receiver below to keep local heads up-to-date
if let Err(e) = connection.new_heads(Some(connections)).await { if let Err(e) = connection.new_heads(Some(connections)).await {
warn!("new_heads error on {}: {:?}", url, e); warn!("new_heads error on {}: {:?}", url, e);
} }
}); });
}
} }
Ok(connections) Ok(connections)

View File

@ -62,7 +62,6 @@ impl<'de> Deserialize<'de> for JsonRpcRequestEnum {
let mut batch: Vec<JsonRpcRequest> = let mut batch: Vec<JsonRpcRequest> =
Vec::with_capacity(seq.size_hint().unwrap_or(10)); Vec::with_capacity(seq.size_hint().unwrap_or(10));
// this was easier than expected
while let Ok(Some(s)) = seq.next_element::<JsonRpcRequest>() { while let Ok(Some(s)) = seq.next_element::<JsonRpcRequest>() {
batch.push(s); batch.push(s);
} }
@ -107,6 +106,7 @@ impl<'de> Deserialize<'de> for JsonRpcRequestEnum {
} }
} }
} }
let id = id.ok_or_else(|| de::Error::missing_field("id"))?; let id = id.ok_or_else(|| de::Error::missing_field("id"))?;
let method = method.ok_or_else(|| de::Error::missing_field("method"))?; let method = method.ok_or_else(|| de::Error::missing_field("method"))?;
let params = params.ok_or_else(|| de::Error::missing_field("params"))?; let params = params.ok_or_else(|| de::Error::missing_field("params"))?;