mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Remove async_recursion for a for loop
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -309,17 +309,6 @@ dependencies = [
|
||||
"event-listener",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-recursion"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.39",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.74"
|
||||
@@ -4851,7 +4840,6 @@ dependencies = [
|
||||
name = "monero-serai"
|
||||
version = "0.1.4-alpha"
|
||||
dependencies = [
|
||||
"async-recursion",
|
||||
"async-trait",
|
||||
"base58-monero",
|
||||
"curve25519-dalek",
|
||||
|
||||
@@ -54,7 +54,6 @@ serde_json = { version = "1", default-features = false, features = ["alloc"] }
|
||||
base58-monero = { version = "2", default-features = false, features = ["check"] }
|
||||
|
||||
# Used for the provided HTTP RPC
|
||||
async-recursion = { version = "1", optional = true }
|
||||
digest_auth = { version = "0.3", default-features = false, optional = true }
|
||||
simple-request = { path = "../../common/request", version = "0.1", default-features = false, optional = true }
|
||||
tokio = { version = "1", default-features = false, optional = true }
|
||||
@@ -101,7 +100,7 @@ std = [
|
||||
"base58-monero/std",
|
||||
]
|
||||
|
||||
http-rpc = ["async-recursion", "digest_auth", "simple-request", "tokio"]
|
||||
http-rpc = ["digest_auth", "simple-request", "tokio"]
|
||||
multisig = ["transcript", "frost", "dleq", "std"]
|
||||
binaries = ["tokio/rt-multi-thread", "tokio/macros", "http-rpc"]
|
||||
experimental = []
|
||||
|
||||
@@ -112,19 +112,14 @@ impl HttpRpc {
|
||||
}
|
||||
|
||||
impl HttpRpc {
|
||||
#[async_recursion::async_recursion]
|
||||
async fn inner_post(
|
||||
&self,
|
||||
route: &str,
|
||||
body: Vec<u8>,
|
||||
recursing: bool,
|
||||
) -> Result<Vec<u8>, RpcError> {
|
||||
async fn inner_post(&self, route: &str, body: Vec<u8>) -> Result<Vec<u8>, RpcError> {
|
||||
let request_fn = |uri| {
|
||||
Request::post(uri)
|
||||
.body(body.clone().into())
|
||||
.map_err(|e| RpcError::ConnectionError(format!("couldn't make request: {e:?}")))
|
||||
};
|
||||
|
||||
for attempt in 0 .. 2 {
|
||||
let response = match &self.authentication {
|
||||
Authentication::Unauthenticated(client) => client
|
||||
.request(request_fn(self.url.clone() + "/" + route)?)
|
||||
@@ -186,11 +181,11 @@ impl HttpRpc {
|
||||
connection_lock.0 = None;
|
||||
}
|
||||
|
||||
// If we're not already recursing and:
|
||||
// 1) We had a connection error
|
||||
// 2) We need to re-auth due to this token being stale
|
||||
// recursively re-call this function
|
||||
if (!recursing) &&
|
||||
// If we're not already on our second attempt and:
|
||||
// A) We had a connection error
|
||||
// B) We need to re-auth due to this token being stale
|
||||
// Move to the next loop iteration (retrying all of this)
|
||||
if (attempt == 0) &&
|
||||
(response_result.is_err() || {
|
||||
let response = response_result.as_ref().unwrap();
|
||||
if response.status() == StatusCode::UNAUTHORIZED {
|
||||
@@ -207,9 +202,9 @@ impl HttpRpc {
|
||||
}
|
||||
})
|
||||
{
|
||||
// Drop the cached authentication before we do
|
||||
connection_lock.0 = None;
|
||||
drop(connection_lock);
|
||||
return self.inner_post(route, body, true).await;
|
||||
continue;
|
||||
}
|
||||
|
||||
response_result?
|
||||
@@ -246,7 +241,10 @@ impl HttpRpc {
|
||||
.read_to_end(&mut res)
|
||||
.unwrap();
|
||||
|
||||
Ok(res)
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +252,7 @@ impl HttpRpc {
|
||||
impl RpcConnection for HttpRpc {
|
||||
async fn post(&self, route: &str, body: Vec<u8>) -> Result<Vec<u8>, RpcError> {
|
||||
// TODO: Make this timeout configurable
|
||||
tokio::time::timeout(core::time::Duration::from_secs(30), self.inner_post(route, body, false))
|
||||
tokio::time::timeout(core::time::Duration::from_secs(30), self.inner_post(route, body))
|
||||
.await
|
||||
.map_err(|e| RpcError::ConnectionError(format!("{e:?}")))?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user