Skip to content

Commit e48478a

Browse files
elnoshclaude
andcommitted
Replace get_payment_preimage_hash! macro with direct function calls
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 63f4f8f commit e48478a

9 files changed

Lines changed: 36 additions & 53 deletions

lightning/src/ln/accountable_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
2626
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
2727
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);
2828

29-
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
29+
let (payment_preimage, payment_hash, payment_secret) =
30+
get_payment_preimage_hash(&nodes[2], None, None);
3031
let route_params = RouteParameters::from_payment_params_and_value(
3132
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
3233
100_000,

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
13821382
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
13831383
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
13841384
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
1385-
get_payment_preimage_hash!(nodes[1]);
1385+
get_payment_preimage_hash(&nodes[1], None, None);
13861386
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
1387-
get_payment_preimage_hash!(nodes[1]);
1387+
get_payment_preimage_hash(&nodes[1], None, None);
13881388

13891389
// Queue up two payments - one will be delivered right away, one immediately goes into the
13901390
// holding cell as nodes[0] is AwaitingRAA. Ultimately this allows us to deliver an RAA
@@ -1872,7 +1872,7 @@ fn test_monitor_update_fail_claim() {
18721872
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
18731873
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);
18741874

1875-
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
1875+
let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
18761876
let id_3 = PaymentId(payment_hash_3.0);
18771877
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
18781878
nodes[2].node.send_payment_with_route(route, payment_hash_3, onion_3, id_3).unwrap();
@@ -2663,7 +2663,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
26632663
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
26642664
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
26652665
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
2666-
get_payment_preimage_hash!(&nodes[1]);
2666+
get_payment_preimage_hash(&nodes[1], None, None);
26672667

26682668
// Do a really complicated dance to get an HTLC into the holding cell, with
26692669
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
50995099
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);
51005100

