Skip to content

Commit 8914ab4

Browse files
add pass_probe_along_route
1 parent 7ebf618 commit 8914ab4

8 files changed

+62
-57
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn do_one_hop_blinded_path(success: bool) {
5454
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(),
5555
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
5656
check_added_monitors(&nodes[0], 1);
57-
pass_along_route(&nodes[0], &[&[&nodes[1]]], amt_msat, payment_hash, payment_secret, false);
57+
pass_along_route(&nodes[0], &[&[&nodes[1]]], amt_msat, payment_hash, payment_secret);
5858
if success {
5959
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
6060
} else {
@@ -104,10 +104,10 @@ fn mpp_to_one_hop_blinded_path() {
104104

105105
let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
106106
pass_along_path(&nodes[0], expected_route[0], amt_msat, payment_hash.clone(),
107-
Some(payment_secret), ev.clone(), false, None, false);
107+
Some(payment_secret), ev.clone(), false, None);
108108

109109
let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
110110
pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(),
111-
Some(payment_secret), ev.clone(), true, None, false);
111+
Some(payment_secret), ev.clone(), true, None);
112112
claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage);
113113
}

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,15 +2014,15 @@ fn test_path_paused_mpp() {
20142014
// Pass the first HTLC of the payment along to nodes[3].
20152015
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
20162016
assert_eq!(events.len(), 1);
2017-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), false, None, false);
2017+
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), false, None);
20182018

20192019
// And check that, after we successfully update the monitor for chan_2 we can pass the second
20202020
// HTLC along to nodes[3] and claim the whole payment back to nodes[0].
20212021
let (outpoint, latest_update, _) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_2_id).unwrap().clone();
20222022
nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update);
20232023
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
20242024
assert_eq!(events.len(), 1);
2025-
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), true, None, false);
2025+
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), true, None);
20262026

20272027
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
20282028
}

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10188,7 +10188,7 @@ mod tests {
1018810188
check_added_monitors!(nodes[0], 1);
1018910189
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1019010190
assert_eq!(events.len(), 1);
10191-
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None, false);
10191+
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
1019210192

1019310193
// Next, send a keysend payment with the same payment_hash and make sure it fails.
1019410194
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
@@ -10220,7 +10220,7 @@ mod tests {
1022010220
check_added_monitors!(nodes[0], 1);
1022110221
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
1022210222
assert_eq!(events.len(), 1);
10223-
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), true, None, false);
10223+
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), true, None);
1022410224

1022510225
// Claim the full MPP payment. Note that we can't use a test utility like
1022610226
// claim_funds_along_route because the ordering of the messages causes the second half of the
@@ -10359,7 +10359,7 @@ mod tests {
1035910359
assert_eq!(events.len(), 1);
1036010360
let event = events.pop().unwrap();
1036110361
let path = vec![&nodes[1]];
10362-
pass_along_path(&nodes[0], &path, 100_000, payment_hash, None, event, true, Some(payment_preimage), false);
10362+
pass_along_path(&nodes[0], &path, 100_000, payment_hash, None, event, true, Some(payment_preimage));
1036310363

1036410364
// Next, attempt a regular payment and make sure it fails.
1036510365
let payment_secret = PaymentSecret([43; 32]);
@@ -10398,7 +10398,7 @@ mod tests {
1039810398
assert_eq!(events.len(), 1);
1039910399
let event = events.pop().unwrap();
1040010400
let path = vec![&nodes[1]];
10401-
pass_along_path(&nodes[0], &path, 100_000, payment_hash, None, event, true, Some(payment_preimage), false);
10401+
pass_along_path(&nodes[0], &path, 100_000, payment_hash, None, event, true, Some(payment_preimage));
1040210402

1040310403
// Next, attempt a keysend payment and make sure it fails.
1040410404
let route_params = RouteParameters::from_payment_params_and_value(

lightning/src/ln/functional_test_utils.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
22472247
origin_node.node.send_payment_with_route(&route, our_payment_hash,
22482248
RecipientOnionFields::secret_only(our_payment_secret), payment_id).unwrap();
22492249
check_added_monitors!(origin_node, expected_paths.len());
2250-
pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret, false);
2250+
pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret);
22512251
payment_id
22522252
}
22532253

