]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Run clippy --fix and cleanup code
authorAllan Douglas R. de Oliveira <allandouglas@gmail.com>
Mon, 27 Feb 2023 18:24:57 +0000 (18:24 +0000)
committerAllan Douglas R. de Oliveira <allandouglas@gmail.com>
Mon, 6 Mar 2023 19:26:48 +0000 (19:26 +0000)
14 files changed:
lightning-background-processor/src/lib.rs
lightning-block-sync/src/init.rs
lightning-block-sync/src/lib.rs
lightning-block-sync/src/poll.rs
lightning-block-sync/src/test_utils.rs
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/payment.rs
lightning-invoice/src/ser.rs
lightning-invoice/src/utils.rs
lightning-net-tokio/src/lib.rs
lightning-persister/src/lib.rs
lightning-persister/src/util.rs
lightning-rapid-gossip-sync/src/lib.rs

index 8711a4aeb5898e393f173886ca8e20de4b9b0d6f..ea369382aee2a32ab82e3682c3a7fa2205fb8d74 100644 (file)
@@ -755,7 +755,7 @@ mod tests {
 
        impl Persister {
                fn new(data_dir: String) -> Self {
-                       let filesystem_persister = FilesystemPersister::new(data_dir.clone());
+                       let filesystem_persister = FilesystemPersister::new(data_dir);
                        Self { graph_error: None, graph_persistence_notifier: None, manager_error: None, scorer_error: None, filesystem_persister }
                }
 
@@ -822,7 +822,7 @@ mod tests {
                }
 
                fn expect(&mut self, expectation: TestResult) {
-                       self.event_expectations.get_or_insert_with(|| VecDeque::new()).push_back(expectation);
+                       self.event_expectations.get_or_insert_with(VecDeque::new).push_back(expectation);
                }
        }
 
@@ -1224,7 +1224,7 @@ mod tests {
                // Set up a background event handler for SpendableOutputs events.
                let (sender, receiver) = std::sync::mpsc::sync_channel(1);
                let event_handler = move |event: Event| match event {
-                       Event::SpendableOutputs { .. } => sender.send(event.clone()).unwrap(),
+                       Event::SpendableOutputs { .. } => sender.send(event).unwrap(),
                        Event::ChannelReady { .. } => {},
                        Event::ChannelClosed { .. } => {},
                        _ => panic!("Unexpected event: {:?}", event),
@@ -1272,7 +1272,7 @@ mod tests {
                let nodes = create_nodes(2, "test_not_pruning_network_graph_until_graph_sync_completion".to_string());
                let data_dir = nodes[0].persister.get_data_dir();
                let (sender, receiver) = std::sync::mpsc::sync_channel(1);
-               let persister = Arc::new(Persister::new(data_dir.clone()).with_graph_persistence_notifier(sender));
+               let persister = Arc::new(Persister::new(data_dir).with_graph_persistence_notifier(sender));
                let network_graph = nodes[0].network_graph.clone();
                let features = ChannelFeatures::empty();
                network_graph.add_channel_from_partial_announcement(42, 53, features, nodes[0].node.get_our_node_id(), nodes[1].node.get_our_node_id())
@@ -1315,7 +1315,7 @@ mod tests {
                // this should have added two channels
                assert_eq!(network_graph.read_only().channels().len(), 3);
 
-               let _ = receiver
+               receiver
                        .recv_timeout(Duration::from_secs(super::FIRST_NETWORK_PRUNE_TIMER * 5))
                        .expect("Network graph not pruned within deadline");
 
@@ -1342,7 +1342,7 @@ mod tests {
 
                let nodes = create_nodes(1, "test_payment_path_scoring".to_string());
                let data_dir = nodes[0].persister.get_data_dir();
-               let persister = Arc::new(Persister::new(data_dir.clone()));
+               let persister = Arc::new(Persister::new(data_dir));
                let bg_processor = BackgroundProcessor::start(persister, event_handler, nodes[0].chain_monitor.clone(), nodes[0].node.clone(), nodes[0].no_gossip_sync(), nodes[0].peer_manager.clone(), nodes[0].logger.clone(), Some(nodes[0].scorer.clone()));
 
                let scored_scid = 4242;
@@ -1429,7 +1429,7 @@ mod tests {
                nodes[0].node.push_pending_event(Event::ProbeFailed {
                        payment_id: PaymentId([42; 32]),
                        payment_hash: PaymentHash([42; 32]),
-                       path: path.clone(),
+                       path,
                        short_channel_id: Some(scored_scid),
                });
                let event = receiver
index 2807bc877694c42b827d22a80cb2f17ce621edd0..866b247edee0b5e6e4b7a0b1faff0a857bfbfbc8 100644 (file)
@@ -181,7 +181,7 @@ pub async fn synchronize_listeners<B: Deref + Sized + Send + Sync, C: Cache, L:
                let chain_listener = &ChainListenerSet(chain_listeners_at_height);
                let mut chain_notifier = ChainNotifier { header_cache, chain_listener };
                chain_notifier.connect_blocks(common_ancestor, most_connected_blocks, &mut chain_poller)
-                       .await.or_else(|(e, _)| Err(e))?;
+                       .await.map_err(|(e, _)| e)?;
        }
 
        Ok(best_header)
index 189a68be0654dab1453ef459d3046d5d0001c17d..f9ce6c636c6d8e50e5df79ade58a30f0f76959cb 100644 (file)
@@ -411,15 +411,15 @@ impl<'a, C: Cache, L: Deref> ChainNotifier<'a, C, L> where L::Target: chain::Lis
                        let height = header.height;
                        let block_data = chain_poller
                                .fetch_block(&header).await
-                               .or_else(|e| Err((e, Some(new_tip))))?;
+                               .map_err(|e| (e, Some(new_tip)))?;
                        debug_assert_eq!(block_data.block_hash, header.block_hash);
 
                        match block_data.deref() {
                                BlockData::FullBlock(block) => {
-                                       self.chain_listener.block_connected(&block, height);
+                                       self.chain_listener.block_connected(block, height);
                                },
                                BlockData::HeaderOnly(header) => {
-                                       self.chain_listener.filtered_block_connected(&header, &[], height);
+                                       self.chain_listener.filtered_block_connected(header, &[], height);
                                },
                        }
 
index 05ccd4504fde0d81a76646d91b44d9b2b1653711..9f7e8becf5060c2f62471825a2aa0cfeca573f5e 100644 (file)
@@ -61,7 +61,7 @@ impl Validate for BlockHeaderData {
        fn validate(self, block_hash: BlockHash) -> BlockSourceResult<Self::T> {
                let pow_valid_block_hash = self.header
                        .validate_pow(&self.header.target())
-                       .or_else(|e| Err(BlockSourceError::persistent(e)))?;
+                       .map_err(BlockSourceError::persistent)?;
 
                if pow_valid_block_hash != block_hash {
                        return Err(BlockSourceError::persistent("invalid block hash"));
@@ -82,7 +82,7 @@ impl Validate for BlockData {
 
                let pow_valid_block_hash = header
                        .validate_pow(&header.target())
-                       .or_else(|e| Err(BlockSourceError::persistent(e)))?;
+                       .map_err(BlockSourceError::persistent)?;
 
                if pow_valid_block_hash != block_hash {
                        return Err(BlockSourceError::persistent("invalid block hash"));
index b9bc519b9e84aeacfb5af3cd36c352bcb99915b2..597d2a85fd51ca8fae8274ec1e6b78adcdc5c9b4 100644 (file)
@@ -106,7 +106,7 @@ impl Blockchain {
                BlockHeaderData {
                        chainwork: self.blocks[0].header.work() + Uint256::from_u64(height as u64).unwrap(),
                        height: height as u32,
-                       header: self.blocks[height].header.clone(),
+                       header: self.blocks[height].header,
                }
        }
 
@@ -162,7 +162,7 @@ impl BlockSource for Blockchain {
                                        }
 
                                        if self.filtered_blocks {
-                                               return Ok(BlockData::HeaderOnly(block.header.clone()));
+                                               return Ok(BlockData::HeaderOnly(block.header));
                                        } else {
                                                return Ok(BlockData::FullBlock(block.clone()));
                                        }
index 92c1cb5c28f5385b5eb2f37c2cbbac62b58ac398..ab9fd9cb2bc21446920360759feefec87291f774 100644 (file)
@@ -6,7 +6,6 @@ use core::num::ParseIntError;
 use core::str;
 use core::str::FromStr;
 
-use bech32;
 use bech32::{u5, FromBase32};
 
 use bitcoin_hashes::Hash;
@@ -18,7 +17,6 @@ use lightning::routing::router::{RouteHint, RouteHintHop};
 
 use num_traits::{CheckedAdd, CheckedMul};
 
-use secp256k1;
 use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
 use secp256k1::PublicKey;
 
@@ -323,9 +321,9 @@ impl FromStr for RawHrp {
                };
 
                Ok(RawHrp {
-                       currency: currency,
+                       currency,
                        raw_amount: amount,
-                       si_prefix: si_prefix,
+                       si_prefix,
                })
        }
 }
@@ -342,7 +340,7 @@ impl FromBase32 for RawDataPart {
                let tagged = parse_tagged_parts(&data[7..])?;
 
                Ok(RawDataPart {
-                       timestamp: timestamp,
+                       timestamp,
                        tagged_fields: tagged,
                })
        }
@@ -515,7 +513,7 @@ impl FromBase32 for ExpiryTime {
 
        fn from_base32(field_data: &[u5]) -> Result<ExpiryTime, ParseError> {
                match parse_int_be::<u64, u5>(field_data, 32)
-                       .map(|t| ExpiryTime::from_seconds(t))
+                       .map(ExpiryTime::from_seconds)
                {
                        Some(t) => Ok(t),
                        None => Err(ParseError::IntegerOverflowError),
@@ -540,7 +538,7 @@ impl FromBase32 for Fallback {
        type Err = ParseError;
 
        fn from_base32(field_data: &[u5]) -> Result<Fallback, ParseError> {
-               if field_data.len() < 1 {
+               if field_data.is_empty() {
                        return Err(ParseError::UnexpectedEndOfTaggedFields);
                }
 
@@ -554,7 +552,7 @@ impl FromBase32 for Fallback {
                                }
 
                                Ok(Fallback::SegWitProgram {
-                                       version: version,
+                                       version,
                                        program: bytes
                                })
                        },
index 17b6e2de2b6efe8582f9f78823289f306c9f4991..37c74922ee6957fcb1a0211808e6e13a62f18fac 100644 (file)
@@ -585,13 +585,13 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, tb
                }).collect::<Vec<_>>();
 
                let data = RawDataPart {
-                       timestamp: timestamp,
-                       tagged_fields: tagged_fields,
+                       timestamp,
+                       tagged_fields,
                };
 
                Ok(RawInvoice {
-                       hrp: hrp,
-                       data: data,
+                       hrp,
+                       data,
                })
        }
 }
@@ -781,7 +781,7 @@ impl SignedRawInvoice {
                        recovered_pub_key = Some(recovered);
                }
 
-               let pub_key = included_pub_key.or_else(|| recovered_pub_key.as_ref())
+               let pub_key = included_pub_key.or(recovered_pub_key.as_ref())
                        .expect("One is always present");
 
                let hash = Message::from_slice(&self.hash[..])
@@ -1014,9 +1014,9 @@ impl PositiveTimestamp {
 }
 
 #[cfg(feature = "std")]
-impl Into<SystemTime> for PositiveTimestamp {
-       fn into(self) -> SystemTime {
-               SystemTime::UNIX_EPOCH + self.0
+impl From<PositiveTimestamp> for SystemTime {
+       fn from(val: PositiveTimestamp) -> Self {
+               SystemTime::UNIX_EPOCH + val.0
        }
 }
 
@@ -1147,7 +1147,7 @@ impl Invoice {
        /// ```
        pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
                let invoice = Invoice {
-                       signed_invoice: signed_invoice,
+                       signed_invoice,
                };
                invoice.check_field_counts()?;
                invoice.check_feature_bits()?;
@@ -1185,9 +1185,9 @@ impl Invoice {
        ///
        /// (C-not exported) because we don't yet export InvoiceDescription
        pub fn description(&self) -> InvoiceDescription {
-               if let Some(ref direct) = self.signed_invoice.description() {
+               if let Some(direct) = self.signed_invoice.description() {
                        return InvoiceDescription::Direct(direct);
-               } else if let Some(ref hash) = self.signed_invoice.description_hash() {
+               } else if let Some(hash) = self.signed_invoice.description_hash() {
                        return InvoiceDescription::Hash(hash);
                }
                unreachable!("ensured by constructor");
@@ -1332,9 +1332,9 @@ impl Description {
        }
 }
 
-impl Into<String> for Description {
-       fn into(self) -> String {
-               self.into_inner()
+impl From<Description> for String {
+       fn from(val: Description) -> Self {
+               val.into_inner()
        }
 }
 
@@ -1398,9 +1398,9 @@ impl PrivateRoute {
        }
 }
 
-impl Into<RouteHint> for PrivateRoute {
-       fn into(self) -> RouteHint {
-               self.into_inner()
+impl From<PrivateRoute> for RouteHint {
+       fn from(val: PrivateRoute) -> Self {
+               val.into_inner()
        }
 }
 
@@ -1766,7 +1766,7 @@ mod test {
 
                // Multiple payment secrets
                let invoice = {
-                       let mut invoice = invoice_template.clone();
+                       let mut invoice = invoice_template;
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
@@ -1792,7 +1792,7 @@ mod test {
                assert_eq!(invoice.hrp.raw_amount, Some(15));
 
 
-               let invoice = builder.clone()
+               let invoice = builder
                        .amount_milli_satoshis(150)
                        .build_raw()
                        .unwrap();
@@ -1846,7 +1846,7 @@ mod test {
                        .build_raw();
                assert_eq!(long_route_res, Err(CreationError::RouteTooLong));
 
-               let sign_error_res = builder.clone()
+               let sign_error_res = builder
                        .description("Test".into())
                        .payment_secret(PaymentSecret([0; 32]))
                        .try_build_signed(|_| {
@@ -1876,7 +1876,7 @@ mod test {
 
                let route_1 = RouteHint(vec![
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: de::parse_int_be(&[123; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
                                        base_msat: 2,
@@ -1887,7 +1887,7 @@ mod test {
                                htlc_maximum_msat: None,
                        },
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: de::parse_int_be(&[42; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
                                        base_msat: 3,
@@ -1901,7 +1901,7 @@ mod test {
 
                let route_2 = RouteHint(vec![
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: 0,
                                fees: RoutingFees {
                                        base_msat: 4,
@@ -1912,7 +1912,7 @@ mod test {
                                htlc_maximum_msat: None,
                        },
                        RouteHintHop {
-                               src_node_id: public_key.clone(),
+                               src_node_id: public_key,
                                short_channel_id: de::parse_int_be(&[1; 8], 256).expect("short chan ID slice too big?"),
                                fees: RoutingFees {
                                        base_msat: 5,
@@ -1927,7 +1927,7 @@ mod test {
                let builder = InvoiceBuilder::new(Currency::BitcoinTestnet)
                        .amount_milli_satoshis(123)
                        .duration_since_epoch(Duration::from_secs(1234567))
-                       .payee_pub_key(public_key.clone())
+                       .payee_pub_key(public_key)
                        .expiry_time(Duration::from_secs(54321))
                        .min_final_cltv_expiry_delta(144)
                        .fallback(Fallback::PubKeyHash([0;20]))
index db47f9954800a2296785bdabd622aa31b7bd41c4..21a5212c4145e2e93f5b62e358759a09dae6b240 100644 (file)
@@ -144,11 +144,11 @@ fn pay_invoice_using_amount<P: Deref>(
        invoice: &Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
        payer: P
 ) -> Result<(), PaymentError> where P::Target: Payer {
-       let payment_hash = PaymentHash(invoice.payment_hash().clone().into_inner());
-       let payment_secret = Some(invoice.payment_secret().clone());
+       let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
+       let payment_secret = Some(*invoice.payment_secret());
        let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
                invoice.min_final_cltv_expiry_delta() as u32)
-               .with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
+               .with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
                .with_route_hints(invoice.route_hints());
        if let Some(features) = invoice.features() {
                payment_params = payment_params.with_features(features.clone());
@@ -204,7 +204,7 @@ where
                payment_id: PaymentId, route_params: RouteParameters, retry_strategy: Retry
        ) -> Result<(), PaymentError> {
                self.send_payment_with_retry(payment_hash, payment_secret, payment_id, route_params, retry_strategy)
-                       .map_err(|e| PaymentError::Sending(e))
+                       .map_err(PaymentError::Sending)
        }
 }
 
@@ -345,7 +345,7 @@ mod tests {
                let invoice = invoice(payment_preimage);
                let amt_msat = 10_000;
 
-               match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), &nodes[0].node) {
+               match pay_zero_value_invoice(&invoice, amt_msat, Retry::Attempts(0), nodes[0].node) {
                        Err(PaymentError::Invoice("amount unexpected")) => {},
                        _ => panic!()
                }
index f5742289118ba1e21382ad899770d9fb028831ce..a6ccf873f3d0dd2117714a51fd267f954ca7f91a 100644 (file)
@@ -47,7 +47,7 @@ impl<'a, W: WriteBase32> BytesToBase32<'a, W> {
                        self.writer.write_u5(
                                u5::try_from_u8((self.buffer & 0b11111000) >> 3 ).expect("<32")
                        )?;
-                       self.buffer = self.buffer << 5;
+                       self.buffer <<= 5;
                        self.buffer_bits -= 5;
                }
 
@@ -58,7 +58,7 @@ impl<'a, W: WriteBase32> BytesToBase32<'a, W> {
 
                self.writer.write_u5(u5::try_from_u8(from_buffer | from_byte).expect("<32"))?;
                self.buffer = byte << (5 - self.buffer_bits);
-               self.buffer_bits = 3 + self.buffer_bits;
+               self.buffer_bits += 3;
 
                Ok(())
        }
@@ -75,7 +75,7 @@ impl<'a, W: WriteBase32> BytesToBase32<'a, W> {
                        self.writer.write_u5(
                                u5::try_from_u8((self.buffer & 0b11111000) >> 3).expect("<32")
                        )?;
-                       self.buffer = self.buffer << 5;
+                       self.buffer <<= 5;
                        self.buffer_bits -= 5;
                }
 
index 868f0b297b1162da0551c8923b4ced23ab880ccb..128fd6160a06a397e39670f6ae765c970bc3c1ad 100644 (file)
@@ -141,7 +141,7 @@ where
        L::Target: Logger,
 {
 
-       if phantom_route_hints.len() == 0 {
+       if phantom_route_hints.is_empty() {
                return Err(SignOrCreationError::CreationError(
                        CreationError::MissingRouteHints,
                ));
@@ -549,11 +549,9 @@ fn filter_channels<L: Deref>(
                        }
                }
 
-               if channel.is_usable {
-                       if !online_channel_exists {
-                               log_trace!(logger, "Channel with connected peer exists for invoice route hints");
-                               online_channel_exists = true;
-                       }
+               if channel.is_usable && !online_channel_exists {
+                       log_trace!(logger, "Channel with connected peer exists for invoice route hints");
+                       online_channel_exists = true;
                }
 
                match filtered_channels.entry(channel.counterparty.node_id) {
@@ -660,7 +658,7 @@ mod test {
                create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
                let non_default_invoice_expiry_secs = 4200;
                let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "test".to_string(), Duration::from_secs(1234567),
                        non_default_invoice_expiry_secs, None).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
@@ -694,14 +692,14 @@ mod test {
                let scorer = test_utils::TestScorer::new();
                let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
                let route = find_route(
-                       &nodes[0].node.get_our_node_id(), &route_params, &network_graph,
+                       &nodes[0].node.get_our_node_id(), &route_params, network_graph,
                        Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
                ).unwrap();
 
                let payment_event = {
                        let mut payment_hash = PaymentHash([0; 32]);
                        payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
-                       nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
+                       nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
                        let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
                        assert_eq!(added_monitors.len(), 1);
                        added_monitors.clear();
@@ -728,7 +726,7 @@ mod test {
                let custom_min_final_cltv_expiry_delta = Some(50);
 
                let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
                        if with_custom_delta { custom_min_final_cltv_expiry_delta } else { None },
                ).unwrap();
@@ -751,7 +749,7 @@ mod test {
                let custom_min_final_cltv_expiry_delta = Some(21);
 
                let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "".into(), Duration::from_secs(1234567), 3600,
                        custom_min_final_cltv_expiry_delta,
                ).unwrap();
@@ -766,7 +764,7 @@ mod test {
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let description_hash = crate::Sha256(Hash::hash("Testing description_hash".as_bytes()));
                let invoice = crate::utils::create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), description_hash, Duration::from_secs(1234567), 3600, None,
                ).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
@@ -782,7 +780,7 @@ mod test {
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let payment_hash = PaymentHash([0; 32]);
                let invoice = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "test".to_string(), Duration::from_secs(1234567), 3600,
                        payment_hash, None,
                ).unwrap();
@@ -973,7 +971,7 @@ mod test {
                mut chan_ids_to_match: HashSet<u64>
        ) {
                let invoice = create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
+                       invoice_node.node, invoice_node.keys_manager, invoice_node.logger,
                        Currency::BitcoinTestnet, invoice_amt, "test".to_string(), Duration::from_secs(1234567),
                        3600, None).unwrap();
                let hints = invoice.private_routes();
@@ -995,9 +993,9 @@ mod test {
        #[cfg(feature = "std")]
        fn do_test_multi_node_receive(user_generated_pmt_hash: bool) {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1027,7 +1025,7 @@ mod test {
                let invoice =
                        crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestLogger>(
                                Some(payment_amt), payment_hash, "test".to_string(), non_default_invoice_expiry_secs,
-                               route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager, &nodes[1].logger,
+                               route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
                                Currency::BitcoinTestnet, None, Duration::from_secs(1234567)
                        ).unwrap();
                let (payment_hash, payment_secret) = (PaymentHash(invoice.payment_hash().into_inner()), *invoice.payment_secret());
@@ -1058,13 +1056,13 @@ mod test {
                let scorer = test_utils::TestScorer::new();
                let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
                let route = find_route(
-                       &nodes[0].node.get_our_node_id(), &params, &network_graph,
+                       &nodes[0].node.get_our_node_id(), &params, network_graph,
                        Some(&first_hops.iter().collect::<Vec<_>>()), &logger, &scorer, &random_seed_bytes
                ).unwrap();
                let (payment_event, fwd_idx) = {
                        let mut payment_hash = PaymentHash([0; 32]);
                        payment_hash.0.copy_from_slice(&invoice.payment_hash().as_ref()[0..32]);
-                       nodes[0].node.send_payment(&route, payment_hash, &Some(invoice.payment_secret().clone()), PaymentId(payment_hash.0)).unwrap();
+                       nodes[0].node.send_payment(&route, payment_hash, &Some(*invoice.payment_secret()), PaymentId(payment_hash.0)).unwrap();
                        let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
                        assert_eq!(added_monitors.len(), 1);
                        added_monitors.clear();
@@ -1094,7 +1092,7 @@ mod test {
 
                let payment_preimage_opt = if user_generated_pmt_hash { None } else { Some(payment_preimage) };
                expect_payment_claimable!(&nodes[fwd_idx], payment_hash, payment_secret, payment_amt, payment_preimage_opt, route.paths[0].last().unwrap().pubkey);
-               do_claim_payment_along_route(&nodes[0], &vec!(&vec!(&nodes[fwd_idx])[..]), false, payment_preimage);
+               do_claim_payment_along_route(&nodes[0], &[&vec!(&nodes[fwd_idx])[..]], false, payment_preimage);
                let events = nodes[0].node.get_and_clear_pending_events();
                assert_eq!(events.len(), 2);
                match events[0] {
@@ -1117,9 +1115,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_has_htlc_min_max_values() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1138,8 +1136,8 @@ mod test {
 
                let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
                        &test_utils::TestKeysInterface, &test_utils::TestLogger>(Some(payment_amt), Some(payment_hash),
-                               "test".to_string(), 3600, route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager,
-                               &nodes[1].logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
+                               "test".to_string(), 3600, route_hints, nodes[1].keys_manager, nodes[1].keys_manager,
+                               nodes[1].logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
 
                let chan_0_1 = &nodes[1].node.list_usable_channels()[0];
                assert_eq!(invoice.route_hints()[0].0[0].htlc_minimum_msat, chan_0_1.inbound_htlc_minimum_msat);
@@ -1170,7 +1168,7 @@ mod test {
                        &test_utils::TestKeysInterface, &test_utils::TestKeysInterface, &test_utils::TestLogger,
                >(
                        Some(payment_amt), None, non_default_invoice_expiry_secs, description_hash,
-                       route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager, &nodes[1].logger,
+                       route_hints, nodes[1].keys_manager, nodes[1].keys_manager, nodes[1].logger,
                        Currency::BitcoinTestnet, None, Duration::from_secs(1234567),
                )
                .unwrap();
@@ -1200,8 +1198,8 @@ mod test {
                let duration_since_epoch = Duration::from_secs(1234567);
                let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
                        &test_utils::TestKeysInterface, &test_utils::TestLogger>(Some(payment_amt), payment_hash,
-                               "".to_string(), non_default_invoice_expiry_secs, route_hints, &nodes[1].keys_manager, &nodes[1].keys_manager,
-                               &nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta, duration_since_epoch).unwrap();
+                               "".to_string(), non_default_invoice_expiry_secs, route_hints, nodes[1].keys_manager, nodes[1].keys_manager,
+                               nodes[1].logger, Currency::BitcoinTestnet, min_final_cltv_expiry_delta, duration_since_epoch).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(200_000));
                assert_eq!(invoice.min_final_cltv_expiry_delta(), (min_final_cltv_expiry_delta.unwrap() + 3) as u64);
                assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
@@ -1211,9 +1209,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_includes_single_channels_to_participating_nodes() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1240,9 +1238,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_includes_one_channel_of_each_counterparty_nodes_per_participating_node() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1271,9 +1269,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_forwarding_info_not_assigned_channel_excluded_from_hints() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[3].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1329,9 +1327,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_with_only_public_channels_hints_includes_only_phantom_route() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1362,9 +1360,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_with_mixed_public_and_private_channel_hints_includes_only_phantom_route() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1396,9 +1394,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_hints_has_only_highest_inbound_capacity_channel() {
                let mut chanmon_cfgs = create_chanmon_cfgs(3);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -1427,9 +1425,9 @@ mod test {
        #[cfg(feature = "std")]
        fn test_multi_node_channels_inbound_capacity_lower_than_invoice_amt_filtering() {
                let mut chanmon_cfgs = create_chanmon_cfgs(4);
-               let seed_1 = [42 as u8; 32];
-               let seed_2 = [43 as u8; 32];
-               let cross_node_seed = [44 as u8; 32];
+               let seed_1 = [42u8; 32];
+               let seed_2 = [43u8; 32];
+               let cross_node_seed = [44u8; 32];
                chanmon_cfgs[1].keys_manager.backing = PhantomKeysManager::new(&seed_1, 43, 44, &cross_node_seed);
                chanmon_cfgs[2].keys_manager.backing = PhantomKeysManager::new(&seed_2, 43, 44, &cross_node_seed);
                let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1514,8 +1512,8 @@ mod test {
 
                let invoice = crate::utils::create_phantom_invoice::<&test_utils::TestKeysInterface,
                        &test_utils::TestKeysInterface, &test_utils::TestLogger>(invoice_amt, None, "test".to_string(),
-                               3600, phantom_route_hints, &invoice_node.keys_manager, &invoice_node.keys_manager,
-                               &invoice_node.logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
+                               3600, phantom_route_hints, invoice_node.keys_manager, invoice_node.keys_manager,
+                               invoice_node.logger, Currency::BitcoinTestnet, None, Duration::from_secs(1234567)).unwrap();
 
                let invoice_hints = invoice.private_routes();
 
@@ -1546,7 +1544,7 @@ mod test {
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
                let result = crate::utils::create_invoice_from_channelmanager_and_duration_since_epoch(
-                       &nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
+                       nodes[1].node, nodes[1].keys_manager, nodes[1].logger, Currency::BitcoinTestnet,
                        Some(10_000), "Some description".into(), Duration::from_secs(1234567), 3600, Some(MIN_FINAL_CLTV_EXPIRY_DELTA - 4),
                );
                match result {
index 81e6157c656f6e39e76525e33ca09e1b55870325..a513e603efe54d2654bdce1a59a74b59fa9e9b93 100644 (file)
@@ -205,7 +205,7 @@ impl Connection {
                        tokio::select! {
                                v = write_avail_receiver.recv() => {
                                        assert!(v.is_some()); // We can't have dropped the sending end, its in the us Arc!
-                                       if let Err(_) = peer_manager.write_buffer_space_avail(&mut our_descriptor) {
+                                       if peer_manager.write_buffer_space_avail(&mut our_descriptor).is_err() {
                                                break Disconnect::CloseConnection;
                                        }
                                },
@@ -313,7 +313,7 @@ pub fn setup_inbound<PM, CMH, RMH, OMH, L, UMH, NS>(
        #[cfg(test)]
        let last_us = Arc::clone(&us);
 
-       let handle_opt = if let Ok(_) = peer_manager.new_inbound_connection(SocketDescriptor::new(us.clone()), remote_addr) {
+       let handle_opt = if peer_manager.new_inbound_connection(SocketDescriptor::new(us.clone()), remote_addr).is_ok() {
                Some(tokio::spawn(Connection::schedule_read(peer_manager, us, reader, read_receiver, write_receiver)))
        } else {
                // Note that we will skip socket_disconnected here, in accordance with the PeerManager
index aaa3ef73d6c6f0e40f51a4c3684d0b4e1ced054b..488378576e5c24ca22bcc5b5de99514e94c8af6a 100644 (file)
@@ -176,7 +176,7 @@ mod tests {
 
                let chanmon_cfgs = create_chanmon_cfgs(1);
                let mut node_cfgs = create_node_cfgs(1, &chanmon_cfgs);
-               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister, &node_cfgs[0].keys_manager);
+               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister, node_cfgs[0].keys_manager);
                node_cfgs[0].chain_monitor = chain_mon_0;
                let node_chanmgrs = create_node_chanmgrs(1, &node_cfgs, &[None]);
                let nodes = create_network(1, &node_cfgs, &node_chanmgrs);
@@ -196,8 +196,8 @@ mod tests {
                let persister_1 = FilesystemPersister::new("test_filesystem_persister_1".to_string());
                let chanmon_cfgs = create_chanmon_cfgs(2);
                let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
-               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister_0, &node_cfgs[0].keys_manager);
-               let chain_mon_1 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[1].chain_source), &chanmon_cfgs[1].tx_broadcaster, &chanmon_cfgs[1].logger, &chanmon_cfgs[1].fee_estimator, &persister_1, &node_cfgs[1].keys_manager);
+               let chain_mon_0 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[0].chain_source), &chanmon_cfgs[0].tx_broadcaster, &chanmon_cfgs[0].logger, &chanmon_cfgs[0].fee_estimator, &persister_0, node_cfgs[0].keys_manager);
+               let chain_mon_1 = test_utils::TestChainMonitor::new(Some(&chanmon_cfgs[1].chain_source), &chanmon_cfgs[1].tx_broadcaster, &chanmon_cfgs[1].logger, &chanmon_cfgs[1].fee_estimator, &persister_1, node_cfgs[1].keys_manager);
                node_cfgs[0].chain_monitor = chain_mon_0;
                node_cfgs[1].chain_monitor = chain_mon_1;
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
index 4adbb33e5b26fd886fb64d05d3d315efd3f28b16..20c4a8151854a4e2b1b51183487305e374d95f89 100644 (file)
@@ -102,10 +102,10 @@ mod tests {
                let test_writeable = TestWriteable{};
                let filename = "test_readonly_dir_persister_filename".to_string();
                let path = "test_readonly_dir_persister_dir";
-               fs::create_dir_all(path.to_string()).unwrap();
-               let mut perms = fs::metadata(path.to_string()).unwrap().permissions();
+               fs::create_dir_all(path).unwrap();
+               let mut perms = fs::metadata(path).unwrap().permissions();
                perms.set_readonly(true);
-               fs::set_permissions(path.to_string(), perms).unwrap();
+               fs::set_permissions(path, perms).unwrap();
                let mut dest_file = PathBuf::from(path);
                dest_file.push(filename);
                match write_to_file(dest_file, &test_writeable) {
index 3bceb2e28e9239c0a7e8b34790275d4f51f064e2..8b8323728c316f342d60d2158a1f5a9f0791ad94 100644 (file)
@@ -181,18 +181,17 @@ mod tests {
                                fs::create_dir_all(graph_sync_test_directory).unwrap();
 
                                let graph_sync_test_file = test.get_test_file_path();
-                               fs::write(&graph_sync_test_file, valid_response).unwrap();
+                               fs::write(graph_sync_test_file, valid_response).unwrap();
 
                                test
                        }
+
                        fn get_test_directory(&self) -> String {
-                               let graph_sync_test_directory = self.directory.clone() + "/graph-sync-tests";
-                               graph_sync_test_directory
+                               self.directory.clone() + "/graph-sync-tests"
                        }
+
                        fn get_test_file_path(&self) -> String {
-                               let graph_sync_test_directory = self.get_test_directory();
-                               let graph_sync_test_file = graph_sync_test_directory.to_owned() + "/test_data.lngossip";
-                               graph_sync_test_file
+                               self.get_test_directory() + "/test_data.lngossip"
                        }
                }