Skip to content

Commit

Permalink
fix: double spend ignored when parent is double spent
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach authored and RolandSherwin committed Jul 11, 2024
1 parent 7b09e37 commit 42e9d6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,7 @@ impl Node {
}

// keep track of double spend with double spent parent
let some_parents_double_spent = !double_spent_parent.is_empty();
let we_re_double_spent = all_verified_spends.len() > 1;
if some_parents_double_spent && we_re_double_spent {
if !all_verified_spends.is_empty() && !double_spent_parent.is_empty() {
warn!("Parent of {unique_pubkey:?} was double spent, but it's also a double spend. So keeping track of this double spend attempt.");
all_verified_spends.extend(double_spent_parent.into_iter())
}
Expand Down
10 changes: 10 additions & 0 deletions sn_node/tests/double_spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ async fn parent_and_child_double_spends_should_lead_to_cashnote_being_invalid()
reason.clone(),
)?;

info!("spend B to C: {:?}", transfer_to_c.all_spend_requests);
client
.send_spends(transfer_to_c.all_spend_requests.iter(), false)
.await?;
Expand Down Expand Up @@ -386,9 +387,18 @@ async fn parent_and_child_double_spends_should_lead_to_cashnote_being_invalid()
wallet_b.address(),
reason.clone(),
)?; // reuse the old cash notes

info!("spend B to Y: {:?}", transfer_to_y.all_spend_requests);
client
.send_spends(transfer_to_y.all_spend_requests.iter(), false)
.await?;
let spend_b_to_y = transfer_to_y
.all_spend_requests
.first()
.expect("should have one");
let b_spends = client.get_spend_from_network(spend_b_to_y.address()).await;
info!("B spends: {b_spends:?}");

info!("Verifying the transfers from B -> Y wallet... It should error out.");
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;
Expand Down

0 comments on commit 42e9d6c

Please sign in to comment.