improve will_work_eventually

This commit is contained in:
Bryan Stitt 2023-05-28 22:47:39 -07:00
parent 84990bb7b6
commit dc6e0559f7

@ -196,7 +196,6 @@ impl ConsensusWeb3Rpcs {
needed_block_num: Option<&U64>, needed_block_num: Option<&U64>,
skip_rpcs: &[Arc<Web3Rpc>], skip_rpcs: &[Arc<Web3Rpc>],
) -> bool { ) -> bool {
// return true if this rpc will never work for us. "false" is good
if skip_rpcs.contains(rpc) { if skip_rpcs.contains(rpc) {
// if rpc is skipped, it must have already been determined it is unable to serve the request // if rpc is skipped, it must have already been determined it is unable to serve the request
return false; return false;
@ -206,7 +205,8 @@ impl ConsensusWeb3Rpcs {
if let Some(rpc_data) = self.rpc_data.get(rpc) { if let Some(rpc_data) = self.rpc_data.get(rpc) {
match rpc_data.head_block_num.cmp(needed_block_num) { match rpc_data.head_block_num.cmp(needed_block_num) {
Ordering::Less => { Ordering::Less => {
debug!("{} is behind. let it catch up", rpc); trace!("{} is behind. let it catch up", rpc);
// TODO: what if this is a pruned rpc that is behind by a lot, and the block is old, too?
return true; return true;
} }
Ordering::Greater | Ordering::Equal => { Ordering::Greater | Ordering::Equal => {
@ -223,10 +223,11 @@ impl ConsensusWeb3Rpcs {
} }
// no rpc data for this rpc. thats not promising // no rpc data for this rpc. thats not promising
return true;
}
false false
} else {
// if no needed_block_num was specified, then this should work
true
}
} }
// TODO: better name for this // TODO: better name for this
@ -267,8 +268,8 @@ impl ConsensusWeb3Rpcs {
} }
// TODO: this might be a big perf hit. benchmark // TODO: this might be a big perf hit. benchmark
if let Some(x) = rpc.hard_limit_until { if let Some(x) = rpc.hard_limit_until.as_ref() {
if x.borrow() > Instant::now() { if *x.borrow() > Instant::now() {
trace!("{} is rate limited. skipping", rpc,); trace!("{} is rate limited. skipping", rpc,);
return false; return false;
} }