Skip to content

Commit 7ee4adf

Browse files
committed
Clean up some send_payment_with_route call rustfmt verticality
`rustfmt` loves to make expressions vertical by putting each method parameter on its own line. In cases where each method parameter is actually doing something, this can be fine, but in some cases we have a few method parameters that are straightforward and shouldn't be the readers focus, mixed with one or two parameters which are key. Here, we clean up a regular instance of this in calls to `send_payment_with_route` in `priv_short_conf_tests.rs` and `shutdown_tests.rs`. In these tests, the fact that we're sending a payment along a route picked on a previous line is important, but the specific parameters of the payment are not. Thus, condensing the calls onto a single line by breaking out some parameters into variables enables the reader to more easily skim past useless details.
1 parent ca8cbb1 commit 7ee4adf

File tree

2 files changed

+41
-100
lines changed

2 files changed

+41
-100
lines changed

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 29 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,11 @@ fn test_priv_forwarding_rejection() {
7979
let (route, our_payment_hash, our_payment_preimage, our_payment_secret) =
8080
get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 10_000);
8181

82+
let onion = RecipientOnionFields::secret_only(our_payment_secret);
83+
let id = PaymentId(our_payment_hash.0);
8284
nodes[0]
8385
.node
84-
.send_payment_with_route(
85-
route.clone(),
86-
our_payment_hash,
87-
RecipientOnionFields::secret_only(our_payment_secret),
88-
PaymentId(our_payment_hash.0),
89-
)
86+
.send_payment_with_route(route.clone(), our_payment_hash, onion, id)
9087
.unwrap();
9188
check_added_monitors!(nodes[0], 1);
9289
let payment_event =
@@ -199,15 +196,9 @@ fn test_priv_forwarding_rejection() {
199196
get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_c_id);
200197
get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, node_b_id);
201198

