From 4cd92bfcf98a464cd15567928b81d109e3b8f104 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 7 Jan 2020 19:42:33 -0500 Subject: [PATCH] rustfmt: apply fn_single_line to codebase --- lightning-net-tokio/src/lib.rs | 8 +- lightning/src/chain/chaininterface.rs | 4 +- lightning/src/chain/keysinterface.rs | 36 ++---- lightning/src/chain/transaction.rs | 4 +- lightning/src/ln/chan_utils.rs | 12 +- lightning/src/ln/channel.rs | 96 ++++----------- lightning/src/ln/channelmanager.rs | 4 +- lightning/src/ln/channelmonitor.rs | 8 +- lightning/src/ln/functional_tests.rs | 8 +- lightning/src/ln/msgs.rs | 126 +++++++++----------- lightning/src/ln/peer_handler.rs | 16 +-- lightning/src/ln/router.rs | 20 +--- lightning/src/util/chacha20.rs | 20 +--- lightning/src/util/enforcing_trait_impls.rs | 24 +--- lightning/src/util/logger.rs | 36 ++---- lightning/src/util/ser.rs | 40 ++----- lightning/src/util/test_utils.rs | 44 ++----- lightning/src/util/transaction_utils.rs | 4 +- 18 files changed, 150 insertions(+), 360 deletions(-) diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index 55def4159ad..5db51c96646 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -309,12 +309,8 @@ impl peer_handler::SocketDescriptor for SocketDescriptor { } impl Eq for SocketDescriptor {} impl PartialEq for SocketDescriptor { - fn eq(&self, o: &Self) -> bool { - self.id == o.id - } + fn eq(&self, o: &Self) -> bool { self.id == o.id } } impl Hash for SocketDescriptor { - fn hash(&self, state: &mut H) { - self.id.hash(state); - } + fn hash(&self, state: &mut H) { self.id.hash(state); } } diff --git a/lightning/src/chain/chaininterface.rs b/lightning/src/chain/chaininterface.rs index 4065ebe9ec0..45fe3fed0e8 100644 --- a/lightning/src/chain/chaininterface.rs +++ b/lightning/src/chain/chaininterface.rs @@ -345,9 +345,7 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil { (matched, matched_index) } - fn reentered(&self) -> usize { - self.reentered.load(Ordering::Relaxed) - } + fn reentered(&self) -> usize { self.reentered.load(Ordering::Relaxed) } } impl ChainWatchInterfaceUtil { diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 643e9134892..e457bdafd06 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -194,24 +194,12 @@ pub struct InMemoryChannelKeys { } impl ChannelKeys for InMemoryChannelKeys { - fn funding_key(&self) -> &SecretKey { - &self.funding_key - } - fn revocation_base_key(&self) -> &SecretKey { - &self.revocation_base_key - } - fn payment_base_key(&self) -> &SecretKey { - &self.payment_base_key - } - fn delayed_payment_base_key(&self) -> &SecretKey { - &self.delayed_payment_base_key - } - fn htlc_base_key(&self) -> &SecretKey { - &self.htlc_base_key - } - fn commitment_seed(&self) -> &[u8; 32] { - &self.commitment_seed - } + fn funding_key(&self) -> &SecretKey { &self.funding_key } + fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key } + fn payment_base_key(&self) -> &SecretKey { &self.payment_base_key } + fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key } + fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key } + fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed } fn sign_remote_commitment(&self, channel_value_satoshis: u64, @@ -418,17 +406,11 @@ impl KeysManager { impl KeysInterface for KeysManager { type ChanKeySigner = InMemoryChannelKeys; - fn get_node_secret(&self) -> SecretKey { - self.node_secret.clone() - } + fn get_node_secret(&self) -> SecretKey { self.node_secret.clone() } - fn get_destination_script(&self) -> Script { - self.destination_script.clone() - } + fn get_destination_script(&self) -> Script { self.destination_script.clone() } - fn get_shutdown_pubkey(&self) -> PublicKey { - self.shutdown_pubkey.clone() - } + fn get_shutdown_pubkey(&self) -> PublicKey { self.shutdown_pubkey.clone() } fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys { // We only seriously intend to rely on the channel_master_key for true secure diff --git a/lightning/src/chain/transaction.rs b/lightning/src/chain/transaction.rs index 8cacf6d83f2..6d7b3b1d615 100644 --- a/lightning/src/chain/transaction.rs +++ b/lightning/src/chain/transaction.rs @@ -17,9 +17,7 @@ pub struct OutPoint { impl OutPoint { /// Creates a new `OutPoint` from the txid and the index. - pub fn new(txid: Sha256dHash, index: u16) -> OutPoint { - OutPoint { txid, index } - } + pub fn new(txid: Sha256dHash, index: u16) -> OutPoint { OutPoint { txid, index } } /// Convert an `OutPoint` to a lightning channel id. pub fn to_channel_id(&self) -> [u8; 32] { diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs index 116b4ada3f4..431e96e6340 100644 --- a/lightning/src/ln/chan_utils.rs +++ b/lightning/src/ln/chan_utils.rs @@ -423,9 +423,7 @@ impl LocalCommitmentTransaction { Self { tx } } - pub fn txid(&self) -> Sha256dHash { - self.tx.txid() - } + pub fn txid(&self) -> Sha256dHash { self.tx.txid() } pub fn has_local_sig(&self) -> bool { if self.tx.input.len() != 1 { @@ -471,9 +469,7 @@ impl LocalCommitmentTransaction { self.tx.input[0].witness.push(funding_redeemscript.as_bytes().to_vec()); } - pub fn without_valid_witness(&self) -> &Transaction { - &self.tx - } + pub fn without_valid_witness(&self) -> &Transaction { &self.tx } pub fn with_valid_witness(&self) -> &Transaction { assert!(self.has_local_sig()); &self.tx @@ -481,9 +477,7 @@ impl LocalCommitmentTransaction { } impl PartialEq for LocalCommitmentTransaction { // We dont care whether we are signed in equality comparison - fn eq(&self, o: &Self) -> bool { - self.txid() == o.txid() - } + fn eq(&self, o: &Self) -> bool { self.txid() == o.txid() } } impl Writeable for LocalCommitmentTransaction { fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index fccc1877da4..91a731d97de 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -3595,15 +3595,11 @@ impl Channel { // Public utilities: - pub fn channel_id(&self) -> [u8; 32] { - self.channel_id - } + pub fn channel_id(&self) -> [u8; 32] { self.channel_id } /// Gets the "user_id" value passed into the construction of this channel. It has no special /// meaning and exists only to allow users to have a persistent identifier of a channel. - pub fn get_user_id(&self) -> u64 { - self.user_id - } + pub fn get_user_id(&self) -> u64 { self.user_id } /// May only be called after funding has been initiated (ie is_funding_initiated() is true) pub fn channel_monitor(&mut self) -> &mut ChannelMonitor { @@ -3616,43 +3612,27 @@ impl Channel { /// Guaranteed to be Some after both FundingLocked messages have been exchanged (and, thus, /// is_usable() returns true). /// Allowed in any state (including after shutdown) - pub fn get_short_channel_id(&self) -> Option { - self.short_channel_id - } + pub fn get_short_channel_id(&self) -> Option { self.short_channel_id } /// Returns the funding_txo we either got from our peer, or were given by /// get_outbound_funding_created. - pub fn get_funding_txo(&self) -> Option { - self.channel_monitor.get_funding_txo() - } + pub fn get_funding_txo(&self) -> Option { self.channel_monitor.get_funding_txo() } /// Allowed in any state (including after shutdown) - pub fn get_their_node_id(&self) -> PublicKey { - self.their_node_id - } + pub fn get_their_node_id(&self) -> PublicKey { self.their_node_id } /// Allowed in any state (including after shutdown) - pub fn get_our_htlc_minimum_msat(&self) -> u64 { - self.our_htlc_minimum_msat - } + pub fn get_our_htlc_minimum_msat(&self) -> u64 { self.our_htlc_minimum_msat } /// Allowed in any state (including after shutdown) - pub fn get_their_htlc_minimum_msat(&self) -> u64 { - self.our_htlc_minimum_msat - } + pub fn get_their_htlc_minimum_msat(&self) -> u64 { self.our_htlc_minimum_msat } - pub fn get_value_satoshis(&self) -> u64 { - self.channel_value_satoshis - } + pub fn get_value_satoshis(&self) -> u64 { self.channel_value_satoshis } - pub fn get_fee_proportional_millionths(&self) -> u32 { - self.config.fee_proportional_millionths - } + pub fn get_fee_proportional_millionths(&self) -> u32 { self.config.fee_proportional_millionths } #[cfg(test)] - pub fn get_feerate(&self) -> u64 { - self.feerate_per_kw - } + pub fn get_feerate(&self) -> u64 { self.feerate_per_kw } pub fn get_cur_local_commitment_transaction_number(&self) -> u64 { self.cur_local_commitment_transaction_number + 1 @@ -3672,9 +3652,7 @@ impl Channel { } #[cfg(test)] - pub fn get_local_keys(&self) -> &ChanSigner { - &self.local_keys - } + pub fn get_local_keys(&self) -> &ChanSigner { &self.local_keys } #[cfg(test)] pub fn get_value_stat(&self) -> ChannelValueStat { @@ -3705,17 +3683,11 @@ impl Channel { } /// Allowed in any state (including after shutdown) - pub fn get_channel_update_count(&self) -> u32 { - self.channel_update_count - } + pub fn get_channel_update_count(&self) -> u32 { self.channel_update_count } - pub fn should_announce(&self) -> bool { - self.config.announced_channel - } + pub fn should_announce(&self) -> bool { self.config.announced_channel } - pub fn is_outbound(&self) -> bool { - self.channel_outbound - } + pub fn is_outbound(&self) -> bool { self.channel_outbound } /// Gets the fee we'd want to charge for adding an HTLC output to this Channel /// Allowed in any state (including after shutdown) @@ -3740,9 +3712,7 @@ impl Channel { } /// Returns true if we've ever received a message from the remote end for this Channel - pub fn have_received_message(&self) -> bool { - self.channel_state > (ChannelState::OurInitSent as u32) - } + pub fn have_received_message(&self) -> bool { self.channel_state > (ChannelState::OurInitSent as u32) } /// Returns true if this channel is fully established and not known to be closing. /// Allowed in any state (including after shutdown) @@ -3767,9 +3737,7 @@ impl Channel { } /// Returns true if funding_created was sent/received. - pub fn is_funding_initiated(&self) -> bool { - self.channel_state >= ChannelState::FundingCreated as u32 - } + pub fn is_funding_initiated(&self) -> bool { self.channel_state >= ChannelState::FundingCreated as u32 } /// Returns true if this channel is fully shut down. True here implies that no further actions /// may/will be taken on this channel, and thus this object should be freed. Any future changes @@ -3783,25 +3751,15 @@ impl Channel { } } - pub fn to_disabled_staged(&mut self) { - self.network_sync = UpdateStatus::DisabledStaged; - } + pub fn to_disabled_staged(&mut self) { self.network_sync = UpdateStatus::DisabledStaged; } - pub fn to_disabled_marked(&mut self) { - self.network_sync = UpdateStatus::DisabledMarked; - } + pub fn to_disabled_marked(&mut self) { self.network_sync = UpdateStatus::DisabledMarked; } - pub fn to_fresh(&mut self) { - self.network_sync = UpdateStatus::Fresh; - } + pub fn to_fresh(&mut self) { self.network_sync = UpdateStatus::Fresh; } - pub fn is_disabled_staged(&self) -> bool { - self.network_sync == UpdateStatus::DisabledStaged - } + pub fn is_disabled_staged(&self) -> bool { self.network_sync == UpdateStatus::DisabledStaged } - pub fn is_disabled_marked(&self) -> bool { - self.network_sync == UpdateStatus::DisabledMarked - } + pub fn is_disabled_marked(&self) -> bool { self.network_sync == UpdateStatus::DisabledMarked } /// Called by channelmanager based on chain blocks being connected. /// Note that we only need to use this to detect funding_signed, anything else is handled by @@ -5116,9 +5074,7 @@ mod tests { fee_est: u64, } impl FeeEstimator for TestFeeEstimator { - fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 { - self.fee_est - } + fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 { self.fee_est } } #[test] @@ -5160,15 +5116,11 @@ mod tests { PublicKey::from_secret_key(&secp_ctx, &channel_close_key) } - fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys { - self.chan_keys.clone() - } + fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys { self.chan_keys.clone() } fn get_onion_rand(&self) -> (SecretKey, [u8; 32]) { panic!(); } - fn get_channel_id(&self) -> [u8; 32] { - [0; 32] - } + fn get_channel_id(&self) -> [u8; 32] { [0; 32] } } #[test] diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index ba4bf5061aa..b0bb11d33a3 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2012,9 +2012,7 @@ impl ChannelManager { } /// Gets the node_id held by this ChannelManager - pub fn get_our_node_id(&self) -> PublicKey { - PublicKey::from_secret_key(&self.secp_ctx, &self.our_network_key) - } + pub fn get_our_node_id(&self) -> PublicKey { PublicKey::from_secret_key(&self.secp_ctx, &self.our_network_key) } /// Used to restore channels to normal operation after a /// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 151751d43a7..0bba6311682 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -1447,9 +1447,7 @@ impl ChannelMonitor { /// the "reorg path" (ie not just starting at the same height but starting at the highest /// common block that appears on your best chain as well as on the chain which contains the /// last block hash returned) upon deserializing the object! - pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, true) - } + pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { self.write(writer, true) } /// Encodes this monitor into the given writer, suitable for sending to a remote watchtower /// @@ -1484,9 +1482,7 @@ impl ChannelMonitor { min } - pub(super) fn get_cur_remote_commitment_number(&self) -> u64 { - self.current_remote_commitment_number - } + pub(super) fn get_cur_remote_commitment_number(&self) -> u64 { self.current_remote_commitment_number } pub(super) fn get_cur_local_commitment_number(&self) -> u64 { if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx { diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index ad9e8369879..47d808f237c 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -6579,14 +6579,10 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno } #[test] -fn test_fail_backwards_latest_remote_announce_a() { - do_test_fail_backwards_unrevoked_remote_announce(false, true); -} +fn test_fail_backwards_latest_remote_announce_a() { do_test_fail_backwards_unrevoked_remote_announce(false, true); } #[test] -fn test_fail_backwards_latest_remote_announce_b() { - do_test_fail_backwards_unrevoked_remote_announce(true, true); -} +fn test_fail_backwards_latest_remote_announce_b() { do_test_fail_backwards_unrevoked_remote_announce(true, true); } #[test] fn test_fail_backwards_previous_remote_announce() { diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 1d30453647a..7107f173b85 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -61,20 +61,12 @@ pub struct LocalFeatures { impl LocalFeatures { /// Create a blank LocalFeatures flags (visibility extended for fuzz tests) #[cfg(not(feature = "fuzztarget"))] - pub(crate) fn new() -> LocalFeatures { - LocalFeatures { flags: vec![2 | 1 << 5] } - } + pub(crate) fn new() -> LocalFeatures { LocalFeatures { flags: vec![2 | 1 << 5] } } #[cfg(feature = "fuzztarget")] - pub fn new() -> LocalFeatures { - LocalFeatures { flags: vec![2 | 1 << 5] } - } + pub fn new() -> LocalFeatures { LocalFeatures { flags: vec![2 | 1 << 5] } } - pub(crate) fn supports_data_loss_protect(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & 3) != 0 - } - pub(crate) fn initial_routing_sync(&self) -> bool { - self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0 - } + pub(crate) fn supports_data_loss_protect(&self) -> bool { self.flags.len() > 0 && (self.flags[0] & 3) != 0 } + pub(crate) fn initial_routing_sync(&self) -> bool { self.flags.len() > 0 && (self.flags[0] & (1 << 3)) != 0 } pub(crate) fn set_initial_routing_sync(&mut self) { if self.flags.len() == 0 { self.flags.resize(1, 1 << 3); @@ -87,9 +79,7 @@ impl LocalFeatures { self.flags.len() > 0 && (self.flags[0] & (3 << 4)) != 0 } #[cfg(test)] - pub(crate) fn unset_upfront_shutdown_script(&mut self) { - self.flags[0] ^= 1 << 5; - } + pub(crate) fn unset_upfront_shutdown_script(&mut self) { self.flags[0] ^= 1 << 5; } pub(crate) fn requires_unknown_bits(&self) -> bool { self.flags @@ -117,9 +107,7 @@ pub struct GlobalFeatures { } impl GlobalFeatures { - pub(crate) fn new() -> GlobalFeatures { - GlobalFeatures { flags: Vec::new() } - } + pub(crate) fn new() -> GlobalFeatures { GlobalFeatures { flags: Vec::new() } } pub(crate) fn requires_unknown_bits(&self) -> bool { for &byte in self.flags.iter() { @@ -759,15 +747,11 @@ impl Error for DecodeError { } } impl fmt::Display for DecodeError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.description()) - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(self.description()) } } impl fmt::Debug for LightningError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.err) - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(self.err) } } impl From<::std::io::Error> for DecodeError { @@ -1792,38 +1776,37 @@ mod tests { "0606060606060606060606060606060606060606060606060606060606060606", secp_ctx ); - let open_channel = - msgs::OpenChannel { chain_hash: if !non_bitcoin_chain_hash { - Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() - } else { - Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() - }, - temporary_channel_id: [2; 32], - funding_satoshis: 1311768467284833366, - push_msat: 2536655962884945560, - dust_limit_satoshis: 3608586615801332854, - max_htlc_value_in_flight_msat: 8517154655701053848, - channel_reserve_satoshis: 8665828695742877976, - htlc_minimum_msat: 2316138423780173, - feerate_per_kw: 821716, - to_self_delay: 49340, - max_accepted_htlcs: 49340, - funding_pubkey: pubkey_1, - revocation_basepoint: pubkey_2, - payment_basepoint: pubkey_3, - delayed_payment_basepoint: pubkey_4, - htlc_basepoint: pubkey_5, - first_per_commitment_point: pubkey_6, - channel_flags: if random_bit { 1 << 5 } else { 0 }, - shutdown_scriptpubkey: if shutdown { - OptionalField::Present(Address::p2pkh( + let open_channel = msgs::OpenChannel { chain_hash: if !non_bitcoin_chain_hash { + Sha256dHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap() + } else { + Sha256dHash::from_hex("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943").unwrap() + }, + temporary_channel_id: [2; 32], + funding_satoshis: 1311768467284833366, + push_msat: 2536655962884945560, + dust_limit_satoshis: 3608586615801332854, + max_htlc_value_in_flight_msat: 8517154655701053848, + channel_reserve_satoshis: 8665828695742877976, + htlc_minimum_msat: 2316138423780173, + feerate_per_kw: 821716, + to_self_delay: 49340, + max_accepted_htlcs: 49340, + funding_pubkey: pubkey_1, + revocation_basepoint: pubkey_2, + payment_basepoint: pubkey_3, + delayed_payment_basepoint: pubkey_4, + htlc_basepoint: pubkey_5, + first_per_commitment_point: pubkey_6, + channel_flags: if random_bit { 1 << 5 } else { 0 }, + shutdown_scriptpubkey: if shutdown { + OptionalField::Present(Address::p2pkh( &::bitcoin::PublicKey { compressed: true, key: pubkey_1, }, Network::Testnet, ).script_pubkey()) - } else { - OptionalField::Absent - } }; + } else { + OptionalField::Absent + } }; let encoded_value = open_channel.encode(); let mut target_value = Vec::new(); if non_bitcoin_chain_hash { @@ -1880,30 +1863,29 @@ mod tests { "0606060606060606060606060606060606060606060606060606060606060606", secp_ctx ); - let accept_channel = - msgs::AcceptChannel { temporary_channel_id: [2; 32], - dust_limit_satoshis: 1311768467284833366, - max_htlc_value_in_flight_msat: 2536655962884945560, - channel_reserve_satoshis: 3608586615801332854, - htlc_minimum_msat: 2316138423780173, - minimum_depth: 821716, - to_self_delay: 49340, - max_accepted_htlcs: 49340, - funding_pubkey: pubkey_1, - revocation_basepoint: pubkey_2, - payment_basepoint: pubkey_3, - delayed_payment_basepoint: pubkey_4, - htlc_basepoint: pubkey_5, - first_per_commitment_point: pubkey_6, - shutdown_scriptpubkey: if shutdown { - OptionalField::Present(Address::p2pkh( + let accept_channel = msgs::AcceptChannel { temporary_channel_id: [2; 32], + dust_limit_satoshis: 1311768467284833366, + max_htlc_value_in_flight_msat: 2536655962884945560, + channel_reserve_satoshis: 3608586615801332854, + htlc_minimum_msat: 2316138423780173, + minimum_depth: 821716, + to_self_delay: 49340, + max_accepted_htlcs: 49340, + funding_pubkey: pubkey_1, + revocation_basepoint: pubkey_2, + payment_basepoint: pubkey_3, + delayed_payment_basepoint: pubkey_4, + htlc_basepoint: pubkey_5, + first_per_commitment_point: pubkey_6, + shutdown_scriptpubkey: if shutdown { + OptionalField::Present(Address::p2pkh( &::bitcoin::PublicKey { compressed: true, key: pubkey_1, }, Network::Testnet, ).script_pubkey()) - } else { - OptionalField::Absent - } }; + } else { + OptionalField::Absent + } }; let encoded_value = accept_channel.encode(); let mut target_value = hex::decode("020202020202020202020202020202020202020202020202020202020202020212345678901234562334032891223698321446687011447600083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap(); if shutdown { diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 7beed89b805..7ac6227bf53 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -88,9 +88,7 @@ impl fmt::Display for PeerHandleError { } } impl error::Error for PeerHandleError { - fn description(&self) -> &str { - "Peer Sent Invalid Data" - } + fn description(&self) -> &str { "Peer Sent Invalid Data" } } enum InitSyncTracker { @@ -187,9 +185,7 @@ impl Writer for VecWriter { self.0.extend_from_slice(buf); Ok(()) } - fn size_hint(&mut self, size: usize) { - self.0.reserve_exact(size); - } + fn size_hint(&mut self, size: usize) { self.0.reserve_exact(size); } } macro_rules! encode_msg { @@ -1297,9 +1293,7 @@ impl PeerManager { /// but must NOT be called if a PeerHandleError was provided out of a new_\*\_connection event! /// /// Panics if the descriptor was not previously registered in a successful new_*_connection event. - pub fn disconnect_event(&self, descriptor: &Descriptor) { - self.disconnect_event_internal(descriptor, false); - } + pub fn disconnect_event(&self, descriptor: &Descriptor) { self.disconnect_event_internal(descriptor, false); } fn disconnect_event_internal(&self, descriptor: &Descriptor, no_connection_possible: bool) { let mut peers = self.peers.lock().unwrap(); @@ -1381,9 +1375,7 @@ mod tests { } impl SocketDescriptor for FileDescriptor { - fn send_data(&mut self, data: &[u8], _resume_read: bool) -> usize { - data.len() - } + fn send_data(&mut self, data: &[u8], _resume_read: bool) -> usize { data.len() } fn disconnect_socket(&mut self) {} } diff --git a/lightning/src/ln/router.rs b/lightning/src/ln/router.rs index bbdf67ac52b..a4733a9ba0f 100644 --- a/lightning/src/ln/router.rs +++ b/lightning/src/ln/router.rs @@ -304,27 +304,19 @@ impl std::fmt::Display for NetworkMap { impl NetworkMap { #[cfg(feature = "non_bitcoin_chain_hash_routing")] #[inline] - fn get_key(short_channel_id: u64, chain_hash: Sha256dHash) -> (u64, Sha256dHash) { - (short_channel_id, chain_hash) - } + fn get_key(short_channel_id: u64, chain_hash: Sha256dHash) -> (u64, Sha256dHash) { (short_channel_id, chain_hash) } #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))] #[inline] - fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 { - short_channel_id - } + fn get_key(short_channel_id: u64, _: Sha256dHash) -> u64 { short_channel_id } #[cfg(feature = "non_bitcoin_chain_hash_routing")] #[inline] - fn get_short_id(id: &(u64, Sha256dHash)) -> &u64 { - &id.0 - } + fn get_short_id(id: &(u64, Sha256dHash)) -> &u64 { &id.0 } #[cfg(not(feature = "non_bitcoin_chain_hash_routing"))] #[inline] - fn get_short_id(id: &u64) -> &u64 { - id - } + fn get_short_id(id: &u64) -> &u64 { id } } /// A channel descriptor which provides a last-hop route to get_route @@ -786,9 +778,7 @@ impl cmp::Ord for RouteGraphNode { } impl cmp::PartialOrd for RouteGraphNode { - fn partial_cmp(&self, other: &RouteGraphNode) -> Option { - Some(self.cmp(other)) - } + fn partial_cmp(&self, other: &RouteGraphNode) -> Option { Some(self.cmp(other)) } } struct DummyDirectionalChannelInfo { diff --git a/lightning/src/util/chacha20.rs b/lightning/src/util/chacha20.rs index 34ddb8bb456..9ba053d8948 100644 --- a/lightning/src/util/chacha20.rs +++ b/lightning/src/util/chacha20.rs @@ -41,21 +41,15 @@ mod real_chacha { } impl ::std::ops::BitXor for u32x4 { type Output = u32x4; - fn bitxor(self, rhs: u32x4) -> u32x4 { - u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3) - } + fn bitxor(self, rhs: u32x4) -> u32x4 { u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3) } } impl ::std::ops::Shr for u32x4 { type Output = u32x4; - fn shr(self, rhs: u32x4) -> u32x4 { - u32x4(self.0 >> rhs.0, self.1 >> rhs.1, self.2 >> rhs.2, self.3 >> rhs.3) - } + fn shr(self, rhs: u32x4) -> u32x4 { u32x4(self.0 >> rhs.0, self.1 >> rhs.1, self.2 >> rhs.2, self.3 >> rhs.3) } } impl ::std::ops::Shl for u32x4 { type Output = u32x4; - fn shl(self, rhs: u32x4) -> u32x4 { - u32x4(self.0 << rhs.0, self.1 << rhs.1, self.2 << rhs.2, self.3 << rhs.3) - } + fn shl(self, rhs: u32x4) -> u32x4 { u32x4(self.0 << rhs.0, self.1 << rhs.1, self.2 << rhs.2, self.3 << rhs.3) } } #[derive(Clone, Copy)] @@ -74,9 +68,7 @@ mod real_chacha { } impl Clone for ChaCha20 { - fn clone(&self) -> ChaCha20 { - *self - } + fn clone(&self) -> ChaCha20 { *self } } macro_rules! swizzle { @@ -268,9 +260,7 @@ mod fuzzy_chacha { Self {} } - pub fn process(&mut self, input: &[u8], output: &mut [u8]) { - output.copy_from_slice(input); - } + pub fn process(&mut self, input: &[u8], output: &mut [u8]) { output.copy_from_slice(input); } } } #[cfg(feature = "fuzztarget")] diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index 481a75d1027..80590830f16 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -26,24 +26,12 @@ impl EnforcingChannelKeys { } } impl ChannelKeys for EnforcingChannelKeys { - fn funding_key(&self) -> &SecretKey { - self.inner.funding_key() - } - fn revocation_base_key(&self) -> &SecretKey { - self.inner.revocation_base_key() - } - fn payment_base_key(&self) -> &SecretKey { - self.inner.payment_base_key() - } - fn delayed_payment_base_key(&self) -> &SecretKey { - self.inner.delayed_payment_base_key() - } - fn htlc_base_key(&self) -> &SecretKey { - self.inner.htlc_base_key() - } - fn commitment_seed(&self) -> &[u8; 32] { - self.inner.commitment_seed() - } + fn funding_key(&self) -> &SecretKey { self.inner.funding_key() } + fn revocation_base_key(&self) -> &SecretKey { self.inner.revocation_base_key() } + fn payment_base_key(&self) -> &SecretKey { self.inner.payment_base_key() } + fn delayed_payment_base_key(&self) -> &SecretKey { self.inner.delayed_payment_base_key() } + fn htlc_base_key(&self) -> &SecretKey { self.inner.htlc_base_key() } + fn commitment_seed(&self) -> &[u8; 32] { self.inner.commitment_seed() } fn sign_remote_commitment(&self, channel_value_satoshis: u64, diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index 108b2b9163e..a0b81e3f330 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -39,50 +39,34 @@ pub enum Level { impl PartialOrd for Level { #[inline] - fn partial_cmp(&self, other: &Level) -> Option { - Some(self.cmp(other)) - } + fn partial_cmp(&self, other: &Level) -> Option { Some(self.cmp(other)) } #[inline] - fn lt(&self, other: &Level) -> bool { - (*self as usize) < *other as usize - } + fn lt(&self, other: &Level) -> bool { (*self as usize) < *other as usize } #[inline] - fn le(&self, other: &Level) -> bool { - *self as usize <= *other as usize - } + fn le(&self, other: &Level) -> bool { *self as usize <= *other as usize } #[inline] - fn gt(&self, other: &Level) -> bool { - *self as usize > *other as usize - } + fn gt(&self, other: &Level) -> bool { *self as usize > *other as usize } #[inline] - fn ge(&self, other: &Level) -> bool { - *self as usize >= *other as usize - } + fn ge(&self, other: &Level) -> bool { *self as usize >= *other as usize } } impl Ord for Level { #[inline] - fn cmp(&self, other: &Level) -> cmp::Ordering { - (*self as usize).cmp(&(*other as usize)) - } + fn cmp(&self, other: &Level) -> cmp::Ordering { (*self as usize).cmp(&(*other as usize)) } } impl fmt::Display for Level { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.pad(LOG_LEVEL_NAMES[*self as usize]) - } + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.pad(LOG_LEVEL_NAMES[*self as usize]) } } impl Level { /// Returns the most verbose logging level. #[inline] - pub fn max() -> Level { - Level::Trace - } + pub fn max() -> Level { Level::Trace } } /// A Record, unit of logging output with Metadata to enable filtering @@ -141,9 +125,7 @@ mod tests { } impl WrapperLog { - fn new(logger: Arc) -> WrapperLog { - WrapperLog { logger } - } + fn new(logger: Arc) -> WrapperLog { WrapperLog { logger } } fn call_macros(&self) { log_error!(self, "This is an error"); diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index ea28bfc31d0..81896c70610 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -47,16 +47,12 @@ impl Writer for W { pub(crate) struct WriterWriteAdaptor<'a, W: Writer + 'a>(pub &'a mut W); impl<'a, W: Writer + 'a> Write for WriterWriteAdaptor<'a, W> { - fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> { - self.0.write_all(buf) - } + fn write_all(&mut self, buf: &[u8]) -> Result<(), ::std::io::Error> { self.0.write_all(buf) } fn write(&mut self, buf: &[u8]) -> Result { self.0.write_all(buf)?; Ok(buf.len()) } - fn flush(&mut self) -> Result<(), ::std::io::Error> { - Ok(()) - } + fn flush(&mut self) -> Result<(), ::std::io::Error> { Ok(()) } } struct VecWriter(Vec); @@ -65,9 +61,7 @@ impl Writer for VecWriter { self.0.extend_from_slice(buf); Ok(()) } - fn size_hint(&mut self, size: usize) { - self.0.reserve_exact(size); - } + fn size_hint(&mut self, size: usize) { self.0.reserve_exact(size); } } /// A trait that various rust-lightning types implement allowing them to be written out to a Writer @@ -153,9 +147,7 @@ impl_writeable_primitive!(u16, be16_to_array, 2, slice_to_be16); impl Writeable for u8 { #[inline] - fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - writer.write_all(&[*self]) - } + fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { writer.write_all(&[*self]) } } impl Readable for u8 { #[inline] @@ -312,9 +304,7 @@ impl Readable for Script { } impl Writeable for PublicKey { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - self.serialize().write(w) - } + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { self.serialize().write(w) } } impl Readable for PublicKey { @@ -346,9 +336,7 @@ impl Readable for SecretKey { } impl Writeable for Sha256dHash { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - w.write_all(&self[..]) - } + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { w.write_all(&self[..]) } } impl Readable for Sha256dHash { @@ -361,9 +349,7 @@ impl Readable for Sha256dHash { } impl Writeable for Signature { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - self.serialize_compact().write(w) - } + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { self.serialize_compact().write(w) } } impl Readable for Signature { @@ -377,9 +363,7 @@ impl Readable for Signature { } impl Writeable for PaymentPreimage { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - self.0.write(w) - } + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { self.0.write(w) } } impl Readable for PaymentPreimage { @@ -390,9 +374,7 @@ impl Readable for PaymentPreimage { } impl Writeable for PaymentHash { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - self.0.write(w) - } + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { self.0.write(w) } } impl Readable for PaymentHash { @@ -451,9 +433,7 @@ impl> Readable for Mutex { } } impl Writeable for Mutex { - fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { - self.lock().unwrap().write(w) - } + fn write(&self, w: &mut W) -> Result<(), ::std::io::Error> { self.lock().unwrap().write(w) } } impl, B: Readable> Readable for (A, B) { diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 6d599b771df..08c053bda2f 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -30,18 +30,14 @@ impl Writer for TestVecWriter { self.0.extend_from_slice(buf); Ok(()) } - fn size_hint(&mut self, size: usize) { - self.0.reserve_exact(size); - } + fn size_hint(&mut self, size: usize) { self.0.reserve_exact(size); } } pub struct TestFeeEstimator { pub sat_per_kw: u64, } impl chaininterface::FeeEstimator for TestFeeEstimator { - fn get_est_sat_per_1000_weight(&self, _confirmation_target: ConfirmationTarget) -> u64 { - self.sat_per_kw - } + fn get_est_sat_per_1000_weight(&self, _confirmation_target: ConfirmationTarget) -> u64 { self.sat_per_kw } } pub struct TestChannelMonitor { @@ -88,18 +84,14 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor { self.update_ret.lock().unwrap().clone() } - fn fetch_pending_htlc_updated(&self) -> Vec { - return self.simple_monitor.fetch_pending_htlc_updated(); - } + fn fetch_pending_htlc_updated(&self) -> Vec { return self.simple_monitor.fetch_pending_htlc_updated(); } } pub struct TestBroadcaster { pub txn_broadcasted: Mutex>, } impl chaininterface::BroadcasterInterface for TestBroadcaster { - fn broadcast_transaction(&self, tx: &Transaction) { - self.txn_broadcasted.lock().unwrap().push(tx.clone()); - } + fn broadcast_transaction(&self, tx: &Transaction) { self.txn_broadcasted.lock().unwrap().push(tx.clone()); } } pub struct TestChannelMessageHandler { @@ -107,9 +99,7 @@ pub struct TestChannelMessageHandler { } impl TestChannelMessageHandler { - pub fn new() -> Self { - TestChannelMessageHandler { pending_events: Mutex::new(Vec::new()) } - } + pub fn new() -> Self { TestChannelMessageHandler { pending_events: Mutex::new(Vec::new()) } } } impl msgs::ChannelMessageHandler for TestChannelMessageHandler { @@ -154,9 +144,7 @@ impl events::MessageSendEventsProvider for TestChannelMessageHandler { pub struct TestRoutingMessageHandler {} impl TestRoutingMessageHandler { - pub fn new() -> Self { - TestRoutingMessageHandler {} - } + pub fn new() -> Self { TestRoutingMessageHandler {} } } impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result { @@ -193,17 +181,13 @@ pub struct TestLogger { } impl TestLogger { - pub fn new() -> TestLogger { - Self::with_id("".to_owned()) - } + pub fn new() -> TestLogger { Self::with_id("".to_owned()) } pub fn with_id(id: String) -> TestLogger { TestLogger { level: Level::Trace, id, lines: Mutex::new(HashMap::new()) } } - pub fn enable(&mut self, level: Level) { - self.level = level; - } + pub fn enable(&mut self, level: Level) { self.level = level; } pub fn assert_log(&self, module: String, line: String, count: usize) { let log_entries = self.lines.lock().unwrap(); assert_eq!(log_entries.get(&(module, line)), Some(&count)); @@ -240,15 +224,9 @@ pub struct TestKeysInterface { impl keysinterface::KeysInterface for TestKeysInterface { type ChanKeySigner = EnforcingChannelKeys; - fn get_node_secret(&self) -> SecretKey { - self.backing.get_node_secret() - } - fn get_destination_script(&self) -> Script { - self.backing.get_destination_script() - } - fn get_shutdown_pubkey(&self) -> PublicKey { - self.backing.get_shutdown_pubkey() - } + fn get_node_secret(&self) -> SecretKey { self.backing.get_node_secret() } + fn get_destination_script(&self) -> Script { self.backing.get_destination_script() } + fn get_shutdown_pubkey(&self) -> PublicKey { self.backing.get_shutdown_pubkey() } fn get_channel_keys(&self, inbound: bool) -> EnforcingChannelKeys { EnforcingChannelKeys::new(self.backing.get_channel_keys(inbound)) } diff --git a/lightning/src/util/transaction_utils.rs b/lightning/src/util/transaction_utils.rs index 5b013c8f4eb..58b8b4f79c2 100644 --- a/lightning/src/util/transaction_utils.rs +++ b/lightning/src/util/transaction_utils.rs @@ -88,9 +88,7 @@ mod tests { assert_eq!(&outputs, &vec![(txout2_, 69), (txout1_, 420)]); } - fn script_from_hex(hex_str: &str) -> Script { - Script::from(decode(hex_str).unwrap()) - } + fn script_from_hex(hex_str: &str) -> Script { Script::from(decode(hex_str).unwrap()) } macro_rules! bip_txout_tests { ($($name:ident: $value:expr,)*) => {