Skip to content

Commit

Permalink
Test sending, and receiving of user_custom_tlvs
Browse files Browse the repository at this point in the history
  • Loading branch information
shaavan committed Nov 7, 2024
1 parent 0c33ae9 commit f9a8608
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ fn custom_tlvs_to_blinded_path() {
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
},
payment_context: PaymentContext::unknown(),
custom_tlvs: Vec::new(),
custom_tlvs: vec![43, 43]
};
let mut secp_ctx = Secp256k1::new();
let blinded_path = BlindedPaymentPath::new(
Expand All @@ -1327,6 +1327,7 @@ fn custom_tlvs_to_blinded_path() {
);

let recipient_onion_fields = RecipientOnionFields::spontaneous_empty()
.with_user_custom_tlvs(vec![43, 43])
.with_sender_custom_tlvs(vec![((1 << 16) + 3, vec![42, 42])])
.unwrap();
nodes[0].node.send_payment(payment_hash, recipient_onion_fields.clone(),
Expand All @@ -1340,10 +1341,12 @@ fn custom_tlvs_to_blinded_path() {
let path = &[&nodes[1]];
let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, ev)
.with_payment_secret(payment_secret)
.with_user_custom_tlvs(recipient_onion_fields.user_custom_tlvs.clone())
.with_sender_custom_tlvs(recipient_onion_fields.sender_custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
.with_user_custom_tlvs(recipient_onion_fields.user_custom_tlvs.clone())
.with_sender_custom_tlvs(recipient_onion_fields.sender_custom_tlvs.clone())
);
}
Expand Down
4 changes: 4 additions & 0 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2828,6 +2828,10 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
self.allow_1_msat_fee_overpay = true;
self
}
pub fn with_user_custom_tlvs(mut self, custom_tlvs: Vec<u8>) -> Self {
self.user_custom_tlvs = custom_tlvs;
self
}
pub fn with_sender_custom_tlvs(mut self, custom_tlvs: Vec<(u64, Vec<u8>)>) -> Self {
self.sender_custom_tlvs = custom_tlvs;
self
Expand Down
5 changes: 5 additions & 0 deletions lightning/src/ln/outbound_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ impl RecipientOnionFields {
Ok(self)
}

pub fn with_user_custom_tlvs(mut self, custom_tlvs: Vec<u8>) -> Self {
self.user_custom_tlvs = custom_tlvs;
self
}

/// Gets the custom TLVs that will be sent or have been received.
///
/// Custom TLVs allow sending extra application-specific data with a payment. They provide
Expand Down
8 changes: 7 additions & 1 deletion lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3787,8 +3787,12 @@ fn test_retry_custom_tlvs() {
let mut route_params = route.route_params.clone().unwrap();

let sender_custom_tlvs = vec![((1 << 16) + 3, vec![0x42u8; 16])];
let user_custom_tlvs = vec![0x43u8; 16];
let onion_fields = RecipientOnionFields::secret_only(payment_secret);
let onion_fields = onion_fields.with_sender_custom_tlvs(sender_custom_tlvs.clone()).unwrap();
let onion_fields = onion_fields
.with_user_custom_tlvs(user_custom_tlvs.clone())
.with_sender_custom_tlvs(sender_custom_tlvs.clone())
.unwrap();

nodes[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
nodes[0].node.send_payment(payment_hash, onion_fields,
Expand Down Expand Up @@ -3840,10 +3844,12 @@ fn test_retry_custom_tlvs() {
let path = &[&nodes[1], &nodes[2]];
let args = PassAlongPathArgs::new(&nodes[0], path, 1_000_000, payment_hash, events.pop().unwrap())
.with_payment_secret(payment_secret)
.with_user_custom_tlvs(user_custom_tlvs.clone())
.with_sender_custom_tlvs(sender_custom_tlvs.clone());
do_pass_along_path(args);
claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
.with_user_custom_tlvs(user_custom_tlvs)
.with_sender_custom_tlvs(sender_custom_tlvs)
);
}
Expand Down

0 comments on commit f9a8608

Please sign in to comment.