From ac15105162cab06375368a925601ebc69424a5f9 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 24 May 2024 16:16:13 -0500 Subject: [PATCH] Pass ClaimAlongRouteArgs to claim_payment_along_route --- lightning/src/ln/blinded_payment_tests.rs | 16 +++++++--- lightning/src/ln/chanmon_update_fail_tests.rs | 4 ++- lightning/src/ln/functional_test_utils.rs | 16 ++++++---- lightning/src/ln/functional_tests.rs | 17 +++++++--- .../src/ln/max_payment_path_len_tests.rs | 24 ++++++++++---- lightning/src/ln/payment_tests.rs | 32 ++++++++++++++----- 6 files changed, 79 insertions(+), 30 deletions(-) diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index d4570ef8c..2a7635b57 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -180,7 +180,9 @@ fn mpp_to_one_hop_blinded_path() { let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events); pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(), Some(payment_secret), ev.clone(), true, None); - claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage) + ); } #[test] @@ -244,7 +246,9 @@ fn mpp_to_three_hop_blinded_paths() { let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events); pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(), Some(payment_secret), ev.clone(), true, None); - claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage) + ); } enum ForwardCheckFail { @@ -1219,7 +1223,9 @@ fn blinded_keysend() { let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events); pass_along_path(&nodes[0], expected_route[0], amt_msat, payment_hash, Some(payment_secret), ev.clone(), true, Some(keysend_preimage)); - claim_payment_along_route(&nodes[0], expected_route, false, keysend_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], expected_route, keysend_preimage) + ); } #[test] @@ -1270,7 +1276,9 @@ fn blinded_mpp_keysend() { let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events); pass_along_path(&nodes[0], expected_route[1], amt_msat, payment_hash.clone(), Some(payment_secret), ev.clone(), true, Some(keysend_preimage)); - claim_payment_along_route(&nodes[0], expected_route, false, keysend_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], expected_route, keysend_preimage) + ); } #[test] diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 7d332f2ad..5e9ce3037 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -2025,7 +2025,9 @@ fn test_path_paused_mpp() { assert_eq!(events.len(), 1); pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), true, None); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage) + ); } #[test] diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index fdcdc0986..0a78a9bf7 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -2950,18 +2950,20 @@ pub fn pass_claimed_payment_along_route<'a, 'b, 'c, 'd>(args: ClaimAlongRouteArg expected_total_fee_msat } -pub fn claim_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_preimage: PaymentPreimage) { - let expected_total_fee_msat = do_claim_payment_along_route( - ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage) - .skip_last(skip_last) - ); +pub fn claim_payment_along_route(args: ClaimAlongRouteArgs) { + let origin_node = args.origin_node; + let payment_preimage = args.payment_preimage; + let skip_last = args.skip_last; + let expected_total_fee_msat = do_claim_payment_along_route(args); if !skip_last { - expect_payment_sent!(origin_node, our_payment_preimage, Some(expected_total_fee_msat)); + expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat)); } } pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], our_payment_preimage: PaymentPreimage) { - claim_payment_along_route(origin_node, &[expected_route], false, our_payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(origin_node, &[expected_route], our_payment_preimage) + ); } pub const TEST_FINAL_CLTV: u32 = 70; diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 78307d0f9..c0e9461f1 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -3780,7 +3780,10 @@ fn test_simple_peer_disconnect() { nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], true, payment_preimage_3); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage_3) + .skip_last(true) + ); fail_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], true, payment_hash_5); let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]); @@ -8264,7 +8267,9 @@ fn test_onion_value_mpp_set_calculation() { let ev = remove_first_msg_event_to_node(&expected_paths[1][0].node.get_our_node_id(), &mut events); pass_along_path(&nodes[0], expected_paths[1], 101_000, our_payment_hash.clone(), Some(our_payment_secret), ev, true, None); - claim_payment_along_route(&nodes[0], expected_paths, false, our_payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], expected_paths, our_payment_preimage) + ); } fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64) { @@ -8330,7 +8335,9 @@ fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64) { pass_along_path(&nodes[src_idx], expected_path, amount_received, our_payment_hash.clone(), Some(our_payment_secret), ev, became_claimable_now, None); } - claim_payment_along_route(&nodes[src_idx], &expected_paths, false, our_payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[src_idx], &expected_paths, our_payment_preimage) + ); } #[test] @@ -8362,7 +8369,9 @@ fn test_simple_mpp() { route.paths[1].hops[0].short_channel_id = chan_2_id; route.paths[1].hops[1].short_channel_id = chan_4_id; send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], 200_000, payment_hash, payment_secret); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage) + ); } #[test] diff --git a/lightning/src/ln/max_payment_path_len_tests.rs b/lightning/src/ln/max_payment_path_len_tests.rs index 36fe098b9..e9e988e45 100644 --- a/lightning/src/ln/max_payment_path_len_tests.rs +++ b/lightning/src/ln/max_payment_path_len_tests.rs @@ -84,7 +84,9 @@ fn large_payment_metadata() { .with_payment_secret(payment_secret) .with_payment_metadata(payment_metadata.clone()); do_pass_along_path(args); - claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage) + ); // Check that the payment parameter for max path length will prevent us from routing past our // next-hop peer given the payment_metadata size. @@ -133,7 +135,9 @@ fn large_payment_metadata() { .with_payment_secret(payment_secret_2) .with_payment_metadata(recipient_onion_allows_2_hops.payment_metadata.unwrap()); do_pass_along_path(args); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage_2); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage_2) + ); } #[test] @@ -201,7 +205,9 @@ fn one_hop_blinded_path_with_custom_tlv() { .with_payment_secret(payment_secret) .with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone()); do_pass_along_path(args); - claim_payment_along_route(&nodes[1], &[&[&nodes[2]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2]]], payment_preimage) + ); // If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding. let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone(); @@ -228,7 +234,9 @@ fn one_hop_blinded_path_with_custom_tlv() { .with_payment_secret(payment_secret) .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs); do_pass_along_path(args); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage) + ); } #[test] @@ -283,7 +291,9 @@ fn blinded_path_with_custom_tlv() { .with_payment_secret(payment_secret) .with_custom_tlvs(recipient_onion_max_custom_tlv_size.custom_tlvs.clone()); do_pass_along_path(args); - claim_payment_along_route(&nodes[1], &[&[&nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[1], &[&[&nodes[2], &nodes[3]]], payment_preimage) + ); // If 1 byte is added to the custom TLV value, we'll fail to send prior to pathfinding. let mut recipient_onion_too_large_custom_tlv = recipient_onion_max_custom_tlv_size.clone(); @@ -322,5 +332,7 @@ fn blinded_path_with_custom_tlv() { .with_payment_secret(payment_secret) .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs); do_pass_along_path(args); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2], &nodes[3]]], payment_preimage) + ); } diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 095064436..83f3053b6 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -160,7 +160,9 @@ fn mpp_retry() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 2_000_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage) + ); } #[test] @@ -351,7 +353,9 @@ fn do_mpp_receive_timeout(send_partial_mpp: bool) { nodes[3].node.timer_tick_occurred(); } - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage) + ); } } @@ -466,7 +470,9 @@ fn test_mpp_keysend() { let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events); pass_along_path(&nodes[0], expected_route[1], recv_value, payment_hash.clone(), Some(payment_secret), ev.clone(), true, Some(payment_preimage)); - claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], expected_route, payment_preimage) + ); } #[test] @@ -1247,7 +1253,9 @@ fn get_ldk_payment_preimage() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); pass_along_path(&nodes[0], &[&nodes[1]], amt_msat, payment_hash, Some(payment_secret), events.pop().unwrap(), true, Some(payment_preimage)); - claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage) + ); } #[test] @@ -2276,7 +2284,9 @@ fn do_automatic_retries(test: AutoRetry) { let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], amt_msat, payment_hash, Some(payment_secret), msg_events.pop().unwrap(), true, None); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage) + ); } else if test == AutoRetry::Spontaneous { nodes[0].node.send_spontaneous_payment_with_retry(Some(payment_preimage), RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0), route_params, @@ -2293,7 +2303,9 @@ fn do_automatic_retries(test: AutoRetry) { let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], amt_msat, payment_hash, None, msg_events.pop().unwrap(), true, Some(payment_preimage)); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage) + ); } else if test == AutoRetry::FailAttempts { // Ensure ChannelManager will not retry a payment if it has run out of payment attempts. nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret), @@ -3813,7 +3825,9 @@ fn test_retry_custom_tlvs() { .with_payment_secret(payment_secret) .with_custom_tlvs(custom_tlvs); do_pass_along_path(args); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage) + ); } #[test] @@ -4109,7 +4123,9 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { } else { expect_pending_htlcs_forwardable!(nodes[3]); expect_payment_claimable!(nodes[3], payment_hash, payment_secret, amt_msat); - claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage); + claim_payment_along_route( + ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], payment_preimage) + ); } } -- 2.39.5