From: Allan Douglas R. de Oliveira Date: Mon, 27 Feb 2023 18:24:57 +0000 (+0000) Subject: Run clippy --fix and cleanup code X-Git-Tag: v0.0.115~74^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=57017dfc0b610ef6095cb69ef50bd13274d5a2c8;p=rust-lightning Run clippy --fix and cleanup code --- diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index 8711a4aeb..ea369382a 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -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 diff --git a/lightning-block-sync/src/init.rs b/lightning-block-sync/src/init.rs index 2807bc877..866b247ed 100644 --- a/lightning-block-sync/src/init.rs +++ b/lightning-block-sync/src/init.rs @@ -181,7 +181,7 @@ pub async fn synchronize_listeners 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); }, } diff --git a/lightning-block-sync/src/poll.rs b/lightning-block-sync/src/poll.rs index 05ccd4504..9f7e8becf 100644 --- a/lightning-block-sync/src/poll.rs +++ b/lightning-block-sync/src/poll.rs @@ -61,7 +61,7 @@ impl Validate for BlockHeaderData { fn validate(self, block_hash: BlockHash) -> BlockSourceResult { 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")); diff --git a/lightning-block-sync/src/test_utils.rs b/lightning-block-sync/src/test_utils.rs index b9bc519b9..597d2a85f 100644 --- a/lightning-block-sync/src/test_utils.rs +++ b/lightning-block-sync/src/test_utils.rs @@ -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())); } diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index 92c1cb5c2..ab9fd9cb2 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -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 { match parse_int_be::(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 { - 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 }) }, diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index 17b6e2de2..37c74922e 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -585,13 +585,13 @@ impl InvoiceBuilder>(); 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 for PositiveTimestamp { - fn into(self) -> SystemTime { - SystemTime::UNIX_EPOCH + self.0 +impl From 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 { 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 for Description { - fn into(self) -> String { - self.into_inner() +impl From for String { + fn from(val: Description) -> Self { + val.into_inner() } } @@ -1398,9 +1398,9 @@ impl PrivateRoute { } } -impl Into for PrivateRoute { - fn into(self) -> RouteHint { - self.into_inner() +impl From 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])) diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index db47f9954..21a5212c4 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -144,11 +144,11 @@ fn pay_invoice_using_amount( 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!() } diff --git a/lightning-invoice/src/ser.rs b/lightning-invoice/src/ser.rs index f57422891..a6ccf873f 100644 --- a/lightning-invoice/src/ser.rs +++ b/lightning-invoice/src/ser.rs @@ -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; } diff --git a/lightning-invoice/src/utils.rs b/lightning-invoice/src/utils.rs index 868f0b297..128fd6160 100644 --- a/lightning-invoice/src/utils.rs +++ b/lightning-invoice/src/utils.rs @@ -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( } } - 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::>()), &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 ) { 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(), ¶ms, &network_graph, + &nodes[0].node.get_our_node_id(), ¶ms, network_graph, Some(&first_hops.iter().collect::>()), &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 { diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 81e6157c6..a513e603e 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -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( #[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 diff --git a/lightning-persister/src/lib.rs b/lightning-persister/src/lib.rs index aaa3ef73d..488378576 100644 --- a/lightning-persister/src/lib.rs +++ b/lightning-persister/src/lib.rs @@ -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]); diff --git a/lightning-persister/src/util.rs b/lightning-persister/src/util.rs index 4adbb33e5..20c4a8151 100644 --- a/lightning-persister/src/util.rs +++ b/lightning-persister/src/util.rs @@ -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) { diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index 3bceb2e28..8b8323728 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -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" } }