diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 4ae10f75961..37d7a1dba7d 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 cbe3e4e1062..5b0c16c933f 100644 --- a/lightning/src/crypto/chacha20.rs +++ b/lightning/src/crypto/chacha20.rs @@ -354,7 +354,7 @@ mod test { keystream: Vec, } // 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, } // 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 876324737a6..c161a9664c0 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/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs index 7fc63d745e8..97047eb3a0d 100644 --- a/lightning/src/ln/interactivetxs.rs +++ b/lightning/src/ln/interactivetxs.rs @@ -1492,12 +1492,6 @@ enum StateMachine { NegotiationAborted(NegotiationAborted), } -impl Default for StateMachine { - fn default() -> Self { - Self::Indeterminate - } -} - // The `StateMachine` internally executes the actual transition between two states and keeps // track of the current state. This macro defines _how_ those state transitions happen to // update the internal state. @@ -1932,7 +1926,8 @@ impl InteractiveTxMessageSend { // This macro executes a state machine transition based on a provided action. macro_rules! do_state_transition { ($self: ident, $transition: ident, $msg: expr) => {{ - let state_machine = core::mem::take(&mut $self.state_machine); + let mut state_machine = StateMachine::Indeterminate; + core::mem::swap(&mut state_machine, &mut $self.state_machine); $self.state_machine = state_machine.$transition($msg); match &$self.state_machine { StateMachine::NegotiationAborted(state) => Err(state.0.clone()), diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 4e1c608dfdf..6dfd6eac508 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 87d7a845b53..dd2c3e2a92e 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 9b68fdf5c59..8434b17698d 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::>()), 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::>()), 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::>()), 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::>()), 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::>()), 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,