202-
nodes[0]
203-
.node
204-
.send_payment_with_route(
205-
route,
206-
our_payment_hash,
207-
RecipientOnionFields::secret_only(our_payment_secret),
208-
PaymentId(our_payment_hash.0),
209-
)
210-
.unwrap();
199+
let onion = RecipientOnionFields::secret_only(our_payment_secret);
200+
let id = PaymentId(our_payment_hash.0);
201+
nodes[0].node.send_payment_with_route(route, our_payment_hash, onion, id).unwrap();
211202
check_added_monitors!(nodes[0], 1);
212203
pass_along_route(
213204
&nodes[0],
@@ -388,15 +379,10 @@ fn test_routed_scid_alias() {
388379
let (route, payment_hash, payment_preimage, payment_secret) =
389380
get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
390381
assert_eq!(route.paths[0].hops[1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap());
391-
nodes[0]
392-
.node
393-
.send_payment_with_route(
394-
route,
395-
payment_hash,
396-
RecipientOnionFields::secret_only(payment_secret),
397-
PaymentId(payment_hash.0),
398-
)
399-
.unwrap();
382+
383+
let onion = RecipientOnionFields::secret_only(payment_secret);
384+
let id = PaymentId(payment_hash.0);
385+
nodes[0].node.send_payment_with_route(route, payment_hash, onion, id).unwrap();
400386
check_added_monitors!(nodes[0], 1);
401387

402388
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 100_000, payment_hash, payment_secret);
@@ -623,15 +609,10 @@ fn test_inbound_scid_privacy() {
623609
let (route, payment_hash, payment_preimage, payment_secret) =
624610
get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
625611
assert_eq!(route.paths[0].hops[1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap());
626-
nodes[0]
627-
.node
628-
.send_payment_with_route(
629-
route,
630-
payment_hash,
631-
RecipientOnionFields::secret_only(payment_secret),
632-
PaymentId(payment_hash.0),
633-
)
634-
.unwrap();
612+
613+
let onion = RecipientOnionFields::secret_only(payment_secret);
614+
let id = PaymentId(payment_hash.0);
615+
nodes[0].node.send_payment_with_route(route, payment_hash, onion, id).unwrap();
635616
check_added_monitors!(nodes[0], 1);
636617

637618
pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 100_000, payment_hash, payment_secret);
@@ -649,15 +630,10 @@ fn test_inbound_scid_privacy() {
649630
let (route_2, payment_hash_2, _, payment_secret_2) =
650631
get_route_and_payment_hash!(nodes[0], nodes[2], payment_params_2, 100_000);
651632
assert_eq!(route_2.paths[0].hops[1].short_channel_id, last_hop[0].short_channel_id.unwrap());
652-
nodes[0]
653-
.node
654-
.send_payment_with_route(
655-
route_2,
656-
payment_hash_2,
657-
RecipientOnionFields::secret_only(payment_secret_2),
658-
PaymentId(payment_hash_2.0),
659-
)
660-
.unwrap();
633+
634+
let onion = RecipientOnionFields::secret_only(payment_secret_2);
635+
let id = PaymentId(payment_hash_2.0);
636+
nodes[0].node.send_payment_with_route(route_2, payment_hash_2, onion, id).unwrap();
661637
check_added_monitors!(nodes[0], 1);
662638

663639
let payment_event = SendEvent::from_node(&nodes[0]);
@@ -751,15 +727,10 @@ fn test_scid_alias_returned() {
751727
route.paths[0].hops[1].fee_msat = 10_000_000; // Overshoot the last channel's value
752728

753729
// Route the HTLC through to the destination.
754-
nodes[0]
755-
.node
756-
.send_payment_with_route(
757-
route.clone(),
758-
payment_hash,
759-
RecipientOnionFields::secret_only(payment_secret),
760-
PaymentId(payment_hash.0),
761-
)
762-
.unwrap();
730+
let onion = RecipientOnionFields::secret_only(payment_secret);
731+
let id = PaymentId(payment_hash.0);
732+
nodes[0].node.send_payment_with_route(route.clone(), payment_hash, onion, id).unwrap();
733+
763734
check_added_monitors!(nodes[0], 1);
764735
let as_updates = get_htlc_update_msgs!(nodes[0], node_b_id);
765736
nodes[1].node.handle_update_add_htlc(node_a_id, &as_updates.update_add_htlcs[0]);
@@ -794,15 +765,10 @@ fn test_scid_alias_returned() {
794765
route.paths[0].hops[0].fee_msat = 0; // But set fee paid to the middle hop to 0
795766

796767
// Route the HTLC through to the destination.
797-
nodes[0]
798-
.node
799-
.send_payment_with_route(
800-
route,
801-
payment_hash,
802-
RecipientOnionFields::secret_only(payment_secret),
803-
PaymentId(payment_hash.0),
804-
)
805-
.unwrap();
768+
let onion = RecipientOnionFields::secret_only(payment_secret);
769+
let id = PaymentId(payment_hash.0);
770+
nodes[0].node.send_payment_with_route(route, payment_hash, onion, id).unwrap();
771+
806772
check_added_monitors!(nodes[0], 1);
807773
let as_updates = get_htlc_update_msgs!(nodes[0], node_b_id);
808774
nodes[1].node.handle_update_add_htlc(node_a_id, &as_updates.update_add_htlcs[0]);
@@ -1003,15 +969,9 @@ fn test_0conf_channel_with_async_monitor() {
1003969
let (route, payment_hash, payment_preimage, payment_secret) =
1004970
get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000);
1005971

1006-
nodes[0]
1007-
.node
1008-
.send_payment_with_route(
1009-
route,
1010-
payment_hash,
1011-
RecipientOnionFields::secret_only(payment_secret),
1012-
PaymentId(payment_hash.0),
1013-
)
1014-
.unwrap();
972+
let onion = RecipientOnionFields::secret_only(payment_secret);
973+
let id = PaymentId(payment_hash.0);
974+
nodes[0].node.send_payment_with_route(route, payment_hash, onion, id).unwrap();
1015975
check_added_monitors!(nodes[0], 1);
1016976

1017977
let as_send = SendEvent::from_node(&nodes[0]);

lightning/src/ln/shutdown_tests.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -441,30 +441,15 @@ fn updates_shutdown_wait() {
441441
&random_seed_bytes,
442442
)
443443
.unwrap();
444-
unwrap_send_err!(
445-
nodes[0],
446-
nodes[0].node.send_payment_with_route(
447-
route_1,
448-
payment_hash,
449-
RecipientOnionFields::secret_only(payment_secret),
450-
PaymentId(payment_hash.0)
451-
),
452-
true,
453-
APIError::ChannelUnavailable { .. },
454-
{}
455-
);
456-
unwrap_send_err!(
457-
nodes[1],
458-
nodes[1].node.send_payment_with_route(
459-
route_2,
460-
payment_hash,
461-
RecipientOnionFields::secret_only(payment_secret),
462-
PaymentId(payment_hash.0)
463-
),
464-
true,
465-
APIError::ChannelUnavailable { .. },
466-
{}
467-
);
444+
445+
let onion = RecipientOnionFields::secret_only(payment_secret);
446+
let id = PaymentId(payment_hash.0);
447+
let res = nodes[0].node.send_payment_with_route(route_1, payment_hash, onion, id);
448+
unwrap_send_err!(nodes[0], res, true, APIError::ChannelUnavailable { .. }, {});
449+
450+
let onion = RecipientOnionFields::secret_only(payment_secret);
451+
let res = nodes[1].node.send_payment_with_route(route_2, payment_hash, onion, id);
452+
unwrap_send_err!(nodes[1], res, true, APIError::ChannelUnavailable { .. }, {});
468453

469454
nodes[2].node.claim_funds(payment_preimage_0);
470455
check_added_monitors!(nodes[2], 1);
@@ -558,15 +543,11 @@ fn do_htlc_fail_async_shutdown(blinded_recipient: bool) {
558543
amt_msat,
559544
)
560545
};
546+
let onion = RecipientOnionFields::secret_only(our_payment_secret);
547+
let id = PaymentId(our_payment_hash.0);
561548
nodes[0]
562549
.node
563-
.send_payment(
564-
our_payment_hash,
565-
RecipientOnionFields::secret_only(our_payment_secret),
566-
PaymentId(our_payment_hash.0),
567-
route_params,
568-
Retry::Attempts(0),
569-
)
550+
.send_payment( our_payment_hash, onion, id, route_params, Retry::Attempts(0))
570551
.unwrap();
571552
check_added_monitors!(nodes[0], 1);
572553
let updates = get_htlc_update_msgs!(nodes[0], node_b_id);

0 commit comments

Comments
 (0)