Replace `get_payment_preimage_hash!` macro with direct function calls
What changed, and why it matters
This commit is a straightforward code cleanup in the project's test suite. It removes a helper macro used only in tests and replaces it with direct calls to an existing function. There is no change to the actual Lightning node logic that runs in production, and nothing in the commit suggests a security fix.
No security action needed. Treat as a normal test-only refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change deletes the get_payment_preimage_hash! macro from lightning/src/ln/functional_test_utils.rs and updates all call sites in test files to invoke the equivalent get_payment_preimage_hash() function directly with explicit None arguments. The function’s implementation is untouched. The diff is purely a refactor of test-only infrastructure.
Changed components
lightning/src/ln/functional_test_utils.rslightning/src/ln/accountable_tests.rslightning/src/ln/chanmon_update_fail_tests.rslightning/src/ln/channelmanager.rslightning/src/ln/functional_tests.rslightning/src/ln/htlc_reserve_unit_tests.rslightning/src/ln/onion_route_tests.rslightning/src/ln/payment_tests.rslightning/src/ln/shutdown_tests.rsInspect captured patch +36 / −53
diff --git a/lightning/src/ln/accountable_tests.rs b/lightning/src/ln/accountable_tests.rs
index 16ca142..35c936f 100644
--- a/lightning/src/ln/accountable_tests.rs
+++ b/lightning/src/ln/accountable_tests.rs
@@ -26,7 +26,8 @@ fn test_accountable_forwarding_with_override(
let _chan_ab = create_announced_chan_between_nodes(&nodes, 0, 1);
let _chan_bc = create_announced_chan_between_nodes(&nodes, 1, 2);
- let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (payment_preimage, payment_hash, payment_secret) =
+ get_payment_preimage_hash(&nodes[2], None, None);
let route_params = RouteParameters::from_payment_params_and_value(
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV),
100_000,
diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs
index 4eb4562..bcdc5b6 100644
--- a/lightning/src/ln/chanmon_update_fail_tests.rs
+++ b/lightning/src/ln/chanmon_update_fail_tests.rs
@@ -1382,9 +1382,9 @@ fn raa_no_response_awaiting_raa_state() {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
- get_payment_preimage_hash!(nodes[1]);
+ get_payment_preimage_hash(&nodes[1], None, None);
let (payment_preimage_3, payment_hash_3, payment_secret_3) =
- get_payment_preimage_hash!(nodes[1]);
+ get_payment_preimage_hash(&nodes[1], None, None);
// Queue up two payments - one will be delivered right away, one immediately goes into the
// 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() {
do_commitment_signed_dance(&nodes[1], &nodes[2], &payment_event.commitment_msg, false, true);
expect_htlc_failure_conditions(nodes[1].node.get_and_clear_pending_events(), &[]);
- let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
+ let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash(&nodes[0], None, None);
let id_3 = PaymentId(payment_hash_3.0);
let onion_3 = RecipientOnionFields::secret_only(payment_secret_3);
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) {
let (route, payment_hash_1, payment_preimage_1, payment_secret_1) =
get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
let (payment_preimage_2, payment_hash_2, payment_secret_2) =
- get_payment_preimage_hash!(&nodes[1]);
+ get_payment_preimage_hash(&nodes[1], None, None);
// Do a really complicated dance to get an HTLC into the holding cell, with
// MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
@@ -5099,7 +5099,8 @@ fn test_mpp_claim_to_holding_cell() {
send_along_route_with_secret(&nodes[0], route, paths, 500_000, paymnt_hash_1, payment_secret);
// Put the C <-> D channel into AwaitingRaa
- let (preimage_2, paymnt_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[3]);
+ let (preimage_2, paymnt_hash_2, payment_secret_2) =
+ get_payment_preimage_hash(&nodes[3], None, None);
let onion = RecipientOnionFields::secret_only(payment_secret_2);
let id = PaymentId([42; 32]);
let pay_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV);
diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs
index 869a431..270f007 100644
--- a/lightning/src/ln/channelmanager.rs
+++ b/lightning/src/ln/channelmanager.rs
@@ -20522,7 +20522,7 @@ mod tests {
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[0]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_data = msgs::FinalOnionHopData {
payment_secret,
total_msat: 100_000,
diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs
index eaa98b1..ed74b39 100644
--- a/lightning/src/ln/functional_test_utils.rs
+++ b/lightning/src/ln/functional_test_utils.rs
@@ -2818,26 +2818,6 @@ pub fn get_payment_preimage_hash(
(payment_preimage, payment_hash, payment_secret)
}
-/// Get a payment preimage and hash.
-///
-/// Don't use this, use the identically-named function instead.
-#[macro_export]
-macro_rules! get_payment_preimage_hash {
- ($dest_node: expr) => {
- get_payment_preimage_hash!($dest_node, None)
- };
- ($dest_node: expr, $min_value_msat: expr) => {
- $crate::get_payment_preimage_hash!($dest_node, $min_value_msat, None)
- };
- ($dest_node: expr, $min_value_msat: expr, $min_final_cltv_expiry_delta: expr) => {
- $crate::ln::functional_test_utils::get_payment_preimage_hash(
- &$dest_node,
- $min_value_msat,
- $min_final_cltv_expiry_delta,
- )
- };
-}
-
/// Gets a route from the given sender to the node described in `payment_params`.
pub fn get_route(send_node: &Node, route_params: &RouteParameters) -> Result<Route, &'static str> {
let scorer = TestScorer::new();
@@ -3809,7 +3789,7 @@ pub fn send_along_route<'a, 'b, 'c>(
recv_value: u64,
) -> (PaymentPreimage, PaymentHash, PaymentSecret, PaymentId) {
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
- get_payment_preimage_hash!(expected_route.last().unwrap());
+ get_payment_preimage_hash(expected_route.last().unwrap(), None, None);
let payment_id = send_along_route_with_secret(
origin_node,
route,
diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs
index da21c12..be90130 100644
--- a/lightning/src/ln/functional_tests.rs
+++ b/lightning/src/ln/functional_tests.rs
@@ -6057,7 +6057,7 @@ pub fn test_check_htlc_underpaying() {
)
.unwrap();
- let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
+ let (_, our_payment_hash, _) = get_payment_preimage_hash(&nodes[0], None, None);
let our_payment_secret = nodes[1]
.node
.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) {
let route = get_route!(nodes[0], payment_params, 10_000).unwrap();
let (our_payment_preimage, our_payment_hash, our_payment_secret) =
- get_payment_preimage_hash!(&nodes[1]);
+ get_payment_preimage_hash(&nodes[1], None, None);
{
let onion = RecipientOnionFields::secret_only(our_payment_secret);
@@ -8467,7 +8467,7 @@ pub fn test_inconsistent_mpp_params() {
}
});
- let (preimage, hash, payment_secret) = get_payment_preimage_hash!(&nodes[3]);
+ let (preimage, hash, payment_secret) = get_payment_preimage_hash(&nodes[3], None, None);
let cur_height = nodes[0].best_block_info().1;
let id = PaymentId([42; 32]);
@@ -9476,7 +9476,7 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash
PaymentParameters::from_node_id(node_b_id, final_cltv_expiry_delta as u32);
let (hash, payment_preimage, payment_secret) = if use_user_hash {
let (payment_preimage, hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value), Some(min_cltv_expiry_delta));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value), Some(min_cltv_expiry_delta));
(hash, payment_preimage, payment_secret)
} else {
let (hash, payment_secret) = nodes[1]
diff --git a/lightning/src/ln/htlc_reserve_unit_tests.rs b/lightning/src/ln/htlc_reserve_unit_tests.rs
index 8cbe2f5..63faa98 100644
--- a/lightning/src/ln/htlc_reserve_unit_tests.rs
+++ b/lightning/src/ln/htlc_reserve_unit_tests.rs
@@ -268,7 +268,8 @@ pub fn test_channel_reserve_holding_cell_htlcs() {
{
let mut route = route_1.clone();
route.paths[0].hops.last_mut().unwrap().fee_msat = recv_value_2 + 1;
- let (_, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (_, our_payment_hash, our_payment_secret) =
+ get_payment_preimage_hash(&nodes[2], None, None);
let onion = RecipientOnionFields::secret_only(our_payment_secret);
let id = PaymentId(our_payment_hash.0);
let res = nodes[0].node.send_payment_with_route(route, our_payment_hash, onion, id);
diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs
index 27e0cfa..fe7d833 100644
--- a/lightning/src/ln/onion_route_tests.rs
+++ b/lightning/src/ln/onion_route_tests.rs
@@ -418,7 +418,7 @@ fn test_fee_failures() {
// If the hop gives fee_insufficient but enough fees were provided, then the previous hop
// malleated the payment before forwarding, taking funds when they shouldn't have. However,
// because we ignore channel update contents, we will still blame the 2nd channel.
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
let short_channel_id = channels[1].0.contents.short_channel_id;
run_onion_failure_test(
"fee_insufficient",
@@ -449,7 +449,7 @@ fn test_fee_failures() {
}
let (payment_preimage_success, payment_hash_success, payment_secret_success) =
- get_payment_preimage_hash!(nodes[2]);
+ get_payment_preimage_hash(&nodes[2], None, None);
let recipient_onion = RecipientOnionFields::secret_only(payment_secret_success);
let payment_id = PaymentId(payment_hash_success.0);
nodes[0]
@@ -667,7 +667,7 @@ fn test_onion_failure() {
Some(route.paths[0].hops[1].short_channel_id),
None,
);
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
// intermediate node failure
run_onion_failure_test_with_fail_intercept(
@@ -738,7 +738,7 @@ fn test_onion_failure() {
Some(route.paths[0].hops[1].short_channel_id),
None,
);
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
// intermediate node failure
run_onion_failure_test_with_fail_intercept(
@@ -811,7 +811,7 @@ fn test_onion_failure() {
Some(route.paths[0].hops[1].short_channel_id),
None,
);
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
// Our immediate peer sent UpdateFailMalformedHTLC because it couldn't understand the onion in
// the UpdateAddHTLC that we sent.
@@ -1142,7 +1142,7 @@ fn test_onion_failure() {
None,
None,
);
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], None, None);
run_onion_failure_test(
"final_expiry_too_soon",
@@ -2426,7 +2426,7 @@ fn test_phantom_onion_hmac_failure() {
// Get the route.
let recv_value_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
// Route the HTLC through to the destination.
@@ -2496,7 +2496,7 @@ fn test_phantom_invalid_onion_payload() {
// Get the route.
let recv_value_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
// We'll use the session priv later when constructing an invalid onion packet.
@@ -2598,7 +2598,7 @@ fn test_phantom_final_incorrect_cltv_expiry() {
// Get the route.
let recv_value_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
let (route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
// Route the HTLC through to the destination.
@@ -2664,7 +2664,7 @@ fn test_phantom_failure_too_low_cltv() {
// Get the route.
let recv_value_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
// Modify the route to have a too-low cltv.
@@ -2720,7 +2720,7 @@ fn test_phantom_failure_modified_cltv() {
// Get the route.
let recv_value_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
// Route the HTLC through to the destination.
@@ -2775,7 +2775,7 @@ fn test_phantom_failure_expires_too_soon() {
// Get the route.
let recv_value_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_value_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_value_msat), None);
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_value_msat, channel);
// Route the HTLC through to the destination.
@@ -2825,7 +2825,7 @@ fn test_phantom_failure_too_low_recv_amt() {
let recv_amt_msat = 10_000;
let bad_recv_amt_msat = recv_amt_msat - 10;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_amt_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_amt_msat), None);
let (mut route, phantom_scid) = get_phantom_route!(nodes, bad_recv_amt_msat, channel);
// Route the HTLC through to the destination.
@@ -2894,7 +2894,7 @@ fn do_test_phantom_dust_exposure_failure(multiplier_dust_limit: bool) {
// Get the route with an amount exceeding the dust exposure threshold of nodes[1].
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(max_dust_exposure + 1));
+ get_payment_preimage_hash(&nodes[1], Some(max_dust_exposure + 1), None);
let (mut route, phantom_scid) = get_phantom_route!(nodes, max_dust_exposure + 1, channel);
// Route the HTLC through to the destination.
@@ -2944,7 +2944,7 @@ fn test_phantom_failure_reject_payment() {
// Get the route with a too-low amount.
let recv_amt_msat = 10_000;
let (_, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[1], Some(recv_amt_msat));
+ get_payment_preimage_hash(&nodes[1], Some(recv_amt_msat), None);
let (mut route, phantom_scid) = get_phantom_route!(nodes, recv_amt_msat, channel);
// Route the HTLC through to the destination.
diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs
index 581b011..f0b2213 100644
--- a/lightning/src/ln/payment_tests.rs
+++ b/lightning/src/ln/payment_tests.rs
@@ -2168,7 +2168,7 @@ fn test_holding_cell_inflight_htlcs() {
let (route, payment_hash_1, _, payment_secret_1) =
get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
- let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(nodes[1]);
+ let (_, payment_hash_2, payment_secret_2) = get_payment_preimage_hash(&nodes[1], None, None);
// Queue up two payments - one will be delivered right away, one immediately goes into the
// holding cell as nodes[0] is AwaitingRAA.
@@ -4290,7 +4290,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) {
let chan_bd = create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 1_000_000, 0).2;
create_announced_chan_between_nodes(&nodes, 2, 3);
- let (payment_preimage, hash, payment_secret) = get_payment_preimage_hash!(nodes[3]);
+ let (payment_preimage, hash, payment_secret) = get_payment_preimage_hash(&nodes[3], None, None);
let payment_params = PaymentParameters::from_node_id(node_d_id, TEST_FINAL_CLTV)
.with_bolt11_features(nodes[1].node.bolt11_invoice_features())
.unwrap();
@@ -4688,7 +4688,7 @@ fn do_test_custom_tlvs_consistency(
}
});
- let (preimage, hash, payment_secret) = get_payment_preimage_hash!(&nodes[3]);
+ let (preimage, hash, payment_secret) = get_payment_preimage_hash(&nodes[3], None, None);
let id = PaymentId([42; 32]);
let amt_msat = 15_000_000;
@@ -4832,7 +4832,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) {
// Pay more than half of each channel's max, requiring MPP
let amt_msat = 750_000_000;
let (payment_preimage, payment_hash, payment_secret) =
- get_payment_preimage_hash!(nodes[3], Some(amt_msat));
+ get_payment_preimage_hash(&nodes[3], Some(amt_msat), None);
let payment_id = PaymentId(payment_hash.0);
let payment_metadata = vec![44, 49, 52, 142];
diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs
index 6cbf879..58c90b8 100644
--- a/lightning/src/ln/shutdown_tests.rs
+++ b/lightning/src/ln/shutdown_tests.rs
@@ -410,7 +410,7 @@ fn updates_shutdown_wait() {
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
- let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[0]);
+ let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[0], None, None);
let payment_params_1 = PaymentParameters::from_node_id(node_b_id, TEST_FINAL_CLTV)
.with_bolt11_features(nodes[1].node.bolt11_invoice_features())
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.