Skip to content

Commit

Permalink
fix: use actual quote instead of dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed Nov 20, 2023
1 parent 2f76b4f commit fb17dc7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion sn_cli/src/subcommands/files/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use xor_name::XorName;

/// Max amount of times to retry uploading a chunk
const MAX_CHUNK_PUT_RETRIES: usize = 10;
/// Max amount of times to retry verification and repay.
/// Max amount of times to retry verification.
const MAX_VERIFICATION_RETRIES: usize = 5;
const CHUNK_PUT_RETRY_WAIT_S: u64 = 2;

Expand Down
1 change: 1 addition & 0 deletions sn_networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ mod tests {
use eyre::bail;

use super::*;
use sn_transfers::PaymentQuote;

#[test]
fn test_get_fee_from_store_cost_responses() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl Node {
// check if the quote is valid
let storecost = payment.quote.cost;
if let Err(e) = self.verify_quote_for_storecost(payment.quote, address) {
trace!("Invalid payment quote for record {pretty_key}");
debug!("Invalid payment quote for record {pretty_key}: {e:?}");
return Err(ProtocolError::RecordNotStored(
pretty_key.clone(),
format!("{e:}"),
Expand Down
4 changes: 4 additions & 0 deletions sn_node/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ impl Node {
timestamp,
signature,
};

debug!("Created payment quote for {address:?}: {quote:?}");
Ok(quote)
}

Expand All @@ -48,6 +50,8 @@ impl Node {
quote: PaymentQuote,
address: &NetworkAddress,
) -> Result<(), ProtocolError> {
debug!("Verifying payment quote for {address:?}: {quote:?}");

// check address
if address.as_xorname().unwrap_or_default() != quote.content {
return Err(ProtocolError::InvalidQuoteContent);
Expand Down
22 changes: 10 additions & 12 deletions sn_transfers/src/wallet/data_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,12 @@ pub struct PaymentQuote {
/// how much the node demands for storing the content
pub cost: NanoTokens,
/// the local node time when the quote was created
#[debug(skip)]
pub timestamp: SystemTime,
/// the node's signature of the 3 fields above
#[debug(skip)]
pub signature: QuoteSignature,
}

impl PaymentQuote {
/// test utility to create a dummy quote
pub fn new_dummy(xorname: XorName, cost: NanoTokens) -> Self {
Self {
content: xorname,
cost,
timestamp: SystemTime::now(),
signature: vec![],
}
}

/// create an empty PaymentQuote
pub fn zero() -> Self {
Self {
Expand All @@ -103,4 +91,14 @@ impl PaymentQuote {
);
bytes
}

/// test utility to create a dummy quote
pub fn new_dummy(xorname: XorName, cost: NanoTokens) -> Self {
Self {
content: xorname,
cost,
timestamp: SystemTime::now(),
signature: vec![],
}
}
}
9 changes: 8 additions & 1 deletion sn_transfers/src/wallet/local_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,18 @@ impl LocalWallet {
let royalties_amount = cash_note_for_royalties.value()?;
trace!("Created network royalties cnr regarding {xorname:?} paying {royalties_amount:?} to {royalties_key:?}.");

let quote = price_map
.get(xorname)
.ok_or(Error::CouldNotSendMoney(format!(
"No quote found for {xorname:?}"
)))?
.1
.clone();
let payment = PaymentDetails {
recipient: node_key,
transfer: (transfer_for_node, transfer_amount),
royalties: (royalties, royalties_amount),
quote: PaymentQuote::new_dummy(*xorname, transfer_amount),
quote,
};

self.wallet.payment_transactions.insert(*xorname, payment);
Expand Down

0 comments on commit fb17dc7

Please sign in to comment.