ln/fmt: clean up ugly formatting of do_test_trampoline_unblinded_receive
What changed, and why it matters
This commit is purely a code cleanup: it tidies up formatting in a test function and extracts a small helper to reduce repetition. There is no change to production behavior, no bug fix, and no security relevance.
No action needed; this is a non-functional formatting/refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors test-only code in rust-lightning. In blinded_payment_tests.rs it rewrites variable bindings, removes inline comments, and uses a new helper get_scid_from_channel_id. The helper is added to functional_test_utils.rs and simply wraps the existing pattern of looking up a channel’s short_channel_id by channel_id. No logic changes; no runtime behavior changes.
Changed components
lightning/src/ln/blinded_payment_tests.rslightning/src/ln/functional_test_utils.rsInspect captured patch +23 / −36
diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs
index a024e24..cb36cb4 100644
--- a/lightning/src/ln/blinded_payment_tests.rs
+++ b/lightning/src/ln/blinded_payment_tests.rs
@@ -2290,17 +2290,14 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
let chanmon_cfgs = create_chanmon_cfgs(TOTAL_NODE_COUNT);
let node_cfgs = create_node_cfgs(TOTAL_NODE_COUNT, &chanmon_cfgs);
- let node_chanmgrs =
- create_node_chanmgrs(TOTAL_NODE_COUNT, &node_cfgs, &vec![None; TOTAL_NODE_COUNT]);
+ let user_cfgs = &vec![None; TOTAL_NODE_COUNT];
+ let node_chanmgrs = create_node_chanmgrs(TOTAL_NODE_COUNT, &node_cfgs, &user_cfgs);
let mut nodes = create_network(TOTAL_NODE_COUNT, &node_cfgs, &node_chanmgrs);
- let (_, _, chan_id_alice_bob, _) =
- create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
- let (_, _, chan_id_bob_carol, _) =
- create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
+ let alice_bob_chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0);
+ let bob_carol_chan = create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 1_000_000, 0);
for i in 0..TOTAL_NODE_COUNT {
- // connect all nodes' blocks
connect_blocks(
&nodes[i],
(TOTAL_NODE_COUNT as u32) * CHAN_CONFIRM_DEPTH + 1 - nodes[i].best_block_info().1,
@@ -2310,22 +2307,8 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
let bob_node_id = nodes[1].node().get_our_node_id();
let carol_node_id = nodes[2].node().get_our_node_id();
- let alice_bob_scid = nodes[0]
- .node()
- .list_channels()
- .iter()
- .find(|c| c.channel_id == chan_id_alice_bob)
- .unwrap()
- .short_channel_id
- .unwrap();
- let bob_carol_scid = nodes[1]
- .node()
- .list_channels()
- .iter()
- .find(|c| c.channel_id == chan_id_bob_carol)
- .unwrap()
- .short_channel_id
- .unwrap();
+ let alice_bob_scid = get_scid_from_channel_id(&nodes[0], alice_bob_chan.2);
+ let bob_carol_scid = get_scid_from_channel_id(&nodes[1], bob_carol_chan.2);
let amt_msat = 1000;
let (payment_preimage, payment_hash, payment_secret) =
@@ -2333,7 +2316,6 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
let route = Route {
paths: vec![Path {
hops: vec![
- // Bob
RouteHop {
pubkey: bob_node_id,
node_features: NodeFeatures::empty(),
@@ -2343,7 +2325,6 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
cltv_expiry_delta: 48,
maybe_announced_channel: false,
},
- // Carol
RouteHop {
pubkey: carol_node_id,
node_features: NodeFeatures::empty(),
@@ -2355,15 +2336,12 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
},
],
blinded_tail: Some(BlindedTail {
- trampoline_hops: vec![
- // Carol
- TrampolineHop {
- pubkey: carol_node_id,
- node_features: Features::empty(),
- fee_msat: amt_msat,
- cltv_expiry_delta: 24,
- },
- ],
+ trampoline_hops: vec![TrampolineHop {
+ pubkey: carol_node_id,
+ node_features: Features::empty(),
+ fee_msat: amt_msat,
+ cltv_expiry_delta: 24,
+ }],
// The blinded path data is unused because we replace the onion of the last hop
hops: vec![BlindedHop {
blinded_node_id: PublicKey::from_slice(&[2; 33]).unwrap(),
@@ -2460,8 +2438,7 @@ fn do_test_trampoline_unblinded_receive(success: bool) {
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1);
- let mut first_message_event =
- remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
+ let mut first_message_event = remove_first_msg_event_to_node(&bob_node_id, &mut events);
let mut update_message = match first_message_event {
MessageSendEvent::UpdateHTLCs { ref mut updates, .. } => {
assert_eq!(updates.update_add_htlcs.len(), 1);
diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs
index e31630a..22cce2c 100644
--- a/lightning/src/ln/functional_test_utils.rs
+++ b/lightning/src/ln/functional_test_utils.rs
@@ -5526,3 +5526,13 @@ pub fn create_batch_channel_funding<'a, 'b, 'c>(
}
return (tx, funding_created_msgs);
}
+
+pub fn get_scid_from_channel_id<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, channel_id: ChannelId) -> u64 {
+ node.node()
+ .list_channels()
+ .iter()
+ .find(|c| c.channel_id == channel_id)
+ .unwrap()
+ .short_channel_id
+ .unwrap()
+}
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.