@@ -2332,29 +2332,34 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
23322332
event
23332333
}
23342334

2335-
pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_claimable_expected: bool, expected_preimage: Option<PaymentPreimage>, is_probe: bool) -> Option<Event> {
2336-
do_pass_along_path(origin_node, expected_path, recv_value, our_payment_hash, our_payment_secret, ev, payment_claimable_expected, true, expected_preimage, is_probe)
2335+
pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_claimable_expected: bool, expected_preimage: Option<PaymentPreimage>) -> Option<Event> {
2336+
do_pass_along_path(origin_node, expected_path, recv_value, our_payment_hash, our_payment_secret, ev, payment_claimable_expected, true, expected_preimage, false)
23372337
}
23382338

2339-
pub fn pass_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret, is_probe: bool) {
2339+
pub fn pass_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&[&Node<'a, 'b, 'c>]]) {
23402340
let mut events = origin_node.node.get_and_clear_pending_msg_events();
23412341
assert_eq!(events.len(), expected_route.len());
2342+
check_added_monitors!(origin_node, expected_route.len());
2343+
for path in expected_route.iter() {
2344+
let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
23422345

2343-
if is_probe {
2344-
check_added_monitors!(origin_node, expected_route.len());
2346+
do_pass_along_path(origin_node, path, 0, PaymentHash([0_u8; 32]), None, ev, false, false, None, true);
2347+
let nodes_to_fail_payment: Vec<_> = vec![origin_node].into_iter().chain(path.iter().cloned()).collect();
2348+
2349+
fail_payment_along_path(nodes_to_fail_payment.as_slice());
23452350
}
2351+
}
2352+
2353+
pub fn pass_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) {
2354+
let mut events = origin_node.node.get_and_clear_pending_msg_events();
2355+
assert_eq!(events.len(), expected_route.len());
23462356

23472357
for (path_idx, expected_path) in expected_route.iter().enumerate() {
23482358
let ev = remove_first_msg_event_to_node(&expected_path[0].node.get_our_node_id(), &mut events);
23492359
// Once we've gotten through all the HTLCs, the last one should result in a
2350-
// PaymentClaimable (but each previous one should not!). Probes should never result in a PaymentClaimable event.
2351-
let expect_payment = path_idx == expected_route.len() - 1 && !is_probe;
2352-
pass_along_path(origin_node, expected_path, recv_value, our_payment_hash.clone(), Some(our_payment_secret), ev, expect_payment, None, is_probe);
2353-
2354-
if is_probe {
2355-
let nodes_to_fail_payment: Vec<_> = vec![origin_node].into_iter().chain(expected_path.iter().cloned()).collect();
2356-
fail_payment_along_path(nodes_to_fail_payment.as_slice());
2357-
}
2360+
// PaymentClaimable (but each previous one should not!).
2361+
let expect_payment = path_idx == expected_route.len() - 1;
2362+
pass_along_path(origin_node, expected_path, recv_value, our_payment_hash.clone(), Some(our_payment_secret), ev, expect_payment, None);
23582363
}
23592364
}
23602365

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4347,7 +4347,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) {
43474347
assert_eq!(events.len(), 1);
43484348
// Now do the relevant commitment_signed/RAA dances along the path, noting that the final
43494349
// hop should *not* yet generate any PaymentClaimable event(s).
4350-
pass_along_path(&nodes[0], &[&nodes[1]], 100000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None, false);
4350+
pass_along_path(&nodes[0], &[&nodes[1]], 100000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
43514351
our_payment_hash
43524352
} else {
43534353
route_payment(&nodes[0], &[&nodes[1]], 100000).1
@@ -8206,7 +8206,7 @@ fn test_onion_value_mpp_set_calculation() {
82068206

82078207
// Second path
82088208
let ev = remove_first_msg_event_to_node(&expected_paths[1][0].node.get_our_node_id(), &mut events);
8209-
pass_along_path(&nodes[0], expected_paths[1], 101_000, our_payment_hash.clone(), Some(our_payment_secret), ev, true, None, false);
8209+
pass_along_path(&nodes[0], expected_paths[1], 101_000, our_payment_hash.clone(), Some(our_payment_secret), ev, true, None);
82108210

82118211
claim_payment_along_route(&nodes[0], expected_paths, false, our_payment_preimage);
82128212
}
@@ -8271,7 +8271,7 @@ fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64) {
82718271
let current_path_amount = msat_amounts[path_idx];
82728272
amount_received += current_path_amount;
82738273
let became_claimable_now = amount_received >= total_msat && amount_received - current_path_amount < total_msat;
8274-
pass_along_path(&nodes[src_idx], expected_path, amount_received, our_payment_hash.clone(), Some(our_payment_secret), ev, became_claimable_now, None, false);
8274+
pass_along_path(&nodes[src_idx], expected_path, amount_received, our_payment_hash.clone(), Some(our_payment_secret), ev, became_claimable_now, None);
82758275
}
82768276

82778277
claim_payment_along_route(&nodes[src_idx], &expected_paths, false, our_payment_preimage);
@@ -9533,7 +9533,7 @@ fn test_inconsistent_mpp_params() {
95339533
{
95349534
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
95359535
assert_eq!(events.len(), 1);
9536-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 15_000_000, our_payment_hash, Some(our_payment_secret), events.pop().unwrap(), false, None, false);
9536+
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 15_000_000, our_payment_hash, Some(our_payment_secret), events.pop().unwrap(), false, None);
95379537
}
95389538
assert!(nodes[3].node.get_and_clear_pending_events().is_empty());
95399539

