Skip to content

Commit

Permalink
Merge pull request #2653 from mickvandijke/fix-client-should-fail-upl…
Browse files Browse the repository at this point in the history
…oad-on-quote-error

fix(networking): throw an error when no quotes could be fetched
  • Loading branch information
maqi authored Jan 22, 2025
2 parents 7d46811 + 495e2ea commit e342a75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ant-networking/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ pub enum NetworkError {
NoGraphEntryFoundInsideRecord(GraphEntryAddress),

// ---------- Store Error
#[error("Not Enough Peers for Store Cost Request")]
NotEnoughPeersForStoreCostRequest,

#[error("No Store Cost Responses")]
NoStoreCostResponses,

Expand Down
14 changes: 13 additions & 1 deletion ant-networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl Network {

if close_nodes.is_empty() {
error!("Can't get store_cost of {record_address:?}, as all close_nodes are ignored");
return Err(NetworkError::NoStoreCostResponses);
return Err(NetworkError::NotEnoughPeersForStoreCostRequest);
}

// Client shall decide whether to carry out storage verification or not.
Expand All @@ -416,6 +416,8 @@ impl Network {
let mut peer_already_have_it = 0;
let enough_peers_already_have_it = close_nodes.len() / 2;

let mut peers_returned_error = 0;

// loop over responses
let mut all_quotes = vec![];
let mut quotes_to_pay = vec![];
Expand Down Expand Up @@ -456,13 +458,23 @@ impl Network {
}
Err(err) => {
error!("Got an error while requesting quote from peer {peer:?}: {err}");
peers_returned_error += 1;
}
_ => {
error!("Got an unexpected response while requesting quote from peer {peer:?}: {response:?}");
peers_returned_error += 1;
}
}
}

if quotes_to_pay.is_empty() {
error!(
"Could not fetch any quotes. {} peers returned an error.",
peers_returned_error
);
return Err(NetworkError::NoStoreCostResponses);
}

Ok(quotes_to_pay)
}

Expand Down

0 comments on commit e342a75

Please sign in to comment.