Skip to content

Commit e1e7903

Browse files
committed
Expose the RecipientOnionFields in Event::PaymentClaimable
This finally completes the piping of the `payment_metadata` from from the BOLT11 invoice on the sending side all the way through the onion sending + receiving ends to the user on the receive events.
1 parent 9c55ada commit e1e7903

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

lightning/src/events/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub mod bump_transaction;
2121
pub use bump_transaction::BumpTransactionEvent;
2222

2323
use crate::chain::keysinterface::SpendableOutputDescriptor;
24-
use crate::ln::channelmanager::{InterceptId, PaymentId};
24+
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
2525
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
2626
use crate::ln::features::ChannelTypeFeatures;
2727
use crate::ln::msgs;
@@ -342,6 +342,11 @@ pub enum Event {
342342
/// The hash for which the preimage should be handed to the ChannelManager. Note that LDK will
343343
/// not stop you from registering duplicate payment hashes for inbound payments.
344344
payment_hash: PaymentHash,
345+
/// The fields in the onion which were received with each HTLC. Only fields which were
346+
/// identical in each HTLC involved in the payment will be included here.
347+
///
348+
/// Payments received on LDK versions prior to 0.0.115 will have this field unset.
349+
onion_fields: Option<RecipientOnionFields>,
345350
/// The value, in thousandths of a satoshi, that this payment is for.
346351
amount_msat: u64,
347352
/// Information for claiming this received payment, based on whether the purpose of the
@@ -780,7 +785,10 @@ impl Writeable for Event {
780785
// We never write out FundingGenerationReady events as, upon disconnection, peers
781786
// drop any channels which have not yet exchanged funding_signed.
782787
},
783-
&Event::PaymentClaimable { ref payment_hash, ref amount_msat, ref purpose, ref receiver_node_id, ref via_channel_id, ref via_user_channel_id, ref claim_deadline } => {
788+
&Event::PaymentClaimable { ref payment_hash, ref amount_msat, ref purpose,
789+
ref receiver_node_id, ref via_channel_id, ref via_user_channel_id,
790+
ref claim_deadline, ref onion_fields
791+
} => {
784792
1u8.write(writer)?;
785793
let mut payment_secret = None;
786794
let payment_preimage;
@@ -803,6 +811,7 @@ impl Writeable for Event {
803811
(6, 0u64, required), // user_payment_id required for compatibility with 0.0.103 and earlier
804812
(7, claim_deadline, option),
805813
(8, payment_preimage, option),
814+
(9, onion_fields, option),
806815
});
807816
},
808817
&Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash, ref fee_paid_msat } => {
@@ -1002,6 +1011,7 @@ impl MaybeReadable for Event {
10021011
let mut via_channel_id = None;
10031012
let mut claim_deadline = None;
10041013
let mut via_user_channel_id = None;
1014+
let mut onion_fields = None;
10051015
read_tlv_fields!(reader, {
10061016
(0, payment_hash, required),
10071017
(1, receiver_node_id, option),
@@ -1012,6 +1022,7 @@ impl MaybeReadable for Event {
10121022
(6, _user_payment_id, option),
10131023
(7, claim_deadline, option),
10141024
(8, payment_preimage, option),
1025+
(9, onion_fields, option),
10151026
});
10161027
let purpose = match payment_secret {
10171028
Some(secret) => PaymentPurpose::InvoicePayment {
@@ -1029,6 +1040,7 @@ impl MaybeReadable for Event {
10291040
via_channel_id,
10301041
via_user_channel_id,
10311042
claim_deadline,
1043+
onion_fields,
10321044
}))
10331045
};
10341046
f()

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,6 +3432,7 @@ where
34323432
via_channel_id: Some(prev_channel_id),
34333433
via_user_channel_id: Some(prev_user_channel_id),
34343434
claim_deadline: Some(earliest_expiry - HTLC_FAIL_BACK_BUFFER),
3435+
onion_fields: claimable_payment.onion_fields.clone(),
34353436
});
34363437
payment_claimable_generated = true;
34373438
} else {
@@ -3501,6 +3502,7 @@ where
35013502
via_channel_id: Some(prev_channel_id),
35023503
via_user_channel_id: Some(prev_user_channel_id),
35033504
claim_deadline,
3505+
onion_fields: Some(onion_fields),
35043506
});
35053507
},
35063508
hash_map::Entry::Occupied(_) => {

lightning/src/ln/functional_test_utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,21 +1981,26 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
19811981
let events_2 = node.node.get_and_clear_pending_events();
19821982
if payment_claimable_expected {
19831983
assert_eq!(events_2.len(), 1);
1984-
match events_2[0] {
1985-
Event::PaymentClaimable { ref payment_hash, ref purpose, amount_msat, receiver_node_id, ref via_channel_id, ref via_user_channel_id, claim_deadline } => {
1984+
match &events_2[0] {
1985+
Event::PaymentClaimable { ref payment_hash, ref purpose, amount_msat,
1986+
receiver_node_id, ref via_channel_id, ref via_user_channel_id,
1987+
claim_deadline, onion_fields,
1988+
} => {
19861989
assert_eq!(our_payment_hash, *payment_hash);
19871990
assert_eq!(node.node.get_our_node_id(), receiver_node_id.unwrap());
1991+
assert!(onion_fields.is_some());
19881992
match &purpose {
19891993
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
19901994
assert_eq!(expected_preimage, *payment_preimage);
19911995
assert_eq!(our_payment_secret.unwrap(), *payment_secret);
1996+
assert_eq!(Some(*payment_secret), onion_fields.as_ref().unwrap().payment_secret);
19921997
},
19931998
PaymentPurpose::SpontaneousPayment(payment_preimage) => {
19941999
assert_eq!(expected_preimage.unwrap(), *payment_preimage);
19952000
assert!(our_payment_secret.is_none());
19962001
},
19972002
}
1998-
assert_eq!(amount_msat, recv_value);
2003+
assert_eq!(*amount_msat, recv_value);
19992004
assert!(node.node.list_channels().iter().any(|details| details.channel_id == via_channel_id.unwrap()));
20002005
assert!(node.node.list_channels().iter().any(|details| details.user_channel_id == via_user_channel_id.unwrap()));
20012006
assert!(claim_deadline.unwrap() > node.best_block_info().1);

lightning/src/ln/outbound_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub enum PaymentSendFailure {
409409
///
410410
/// This should generally be constructed with data communicated to us from the recipient (via a
411411
/// BOLT11 or BOLT12 invoice).
412-
#[derive(Clone)]
412+
#[derive(Clone, Debug, PartialEq, Eq)]
413413
pub struct RecipientOnionFields {
414414
/// The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
415415
/// in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to

0 commit comments

Comments
 (0)