Skip to content

Commit

Permalink
Merge pull request #2020 from maqi/check_spent
Browse files Browse the repository at this point in the history
chore(node): check confirmed_spend existence
  • Loading branch information
joshuef authored Aug 2, 2024
2 parents 4255e0d + 6d184b1 commit 13b885a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,23 @@ impl Node {
}

let spend_addr = SpendAddress::from_unique_pubkey(&cash_note.unique_pubkey());
let already_spent = matches!(wallet.get_confirmed_spend(spend_addr), Ok(Some(_spend)));
if already_spent {
warn!(
"Double spend {} detected for record payment {pretty_key}",
cash_note.unique_pubkey()
);
match wallet.get_confirmed_spend(spend_addr) {
Ok(None) => true,
Ok(Some(_spend)) => {
warn!(
"Burnt spend {} detected for record payment {pretty_key}",
cash_note.unique_pubkey()
);
false
}
Err(err) => {
error!(
"When checking confirmed_spend {}, enountered error {err:?}",
cash_note.unique_pubkey()
);
true
}
}
// retain the `CashNote` if it's not already spent
!already_spent
});
if cash_notes.is_empty() {
info!("All incoming cash notes were already received, no need to further process");
Expand Down
2 changes: 1 addition & 1 deletion sn_transfers/src/wallet/wallet_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(super) fn get_confirmed_spend(
let spend_hex_name = spend_addr.to_hex();
let spend_file_path = spends_dir.join(spend_hex_name);
debug!("Try to getting a confirmed_spend instance from: {spend_file_path:?}");
if !spend_file_path.is_file() {
if !spend_file_path.exists() {
return Ok(None);
}

Expand Down

0 comments on commit 13b885a

Please sign in to comment.