eth_sendRawTransactions should use backups more often

This commit is contained in:
Bryan Stitt 2023-02-09 11:47:56 -08:00
parent 1efa8e7772
commit 5ffe2aa72a
2 changed files with 21 additions and 11 deletions

View File

@ -1217,6 +1217,7 @@ impl Web3ProxyApp {
// if we are sending the transaction privately, no matter the proxy_mode, we send to ALL private rpcs
(private_rpcs, None)
} else {
// TODO: send to balanced_rpcs AND private_rpcs
(&self.balanced_rpcs, default_num)
}
} else {
@ -1232,6 +1233,7 @@ impl Web3ProxyApp {
None,
Level::Trace,
num,
true,
)
.await?;
@ -1528,10 +1530,7 @@ impl Web3ProxyApp {
self.response_cache
.try_get_with(cache_key, async move {
// TODO: retry some failures automatically!
// TODO: try private_rpcs if all the balanced_rpcs fail!
// TODO: put the hash here instead of the block number? its in the request already.
let mut response = self
.balanced_rpcs
.try_proxy_connection(
@ -1547,6 +1546,8 @@ impl Web3ProxyApp {
response.id = Default::default();
// TODO: only cache the inner response
// TODO: how are we going to stream this?
// TODO: check response size. if its very large, return it in a custom Error type that bypasses caching
Ok::<_, anyhow::Error>(response)
})
.await

View File

@ -639,12 +639,15 @@ impl Web3Rpcs {
authorization: &Arc<Authorization>,
block_needed: Option<&U64>,
max_count: Option<usize>,
always_include_backups: bool,
) -> Result<Vec<OpenRequestHandle>, Option<Instant>> {
if let Ok(without_backups) = self
._all_connections(false, authorization, block_needed, max_count)
.await
{
return Ok(without_backups);
if !always_include_backups {
if let Ok(without_backups) = self
._all_connections(false, authorization, block_needed, max_count)
.await
{
return Ok(without_backups);
}
}
self._all_connections(true, authorization, block_needed, max_count)
@ -1008,10 +1011,16 @@ impl Web3Rpcs {
block_needed: Option<&U64>,
error_level: Level,
max_count: Option<usize>,
always_include_backups: bool,
) -> anyhow::Result<JsonRpcForwardedResponse> {
loop {
match self
.all_connections(authorization, block_needed, max_count)
.all_connections(
authorization,
block_needed,
max_count,
always_include_backups,
)
.await
{
Ok(active_request_handles) => {
@ -1382,10 +1391,10 @@ mod tests {
// no head block because the rpcs haven't communicated through their channels
assert!(conns.head_block_hash().is_none());
// all_backend_connections gives everything regardless of sync status
// all_backend_connections gives all non-backup servers regardless of sync status
assert_eq!(
conns
.all_connections(&authorization, None, None)
.all_connections(&authorization, None, None, false)
.await
.unwrap()
.len(),