Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 4df12d5

Browse files
authored
Merge pull request #1172 from MutinyWallet/fix-duplicate-payment
Fix duplicate payment when paying lightning address
2 parents 2c18ebe + 9cd459c commit 4df12d5

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

mutiny-core/src/federation.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,12 @@ impl<S: MutinyStorage> FederationClient<S> {
603603
fn maybe_update_after_checking_fedimint(
604604
&self,
605605
updated_invoice: MutinyInvoice,
606-
) -> Result<(), MutinyError> {
606+
) -> Result<MutinyInvoice, MutinyError> {
607607
maybe_update_after_checking_fedimint(
608608
updated_invoice,
609609
self.logger.clone(),
610610
self.storage.clone(),
611-
)?;
612-
Ok(())
611+
)
613612
}
614613

615614
pub(crate) async fn pay_invoice(
@@ -679,7 +678,7 @@ impl<S: MutinyStorage> FederationClient<S> {
679678
};
680679
inv.fees_paid = Some(sats_round_up(&outgoing_payment.fee));
681680

682-
self.maybe_update_after_checking_fedimint(inv.clone())?;
681+
inv = self.maybe_update_after_checking_fedimint(inv)?;
683682

684683
match inv.status {
685684
HTLCStatus::Succeeded => Ok(inv),
@@ -1081,23 +1080,28 @@ fn subscribe_operation_ext<S: MutinyStorage>(
10811080
}
10821081

10831082
fn maybe_update_after_checking_fedimint<S: MutinyStorage>(
1084-
updated_invoice: MutinyInvoice,
1083+
mut updated_invoice: MutinyInvoice,
10851084
logger: Arc<MutinyLogger>,
10861085
storage: S,
1087-
) -> Result<(), MutinyError> {
1086+
) -> Result<MutinyInvoice, MutinyError> {
10881087
match updated_invoice.status {
10891088
HTLCStatus::Succeeded | HTLCStatus::Failed => {
1090-
log_debug!(logger, "Saving updated payment");
10911089
let hash = updated_invoice.payment_hash.into_32();
10921090
let inbound = updated_invoice.inbound;
1093-
let mut payment_info = PaymentInfo::from(updated_invoice);
1094-
payment_info.last_update = now().as_secs();
1091+
updated_invoice.last_updated = now().as_secs();
1092+
let payment_info = PaymentInfo::from(updated_invoice.clone());
1093+
log_debug!(
1094+
logger,
1095+
"Saving updated payment: {} {}",
1096+
hash.to_lower_hex_string(),
1097+
payment_info.last_update
1098+
);
10951099
persist_payment_info(&storage, &hash, &payment_info, inbound)?;
10961100
}
10971101
HTLCStatus::Pending | HTLCStatus::InFlight => (),
10981102
}
10991103

1100-
Ok(())
1104+
Ok(updated_invoice)
11011105
}
11021106

11031107
impl<S: MutinyStorage> FedimintClient for FederationClient<S> {

mutiny-core/src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,15 +3132,18 @@ impl<S: MutinyStorage> MutinyWallet<S> {
31323132
}
31333133

31343134
let mut inv = self.pay_invoice(&invoice, None, labels).await?;
3135-
// save privacy level to storage
3136-
inv.privacy_level = privacy_level;
3137-
persist_payment_info(
3138-
&self.storage,
3139-
&inv.payment_hash.into_32(),
3140-
&inv.clone().into(),
3141-
false,
3142-
)?;
3143-
3135+
// save privacy level to storage, can skip if its the default privacy level
3136+
if privacy_level != PrivacyLevel::default() {
3137+
inv.privacy_level = privacy_level;
3138+
let hash = inv.payment_hash.into_32();
3139+
log_debug!(
3140+
self.logger,
3141+
"Saving updated payment: {} {}",
3142+
hash.to_lower_hex_string(),
3143+
inv.last_updated
3144+
);
3145+
persist_payment_info(&self.storage, &hash, &inv.clone().into(), false)?;
3146+
}
31443147
Ok(inv)
31453148
} else {
31463149
log_error!(self.logger, "LNURL return invoice with incorrect amount");

0 commit comments

Comments
 (0)