Skip to content

Commit

Permalink
fix: update based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and grumbach committed Jul 3, 2024
1 parent 044d314 commit 01ee874
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sn_protocol::{
use sn_registers::SignedRegister;
use sn_transfers::{
calculate_royalties_fee, CashNote, CashNoteRedemption, HotWallet, NanoTokens, Payment,
SignedSpend, Transfer, UniquePubkey, WalletError, NETWORK_ROYALTIES_PK,
SignedSpend, Transfer, TransferError, UniquePubkey, WalletError, NETWORK_ROYALTIES_PK,
};
use std::collections::BTreeSet;
use tokio::task::JoinSet;
Expand Down Expand Up @@ -743,8 +743,8 @@ impl Node {

if parent_is_a_double_spend && all_verified_spends.len() == 1 {
warn!("Parent is a double spend for {unique_pubkey:?}, ignoring this spend");
return Err(Error::InvalidRequest(format!(
"Parent is a double spend for {unique_pubkey:?}, ignoring this spend."
return Err(Error::Transfers(TransferError::InvalidParentSpend(
format!("Parent is a double spend for {unique_pubkey:?}"),
)));
} else if parent_is_a_double_spend && all_verified_spends.len() > 1 {
warn!("Parent is a double spend for {unique_pubkey:?}, but we're also a double spend. So storing our double spend attempt.");
Expand Down
20 changes: 15 additions & 5 deletions sn_node/tests/double_spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async fn parent_and_child_double_spends_should_lead_to_cashnote_being_invalid()
info!("Verifying the transfers from B -> C wallet...");
let cash_notes_for_c: Vec<_> = transfer_to_c.cash_notes_for_recipient.clone();
client.verify_cashnote(&cash_notes_for_c[0]).await?;
wallet_c.deposit_and_store_to_disk(&cash_notes_for_c)?; // store inside c
wallet_c.deposit_and_store_to_disk(&cash_notes_for_c.clone())?; // store inside c

// Try to double spend from A -> X
let wallet_dir_x = TempDir::new()?;
Expand All @@ -362,7 +362,11 @@ async fn parent_and_child_double_spends_should_lead_to_cashnote_being_invalid()
.await?;
info!("Verifying the transfers from A -> X wallet... It should error out.");
let cash_notes_for_x: Vec<_> = transfer_to_x.cash_notes_for_recipient.clone();
assert!(client.verify_cashnote(&cash_notes_for_x[0]).await.is_err()); // the old spend has been poisoned
let result = client.verify_cashnote(&cash_notes_for_x[0]).await;
info!("Got result while verifying double spend from A -> X: {result:?}");
assert_matches!(result, Err(WalletError::CouldNotVerifyTransfer(str)) => {
assert!(str.starts_with("Network Error Double spend(s) was detected"));
}); // poisoned

// Try to double spend from B -> Y
let wallet_dir_y = TempDir::new()?;
Expand All @@ -387,17 +391,23 @@ async fn parent_and_child_double_spends_should_lead_to_cashnote_being_invalid()
let cash_notes_for_y: Vec<_> = transfer_to_y.cash_notes_for_recipient.clone();
let result = client.verify_cashnote(&cash_notes_for_y[0]).await;
info!("Got result while verifying double spend from B -> Y: {result:?}");
assert!(result.is_err());
assert_matches!(result, Err(WalletError::CouldNotVerifyTransfer(str)) => {
assert!(str.starts_with("Network Error Double spend(s) was detected"));
});

info!("Verifying the original cashnote of A -> B");
let result = client.verify_cashnote(&cash_notes_for_b[0]).await;
info!("Got result while verifying the original spend from A -> B: {result:?}");
assert!(result.is_err());
assert_matches!(result, Err(WalletError::CouldNotVerifyTransfer(str)) => {
assert!(str.starts_with("Network Error Double spend(s) was detected"));
});

info!("Verifying the original cashnote of B -> C");
let result = client.verify_cashnote(&cash_notes_for_c[0]).await;
info!("Got result while verifying the original spend from B -> C: {result:?}");
assert!(result.is_err());
assert_matches!(result, Err(WalletError::CouldNotVerifyTransfer(str)) => {
assert!(str.starts_with("Network Error Double spend(s) was detected"));
});

Ok(())
}
1 change: 0 additions & 1 deletion sn_transfers/src/cashnotes/signed_spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ impl SignedSpend {
}

// if parent is a double spend, get the actual parent among the parent double spends
// We cannot have more than 1 parent double spend with same tx hash.
let actual_parent = parents
.iter()
.find(|p| p.spent_tx_hash() == tx_our_cash_note_was_created_in)
Expand Down

0 comments on commit 01ee874

Please sign in to comment.