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 committed Jul 10, 2024
1 parent 8071507 commit 0e489e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ impl Node {
Ok((spend, Err(NetworkError::Transfer(TransferError::DoubleSpentParent)))) => {
warn!("Parent of {spend:?} was double spent, keeping aside in case we're a double spend as well");
let _ = double_spent_parent.insert(spend.clone());
let _ = all_verified_spends.insert(spend.clone());
}
Ok((spend, Err(e))) => {
// an error here most probably means the received spend is invalid
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 0e489e1

Please sign in to comment.