@@ -9591,7 +9591,7 @@ fn test_inconsistent_mpp_params() {
95919591

95929592
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
95939593
assert_eq!(events.len(), 1);
9594-
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 15_000_000, our_payment_hash, Some(our_payment_secret), events.pop().unwrap(), true, None, false);
9594+
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 15_000_000, our_payment_hash, Some(our_payment_secret), events.pop().unwrap(), true, None);
95959595

95969596
do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, our_payment_preimage);
95979597
expect_payment_sent(&nodes[0], our_payment_preimage, Some(None), true, true);
@@ -9645,7 +9645,7 @@ fn test_double_partial_claim() {
96459645
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
96469646
assert_eq!(events.len(), 2);
96479647
let node_1_msgs = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
9648-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 15_000_000, payment_hash, Some(payment_secret), node_1_msgs, false, None, false);
9648+
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 15_000_000, payment_hash, Some(payment_secret), node_1_msgs, false, None);
96499649

96509650
// At this point nodes[3] has received one half of the payment, and the user goes to handle
96519651
// that PaymentClaimable event they got hours ago and never handled...we should refuse to claim.

lightning/src/ln/onion_route_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ fn test_fee_failures() {
295295
nodes[0].node.send_payment_with_route(&route, payment_hash_success,
296296
RecipientOnionFields::secret_only(payment_secret_success), PaymentId(payment_hash_success.0)).unwrap();
297297
check_added_monitors!(nodes[0], 1);
298-
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 40_000, payment_hash_success, payment_secret_success, false);
298+
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 40_000, payment_hash_success, payment_secret_success);
299299
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage_success);
300300

301301
// If the hop gives fee_insufficient but enough fees were provided, then the previous hop
@@ -317,7 +317,7 @@ fn test_fee_failures() {
317317
nodes[0].node.send_payment_with_route(&route, payment_hash_success,
318318
RecipientOnionFields::secret_only(payment_secret_success), PaymentId(payment_hash_success.0)).unwrap();
319319
check_added_monitors!(nodes[0], 1);
320-
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 40_000, payment_hash_success, payment_secret_success, false);
320+
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 40_000, payment_hash_success, payment_secret_success);
321321
claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage_success);
322322
}
323323

0 commit comments

Comments
 (0)