Skip to content

Commit

Permalink
Merge branch 'release' into scx1332/net
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Mar 20, 2024
2 parents 6258313 + 9997111 commit ca898a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion crates/erc20_rpc_pool/src/rpc_pool/eth_generic_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ impl Web3RpcPool {
let mut loop_no = 0;
const LOOP_COUNT: usize = 4;
loop {
let idx_vec = self.clone().choose_best_endpoints().await;
let resp = self.clone().choose_best_endpoints().await;
if resp.allowed_endpoints.is_empty() && !resp.is_resolving {
log::warn!("No valid endpoints found for chain id {}, wait until next check. Call yagna payment driver rpc --verify for details", self.chain_id);
return Err(web3::Error::Unreachable);
}
let idx_vec = resp.allowed_endpoints;
if let Some(idx_chosen) = idx_vec.first() {
self.mark_rpc_chosen(*idx_chosen);
}
Expand Down
27 changes: 22 additions & 5 deletions crates/erc20_rpc_pool/src/rpc_pool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ pub async fn resolve_txt_record_to_string_array(record: &str) -> std::io::Result
.collect::<Vec<_>>())
}

pub struct ChooseBestEndpointsResult {
pub allowed_endpoints: Vec<Index>,
pub is_resolving: bool,
}

impl Web3RpcPool {
pub fn new(
chain_id: u64,
Expand Down Expand Up @@ -327,11 +332,14 @@ impl Web3RpcPool {
});
}

pub async fn choose_best_endpoints(self: Arc<Self>) -> Vec<Index> {
self.external_sources_resolver
pub async fn choose_best_endpoints(self: Arc<Self>) -> ChooseBestEndpointsResult {
let task = self
.external_sources_resolver
.clone()
.start_resolve_if_needed(self.clone(), false);

let is_resolving = task.is_some();

let endpoints_copy = self
.endpoints
.try_lock_for(Duration::from_secs(5))
Expand Down Expand Up @@ -379,7 +387,10 @@ impl Web3RpcPool {
.clone()
.start_verify_if_needed(self.clone(), false);

allowed_endpoints
ChooseBestEndpointsResult {
allowed_endpoints,
is_resolving,
}
} else {
let self_cloned = self.clone();
self_cloned
Expand Down Expand Up @@ -408,7 +419,10 @@ impl Web3RpcPool {
})
.map(|(idx, _element)| idx)
{
return vec![el];
return ChooseBestEndpointsResult {
allowed_endpoints: vec![el],
is_resolving,
};
}

if is_finished {
Expand All @@ -417,7 +431,10 @@ impl Web3RpcPool {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
//no endpoint could be selected
vec![]
ChooseBestEndpointsResult {
allowed_endpoints: vec![],
is_resolving,
}
}
}

Expand Down

0 comments on commit ca898a6

Please sign in to comment.