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"
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,
Some(http_client.clone()),
&clock,
true,
)
}))
.await
@ -103,6 +104,7 @@ impl Web3ProxyApp {
private_rpcs,
Some(http_client),
&clock,
false,
)
.await?,
)

View File

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

View File

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