Skip to content

Commit

Permalink
chore(uploader): return summary when upload fails due to max repayments
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and maqi committed May 23, 2024
1 parent ca4663f commit 0c3fa34
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
12 changes: 10 additions & 2 deletions sn_client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

pub(crate) type Result<T> = std::result::Result<T, Error>;

use crate::UploadSummary;

use super::ClientEvent;
use sn_protocol::NetworkAddress;
use sn_registers::{Entry, EntryHash};
Expand Down Expand Up @@ -140,8 +142,14 @@ pub enum Error {
#[error("Too many sequential payment errors reported during upload")]
SequentialUploadPaymentError,

#[error("The maximum specified repayments has been reached for {0:?}")]
MaximumRepaymentsReached(Vec<XorName>),
#[error("The maximum specified repayments has been reached for a single item: {0:?}")]
MaximumRepaymentsReached(XorName),

#[error("The upload failed with maximum repayments reached for multiple items: {items:?} Summary: {summary:?}")]
UploadFailedWithMaximumRepaymentsReached {
items: Vec<XorName>,
summary: UploadSummary,
},

#[error("Error occurred when access wallet file")]
FailedToAccessWallet,
Expand Down
2 changes: 1 addition & 1 deletion sn_client/src/uploader/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async fn maximum_repayment_error_should_be_triggered_during_get_store_cost() ->

assert_matches!(
upload_handle.await?,
Err(ClientError::MaximumRepaymentsReached(_))
Err(ClientError::UploadFailedWithMaximumRepaymentsReached { .. })
);
let events = events_handle.await?;

Expand Down
25 changes: 13 additions & 12 deletions sn_client/src/uploader/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ pub(super) async fn start_upload(
.balance();
#[cfg(test)]
trace!("UPLOADER STATE: finished uploading all items {uploader:?}");

if !uploader.max_repayments_reached.is_empty() {
error!(
"The maximum repayments were reached for these addresses: {:?}",
uploader.max_repayments_reached
);
return Err(ClientError::MaximumRepaymentsReached(
uploader.max_repayments_reached.into_iter().collect(),
));
}

let summary = UploadSummary {
storage_cost: uploader.upload_storage_cost,
royalty_fees: uploader.upload_royalty_fees,
Expand All @@ -142,6 +131,18 @@ pub(super) async fn start_upload(
skipped_count: uploader.skipped_count,
uploaded_registers: uploader.uploaded_registers,
};

if !uploader.max_repayments_reached.is_empty() {
error!(
"The maximum repayments were reached for these addresses: {:?}",
uploader.max_repayments_reached
);
return Err(ClientError::UploadFailedWithMaximumRepaymentsReached {
items: uploader.max_repayments_reached.into_iter().collect(),
summary,
});
}

return Ok(summary);
}

Expand Down Expand Up @@ -942,7 +943,7 @@ impl InnerUploader {
max_repayments_for_failed_data,
) {
// error is used by the caller.
return Err(ClientError::MaximumRepaymentsReached(vec![xorname]));
return Err(ClientError::MaximumRepaymentsReached(xorname));
}

debug!("Filtering out payments from {filter_list:?} during get_store_cost for {xorname:?}");
Expand Down

0 comments on commit 0c3fa34

Please sign in to comment.