from_rpcs never returns None
This commit is contained in:
parent
53b4eacaa7
commit
971f690d4f
|
@ -102,7 +102,7 @@ pub struct RpcsForRequest {
|
|||
}
|
||||
|
||||
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
|
||||
// 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 ranked_rpcs = RankedRpcs {
|
||||
Self {
|
||||
backups_needed,
|
||||
head_block,
|
||||
inner: rpcs,
|
||||
num_synced,
|
||||
sort_mode,
|
||||
};
|
||||
|
||||
Some(ranked_rpcs)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_votes(
|
||||
|
@ -904,12 +902,7 @@ impl RpcsForRequest {
|
|||
let error_handler = None;
|
||||
|
||||
// todo!("be sure to set server_error if we exit without any rpcs!");
|
||||
#[allow(clippy::never_loop)]
|
||||
loop {
|
||||
if self.request.connect_timeout() {
|
||||
break;
|
||||
}
|
||||
|
||||
while !self.request.connect_timeout() {
|
||||
let mut earliest_retry_at = None;
|
||||
let mut opened = 0;
|
||||
let mut tried = 0;
|
||||
|
|
|
@ -408,7 +408,6 @@ impl Web3Rpcs {
|
|||
ranked_rpcs
|
||||
} 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
|
||||
trace!("watch_head_block is some");
|
||||
return Err(Web3ProxyError::NoServersSynced);
|
||||
} else {
|
||||
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
|
||||
let rpcs = self.by_name.read().values().cloned().collect();
|
||||
|
||||
if let Some(x) = RankedRpcs::from_rpcs(rpcs, web3_request.head_block.clone()) {
|
||||
Arc::new(x)
|
||||
} else {
|
||||
// i doubt we will ever get here
|
||||
return Err(Web3ProxyError::NoServersSynced);
|
||||
}
|
||||
// TODO: does this need the head_block? i don't think so
|
||||
let x = RankedRpcs::from_rpcs(rpcs, web3_request.head_block.clone());
|
||||
|
||||
Arc::new(x)
|
||||
};
|
||||
|
||||
match ranked_rpcs.for_request(web3_request) {
|
||||
|
@ -549,6 +546,7 @@ impl Web3Rpcs {
|
|||
|
||||
// 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}
|
||||
// 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 {
|
||||
message: "Requested data is not available".into(),
|
||||
code: -32001,
|
||||
|
|
Loading…
Reference in New Issue