Skip to content

Commit 7baa1ca

Browse files
committed
f: Improve documentation
1 parent 136a558 commit 7baa1ca

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,13 @@ pub enum PendingHTLCRouting {
194194
///
195195
/// For HTLCs received by LDK, this will ultimately be exposed in
196196
/// [`Event::PaymentClaimable::onion_fields`] as
197-
/// [`RecipientOnionFields::custom_tlvs`].
197+
/// [`RecipientOnionFields::sender_custom_tlvs`].
198198
sender_custom_tlvs: Vec<(u64, Vec<u8>)>,
199-
/// Custom TLVs which were set by us through the reply path
199+
/// Custom TLVs set by the receiver in the blinded path used to reach them.
200+
///
201+
/// For HTLCs received by LDK, this will be exposed in
202+
/// [`Event::PaymentClaimable::onion_fields`] as
203+
/// [`RecipientOnionFields::user_custom_tlvs`].
200204
user_custom_tlvs: Vec<u8>,
201205
/// Set if this HTLC is the final hop in a multi-hop blinded path.
202206
requires_blinded_error: bool,
@@ -226,9 +230,12 @@ pub enum PendingHTLCRouting {
226230
/// Custom TLVs which were set by the sender.
227231
///
228232
/// For HTLCs received by LDK, these will ultimately bubble back up as
229-
/// [`RecipientOnionFields::custom_tlvs`].
233+
/// [`RecipientOnionFields::sender_custom_tlvs`].
230234
sender_custom_tlvs: Vec<(u64, Vec<u8>)>,
231-
/// Custom TLVs which were set by us through the reply path
235+
/// Custom TLVs set by the receiver in the blinded path used to reach them.
236+
///
237+
/// For HTLCs received by LDK, these will ultimately bubble back up as
238+
/// [`RecipientOnionFields::user_custom_tlvs`].
232239
user_custom_tlvs: Vec<u8>,
233240
/// Set if this HTLC is the final hop in a multi-hop blinded path.
234241
requires_blinded_error: bool,

lightning/src/ln/outbound_payment.rs

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ pub enum RetryableSendFailure {
471471
/// [`Event::PaymentSent`]: crate::events::Event::PaymentSent
472472
/// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed
473473
DuplicatePayment,
474-
/// The [`RecipientOnionFields::payment_metadata`], [`RecipientOnionFields::custom_tlvs`], or
475-
/// [`BlindedPaymentPath`]s provided are too large and caused us to exceed the maximum onion
476-
/// packet size of 1300 bytes.
474+
/// The [`RecipientOnionFields::payment_metadata`], [`RecipientOnionFields::sender_custom_tlvs`],
475+
/// [`RecipientOnionFields::user_custom_tlvs`] or [`BlindedPaymentPath`]s provided are too large
476+
/// and caused us to exceed the maximum onion packet size of 1300 bytes.
477477
///
478478
/// [`BlindedPaymentPath`]: crate::blinded_path::payment::BlindedPaymentPath
479479
OnionPacketSizeExceeded,
@@ -614,9 +614,9 @@ pub struct RecipientOnionFields {
614614
/// [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
615615
/// may not be supported as universally.
616616
pub payment_metadata: Option<Vec<u8>>,
617-
/// See [`Self::custom_tlvs`] for more info.
617+
/// See [`Self::sender_custom_tlvs`] for more info.
618618
pub(super) sender_custom_tlvs: Vec<(u64, Vec<u8>)>,
619-
/// Custom Tlvs sent by user to themself.
619+
/// See [`Self::user_custom_tlvs`] for more info.
620620
pub(super) user_custom_tlvs: Vec<u8>
621621
}
622622

@@ -647,15 +647,15 @@ impl RecipientOnionFields {
647647
Self { payment_secret: None, payment_metadata: None, sender_custom_tlvs: Vec::new(), user_custom_tlvs: Vec::new() }
648648
}
649649

650-
/// Creates a new [`RecipientOnionFields`] from an existing one, adding custom TLVs. Each
651-
/// TLV is provided as a `(u64, Vec<u8>)` for the type number and serialized value
650+
/// Creates a new [`RecipientOnionFields`] from an existing one, adding sender custom TLVs.
651+
/// Each TLV is provided as a `(u64, Vec<u8>)` for the type number and serialized value
652652
/// respectively. TLV type numbers must be unique and within the range
653653
/// reserved for custom types, i.e. >= 2^16, otherwise this method will return `Err(())`.
654654
///
655655
/// This method will also error for types in the experimental range which have been
656656
/// standardized within the protocol, which only includes 5482373484 (keysend) for now.
657657
///
658-
/// See [`Self::custom_tlvs`] for more info.
658+
/// See [`Self::sender_custom_tlvs`] for more info.
659659
pub fn with_sender_custom_tlvs(mut self, mut sender_custom_tlvs: Vec<(u64, Vec<u8>)>) -> Result<Self, ()> {
660660
sender_custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ);
661661
let mut prev_type = None;
@@ -674,36 +674,72 @@ impl RecipientOnionFields {
674674
Ok(self)
675675
}
676676

677-
/// Gets the custom TLVs that will be sent or have been received.
677+
/// Creates a new [`RecipientOnionFields`] from an existing one, adding user custom TLVs.
678678
///
679-
/// Custom TLVs allow sending extra application-specific data with a payment. They provide
680-
/// additional flexibility on top of payment metadata, as while other implementations may
681-
/// require `payment_metadata` to reflect metadata provided in an invoice, custom TLVs
682-
/// do not have this restriction.
679+
/// See [`Self::user_custom_tlvs`] for more info.
680+
pub fn with_user_custom_tlvs(mut self, custom_tlvs: Vec<u8>) -> Self {
681+
self.user_custom_tlvs = custom_tlvs;
682+
self
683+
}
684+
685+
/// Gets the sender custom TLVs that will be sent or have been received.
686+
///
687+
/// Sender custom TLVs allow sending extra application-specific data with a payment.
688+
/// They provide additional flexibility on top of payment metadata, as while other
689+
/// implementations may require `payment_metadata` to reflect metadata provided in
690+
/// an invoice, custom TLVs do not have this restriction.
683691
///
684692
/// Note that if this field is non-empty, it will contain strictly increasing TLVs, each
685693
/// represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
686-
/// This is validated when setting this field using [`Self::with_custom_tlvs`].
694+
/// This is validated when setting this field using [`Self::with_sender_custom_tlvs`].
687695
#[cfg(not(c_bindings))]
688696
pub fn sender_custom_tlvs(&self) -> &Vec<(u64, Vec<u8>)> {
689697
&self.sender_custom_tlvs
690698
}
691699

692-
/// Gets the custom TLVs that will be sent or have been received.
700+
/// Gets the sender custom TLVs that will be sent or have been received.
693701
///
694-
/// Custom TLVs allow sending extra application-specific data with a payment. They provide
695-
/// additional flexibility on top of payment metadata, as while other implementations may
696-
/// require `payment_metadata` to reflect metadata provided in an invoice, custom TLVs
697-
/// do not have this restriction.
702+
/// Sender custom TLVs allow sending extra application-specific data with a payment.
703+
/// They provide additional flexibility on top of payment metadata, as while other
704+
/// implementations may require `payment_metadata` to reflect metadata provided in
705+
/// an invoice, custom TLVs do not have this restriction.
698706
///
699707
/// Note that if this field is non-empty, it will contain strictly increasing TLVs, each
700708
/// represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
701-
/// This is validated when setting this field using [`Self::with_custom_tlvs`].
709+
/// This is validated when setting this field using [`Self::with_sender_custom_tlvs`].
702710
#[cfg(c_bindings)]
703711
pub fn sender_custom_tlvs(&self) -> Vec<(u64, Vec<u8>)> {
704712
self.sender_custom_tlvs.clone()
705713
}
706714

715+
/// Gets the user custom TLVs that will be sent or have been received.
716+
///
717+
/// User custom TLVs allow receiving back extra application-specific
718+
/// data that was set by the receiver in the Blinded Path used by the sender
719+
/// to reach them.
720+
///
721+
/// This provides additional flexibility to users by enabling them to include
722+
/// extra data they want to receive back, which can be used for authentication
723+
/// or other purposes.
724+
#[cfg(not(c_bindings))]
725+
pub fn user_custom_tlvs(&self) -> &Vec<u8> {
726+
&self.user_custom_tlvs
727+
}
728+
729+
/// Gets the user custom TLVs that will be sent or have been received.
730+
///
731+
/// User custom TLVs allow receiving back extra application-specific
732+
/// data that was set by the receiver in the Blinded Path used by the sender
733+
/// to reach them.
734+
///
735+
/// This provides additional flexibility to users by enabling them to include
736+
/// extra data they want to receive back, which can be used for authentication
737+
/// or other purposes.
738+
#[cfg(c_bindings)]
739+
pub fn user_custom_tlvs(&self) -> Vec<u8> {
740+
self.user_custom_tlvs.clone()
741+
}
742+
707743
/// When we have received some HTLC(s) towards an MPP payment, as we receive further HTLC(s) we
708744
/// have to make sure that some fields match exactly across the parts. For those that aren't
709745
/// required to match, if they don't match we should remove them so as to not expose data

0 commit comments

Comments
 (0)