From 49fbb5b78d1a669a061233de68808b2a9a7e5066 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 3 Jun 2025 16:36:24 +0000 Subject: [PATCH 1/4] Run `rustfmt` on `chain/mod.rs`/re-enable it on the `chain` module In d257b8a85a79b04faffa397a18a133f226c77804 we dropped our old `rustfmt` per-file exclusion logic and replaced it with `rustfmt_skip` tags in each previously-skipped files. This had the unintended consequence of fully disabling `rustfmt` across the `lightning` crate: `rustfmt` operates recursively across files in any module it is told to format. Previously, because we were running `rustfmt` on each non-excluded file, this meant we wanted to exclude `mod.rs` and `lib.rs` files - not doing so would result in the entire module/crate being formatted. However, `cargo fmt --check` only runs `rustfmt` once - on `lib.rs`. Because we added a top-level `rustfmt_skip` in `lib.rs` this caused `rustfmt` to ignore it and all modules. Here we prepare to fix this by formatting `lightning/src/chain/mod.rs`. --- lightning/src/chain/mod.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lightning/src/chain/mod.rs b/lightning/src/chain/mod.rs index 7ee7ad9804d..c16ee2519f7 100644 --- a/lightning/src/chain/mod.rs +++ b/lightning/src/chain/mod.rs @@ -1,5 +1,3 @@ -#![cfg_attr(rustfmt, rustfmt_skip)] - // This file is Copyright its original authors, visible in version control // history. // @@ -13,16 +11,16 @@ use bitcoin::block::{Block, Header}; use bitcoin::constants::genesis_block; -use bitcoin::script::{Script, ScriptBuf}; use bitcoin::hash_types::{BlockHash, Txid}; use bitcoin::network::Network; +use bitcoin::script::{Script, ScriptBuf}; use bitcoin::secp256k1::PublicKey; use crate::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, MonitorEvent}; -use crate::ln::types::ChannelId; -use crate::sign::ecdsa::EcdsaChannelSigner; use crate::chain::transaction::{OutPoint, TransactionData}; use crate::impl_writeable_tlv_based; +use crate::ln::types::ChannelId; +use crate::sign::ecdsa::EcdsaChannelSigner; #[allow(unused_imports)] use crate::prelude::*; @@ -30,9 +28,9 @@ use crate::prelude::*; pub mod chaininterface; pub mod chainmonitor; pub mod channelmonitor; -pub mod transaction; pub(crate) mod onchaintx; pub(crate) mod package; +pub mod transaction; /// The best known block as identified by its hash and height. #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] @@ -47,10 +45,7 @@ impl BestBlock { /// Constructs a `BestBlock` that represents the genesis block at height 0 of the given /// network. pub fn from_network(network: Network) -> Self { - BestBlock { - block_hash: genesis_block(network).header.block_hash(), - height: 0, - } + BestBlock { block_hash: genesis_block(network).header.block_hash(), height: 0 } } /// Returns a `BestBlock` as identified by the given block hash and height. @@ -67,7 +62,6 @@ impl_writeable_tlv_based!(BestBlock, { (2, height, required), }); - /// The `Listen` trait is used to notify when blocks have been connected or disconnected from the /// chain. /// @@ -289,7 +283,9 @@ pub trait Watch { /// [`get_outputs_to_watch`]: channelmonitor::ChannelMonitor::get_outputs_to_watch /// [`block_connected`]: channelmonitor::ChannelMonitor::block_connected /// [`block_disconnected`]: channelmonitor::ChannelMonitor::block_disconnected - fn watch_channel(&self, channel_id: ChannelId, monitor: ChannelMonitor) -> Result; + fn watch_channel( + &self, channel_id: ChannelId, monitor: ChannelMonitor, + ) -> Result; /// Updates a channel identified by `channel_id` by applying `update` to its monitor. /// @@ -306,7 +302,9 @@ pub trait Watch { /// [`ChannelMonitorUpdateStatus::UnrecoverableError`], see its documentation for more info. /// /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager - fn update_channel(&self, channel_id: ChannelId, update: &ChannelMonitorUpdate) -> ChannelMonitorUpdateStatus; + fn update_channel( + &self, channel_id: ChannelId, update: &ChannelMonitorUpdate, + ) -> ChannelMonitorUpdateStatus; /// Returns any monitor events since the last call. Subsequent calls must only return new /// events. @@ -317,7 +315,9 @@ pub trait Watch { /// /// For details on asynchronous [`ChannelMonitor`] updating and returning /// [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`]. - fn release_pending_monitor_events(&self) -> Vec<(OutPoint, ChannelId, Vec, PublicKey)>; + fn release_pending_monitor_events( + &self, + ) -> Vec<(OutPoint, ChannelId, Vec, PublicKey)>; } /// The `Filter` trait defines behavior for indicating chain activity of interest pertaining to From 8a9419a0c69ad6d3d9e9481b5f2807f12589d671 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 3 Jun 2025 16:40:30 +0000 Subject: [PATCH 2/4] Run `rustfmt` on `ln/mod.rs`/re-enable it on the `ln` module In d257b8a85a79b04faffa397a18a133f226c77804 we dropped our old `rustfmt` per-file exclusion logic and replaced it with `rustfmt_skip` tags in each previously-skipped files. This had the unintended consequence of fully disabling `rustfmt` across the `lightning` crate: `rustfmt` operates recursively across files in any module it is told to format. Previously, because we were running `rustfmt` on each non-excluded file, this meant we wanted to exclude `mod.rs` and `lib.rs` files - not doing so would result in the entire module/crate being formatted. However, `cargo fmt --check` only runs `rustfmt` once - on `lib.rs`. Because we added a top-level `rustfmt_skip` in `lib.rs` this caused `rustfmt` to ignore it and all modules. Here we prepare to fix this by formatting `lightning/src/ln/mod.rs`. --- lightning/src/ln/mod.rs | 60 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/lightning/src/ln/mod.rs b/lightning/src/ln/mod.rs index 89f877686ca..8d741f2954d 100644 --- a/lightning/src/ln/mod.rs +++ b/lightning/src/ln/mod.rs @@ -1,5 +1,3 @@ -#![cfg_attr(rustfmt, rustfmt_skip)] - // This file is Copyright its original authors, visible in version control // history. // @@ -15,15 +13,15 @@ #[macro_use] pub mod functional_test_utils; -pub mod onion_payment; -pub mod channelmanager; +pub mod chan_utils; pub mod channel_keys; pub mod channel_state; +pub mod channelmanager; +mod features; pub mod inbound_payment; pub mod msgs; +pub mod onion_payment; pub mod peer_handler; -pub mod chan_utils; -mod features; pub mod script; pub mod types; @@ -59,64 +57,64 @@ pub use onion_utils::process_onion_failure; #[cfg(fuzzing)] pub use onion_utils::AttributionData; +#[cfg(all(test, async_payments))] +#[allow(unused_mut)] +mod async_payments_tests; #[cfg(test)] #[allow(unused_mut)] -pub mod bolt11_payment_tests; +mod async_signer_tests; #[cfg(test)] #[allow(unused_mut)] mod blinded_payment_tests; -#[cfg(all(test, async_payments))] +#[cfg(test)] #[allow(unused_mut)] -mod async_payments_tests; +pub mod bolt11_payment_tests; +#[cfg(test)] +#[allow(unused_mut)] +mod chanmon_update_fail_tests; +#[cfg(test)] +#[allow(unused_mut)] +mod dual_funding_tests; #[cfg(any(test, feature = "_externalize_tests"))] #[allow(unused_mut)] pub mod functional_tests; #[cfg(any(test, feature = "_externalize_tests"))] #[allow(unused_mut)] pub mod htlc_reserve_unit_tests; -#[cfg(any(test, feature = "_externalize_tests"))] -#[allow(unused_mut)] -pub mod update_fee_tests; -#[cfg(all(test, splicing))] -#[allow(unused_mut)] -mod splicing_tests; #[cfg(test)] #[allow(unused_mut)] mod max_payment_path_len_tests; #[cfg(test)] #[allow(unused_mut)] -mod payment_tests; -#[cfg(test)] -#[allow(unused_mut)] -mod priv_short_conf_tests; -#[cfg(test)] -#[allow(unused_mut)] -mod chanmon_update_fail_tests; -#[cfg(test)] -#[allow(unused_mut)] -mod reorg_tests; +mod monitor_tests; #[cfg(test)] #[allow(unused_mut)] -mod reload_tests; +mod offers_tests; #[cfg(test)] #[allow(unused_mut)] mod onion_route_tests; #[cfg(test)] #[allow(unused_mut)] -mod monitor_tests; +mod payment_tests; #[cfg(test)] #[allow(unused_mut)] -mod shutdown_tests; +mod priv_short_conf_tests; #[cfg(test)] mod quiescence_tests; #[cfg(test)] #[allow(unused_mut)] -mod async_signer_tests; +mod reload_tests; #[cfg(test)] #[allow(unused_mut)] -mod offers_tests; +mod reorg_tests; #[cfg(test)] #[allow(unused_mut)] -mod dual_funding_tests; +mod shutdown_tests; +#[cfg(all(test, splicing))] +#[allow(unused_mut)] +mod splicing_tests; +#[cfg(any(test, feature = "_externalize_tests"))] +#[allow(unused_mut)] +pub mod update_fee_tests; pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN; From 0ab34bd75d829163a6dc2eccabb0b9029d3a7552 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 3 Jun 2025 16:41:30 +0000 Subject: [PATCH 3/4] Run `rustfmt` on `routing/mod.rs`/re-enable it on the `routing` mod In d257b8a85a79b04faffa397a18a133f226c77804 we dropped our old `rustfmt` per-file exclusion logic and replaced it with `rustfmt_skip` tags in each previously-skipped files. This had the unintended consequence of fully disabling `rustfmt` across the `lightning` crate: `rustfmt` operates recursively across files in any module it is told to format. Previously, because we were running `rustfmt` on each non-excluded file, this meant we wanted to exclude `mod.rs` and `lib.rs` files - not doing so would result in the entire module/crate being formatted. However, `cargo fmt --check` only runs `rustfmt` once - on `lib.rs`. Because we added a top-level `rustfmt_skip` in `lib.rs` this caused `rustfmt` to ignore it and all modules. Here we prepare to fix this by formatting `lightning/src/routing/mod.rs`. --- lightning/src/routing/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lightning/src/routing/mod.rs b/lightning/src/routing/mod.rs index af9e7c17dba..cb16461dd66 100644 --- a/lightning/src/routing/mod.rs +++ b/lightning/src/routing/mod.rs @@ -1,5 +1,3 @@ -#![cfg_attr(rustfmt, rustfmt_skip)] - // This file is Copyright its original authors, visible in version control // history. // @@ -11,10 +9,10 @@ //! Structs and impls for receiving messages about the network and storing the topology live here. -pub mod utxo; pub mod gossip; +mod log_approx; pub mod router; pub mod scoring; -mod log_approx; #[cfg(test)] pub(crate) mod test_utils; +pub mod utxo; From aed8a109d1006dbfb95aa0371caeee5d47625d80 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 3 Jun 2025 16:42:02 +0000 Subject: [PATCH 4/4] Re-enable `rustfmt` on the `lightning` crate In d257b8a85a79b04faffa397a18a133f226c77804 we dropped our old `rustfmt` per-file exclusion logic and replaced it with `rustfmt_skip` tags in each previously-skipped files. This had the unintended consequence of fully disabling `rustfmt` across the `lightning` crate: `rustfmt` operates recursively across files in any module it is told to format. Previously, because we were running `rustfmt` on each non-excluded file, this meant we wanted to exclude `mod.rs` and `lib.rs` files - not doing so would result in the entire module/crate being formatted. However, `cargo fmt --check` only runs `rustfmt` once - on `lib.rs`. Because we added a top-level `rustfmt_skip` in `lib.rs` this caused `rustfmt` to ignore it and all modules. Here we resume `rustfmt`'ing the `lightning` crate by removing the `rustfmt_skip` in `lightning/src/lib.rs` (and `rustfmt`'ing `lightning/src/lib.rs`. --- lightning/src/lib.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 4b4aed5e673..4e9d105df5f 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(rustfmt, rustfmt_skip)] - // This file is Copyright its original authors, visible in version control // history. // @@ -32,18 +30,14 @@ //! * `grind_signatures` #![cfg_attr(not(any(test, fuzzing, feature = "_test_utils")), deny(missing_docs))] - #![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::private_intra_doc_links)] - // In general, rust is absolutely horrid at supporting users doing things like, // for example, compiling Rust code for real environments. Disable useless lints // that don't do anything but annoy us and cant actually ever be resolved. #![allow(bare_trait_objects)] #![allow(ellipsis_inclusive_range_patterns)] - #![cfg_attr(docsrs, feature(doc_auto_cfg))] - #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] #[cfg(all(fuzzing, test))] @@ -61,24 +55,29 @@ pub extern crate lightning_invoice as bolt11_invoice; #[cfg(any(test, feature = "std"))] extern crate core; -#[cfg(any(test, feature = "_test_utils"))] extern crate regex; +#[cfg(any(test, feature = "_test_utils"))] +extern crate regex; -#[cfg(not(feature = "std"))] extern crate libm; +#[cfg(not(feature = "std"))] +extern crate libm; -#[cfg(ldk_bench)] extern crate criterion; +#[cfg(ldk_bench)] +extern crate criterion; -#[cfg(all(feature = "std", test))] extern crate parking_lot; +#[cfg(all(feature = "std", test))] +extern crate parking_lot; #[macro_use] pub mod util; + +pub mod blinded_path; pub mod chain; +pub mod events; pub mod ln; pub mod offers; +pub mod onion_message; pub mod routing; pub mod sign; -pub mod onion_message; -pub mod blinded_path; -pub mod events; pub(crate) mod crypto; @@ -96,7 +95,7 @@ pub mod io_extras { pub use bitcoin::io::sink; pub fn copy(reader: &mut R, writer: &mut W) -> Result - where + where R: Read, W: Write, { @@ -106,7 +105,10 @@ pub mod io_extras { loop { match reader.read(&mut buf) { Ok(0) => break, - Ok(n) => { writer.write_all(&buf[0..n])?; count += n as u64; }, + Ok(n) => { + writer.write_all(&buf[0..n])?; + count += n as u64; + }, Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}, Err(e) => return Err(e.into()), }; @@ -132,7 +134,7 @@ pub mod io_extras { mod prelude { #![allow(unused_imports)] - pub use alloc::{vec, vec::Vec, string::String, collections::VecDeque, boxed::Box}; + pub use alloc::{boxed::Box, collections::VecDeque, string::String, vec, vec::Vec}; pub use alloc::borrow::ToOwned; pub use alloc::string::ToString;