@@ -46,6 +46,7 @@ pub(crate) enum PendingOutboundPayment {
46
46
session_privs : HashSet < [ u8 ; 32 ] > ,
47
47
payment_hash : PaymentHash ,
48
48
payment_secret : Option < PaymentSecret > ,
49
+ payment_metadata : Option < Vec < u8 > > ,
49
50
keysend_preimage : Option < PaymentPreimage > ,
50
51
pending_amt_msat : u64 ,
51
52
/// Used to track the fee paid. Only present if the payment was serialized on 0.0.103+.
@@ -422,14 +423,27 @@ pub struct RecipientOnionFields {
422
423
/// receives, thus you should generally never be providing a secret here for spontaneous
423
424
/// payments.
424
425
pub payment_secret : Option < PaymentSecret > ,
426
+ /// The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
427
+ /// arbitrary length. This gives recipients substantially more flexibility to receive
428
+ /// additional data.
429
+ ///
430
+ /// In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
431
+ /// scheme to authenticate received payments against expected payments and invoices, this field
432
+ /// is not used in LDK for received payments, and can be used to store arbitrary data in
433
+ /// invoices which will be received with the payment.
434
+ ///
435
+ /// Note that this field was added to the lightning specification more recently than
436
+ /// [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
437
+ /// may not be supported as universally.
438
+ pub payment_metadata : Option < Vec < u8 > > ,
425
439
}
426
440
427
441
impl RecipientOnionFields {
428
442
/// Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
429
443
/// set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
430
444
/// but do not require or provide any further data.
431
445
pub fn secret_only ( payment_secret : PaymentSecret ) -> Self {
432
- Self { payment_secret : Some ( payment_secret) }
446
+ Self { payment_secret : Some ( payment_secret) , payment_metadata : None }
433
447
}
434
448
435
449
/// Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
@@ -438,7 +452,7 @@ impl RecipientOnionFields {
438
452
///
439
453
/// [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
440
454
pub fn spontaneous_empty ( ) -> Self {
441
- Self { payment_secret : None }
455
+ Self { payment_secret : None , payment_metadata : None }
442
456
}
443
457
}
444
458
@@ -719,7 +733,7 @@ impl OutboundPayments {
719
733
hash_map:: Entry :: Occupied ( mut payment) => {
720
734
let res = match payment. get ( ) {
721
735
PendingOutboundPayment :: Retryable {
722
- total_msat, keysend_preimage, payment_secret, pending_amt_msat, ..
736
+ total_msat, keysend_preimage, payment_secret, payment_metadata , pending_amt_msat, ..
723
737
} => {
724
738
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
725
739
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
@@ -729,6 +743,7 @@ impl OutboundPayments {
729
743
}
730
744
( * total_msat, RecipientOnionFields {
731
745
payment_secret : * payment_secret,
746
+ payment_metadata : payment_metadata. clone ( ) ,
732
747
} , * keysend_preimage)
733
748
} ,
734
749
PendingOutboundPayment :: Legacy { .. } => {
@@ -912,6 +927,7 @@ impl OutboundPayments {
912
927
pending_fee_msat : Some ( 0 ) ,
913
928
payment_hash,
914
929
payment_secret : recipient_onion. payment_secret ,
930
+ payment_metadata : recipient_onion. payment_metadata ,
915
931
keysend_preimage,
916
932
starting_block_height : best_block_height,
917
933
total_msat : route. get_total_amount ( ) ,
@@ -1345,6 +1361,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
1345
1361
( 4 , payment_secret, option) ,
1346
1362
( 5 , keysend_preimage, option) ,
1347
1363
( 6 , total_msat, required) ,
1364
+ ( 7 , payment_metadata, option) ,
1348
1365
( 8 , pending_amt_msat, required) ,
1349
1366
( 10 , starting_block_height, required) ,
1350
1367
( not_written, retry_strategy, ( static_value, None ) ) ,
0 commit comments