Skip to content

Commit

Permalink
Fix SIGINT handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pbeza committed Sep 13, 2024
1 parent dd57cad commit f11bdec
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions bin/verify-era-proof-attestation/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,30 @@ pub async fn get_proofs(
let max_backoff = Duration::from_secs(128);
let retry_backoff_multiplier: f32 = 2.0;

let proofs = loop {
while !*stop_receiver.borrow() {
let proofs = proofs_request
.send(stop_receiver, http_client, rpc_url)
.await?;

if proofs.is_empty() {
retries += 1;
warn!(
batch_no = batch_number.0, retries,
"No TEE proofs found for batch #{}. They may not be ready yet. Retrying in {} milliseconds.",
batch_number, backoff.as_millis(),
);
tokio::time::timeout(backoff, stop_receiver.changed())
.await
.ok();
backoff = std::cmp::min(backoff.mul_f32(retry_backoff_multiplier), max_backoff);
} else {
break proofs;
if !proofs.is_empty() {
return Ok(proofs);
}
};

Ok(proofs)
retries += 1;
warn!(
batch_no = batch_number.0, retries,
"No TEE proofs found for batch #{}. They may not be ready yet. Retrying in {} milliseconds.",
batch_number, backoff.as_millis(),
);

tokio::time::timeout(backoff, stop_receiver.changed())
.await
.ok();

backoff = std::cmp::min(backoff.mul_f32(retry_backoff_multiplier), max_backoff);
}

Ok(vec![])
}

impl GetProofsRequest {
Expand All @@ -76,8 +78,9 @@ impl GetProofsRequest {
let mut backoff = Duration::from_secs(1);
let max_backoff = Duration::from_secs(128);
let retry_backoff_multiplier: f32 = 2.0;
let mut response = None;

let response = loop {
while !*stop_receiver.borrow() {
let result = http_client
.post(rpc_url.clone())
.json(self)
Expand All @@ -88,8 +91,11 @@ impl GetProofsRequest {
.await;

match result {
Ok(response) => match response.error {
None => break response,
Ok(res) => match res.error {
None => {
response = Some(res);
break;
}
Some(error) => {
// Handle corner case, where the old RPC interface expects 'Sgx'
if let Some(data) = error.data() {
Expand Down Expand Up @@ -125,9 +131,9 @@ impl GetProofsRequest {
backoff = std::cmp::min(backoff.mul_f32(retry_backoff_multiplier), max_backoff);
}
};
};
}

Ok(response.result.unwrap_or(Vec::new()))
Ok(response.map_or_else(Vec::new, |res| res.result.unwrap_or_default()))
}
}

Expand Down

0 comments on commit f11bdec

Please sign in to comment.