add to skip list earlier

This commit is contained in:
Bryan Stitt 2023-05-18 13:51:28 -07:00
parent a92c93706b
commit 9c584354d9
3 changed files with 32 additions and 27 deletions

@ -153,7 +153,7 @@ pub async fn user_balance_post(
// Just make an rpc request, idk if i need to call this super extensive code
let transaction_receipt: TransactionReceipt = match app
.balanced_rpcs
.best_available_rpc(&authorization, None, &[], None, None)
.best_available_rpc(&authorization, None, &mut vec![], None, None)
.await
{
Ok(OpenRequestResult::Handle(handle)) => {
@ -188,7 +188,7 @@ pub async fn user_balance_post(
debug!("Transaction receipt is: {:?}", transaction_receipt);
let accepted_token: Address = match app
.balanced_rpcs
.best_available_rpc(&authorization, None, &[], None, None)
.best_available_rpc(&authorization, None, &mut vec![], None, None)
.await
{
Ok(OpenRequestResult::Handle(handle)) => {
@ -243,7 +243,7 @@ pub async fn user_balance_post(
debug!("Accepted token is: {:?}", accepted_token);
let decimals: u32 = match app
.balanced_rpcs
.best_available_rpc(&authorization, None, &[], None, None)
.best_available_rpc(&authorization, None, &mut vec![], None, None)
.await
{
Ok(OpenRequestResult::Handle(handle)) => {

@ -130,18 +130,18 @@ impl ConsensusWeb3Rpcs {
skip_rpcs: &[Arc<Web3Rpc>],
) -> ShouldWaitForBlock {
// TODO: i think checking synced is always a waste of time. though i guess there could be a race
// if self
// .head_rpcs
// .iter()
// .any(|rpc| self.rpc_will_work_eventually(rpc, needed_block_num, skip_rpcs))
// {
// let head_num = self.head_block.number();
if self
.head_rpcs
.iter()
.any(|rpc| self.rpc_will_work_eventually(rpc, needed_block_num, skip_rpcs))
{
let head_num = self.head_block.number();
// if Some(head_num) >= needed_block_num {
// debug!("best (head) block: {}", head_num);
// return ShouldWaitForBlock::Ready;
// }
// }
if Some(head_num) >= needed_block_num {
debug!("best (head) block: {}", head_num);
return ShouldWaitForBlock::Ready;
}
}
// all of the head rpcs are skipped

@ -495,7 +495,7 @@ impl Web3Rpcs {
&self,
authorization: &Arc<Authorization>,
request_metadata: Option<&Arc<RequestMetadata>>,
skip: &[Arc<Web3Rpc>],
skip: &mut Vec<Arc<Web3Rpc>>,
min_block_needed: Option<&U64>,
max_block_needed: Option<&U64>,
) -> Web3ProxyResult<OpenRequestResult> {
@ -592,6 +592,8 @@ impl Web3Rpcs {
let best_rpc = min_by_key(rpc_a, rpc_b, |x| x.peak_ewma());
trace!("{:?} - winner: {}", request_ulid, best_rpc);
skip.push(best_rpc.clone());
// just because it has lower latency doesn't mean we are sure to get a connection
match best_rpc.try_request_handle(authorization, None).await {
Ok(OpenRequestResult::Handle(handle)) => {
@ -805,7 +807,7 @@ impl Web3Rpcs {
.best_available_rpc(
authorization,
request_metadata,
&skip_rpcs,
&mut skip_rpcs,
min_block_needed,
max_block_needed,
)
@ -822,9 +824,6 @@ impl Web3Rpcs {
let is_backup_response = rpc.backup;
// TODO: instead of entirely skipping, maybe demote a tier?
skip_rpcs.push(rpc);
// TODO: get the log percent from the user data
let response_result: Result<Box<RawValue>, _> = active_request_handle
.request(
@ -1493,7 +1492,7 @@ mod tests {
.best_available_rpc(
&authorization,
None,
&[],
&mut vec![],
Some(head_block.number.as_ref().unwrap()),
None,
)
@ -1587,28 +1586,28 @@ mod tests {
// TODO: make sure the handle is for the expected rpc
assert!(matches!(
rpcs.best_available_rpc(&authorization, None, &[], None, None)
rpcs.best_available_rpc(&authorization, None, &mut vec![], None, None)
.await,
Ok(OpenRequestResult::Handle(_))
));
// TODO: make sure the handle is for the expected rpc
assert!(matches!(
rpcs.best_available_rpc(&authorization, None, &[], Some(&0.into()), None)
rpcs.best_available_rpc(&authorization, None, &mut vec![], Some(&0.into()), None)
.await,
Ok(OpenRequestResult::Handle(_))
));
// TODO: make sure the handle is for the expected rpc
assert!(matches!(
rpcs.best_available_rpc(&authorization, None, &[], Some(&1.into()), None)
rpcs.best_available_rpc(&authorization, None, &mut vec![], Some(&1.into()), None)
.await,
Ok(OpenRequestResult::Handle(_))
));
// future block should not get a handle
let future_rpc = rpcs
.best_available_rpc(&authorization, None, &[], Some(&2.into()), None)
.best_available_rpc(&authorization, None, &mut vec![], Some(&2.into()), None)
.await;
assert!(matches!(future_rpc, Ok(OpenRequestResult::NotReady)));
}
@ -1733,7 +1732,13 @@ mod tests {
// best_synced_backend_connection requires servers to be synced with the head block
// TODO: test with and without passing the head_block.number?
let best_available_server = rpcs
.best_available_rpc(&authorization, None, &[], Some(head_block.number()), None)
.best_available_rpc(
&authorization,
None,
&mut vec![],
Some(head_block.number()),
None,
)
.await;
debug!("best_available_server: {:#?}", best_available_server);
@ -1744,13 +1749,13 @@ mod tests {
));
let _best_available_server_from_none = rpcs
.best_available_rpc(&authorization, None, &[], None, None)
.best_available_rpc(&authorization, None, &mut vec![], None, None)
.await;
// assert_eq!(best_available_server, best_available_server_from_none);
let best_archive_server = rpcs
.best_available_rpc(&authorization, None, &[], Some(&1.into()), None)
.best_available_rpc(&authorization, None, &mut vec![], Some(&1.into()), None)
.await;
match best_archive_server {