@@ -819,10 +819,20 @@ mod fuzzy_channelmanager {
819819 /// doing a double-pass on route when we get a failure back
820820 first_hop_htlc_msat: u64,
821821 payment_id: PaymentId,
822- /// The BOLT12 invoice associated with this payment, if any. This is stored here to ensure
823- /// we can provide proof-of-payment details in payment claim events even after a restart
824- /// with a stale ChannelManager state.
822+ /// The BOLT 12 invoice associated with this payment, if any. Stored here so it can
823+ /// be bundled into [`PaidBolt12Invoice`] in [`Event::PaymentSent`] even after a
824+ /// restart with a stale `ChannelManager` state.
825+ ///
826+ /// [`PaidBolt12Invoice`]: crate::offers::payer_proof::PaidBolt12Invoice
827+ /// [`Event::PaymentSent`]: crate::events::Event::PaymentSent
825828 bolt12_invoice: Option<Bolt12InvoiceType>,
829+ /// The [`Nonce`] used when the BOLT 12 [`InvoiceRequest`] was created. Stored here so
830+ /// it can be bundled into [`PaidBolt12Invoice`] for building payer proofs, even after
831+ /// a restart with a stale `ChannelManager` state.
832+ ///
833+ /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
834+ /// [`PaidBolt12Invoice`]: crate::offers::payer_proof::PaidBolt12Invoice
835+ payment_nonce: Option<Nonce>,
826836 },
827837 }
828838
@@ -896,6 +906,7 @@ impl core::hash::Hash for HTLCSource {
896906 payment_id,
897907 first_hop_htlc_msat,
898908 bolt12_invoice,
909+ ..
899910 } => {
900911 1u8.hash(hasher);
901912 path.hash(hasher);
@@ -930,6 +941,7 @@ impl HTLCSource {
930941 first_hop_htlc_msat: 0,
931942 payment_id: PaymentId([2; 32]),
932943 bolt12_invoice: None,
944+ payment_nonce: None,
933945 }
934946 }
935947
@@ -958,9 +970,9 @@ impl HTLCSource {
958970 pub(crate) fn static_invoice(&self) -> Option<StaticInvoice> {
959971 match self {
960972 Self::OutboundRoute {
961- bolt12_invoice: Some(Bolt12InvoiceType::StaticInvoice(inv )),
973+ bolt12_invoice: Some(Bolt12InvoiceType::StaticInvoice(invoice )),
962974 ..
963- } => Some(inv .clone()),
975+ } => Some(invoice .clone()),
964976 _ => None,
965977 }
966978 }
@@ -5348,6 +5360,7 @@ impl<
53485360 keysend_preimage,
53495361 invoice_request: None,
53505362 bolt12_invoice: None,
5363+ payment_nonce: None,
53515364 session_priv_bytes,
53525365 hold_htlc_at_next_hop: false,
53535366 })
@@ -5363,6 +5376,7 @@ impl<
53635376 keysend_preimage,
53645377 invoice_request,
53655378 bolt12_invoice,
5379+ payment_nonce,
53665380 session_priv_bytes,
53675381 hold_htlc_at_next_hop,
53685382 } = args;
@@ -5439,6 +5453,7 @@ impl<
54395453 first_hop_htlc_msat: htlc_msat,
54405454 payment_id,
54415455 bolt12_invoice: bolt12_invoice.cloned(),
5456+ payment_nonce,
54425457 };
54435458 let send_res = chan.send_htlc_and_commit(
54445459 htlc_msat,
@@ -5732,21 +5747,29 @@ impl<
57325747 pub fn send_payment_for_bolt12_invoice(
57335748 &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
57345749 ) -> Result<(), Bolt12PaymentError> {
5750+ let nonce = context.and_then(|ctx| match ctx {
5751+ OffersContext::OutboundPaymentForOffer { nonce, .. }
5752+ | OffersContext::OutboundPaymentForRefund { nonce, .. } => Some(*nonce),
5753+ _ => None,
5754+ });
57355755 match self.flow.verify_bolt12_invoice(invoice, context) {
5736- Ok(payment_id) => self.send_payment_for_verified_bolt12_invoice(invoice, payment_id),
5756+ Ok(payment_id) => {
5757+ self.send_payment_for_verified_bolt12_invoice(invoice, payment_id, nonce)
5758+ },
57375759 Err(()) => Err(Bolt12PaymentError::UnexpectedInvoice),
57385760 }
57395761 }
57405762
57415763 fn send_payment_for_verified_bolt12_invoice(
5742- &self, invoice: &Bolt12Invoice, payment_id: PaymentId,
5764+ &self, invoice: &Bolt12Invoice, payment_id: PaymentId, payment_nonce: Option<Nonce>,
57435765 ) -> Result<(), Bolt12PaymentError> {
57445766 let best_block_height = self.best_block.read().unwrap().height;
57455767 let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
57465768 let features = self.bolt12_invoice_features();
57475769 self.pending_outbound_payments.send_payment_for_bolt12_invoice(
57485770 invoice,
57495771 payment_id,
5772+ payment_nonce,
57505773 &self.router,
57515774 self.list_usable_channels(),
57525775 features,
@@ -9964,7 +9987,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
99649987 let htlc_id = SentHTLCId::from_source(&source);
99659988 match source {
99669989 HTLCSource::OutboundRoute {
9967- session_priv, payment_id, path, bolt12_invoice, ..
9990+ session_priv,
9991+ payment_id,
9992+ path,
9993+ bolt12_invoice,
9994+ payment_nonce,
9995+ ..
99689996 } => {
99699997 debug_assert!(!startup_replay,
99709998 "We don't support claim_htlc claims during startup - monitors may not be available yet");
@@ -9996,6 +10024,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
999610024 payment_id,
999710025 payment_preimage,
999810026 bolt12_invoice,
10027+ payment_nonce,
999910028 session_priv,
1000010029 path,
1000110030 from_onchain,
@@ -17036,7 +17065,12 @@ impl<
1703617065 return None;
1703717066 }
1703817067
17039- let res = self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id);
17068+ let payment_nonce = context.as_ref().and_then(|ctx| match ctx {
17069+ OffersContext::OutboundPaymentForOffer { nonce, .. }
17070+ | OffersContext::OutboundPaymentForRefund { nonce, .. } => Some(*nonce),
17071+ _ => None,
17072+ });
17073+ let res = self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id, payment_nonce);
1704017074 handle_pay_invoice_res!(res, invoice, logger);
1704117075 },
1704217076 OffersMessage::StaticInvoice(invoice) => {
@@ -17677,6 +17711,7 @@ impl Readable for HTLCSource {
1767717711 let mut payment_params: Option<PaymentParameters> = None;
1767817712 let mut blinded_tail: Option<BlindedTail> = None;
1767917713 let mut bolt12_invoice: Option<Bolt12InvoiceType> = None;
17714+ let mut payment_nonce: Option<Nonce> = None;
1768017715 read_tlv_fields!(reader, {
1768117716 (0, session_priv, required),
1768217717 (1, payment_id, option),
@@ -17685,6 +17720,7 @@ impl Readable for HTLCSource {
1768517720 (5, payment_params, (option: ReadableArgs, 0)),
1768617721 (6, blinded_tail, option),
1768717722 (7, bolt12_invoice, option),
17723+ (9, payment_nonce, option),
1768817724 });
1768917725 if payment_id.is_none() {
1769017726 // For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -17708,6 +17744,7 @@ impl Readable for HTLCSource {
1770817744 path,
1770917745 payment_id: payment_id.unwrap(),
1771017746 bolt12_invoice,
17747+ payment_nonce,
1771117748 })
1771217749 }
1771317750 1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
@@ -17727,6 +17764,7 @@ impl Writeable for HTLCSource {
1772717764 ref path,
1772817765 payment_id,
1772917766 bolt12_invoice,
17767+ payment_nonce,
1773017768 } => {
1773117769 0u8.write(writer)?;
1773217770 let payment_id_opt = Some(payment_id);
@@ -17739,6 +17777,7 @@ impl Writeable for HTLCSource {
1773917777 (5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
1774017778 (6, path.blinded_tail, option),
1774117779 (7, bolt12_invoice, option),
17780+ (9, payment_nonce, option),
1774217781 });
1774317782 },
1774417783 HTLCSource::PreviousHopData(ref field) => {
@@ -19603,6 +19642,7 @@ impl<
1960319642 session_priv,
1960419643 path,
1960519644 bolt12_invoice,
19645+ payment_nonce,
1960619646 ..
1960719647 } => {
1960819648 if let Some(preimage) = preimage_opt {
@@ -19620,6 +19660,7 @@ impl<
1962019660 payment_id,
1962119661 preimage,
1962219662 bolt12_invoice,
19663+ payment_nonce,
1962319664 session_priv,
1962419665 path,
1962519666 true,
0 commit comments