Drop useless `vec!` macro calls
What changed, and why it matters
This commit is a routine code cleanup. It replaces unnecessary `vec!` macro calls with plain array literals in test code and internal test modules. There is no functional change, no bug fix, and no security relevance.
No action required. This is a non-security refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff changes vec![...] to [...] in six files, all within mod tests or test functions. In Rust, when a vector is only iterated once or passed to a function accepting impl IntoIterator, an array literal works the same and avoids a heap allocation. The surrounding code already calls .iter().collect::<Vec<_>>() where a Vec is actually needed, so behavior is unchanged. No production logic, cryptography, or network parsing code is modified.
Changed components
lightning/src/blinded_path/payment.rs (tests)lightning/src/crypto/chacha20.rs (tests)lightning/src/ln/functional_tests.rs (tests)lightning/src/offers/invoice.rs (tests)lightning/src/offers/refund.rs (tests)lightning/src/routing/router.rs (tests)Inspect captured patch +35 / −33
diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs
index 4ae10f7..37d7a1d 100644
--- a/lightning/src/blinded_path/payment.rs
+++ b/lightning/src/blinded_path/payment.rs
@@ -869,7 +869,7 @@ mod tests {
// Taken from the spec example for aggregating blinded payment info. See
// https://github.com/lightning/bolts/blob/master/proposals/route-blinding.md#blinded-payments
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
- let intermediate_nodes = vec![
+ let intermediate_nodes = [
PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
@@ -944,7 +944,7 @@ mod tests {
// If no hops charge fees, the htlc_minimum_msat should just be the maximum htlc_minimum_msat
// along the path.
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
- let intermediate_nodes = vec![
+ let intermediate_nodes = [
PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
@@ -1003,7 +1003,7 @@ mod tests {
// Create a path with varying fees and htlc_mins, and make sure htlc_minimum_msat ends up as the
// max (htlc_min - following_fees) along the path.
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
- let intermediate_nodes = vec![
+ let intermediate_nodes = [
PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
@@ -1072,7 +1072,7 @@ mod tests {
// Create a path with varying fees and `htlc_maximum_msat`s, and make sure the aggregated max
// htlc ends up as the min (htlc_max - following_fees) along the path.
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
- let intermediate_nodes = vec![
+ let intermediate_nodes = [
PaymentForwardNode {
node_id: dummy_pk,
tlvs: ForwardTlvs {
diff --git a/lightning/src/crypto/chacha20.rs b/lightning/src/crypto/chacha20.rs
index cbe3e4e..5b0c16c 100644
--- a/lightning/src/crypto/chacha20.rs
+++ b/lightning/src/crypto/chacha20.rs
@@ -354,7 +354,7 @@ mod test {
keystream: Vec<u8>,
}
// taken from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04
- let test_vectors = vec![
+ let test_vectors = [
TestVector {
key: [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -464,7 +464,7 @@ mod test {
keystream: Vec<u8>,
}
// taken from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04
- let test_vectors = vec![
+ let test_vectors = [
TestVector {
key: [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs
index 8763247..c161a96 100644
--- a/lightning/src/ln/functional_tests.rs
+++ b/lightning/src/ln/functional_tests.rs
@@ -999,7 +999,7 @@ fn do_test_forming_justice_tx_from_monitor_updates(broadcast_initial_commitment:
let chanmon_cfgs = create_chanmon_cfgs(2);
let destination_script0 = chanmon_cfgs[0].keys_manager.get_destination_script([0; 32]).unwrap();
let destination_script1 = chanmon_cfgs[1].keys_manager.get_destination_script([0; 32]).unwrap();
- let persisters = vec![
+ let persisters = [
WatchtowerPersister::new(destination_script0),
WatchtowerPersister::new(destination_script1),
];
diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs
index 4e1c608..6dfd6ea 100644
--- a/lightning/src/offers/invoice.rs
+++ b/lightning/src/offers/invoice.rs
@@ -3002,7 +3002,7 @@ mod tests {
let secp_ctx = Secp256k1::new();
let payment_id = PaymentId([1; 32]);
- let paths = vec![
+ let paths = [
BlindedMessagePath::from_blinded_path(
pubkey(40),
pubkey(41),
diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs
index 87d7a84..dd2c3e2 100644
--- a/lightning/src/offers/refund.rs
+++ b/lightning/src/offers/refund.rs
@@ -1587,7 +1587,7 @@ mod tests {
#[test]
fn parses_refund_with_optional_fields() {
let past_expiry = Duration::from_secs(0);
- let paths = vec![
+ let paths = [
BlindedMessagePath::from_blinded_path(
pubkey(40),
pubkey(41),
diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs
index 9b68fdf..8434b17 100644
--- a/lightning/src/routing/router.rs
+++ b/lightning/src/routing/router.rs
@@ -4053,7 +4053,7 @@ mod tests {
// Simple route to 2 via 1
- let our_chans = vec![get_channel_details(Some(2), our_id, InitFeatures::from_le_bytes(vec![0b11]), 100000)];
+ let our_chans = [get_channel_details(Some(2), our_id, InitFeatures::from_le_bytes(vec![0b11]), 100000)];
let route_params = RouteParameters::from_payment_params_and_value(payment_params, 100);
if let Err(err) = get_route(&our_id,
@@ -4472,7 +4472,7 @@ mod tests {
} else { panic!(); }
// If we specify a channel to node7, that overrides our local channel view and that gets used
- let our_chans = vec![get_channel_details(Some(42), nodes[7].clone(),
+ let our_chans = [get_channel_details(Some(42), nodes[7].clone(),
InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
route_params.payment_params.max_path_length = 2;
let route = get_route(&our_id, &route_params, &network_graph.read_only(),
@@ -4520,7 +4520,7 @@ mod tests {
} else { panic!(); }
// If we specify a channel to node7, that overrides our local channel view and that gets used
- let our_chans = vec![get_channel_details(Some(42), nodes[7].clone(),
+ let our_chans = [get_channel_details(Some(42), nodes[7].clone(),
InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
let route = get_route(&our_id, &route_params, &network_graph.read_only(),
Some(&our_chans.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
@@ -4585,7 +4585,7 @@ mod tests {
// If we specify a channel to node7, that overrides our local channel view and that gets used
let payment_params = PaymentParameters::from_node_id(nodes[2], 42);
let route_params = RouteParameters::from_payment_params_and_value(payment_params, 100);
- let our_chans = vec![get_channel_details(Some(42), nodes[7].clone(),
+ let our_chans = [get_channel_details(Some(42), nodes[7].clone(),
InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
let route = get_route(&our_id, &route_params, &network_graph.read_only(),
Some(&our_chans.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
@@ -5136,7 +5136,7 @@ mod tests {
let random_seed_bytes = [42; 32];
// Simple test with outbound channel to 4 to test that last_hops and first_hops connect
- let our_chans = vec![get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
+ let our_chans = [get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
let mut last_hops = last_hops(&nodes);
let payment_params = PaymentParameters::from_node_id(nodes[6], 42)
.with_route_hints(last_hops.clone()).unwrap();
@@ -5264,7 +5264,7 @@ mod tests {
htlc_maximum_msat: last_hop_htlc_max,
}]);
let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]).unwrap();
- let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
+ let our_chans = [get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
let scorer = ln_test_utils::TestScorer::new();
let random_seed_bytes = [42; 32];
let logger = ln_test_utils::TestLogger::new();
@@ -5441,7 +5441,7 @@ mod tests {
});
// Now, limit the first_hop by the next_outbound_htlc_limit_msat of 200_000 sats.
- let our_chans = vec![get_channel_details(Some(42), nodes[0].clone(), InitFeatures::from_le_bytes(vec![0b11]), 200_000_000)];
+ let our_chans = [get_channel_details(Some(42), nodes[0].clone(), InitFeatures::from_le_bytes(vec![0b11]), 200_000_000)];
{
// Attempt to route more than available results in a failure.
@@ -7826,7 +7826,7 @@ mod tests {
let our_node_id = ln_test_utils::pubkey(42);
let intermed_node_id = ln_test_utils::pubkey(43);
- let first_hop = vec![get_channel_details(Some(42), intermed_node_id, InitFeatures::from_le_bytes(vec![0b11]), 10_000_000)];
+ let first_hop = [get_channel_details(Some(42), intermed_node_id, InitFeatures::from_le_bytes(vec![0b11]), 10_000_000)];
let amt_msat = 900_000;
let max_htlc_msat = 500_000;
@@ -7873,7 +7873,7 @@ mod tests {
// Re-run but with two first hop channels connected to the same route hint peers that must be
// split between.
- let first_hops = vec![
+ let first_hops = [
get_channel_details(Some(42), intermed_node_id, InitFeatures::from_le_bytes(vec![0b11]), amt_msat - 10),
get_channel_details(Some(43), intermed_node_id, InitFeatures::from_le_bytes(vec![0b11]), amt_msat - 10),
];
@@ -8285,8 +8285,9 @@ mod tests {
fee_proportional_millionths: 0,
excess_data: Vec::new()
});
- let first_hops = vec![
- get_channel_details(Some(1), nodes[1], InitFeatures::from_le_bytes(vec![0b11]), 10_000_000)];
+ let first_hops = [
+ get_channel_details(Some(1), nodes[1], InitFeatures::from_le_bytes(vec![0b11]), 10_000_000)
+ ];
let blinded_payinfo = BlindedPayInfo {
fee_base_msat: 1000,
@@ -8346,9 +8347,10 @@ mod tests {
// Values are taken from the fuzz input that uncovered this panic.
let amt_msat = 21_7020_5185_1403_2640;
let (_, _, _, nodes) = get_nodes(&secp_ctx);
- let first_hops = vec![
+ let first_hops = [
get_channel_details(Some(1), nodes[1], channelmanager::provided_init_features(&config),
- 18446744073709551615)];
+ 18446744073709551615),
+ ];
let blinded_payinfo = BlindedPayInfo {
fee_base_msat: 5046_2720,
@@ -8492,7 +8494,7 @@ mod tests {
let amt_msat = 7_4009_8048;
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let first_hop_outbound_capacity = 2_7345_2000;
- let first_hops = vec![get_channel_details(
+ let first_hops = [get_channel_details(
Some(200), nodes[0], channelmanager::provided_init_features(&config),
first_hop_outbound_capacity
)];
@@ -8565,7 +8567,7 @@ mod tests {
// Values are taken from the fuzz input that uncovered this panic.
let amt_msat = 52_4288;
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let first_hops = vec![get_channel_details(
+ let first_hops = [get_channel_details(
Some(161), nodes[0], channelmanager::provided_init_features(&config), 486_4000
), get_channel_details(
Some(122), nodes[0], channelmanager::provided_init_features(&config), 179_5000
@@ -8640,7 +8642,7 @@ mod tests {
// Values are taken from the fuzz input that uncovered this panic.
let amt_msat = 7_4009_8048;
let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let first_hops = vec![get_channel_details(
+ let first_hops = [get_channel_details(
Some(200), nodes[0], channelmanager::provided_init_features(&config), 2_7345_2000
)];
@@ -8704,7 +8706,7 @@ mod tests {
// Values are taken from the fuzz input that uncovered this panic.
let amt_msat = 562_0000;
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let first_hops = vec![
+ let first_hops = [
get_channel_details(
Some(83), nodes[0], channelmanager::provided_init_features(&config), 2199_0000,
),
@@ -8848,9 +8850,8 @@ mod tests {
// First create an insufficient first hop for channel with SCID 1 and check we'd use the
// route hint.
- let first_hop = get_channel_details(Some(1), nodes[0],
- channelmanager::provided_init_features(&config), 999_999);
- let first_hops = vec![first_hop];
+ let first_hops = [get_channel_details(Some(1), nodes[0],
+ channelmanager::provided_init_features(&config), 999_999)];
let route = get_route(&our_node_id, &route_params.clone(), &network_graph.read_only(),
Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
@@ -8866,7 +8867,7 @@ mod tests {
// for a first hop channel.
let mut first_hop = get_channel_details(Some(1), nodes[0], channelmanager::provided_init_features(&config), 999_999);
first_hop.outbound_scid_alias = Some(44);
- let first_hops = vec![first_hop];
+ let first_hops = [first_hop];
let route_res = get_route(&our_node_id, &route_params.clone(), &network_graph.read_only(),
Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
@@ -8878,7 +8879,7 @@ mod tests {
let mut first_hop = get_channel_details(Some(1), nodes[0],
channelmanager::provided_init_features(&config), 10_000_000);
first_hop.outbound_scid_alias = Some(44);
- let first_hops = vec![first_hop];
+ let first_hops = [first_hop];
let route = get_route(&our_node_id, &route_params.clone(), &network_graph.read_only(),
Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
@@ -9001,8 +9002,9 @@ mod tests {
let amt_msat = 1_000_000;
let dest_node_id = nodes[1];
- let first_hop = get_channel_details(Some(1), nodes[0], channelmanager::provided_init_features(&config), 10_000_000);
- let first_hops = vec![first_hop];
+ let first_hops = [
+ get_channel_details(Some(1), nodes[0], channelmanager::provided_init_features(&config), 10_000_000),
+ ];
let route_hint = RouteHint(vec![RouteHintHop {
src_node_id: our_node_id,
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.