51015101
// Put the C <-> D channel into AwaitingRaa
5102-
let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
5102+
let (preimage_2, paymnt_hash_2, payment_secret_2) =
5103+
get_payment_preimage_hash(&nodes[3], None, None);
51035104
let onion = RecipientOnionFields::secret_only(payment_secret_2);
51045105
let id = PaymentId([42; 32]);
51055106
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20522,7 +20522,7 @@ mod tests {
2052220522
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
2052320523
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
2052420524

20525-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
20525+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
2052620526
let payment_data = msgs::FinalOnionHopData {
2052720527
payment_secret,
2052820528
total_msat: 100_000,

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,26 +2818,6 @@ pub fn get_payment_preimage_hash(
28182818
(payment_preimage, payment_hash, payment_secret)
28192819
}
28202820

2821-
/// Get a payment preimage and hash.
2822-
///
2823-
/// Don't use this, use the identically-named function instead.
2824-
#[macro_export]
2825-
macro_rules! get_payment_preimage_hash {
2826-
($dest_node: expr) => {
2827-
get_payment_preimage_hash!($dest_node, None)
2828-
};
2829-
($dest_node: expr, $min_value_msat: expr) => {
2830-
$crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
2831-
};
2832-
($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
2833-
$crate::ln::functional_test_utils::get_payment_preimage_hash(
2834-
&$dest_node,
2835-
$min_value_msat,
2836-
$min_final_cltv_expiry_delta,
2837-
)
2838-
};
2839-
}
2840-
28412821
/// Gets a route from the given sender to the node described in `payment_params`.
28422822
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
28432823
let scorer = TestScorer::new();
@@ -3809,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
38093789
recv_value: u64,
38103790
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
38113791
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
3812-
get_payment_preimage_hash!(expected_route.last().unwrap());
3792+
get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
38133793
let payment_id = send_along_route_with_secret(
38143794
origin_node,
38153795
route,

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6057,7 +6057,7 @@ pub fn test_check_htlc_underpaying() {
60576057
)
60586058
.unwrap();
60596059

6060-
let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
6060+
let (_, our_payment_hash, _) = get_payment_preimage_hash(&nodes[0], None, None);
60616061
let our_payment_secret = nodes[1]
60626062
.node
60636063
.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, None)
@@ -8318,7 +8318,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) {
83188318
let route = get_route!(nodes[0], payment_params, 10_000).unwrap();
83198319

83208320
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
8321-
get_payment_preimage_hash!(&nodes[1]);
8321+
get_payment_preimage_hash(&nodes[1], None, None);
83228322

83238323
{
83248324
let onion = RecipientOnionFields::secret_only(our_payment_secret);
@@ -8467,7 +8467,7 @@ pub fn test_inconsistent_mpp_params() {
84678467
}
84688468
});
84698469

8470-
let (preimage, hash, payment_secret) = get_payment_preimage_hash!(&nodes[3]);
8470+
let (preimage, hash, payment_secret) = get_payment_preimage_hash(&nodes[3], None, None);
84718471

84728472
let cur_height = nodes[0].best_block_info().1;
84738473
let id = PaymentId([42; 32]);
@@ -9476,7 +9476,7 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash
94769476
PaymentParameters::from_node_id(node_b_id, final_cltv_expiry_delta as u32);
94779477
let (hash, payment_preimage, payment_secret) = if use_user_hash {
94789478
let (payment_preimage, hash, payment_secret) =
9479-
get_payment_preimage_hash!(nodes[1], Some(recv_value), Some(min_cltv_expiry_delta));
9479+
get_payment_preimage_hash(&nodes[1], Some(recv_value), Some(min_cltv_expiry_delta));
94809480
(hash, payment_preimage, payment_secret)
94819481
} else {
94829482
let (hash, payment_secret) = nodes[1]

lightning/src/ln/htlc_reserve_unit_tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ pub fn test_channel_reserve_holding_cell_htlcs() {
268268
{
269269
let mut route = route_1.clone();
270270
route.paths[0].hops.last_mut().unwrap().fee_msat = recv_value_2 + 1;
271-
let (_, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(nodes[2]);
271+
let (_, our_payment_hash, our_payment_secret) =
272+
get_payment_preimage_hash(&nodes[2], None, None);
272273
let onion = RecipientOnionFields::secret_only(our_payment_secret);
273274
let id = PaymentId(our_payment_hash.0);
274275
let res = nodes[0].node.send_payment_with_route(route, our_payment_hash, onion, id);

lightning/src/ln/onion_route_tests.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn test_fee_failures() {
418418
// If the hop gives fee_insufficient but enough fees were provided, then the previous hop
419419
// malleated the payment before forwarding, taking funds when they shouldn't have. However,
420420
// because we ignore channel update contents, we will still blame the 2nd channel.
421-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
421+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
422422
let short_channel_id = channels[1].0.contents.short_channel_id;
423423
run_onion_failure_test(
424424
"fee_insufficient",
@@ -449,7 +449,7 @@ fn test_fee_failures() {
449449
}
450450

451451
let (payment_preimage_success, payment_hash_success, payment_secret_success) =
452-
get_payment_preimage_hash!(nodes[2]);
452+
get_payment_preimage_hash(&nodes[2], None, None);
453453
let recipient_onion = RecipientOnionFields::secret_only(payment_secret_success);
454454
let payment_id = PaymentId(payment_hash_success.0);
455455
nodes[0]
@@ -667,7 +667,7 @@ fn test_onion_failure() {
667667
Some(route.paths[0].hops[1].short_channel_id),
668668
None,
669669
);
670-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
670+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
671671

672672
// intermediate node failure
673673
run_onion_failure_test_with_fail_intercept(
@@ -738,7 +738,7 @@ fn test_onion_failure() {
738738
Some(route.paths[0].hops[1].short_channel_id),
739739
None,
740740
);
741-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
741+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
742742

743743
// intermediate node failure
744744
run_onion_failure_test_with_fail_intercept(
@@ -811,7 +811,7 @@ fn test_onion_failure() {
811811
Some(route.paths[0].hops[1].short_channel_id),
812812
None,
813813
);
814-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
814+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
815815

816816
// Our immediate peer sent UpdateFailMalformedHTLC because it couldn't understand the onion in
817817
// the UpdateAddHTLC that we sent.
@@ -1142,7 +1142,7 @@ fn test_onion_failure() {
11421142
None,
11431143
None,
11441144
);
1145-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
1145+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
11461146

11471147
run_onion_failure_test(
11481148
"final_expiry_too_soon",
@@ -2426,7 +2426,7 @@ fn test_phantom_onion_hmac_failure() {
24262426
// Get the route.
24272427
let recv_value_msat = 10_000;
24282428
let (_, payment_hash, payment_secret) =
2429-
get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
2429+
get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
24302430
let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
24312431

24322432
// Route the HTLC through to the destination.
@@ -2496,7 +2496,7 @@ fn test_phantom_invalid_onion_payload() {
24962496
// Get the route.
24972497
let recv_value_msat = 10_000;
24982498
let (_, payment_hash, payment_secret) =
2499-
get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
2499+
get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
25002500
let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
25012501

25022502
// We'll use the session priv later when constructing an invalid onion packet.
@@ -2598,7 +2598,7 @@ fn test_phantom_final_incorrect_cltv_expiry() {
25982598
// Get the route.
25992599
let recv_value_msat = 10_000;
26002600
let (_, payment_hash, payment_secret) =
2601-
get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
2601+
get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
26022602
let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
26032603

26042604
// Route the HTLC through to the destination.
@@ -2664,7 +2664,7 @@ fn test_phantom_failure_too_low_cltv() {
26642664
// Get the route.
26652665
let recv_value_msat = 10_000;
26662666
let (_, payment_hash, payment_secret) =
2667-
get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
2667+
get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
26682668
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
26692669

26702670
// Modify the route to have a too-low cltv.
@@ -2720,7 +2720,7 @@ fn test_phantom_failure_modified_cltv() {
27202720
// Get the route.
27212721
let recv_value_msat = 10_000;
27222722
let (_, payment_hash, payment_secret) =
2723-
get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
2723+
get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
27242724
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
27252725

27262726
// Route the HTLC through to the destination.
@@ -2775,7 +2775,7 @@ fn test_phantom_failure_expires_too_soon() {
27752775
// Get the route.
27762776
let recv_value_msat = 10_000;
27772777
let (_, payment_hash, payment_secret) =
2778-
get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
2778+
get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
27792779
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
27802780

27812781
// Route the HTLC through to the destination.
@@ -2825,7 +2825,7 @@ fn test_phantom_failure_too_low_recv_amt() {
28252825
let recv_amt_msat = 10_000;
28262826
let bad_recv_amt_msat = recv_amt_msat - 10;
28272827
let (_, payment_hash, payment_secret) =
2828-
get_payment_preimage_hash!(nodes[1], Some(recv_amt_msat));
2828+
get_payment_preimage_hash(&nodes[1], Some(recv_amt_msat), None);
28292829
let (mut route, phantom_scid) = get_phantom_route!(nodes, bad_recv_amt_msat, channel);
28302830

28312831
// Route the HTLC through to the destination.
@@ -2894,7 +2894,7 @@ fn do_test_phantom_dust_exposure_failure(multiplier_dust_limit: bool) {
28942894

28952895
// Get the route with an amount exceeding the dust exposure threshold of nodes[1].
28962896
let (_, payment_hash, payment_secret) =
2897-
get_payment_preimage_hash!(nodes[1], Some(max_dust_exposure + 1));
2897+
get_payment_preimage_hash(&nodes[1], Some(max_dust_exposure + 1), None);
28982898
let (mut route, phantom_scid) = get_phantom_route!(nodes, max_dust_exposure + 1, channel);
28992899

29002900
// Route the HTLC through to the destination.
@@ -2944,7 +2944,7 @@ fn test_phantom_failure_reject_payment() {
29442944
// Get the route with a too-low amount.
29452945
let recv_amt_msat = 10_000;
29462946
let (_, payment_hash, payment_secret) =
2947-
get_payment_preimage_hash!(nodes[1], Some(recv_amt_msat));
2947+
get_payment_preimage_hash(&nodes[1], Some(recv_amt_msat), None);
29482948
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_amt_msat, channel);
29492949

29502950
// Route the HTLC through to the destination.

lightning/src/ln/payment_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ fn test_holding_cell_inflight_htlcs() {
21682168

21692169
let (route, payment_hash_1, _, payment_secret_1) =
21702170
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
2171-
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[1]);
2171+
let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash(&nodes[1], None, None);
21722172

21732173
// Queue up two payments - one will be delivered right away, one immediately goes into the
21742174
// holding cell as nodes[0] is AwaitingRAA.
@@ -4290,7 +4290,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) {
42904290
let chan_bd = create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0).2;
42914291
create_announced_chan_between_nodes(&nodes, 2, 3);
42924292

4293-
let (payment_preimage, hash, payment_secret) = get_payment_preimage_hash!(nodes[3]);
4293+
let (payment_preimage, hash, payment_secret) = get_payment_preimage_hash(&nodes[3], None, None);
42944294
let payment_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV)
42954295
.with_bolt11_features(nodes[1].node.bolt11_invoice_features())
42964296
.unwrap();
@@ -4688,7 +4688,7 @@ fn do_test_custom_tlvs_consistency(
46884688
}
46894689
});
46904690

4691-
let (preimage, hash, payment_secret) = get_payment_preimage_hash!(&nodes[3]);
4691+
let (preimage, hash, payment_secret) = get_payment_preimage_hash(&nodes[3], None, None);
46924692
let id = PaymentId([42; 32]);
46934693
let amt_msat = 15_000_000;
46944694

@@ -4832,7 +4832,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) {
48324832
// Pay more than half of each channel's max, requiring MPP
48334833
let amt_msat = 750_000_000;
48344834
let (payment_preimage, payment_hash, payment_secret) =
4835-
get_payment_preimage_hash!(nodes[3], Some(amt_msat));
4835+
get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
48364836
let payment_id = PaymentId(payment_hash.0);
48374837
let payment_metadata = vec![44, 49, 52, 142];
48384838

lightning/src/ln/shutdown_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ fn updates_shutdown_wait() {
410410
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
411411
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
412412

413-
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[0]);
413+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
414414

415415
let payment_params_1 = PaymentParameters::from_node_id(node_b_id, TEST_FINAL_CLTV)
416416
.with_bolt11_features(nodes[1].node.bolt11_invoice_features())

0 commit comments

Comments
 (0)