Skip to content

Commit

Permalink
Pass ClaimAlongRouteArgs to do_claim_payment_along_route
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed May 24, 2024
1 parent b745047 commit b6ff46d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
4 changes: 3 additions & 1 deletion lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,9 @@ mod test {
let payment_preimage_opt = if user_generated_pmt_hash { None } else { Some(payment_preimage) };
assert_eq!(other_events.borrow().len(), 1);
check_payment_claimable(&other_events.borrow()[0], payment_hash, payment_secret, payment_amt, payment_preimage_opt, invoice.recover_payee_pub_key());
do_claim_payment_along_route(&nodes[0], &[&vec!(&nodes[fwd_idx])[..]], false, payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[fwd_idx]]], payment_preimage)
);
expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
}

Expand Down
4 changes: 3 additions & 1 deletion lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
expect_pending_htlcs_forwardable!(nodes[2]);

expect_payment_claimable!(&nodes[2], payment_hash, payment_secret, amt_msat, None, nodes[2].node.get_our_node_id());
do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[1], &nodes[2])[..]), false, payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
);
expect_payment_sent(&nodes[0], payment_preimage, Some(Some(1000)), true, true);
}

Expand Down
21 changes: 9 additions & 12 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2716,18 +2716,12 @@ pub fn send_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route
(our_payment_preimage, our_payment_hash, our_payment_secret, payment_id)
}

pub fn do_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
) -> u64 {
for path in expected_paths.iter() {
assert_eq!(path.last().unwrap().node.get_our_node_id(), expected_paths[0].last().unwrap().node.get_our_node_id());
pub fn do_claim_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
for path in args.expected_paths.iter() {
assert_eq!(path.last().unwrap().node.get_our_node_id(), args.expected_paths[0].last().unwrap().node.get_our_node_id());
}
expected_paths[0].last().unwrap().node.claim_funds(our_payment_preimage);
pass_claimed_payment_along_route(
ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage)
.skip_last(skip_last)
)
args.expected_paths[0].last().unwrap().node.claim_funds(args.payment_preimage);
pass_claimed_payment_along_route(args)
}

pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
Expand Down Expand Up @@ -2957,7 +2951,10 @@ 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(origin_node, expected_paths, skip_last, our_payment_preimage);
let expected_total_fee_msat = do_claim_payment_along_route(
ClaimAlongRouteArgs::new(origin_node, expected_paths, our_payment_preimage)
.skip_last(skip_last)
);
if !skip_last {
expect_payment_sent!(origin_node, our_payment_preimage, Some(expected_total_fee_msat));
}
Expand Down
4 changes: 3 additions & 1 deletion lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9806,7 +9806,9 @@ fn test_inconsistent_mpp_params() {
assert_eq!(events.len(), 1);
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 15_000_000, our_payment_hash, Some(our_payment_secret), events.pop().unwrap(), true, None);

do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, our_payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], our_payment_preimage)
);
expect_payment_sent(&nodes[0], our_payment_preimage, Some(None), true, true);
}

Expand Down
4 changes: 3 additions & 1 deletion lightning/src/ln/monitor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,9 @@ fn test_event_replay_causing_monitor_replay() {

let payment_preimage = route_payment(&nodes[0], &[&nodes[1]], 1_000_000).0;

do_claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], payment_preimage)
);

// At this point the `PaymentSent` event has not been processed but the full commitment signed
// dance has completed.
Expand Down
17 changes: 12 additions & 5 deletions lightning/src/ln/payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) {
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1);
pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None);
do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
);
expect_payment_sent!(nodes[0], payment_preimage, Some(new_route.paths[0].hops[0].fee_msat));
}

Expand Down Expand Up @@ -1579,7 +1581,9 @@ fn claimed_send_payment_idempotent() {
// Claim the payment backwards, but note that the PaymentSent event is still pending and has
// not been seen by the user. At this point, from the user perspective nothing has changed, so
// we must remain just as idempotent as we were before.
do_claim_payment_along_route(&nodes[0], &[&[&nodes[1]]], false, first_payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1]]], first_payment_preimage)
);

for _ in 0..=IDEMPOTENCY_TIMEOUT_TICKS {
nodes[0].node.timer_tick_occurred();
Expand Down Expand Up @@ -1980,7 +1984,9 @@ fn do_test_intercepted_payment(test: InterceptTest) {

let payment_preimage = nodes[2].node.get_payment_preimage(payment_hash, payment_secret).unwrap();
expect_payment_claimable!(&nodes[2], payment_hash, payment_secret, amt_msat, Some(payment_preimage), nodes[2].node.get_our_node_id());
do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[1], &nodes[2])[..]), false, payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage)
);
let events = nodes[0].node.get_and_clear_pending_events();
assert_eq!(events.len(), 2);
match events[0] {
Expand Down Expand Up @@ -3938,8 +3944,9 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec<u8>)>, second_tlvs:
_ => panic!("Unexpected event"),
}

do_claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]],
false, our_payment_preimage);
do_claim_payment_along_route(
ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], our_payment_preimage)
);
expect_payment_sent(&nodes[0], our_payment_preimage, Some(Some(2000)), true, true);
} else {
// Expect fail back
Expand Down

0 comments on commit b6ff46d

Please sign in to comment.