From e4a0352c6681ecae70491afb48301c2e3b663eb5 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 9 Oct 2025 14:11:45 +0200 Subject: [PATCH] Switch to `nightly` `rustfmt` --- .github/workflows/rust.yml | 1 - rust-toolchain.toml | 4 ++++ rustfmt.toml | 21 ++++++++++++------- src/builder.rs | 7 +++---- src/chain/bitcoind.rs | 10 ++++----- src/io/test_utils.rs | 3 +-- src/io/utils.rs | 9 +++++++- src/lib.rs | 16 +++++++------- .../asynchronous/static_invoice_store.rs | 12 ++++------- src/payment/onchain.rs | 2 +- src/payment/store.rs | 2 +- src/wallet/mod.rs | 2 +- tests/common/mod.rs | 14 ++++++------- tests/integration_tests_rust.rs | 16 +++++++------- 14 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index aff610908..87249bd72 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -38,7 +38,6 @@ jobs: - name: Install Rust ${{ matrix.toolchain }} toolchain run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain ${{ matrix.toolchain }} - rustup override set ${{ matrix.toolchain }} - name: Check formatting on Rust ${{ matrix.toolchain }} if: matrix.check-fmt run: rustup component add rustfmt && cargo fmt --all -- --check diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..d35f8fac6 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2025-10-08" +components = [ "rustfmt" ] +profile = "minimal" diff --git a/rustfmt.toml b/rustfmt.toml index 66161555c..26a260b50 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,11 +4,16 @@ hard_tabs = true use_field_init_shorthand = true max_width = 100 match_block_trailing_comma = true -# UNSTABLE: format_code_in_doc_comments = true -# UNSTABLE: overflow_delimited_expr = true -# UNSTABLE: comment_width = 100 -# UNSTABLE: format_macro_matchers = true -# UNSTABLE: format_strings = true -# UNSTABLE: group_imports = "StdExternalCrate" -# UNSTABLE: reorder_imports = true -# UNSTABLE: imports_granularity = "Module" +format_code_in_doc_comments = true +overflow_delimited_expr = true +comment_width = 100 +format_macro_matchers = true +group_imports = "StdExternalCrate" +reorder_imports = true +imports_granularity = "Module" +normalize_comments = true +normalize_doc_attributes = true +style_edition = "2021" +# TBD: do we want comment and string wrapping? +#wrap_comments = true +#format_strings = true diff --git a/src/builder.rs b/src/builder.rs index b4a146e7c..0c843447a 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -628,10 +628,9 @@ impl NodeBuilder { derive_xprv(config, &seed_bytes, VSS_HARDENED_CHILD_INDEX, Arc::clone(&logger))?; let lnurl_auth_xprv = vss_xprv - .derive_priv( - &Secp256k1::new(), - &[ChildNumber::Hardened { index: VSS_LNURL_AUTH_HARDENED_CHILD_INDEX }], - ) + .derive_priv(&Secp256k1::new(), &[ChildNumber::Hardened { + index: VSS_LNURL_AUTH_HARDENED_CHILD_INDEX, + }]) .map_err(|e| { log_error!(logger, "Failed to derive VSS secret: {}", e); BuildError::KVStoreSetupFailed diff --git a/src/chain/bitcoind.rs b/src/chain/bitcoind.rs index e97546e88..934e4aabf 100644 --- a/src/chain/bitcoind.rs +++ b/src/chain/bitcoind.rs @@ -415,7 +415,7 @@ impl BitcoindChainSource { pub(super) async fn update_fee_rate_estimates(&self) -> Result<(), Error> { macro_rules! get_fee_rate_update { - ($estimation_fut: expr) => {{ + ($estimation_fut:expr) => {{ let update_res = tokio::time::timeout( Duration::from_secs(FEE_RATE_CACHE_UPDATE_TIMEOUT_SECS), $estimation_fut, @@ -701,10 +701,10 @@ impl BitcoindClient { let num_blocks_json = serde_json::json!(num_blocks); let estimation_mode_json = serde_json::json!(estimation_mode); rpc_client - .call_method::( - "estimatesmartfee", - &[num_blocks_json, estimation_mode_json], - ) + .call_method::("estimatesmartfee", &[ + num_blocks_json, + estimation_mode_json, + ]) .await .map(|resp| resp.0) } diff --git a/src/io/test_utils.rs b/src/io/test_utils.rs index 8fbf4279d..59ad09458 100644 --- a/src/io/test_utils.rs +++ b/src/io/test_utils.rs @@ -16,7 +16,6 @@ use lightning::ln::functional_test_utils::{ use lightning::util::persist::{ KVStoreSync, MonitorUpdatingPersister, KVSTORE_NAMESPACE_KEY_MAX_LEN, }; - use lightning::util::test_utils; use lightning::{check_added_monitors, check_closed_broadcast, check_closed_event}; use rand::distributions::Alphanumeric; @@ -149,7 +148,7 @@ pub(crate) fn do_test_store(store_0: &K, store_1: &K) { // Helper to make sure the channel is on the expected update ID. macro_rules! check_persisted_data { - ($expected_update_id: expr) => { + ($expected_update_id:expr) => { persisted_chan_data_0 = persister_0.read_all_channel_monitors_with_updates().unwrap(); assert_eq!(persisted_chan_data_0.len(), 1); for (_, mon) in persisted_chan_data_0.iter() { diff --git a/src/io/utils.rs b/src/io/utils.rs index 1556314c4..7b7906d4f 100644 --- a/src/io/utils.rs +++ b/src/io/utils.rs @@ -399,7 +399,14 @@ pub(crate) fn check_namespace_key_validity( } macro_rules! impl_read_write_change_set_type { - ( $read_name: ident, $write_name: ident, $change_set_type:ty, $primary_namespace: expr, $secondary_namespace: expr, $key: expr ) => { + ( + $read_name:ident, + $write_name:ident, + $change_set_type:ty, + $primary_namespace:expr, + $secondary_namespace:expr, + $key:expr + ) => { pub(crate) fn $read_name( kv_store: Arc, logger: L, ) -> Result, std::io::Error> diff --git a/src/lib.rs b/src/lib.rs index c235d2a88..f07b2def3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,18 +25,21 @@ //! ```no_run //! # #[cfg(not(feature = "uniffi"))] //! # { -//! use ldk_node::Builder; -//! use ldk_node::lightning_invoice::Bolt11Invoice; -//! use ldk_node::lightning::ln::msgs::SocketAddress; -//! use ldk_node::bitcoin::Network; -//! use ldk_node::bitcoin::secp256k1::PublicKey; //! use std::str::FromStr; //! +//! use ldk_node::bitcoin::secp256k1::PublicKey; +//! use ldk_node::bitcoin::Network; +//! use ldk_node::lightning::ln::msgs::SocketAddress; +//! use ldk_node::lightning_invoice::Bolt11Invoice; +//! use ldk_node::Builder; +//! //! fn main() { //! let mut builder = Builder::new(); //! builder.set_network(Network::Testnet); //! builder.set_chain_source_esplora("https://blockstream.info/testnet/api".to_string(), None); -//! builder.set_gossip_source_rgs("https://rapidsync.lightningdevkit.org/testnet/snapshot".to_string()); +//! builder.set_gossip_source_rgs( +//! "https://rapidsync.lightningdevkit.org/testnet/snapshot".to_string(), +//! ); //! //! let node = builder.build().unwrap(); //! @@ -67,7 +70,6 @@ //! [`stop`]: Node::stop //! [`open_channel`]: Node::open_channel //! [`send`]: Bolt11Payment::send -//! #![cfg_attr(not(feature = "uniffi"), deny(missing_docs))] #![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::private_intra_doc_links)] diff --git a/src/payment/asynchronous/static_invoice_store.rs b/src/payment/asynchronous/static_invoice_store.rs index a7e2d2f9e..7fec4fe9a 100644 --- a/src/payment/asynchronous/static_invoice_store.rs +++ b/src/payment/asynchronous/static_invoice_store.rs @@ -271,14 +271,10 @@ mod tests { } fn blinded_path() -> BlindedMessagePath { - BlindedMessagePath::from_blinded_path( - pubkey(40), - pubkey(41), - vec![ - BlindedHop { blinded_node_id: pubkey(42), encrypted_payload: vec![0; 43] }, - BlindedHop { blinded_node_id: pubkey(43), encrypted_payload: vec![0; 44] }, - ], - ) + BlindedMessagePath::from_blinded_path(pubkey(40), pubkey(41), vec![ + BlindedHop { blinded_node_id: pubkey(42), encrypted_payload: vec![0; 43] }, + BlindedHop { blinded_node_id: pubkey(43), encrypted_payload: vec![0; 44] }, + ]) } fn pubkey(byte: u8) -> PublicKey { diff --git a/src/payment/onchain.rs b/src/payment/onchain.rs index c5100d772..695f96d43 100644 --- a/src/payment/onchain.rs +++ b/src/payment/onchain.rs @@ -23,7 +23,7 @@ type FeeRate = bitcoin::FeeRate; type FeeRate = Arc; macro_rules! maybe_map_fee_rate_opt { - ($fee_rate_opt: expr) => {{ + ($fee_rate_opt:expr) => {{ #[cfg(not(feature = "uniffi"))] { $fee_rate_opt diff --git a/src/payment/store.rs b/src/payment/store.rs index b17898d9c..184de2ea9 100644 --- a/src/payment/store.rs +++ b/src/payment/store.rs @@ -179,7 +179,7 @@ impl StorableObject for PaymentDetails { let mut updated = false; macro_rules! update_if_necessary { - ($val: expr, $update: expr) => { + ($val:expr, $update:expr) => { if $val != $update { $val = $update; updated = true; diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index 8f8151b9c..0f3797431 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -631,7 +631,7 @@ impl Wallet { script_pubkey: ScriptBuf::new_witness_program(&witness_program), }, satisfaction_weight: 1 /* empty script_sig */ * WITNESS_SCALE_FACTOR as u64 + - 1 /* witness items */ + 1 /* schnorr sig len */ + 64, /* schnorr sig */ + 1 /* witness items */ + 1 /* schnorr sig len */ + 64, // schnorr sig }; utxos.push(utxo); }, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 3ac0e8432..4d02895c7 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -48,7 +48,7 @@ use rand::{thread_rng, Rng}; use serde_json::{json, Value}; macro_rules! expect_event { - ($node: expr, $event_type: ident) => {{ + ($node:expr, $event_type:ident) => {{ match $node.wait_next_event() { ref e @ Event::$event_type { .. } => { println!("{} got event {:?}", $node.node_id(), e); @@ -64,7 +64,7 @@ macro_rules! expect_event { pub(crate) use expect_event; macro_rules! expect_channel_pending_event { - ($node: expr, $counterparty_node_id: expr) => {{ + ($node:expr, $counterparty_node_id:expr) => {{ match $node.wait_next_event() { ref e @ Event::ChannelPending { funding_txo, counterparty_node_id, .. } => { println!("{} got event {:?}", $node.node_id(), e); @@ -82,7 +82,7 @@ macro_rules! expect_channel_pending_event { pub(crate) use expect_channel_pending_event; macro_rules! expect_channel_ready_event { - ($node: expr, $counterparty_node_id: expr) => {{ + ($node:expr, $counterparty_node_id:expr) => {{ match $node.wait_next_event() { ref e @ Event::ChannelReady { user_channel_id, counterparty_node_id, .. } => { println!("{} got event {:?}", $node.node_id(), e); @@ -100,7 +100,7 @@ macro_rules! expect_channel_ready_event { pub(crate) use expect_channel_ready_event; macro_rules! expect_payment_received_event { - ($node: expr, $amount_msat: expr) => {{ + ($node:expr, $amount_msat:expr) => {{ match $node.wait_next_event() { ref e @ Event::PaymentReceived { payment_id, amount_msat, .. } => { println!("{} got event {:?}", $node.node_id(), e); @@ -122,7 +122,7 @@ macro_rules! expect_payment_received_event { pub(crate) use expect_payment_received_event; macro_rules! expect_payment_claimable_event { - ($node: expr, $payment_id: expr, $payment_hash: expr, $claimable_amount_msat: expr) => {{ + ($node:expr, $payment_id:expr, $payment_hash:expr, $claimable_amount_msat:expr) => {{ match $node.wait_next_event() { ref e @ Event::PaymentClaimable { payment_id, @@ -147,7 +147,7 @@ macro_rules! expect_payment_claimable_event { pub(crate) use expect_payment_claimable_event; macro_rules! expect_payment_successful_event { - ($node: expr, $payment_id: expr, $fee_paid_msat: expr) => {{ + ($node:expr, $payment_id:expr, $fee_paid_msat:expr) => {{ match $node.wait_next_event() { ref e @ Event::PaymentSuccessful { payment_id, fee_paid_msat, .. } => { println!("{} got event {:?}", $node.node_id(), e); @@ -269,7 +269,7 @@ pub(crate) struct TestConfig { } macro_rules! setup_builder { - ($builder: ident, $config: expr) => { + ($builder:ident, $config:expr) => { #[cfg(feature = "uniffi")] let $builder = Builder::from_config($config.clone()); #[cfg(not(feature = "uniffi"))] diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index 64a78e11b..804bba876 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -687,7 +687,7 @@ fn run_rbf_test(is_insert_block: bool) { let chain_source_esplora = TestChainSource::Esplora(&electrsd); macro_rules! config_node { - ($chain_source: expr, $anchor_channels: expr) => {{ + ($chain_source:expr, $anchor_channels:expr) => {{ let config_a = random_config($anchor_channels); let node = setup_node(&$chain_source, config_a, None); node @@ -719,7 +719,7 @@ fn run_rbf_test(is_insert_block: bool) { }; } macro_rules! validate_balances { - ($expected_balance_sat: expr, $is_spendable: expr) => { + ($expected_balance_sat:expr, $is_spendable:expr) => { let spend_balance = if $is_spendable { $expected_balance_sat } else { 0 }; for node in &nodes { node.sync_wallets().unwrap(); @@ -972,8 +972,8 @@ fn simple_bolt12_send_receive() { assert_eq!(offer_id, offer.id()); assert_eq!(&expected_quantity, qty); assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0); - //TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 - //API currently doesn't allow to do that. + // TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 + // API currently doesn't allow to do that. }, _ => { panic!("Unexpected payment kind"); @@ -1038,8 +1038,8 @@ fn simple_bolt12_send_receive() { assert_eq!(offer_id, offer.id()); assert_eq!(&expected_quantity, qty); assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0); - //TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 - //API currently doesn't allow to do that. + // TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 + // API currently doesn't allow to do that. hash.unwrap() }, _ => { @@ -1104,8 +1104,8 @@ fn simple_bolt12_send_receive() { assert!(preimage.is_some()); assert_eq!(&expected_quantity, qty); assert_eq!(expected_payer_note.unwrap(), note.clone().unwrap().0) - //TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 - //API currently doesn't allow to do that. + // TODO: We should eventually set and assert the secret sender-side, too, but the BOLT12 + // API currently doesn't allow to do that. }, _ => { panic!("Unexpected payment kind");