From e1394f3ea04816ee5cf7d155702581363328dfb5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 5 May 2023 03:33:54 +0000 Subject: [PATCH] Document when `PaymentPathSuccessful::payment_hash` is filled in. The `payment_hash` field in `PaymentPathSuccessful` is always `Some` as long as the pening payment tracker has a `payment_hash`, which is true for all `Pending` payments as well as all `Fulfilled` payments starting with the commit which added `PaymentPathSuccessful` - 3b5c370b404e2f5a8f3c35093b97406f149a9340c177c05252574083d68df0da. --- lightning/src/events/mod.rs | 2 ++ lightning/src/ln/outbound_payment.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index 4d8b8cee9..046eb22f7 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -498,6 +498,8 @@ pub enum Event { payment_id: PaymentId, /// The hash that was given to [`ChannelManager::send_payment`]. /// + /// This will be `Some` for all payments which completed on LDK 0.0.104 or later. + /// /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment payment_hash: Option, /// The payment path that was successful. diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 569e664ba..f107f3b55 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -60,6 +60,7 @@ pub(crate) enum PendingOutboundPayment { /// and add a pending payment that was already fulfilled. Fulfilled { session_privs: HashSet<[u8; 32]>, + /// Filled in for any payment which moved to `Fulfilled` on LDK 0.0.104 or later. payment_hash: Option, timer_ticks_without_htlcs: u8, }, @@ -1168,9 +1169,11 @@ impl OutboundPayments { if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(payment_id) { assert!(payment.get().is_fulfilled()); if payment.get_mut().remove(&session_priv_bytes, None) { + let payment_hash = payment.get().payment_hash(); + debug_assert!(payment_hash.is_some()); pending_events.push_back((events::Event::PaymentPathSuccessful { payment_id, - payment_hash: payment.get().payment_hash(), + payment_hash, path, }, None)); } -- 2.39.5