diff --git a/web3_proxy/src/rpcs/consensus.rs b/web3_proxy/src/rpcs/consensus.rs index 3b666228..9ea4dcf1 100644 --- a/web3_proxy/src/rpcs/consensus.rs +++ b/web3_proxy/src/rpcs/consensus.rs @@ -129,16 +129,24 @@ pub struct RpcsForRequest { } impl RankedRpcs { - pub fn from_rpcs(rpcs: Vec>, head_block: Web3ProxyBlock) -> Option { + pub fn from_rpcs(rpcs: Vec>, head_block: Option) -> Option { // 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 + let head_block = head_block?; + let backups_needed = rpcs.iter().any(|x| x.backup); let num_synced = rpcs.len(); // TODO: do we need real data in here? if we are calling from_rpcs, we probably don't even track their block - let rpc_data = Default::default(); + let mut rpc_data = HashMap::, ConsensusRpcData>::with_capacity(num_synced); + + for rpc in rpcs.iter().cloned() { + let data = ConsensusRpcData::new(&rpc, &head_block); + + rpc_data.insert(rpc, data); + } let sort_mode = SortMethod::Shuffle; diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 844aa82b..2bfefcbc 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -445,20 +445,21 @@ impl Web3Rpcs { let ranked_rpcs: Arc = if let Some(ranked_rpcs) = self.watch_ranked_rpcs.borrow().clone() { ranked_rpcs - } else if let Some(head_block) = web3_request.head_block.clone() { - // if we are here, self isn't watching head blocks but some other Web3Rpcs is. Return all the 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 + return Err(Web3ProxyError::NoServersSynced); + } else { + // no RankedRpcs, but also no newHeads subscription. This is probably a set of "protected" rpcs or similar + // TODO: return a future that resolves once we do have something? let rpcs = self.by_name.read().values().cloned().collect(); - if let Some(x) = RankedRpcs::from_rpcs(rpcs, head_block) { + if let Some(x) = RankedRpcs::from_rpcs(rpcs, web3_request.head_block.clone()) { Arc::new(x) } else { // i doubt we will ever get here // TODO: return a future that resolves once we do have something? return Err(Web3ProxyError::NoServersSynced); } - } else { - // TODO: return a future that resolves once we do have something? - return Err(Web3ProxyError::NoServersSynced); }; match ranked_rpcs.for_request(web3_request) {