Skip to content

Commit 2bad99a

Browse files
committed
Check custom_tlvs in Event::PaymentClaimed
1 parent ef28e9f commit 2bad99a

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

lightning/src/ln/blinded_payment_tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1326,5 +1326,8 @@ fn custom_tlvs_to_blinded_path() {
13261326
.with_payment_secret(payment_secret)
13271327
.with_custom_tlvs(recipient_onion_fields.custom_tlvs.clone());
13281328
do_pass_along_path(args);
1329-
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
1329+
claim_payment_along_route(
1330+
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
1331+
.with_custom_tlvs(recipient_onion_fields.custom_tlvs.clone())
1332+
);
13301333
}

lightning/src/ln/functional_test_utils.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -2731,6 +2731,7 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
27312731
pub expected_min_htlc_overpay: Vec<u32>,
27322732
pub skip_last: bool,
27332733
pub payment_preimage: PaymentPreimage,
2734+
pub custom_tlvs: Vec<(u64, Vec<u8>)>,
27342735
// Allow forwarding nodes to have taken 1 msat more fee than expected based on the downstream
27352736
// fulfill amount.
27362737
//
@@ -2749,7 +2750,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
27492750
Self {
27502751
origin_node, expected_paths, expected_extra_fees: vec![0; expected_paths.len()],
27512752
expected_min_htlc_overpay: vec![0; expected_paths.len()], skip_last: false, payment_preimage,
2752-
allow_1_msat_fee_overpay: false,
2753+
allow_1_msat_fee_overpay: false, custom_tlvs: vec![],
27532754
}
27542755
}
27552756
pub fn skip_last(mut self, skip_last: bool) -> Self {
@@ -2768,12 +2769,16 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
27682769
self.allow_1_msat_fee_overpay = true;
27692770
self
27702771
}
2772+
pub fn with_custom_tlvs(mut self, custom_tlvs: Vec<(u64, Vec<u8>)>) -> Self {
2773+
self.custom_tlvs = custom_tlvs;
2774+
self
2775+
}
27712776
}
27722777

2773-
pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArgs) -> u64 {
2778+
pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
27742779
let ClaimAlongRouteArgs {
27752780
origin_node, expected_paths, expected_extra_fees, expected_min_htlc_overpay, skip_last,
2776-
payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay,
2781+
payment_preimage: our_payment_preimage, allow_1_msat_fee_overpay, custom_tlvs,
27772782
} = args;
27782783
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
27792784
assert_eq!(claim_event.len(), 1);
@@ -2787,11 +2792,13 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
27872792
| PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(preimage), .. },
27882793
amount_msat,
27892794
ref htlcs,
2795+
ref onion_fields,
27902796
..
27912797
} => {
27922798
assert_eq!(preimage, our_payment_preimage);
27932799
assert_eq!(htlcs.len(), expected_paths.len()); // One per path.
27942800
assert_eq!(htlcs.iter().map(|h| h.value_msat).sum::<u64>(), amount_msat);
2801+
assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
27952802
expected_paths.iter().zip(htlcs).for_each(|(path, htlc)| check_claimed_htlc_channel(origin_node, path, htlc));
27962803
fwd_amt_msat = amount_msat;
27972804
},
@@ -2802,11 +2809,13 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg
28022809
payment_hash,
28032810
amount_msat,
28042811
ref htlcs,
2812+
ref onion_fields,
28052813
..
28062814
} => {
28072815
assert_eq!(&payment_hash.0, &Sha256::hash(&our_payment_preimage.0)[..]);
28082816
assert_eq!(htlcs.len(), expected_paths.len()); // One per path.
28092817
assert_eq!(htlcs.iter().map(|h| h.value_msat).sum::<u64>(), amount_msat);
2818+
assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
28102819
expected_paths.iter().zip(htlcs).for_each(|(path, htlc)| check_claimed_htlc_channel(origin_node, path, htlc));
28112820
fwd_amt_msat = amount_msat;
28122821
}

lightning/src/ln/max_payment_path_len_tests.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ fn one_hop_blinded_path_with_custom_tlv() {
207207
do_pass_along_path(args);
208208
claim_payment_along_route(
209209
ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2]]], payment_preimage)
210+
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone())
210211
);
211212

212213
// If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
@@ -232,10 +233,11 @@ fn one_hop_blinded_path_with_custom_tlv() {
232233
let path = &[&nodes[1], &nodes[2]];
233234
let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
234235
.with_payment_secret(payment_secret)
235-
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs);
236+
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
236237
do_pass_along_path(args);
237238
claim_payment_along_route(
238239
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
240+
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs)
239241
);
240242
}
241243

@@ -293,6 +295,7 @@ fn blinded_path_with_custom_tlv() {
293295
do_pass_along_path(args);
294296
claim_payment_along_route(
295297
ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2], &nodes[3]]], payment_preimage)
298+
.with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone())
296299
);
297300

298301
// If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding.
@@ -330,9 +333,10 @@ fn blinded_path_with_custom_tlv() {
330333
let path = &[&nodes[1], &nodes[2], &nodes[3]];
331334
let args = PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, events.pop().unwrap())
332335
.with_payment_secret(payment_secret)
333-
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs);
336+
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs.clone());
334337
do_pass_along_path(args);
335338
claim_payment_along_route(
336339
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], payment_preimage)
340+
.with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs)
337341
);
338342
}

lightning/src/ln/payment_tests.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -3732,11 +3732,17 @@ fn do_test_custom_tlvs(spontaneous: bool, even_tlvs: bool, known_tlvs: bool) {
37323732
match (known_tlvs, even_tlvs) {
37333733
(true, _) => {
37343734
nodes[1].node.claim_funds_with_known_custom_tlvs(our_payment_preimage);
3735-
let expected_total_fee_msat = pass_claimed_payment_along_route(ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage));
3735+
let expected_total_fee_msat = pass_claimed_payment_along_route(
3736+
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage)
3737+
.with_custom_tlvs(custom_tlvs)
3738+
);
37363739
expect_payment_sent!(&nodes[0], our_payment_preimage, Some(expected_total_fee_msat));
37373740
},
37383741
(false, false) => {
3739-
claim_payment(&nodes[0], &[&nodes[1]], our_payment_preimage);
3742+
claim_payment_along_route(
3743+
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], our_payment_preimage)
3744+
.with_custom_tlvs(custom_tlvs)
3745+
);
37403746
},
37413747
(false, true) => {
37423748
nodes[1].node.claim_funds(our_payment_preimage);
@@ -3823,10 +3829,11 @@ fn test_retry_custom_tlvs() {
38233829
let path = &[&nodes[1], &nodes[2]];
38243830
let args = PassAlongPathArgs::new(&nodes[0], path, 1_000_000, payment_hash, events.pop().unwrap())
38253831
.with_payment_secret(payment_secret)
3826-
.with_custom_tlvs(custom_tlvs);
3832+
.with_custom_tlvs(custom_tlvs.clone());
38273833
do_pass_along_path(args);
38283834
claim_payment_along_route(
38293835
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
3836+
.with_custom_tlvs(custom_tlvs)
38303837
);
38313838
}
38323839

@@ -3960,6 +3967,7 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec<u8>)>, second_tlvs:
39603967

39613968
do_claim_payment_along_route(
39623969
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], our_payment_preimage)
3970+
.with_custom_tlvs(expected_tlvs)
39633971
);
39643972
expect_payment_sent(&nodes[0], our_payment_preimage, Some(Some(2000)), true, true);
39653973
} else {

0 commit comments

Comments
 (0)