from_rpcs never returns None

This commit is contained in:
Bryan Stitt 2023-11-01 22:45:32 -07:00
parent 53b4eacaa7
commit 971f690d4f
2 changed files with 9 additions and 18 deletions

View File

@ -102,7 +102,7 @@ pub struct RpcsForRequest {
} }
impl RankedRpcs { impl RankedRpcs {
pub fn from_rpcs(rpcs: Vec<Arc<Web3Rpc>>, head_block: Option<Web3ProxyBlock>) -> Option<Self> { pub fn from_rpcs(rpcs: Vec<Arc<Web3Rpc>>, head_block: Option<Web3ProxyBlock>) -> Self {
// we don't need to sort the rpcs now. we will sort them when a request neds them // we don't need to sort the rpcs now. we will sort them when a request neds them
// TODO: the shame about this is that we lose just being able to compare 2 random servers // TODO: the shame about this is that we lose just being able to compare 2 random servers
@ -117,15 +117,13 @@ impl RankedRpcs {
let sort_mode = SortMethod::Shuffle; let sort_mode = SortMethod::Shuffle;
let ranked_rpcs = RankedRpcs { Self {
backups_needed, backups_needed,
head_block, head_block,
inner: rpcs, inner: rpcs,
num_synced, num_synced,
sort_mode, sort_mode,
}; }
Some(ranked_rpcs)
} }
pub fn from_votes( pub fn from_votes(
@ -904,12 +902,7 @@ impl RpcsForRequest {
let error_handler = None; let error_handler = None;
// todo!("be sure to set server_error if we exit without any rpcs!"); // todo!("be sure to set server_error if we exit without any rpcs!");
#[allow(clippy::never_loop)] while !self.request.connect_timeout() {
loop {
if self.request.connect_timeout() {
break;
}
let mut earliest_retry_at = None; let mut earliest_retry_at = None;
let mut opened = 0; let mut opened = 0;
let mut tried = 0; let mut tried = 0;

View File

@ -408,7 +408,6 @@ impl Web3Rpcs {
ranked_rpcs ranked_rpcs
} else if self.watch_head_block.is_some() { } else if self.watch_head_block.is_some() {
// if we are here, this set of rpcs is subscribed to newHeads. But we didn't get a RankedRpcs. that means something is wrong // if we are here, this set of rpcs is subscribed to newHeads. But we didn't get a RankedRpcs. that means something is wrong
trace!("watch_head_block is some");
return Err(Web3ProxyError::NoServersSynced); return Err(Web3ProxyError::NoServersSynced);
} else { } else {
trace!("watch_head_block is none"); trace!("watch_head_block is none");
@ -416,12 +415,10 @@ impl Web3Rpcs {
// no RankedRpcs, but also no newHeads subscription. This is probably a set of "protected" rpcs or similar // no RankedRpcs, but also no newHeads subscription. This is probably a set of "protected" rpcs or similar
let rpcs = self.by_name.read().values().cloned().collect(); let rpcs = self.by_name.read().values().cloned().collect();
if let Some(x) = RankedRpcs::from_rpcs(rpcs, web3_request.head_block.clone()) { // TODO: does this need the head_block? i don't think so
Arc::new(x) let x = RankedRpcs::from_rpcs(rpcs, web3_request.head_block.clone());
} else {
// i doubt we will ever get here Arc::new(x)
return Err(Web3ProxyError::NoServersSynced);
}
}; };
match ranked_rpcs.for_request(web3_request) { match ranked_rpcs.for_request(web3_request) {
@ -549,6 +546,7 @@ impl Web3Rpcs {
// TODO: what error code? what data? // TODO: what error code? what data?
// cloudflare gives {"jsonrpc":"2.0","error":{"code":-32043,"message":"Requested data cannot be older than 128 blocks."},"id":1} // cloudflare gives {"jsonrpc":"2.0","error":{"code":-32043,"message":"Requested data cannot be older than 128 blocks."},"id":1}
// TODO: some queries other providers give "successful" results with null data. i don't like that at all but its what is often expected
Err(JsonRpcErrorData { Err(JsonRpcErrorData {
message: "Requested data is not available".into(), message: "Requested data is not available".into(),
code: -32001, code: -32001,