Skip to content

Commit 095fca9

Browse files
committed
Avoid ref to a Vec when accessing custom onion TLVs
The bindings can't easily return a reference to a `Vec`, so we instead split the implementation into vec/slice depending on the `c_bindings` flag.
1 parent 087c8f6 commit 095fca9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lightning/src/ln/outbound_payment.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,26 @@ impl RecipientOnionFields {
594594
/// Note that if this field is non-empty, it will contain strictly increasing TLVs, each
595595
/// represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
596596
/// This is validated when setting this field using [`Self::with_custom_tlvs`].
597+
#[cfg(not(c_bindings))]
597598
pub fn custom_tlvs(&self) -> &Vec<(u64, Vec<u8>)> {
598599
&self.custom_tlvs
599600
}
600601

602+
/// Gets the custom TLVs that will be sent or have been received.
603+
///
604+
/// Custom TLVs allow sending extra application-specific data with a payment. They provide
605+
/// additional flexibility on top of payment metadata, as while other implementations may
606+
/// require `payment_metadata` to reflect metadata provided in an invoice, custom TLVs
607+
/// do not have this restriction.
608+
///
609+
/// Note that if this field is non-empty, it will contain strictly increasing TLVs, each
610+
/// represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
611+
/// This is validated when setting this field using [`Self::with_custom_tlvs`].
612+
#[cfg(c_bindings)]
613+
pub fn custom_tlvs(&self) -> Vec<(u64, Vec<u8>)> {
614+
self.custom_tlvs.clone()
615+
}
616+
601617
/// When we have received some HTLC(s) towards an MPP payment, as we receive further HTLC(s) we
602618
/// have to make sure that some fields match exactly across the parts. For those that aren't
603619
/// required to match, if they don't match we should remove them so as to not expose data

lightning/src/ln/payment_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,7 @@ fn test_retry_custom_tlvs() {
37813781
payment_hash, Some(payment_secret), events.pop().unwrap(), true, None).unwrap();
37823782
match payment_claimable {
37833783
Event::PaymentClaimable { onion_fields, .. } => {
3784-
assert_eq!(onion_fields.unwrap().custom_tlvs(), &custom_tlvs);
3784+
assert_eq!(&onion_fields.unwrap().custom_tlvs()[..], &custom_tlvs[..]);
37853785
},
37863786
_ => panic!("Unexpected event"),
37873787
};

0 commit comments

Comments
 (0)