Skip to content

Commit bf380da

Browse files
committed
Replace rustfmt_excluded_files with rustfmt_skip cfg attribute
This change removes the custom `rustfmt_excluded_files` mechanism and instead uses the an attribute at the top of each excluded file. No functional changes are introduced. This simplifies formatting workflows by enabling standard `cargo fmt` and editor format-on-save features without custom scripts. The older `rustfmt` cfg attribute is used because newer formatting directives only support code blocks, which would require more effort to apply consistently. This commit focuses on improving developer experience by streamlining formatting setup, while more granular or comprehensive formatting can be addressed later.
1 parent 1156efb commit bf380da

39 files changed

+111
-96
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ jobs:
305305
run: |
306306
rustup component add rustfmt
307307
- name: Run rustfmt checks
308-
run: ci/rustfmt.sh
308+
run: cargofmt --check
309309

310310
incremental-mutants:
311311
runs-on: ubuntu-latest

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ display fine at any tab-length display setting. We use `rustfmt` to establish
124124
uniform coding standards throughout the codebase. Please run
125125

126126
```bash
127-
./contrib/run-rustfmt.sh
127+
cargo fmt
128128
```
129129

130130
before committing and pushing any changes, as compliance will also be checked

ci/rustfmt.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

contrib/run-rustfmt.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

lightning-background-processor/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
//! Utilities that take care of tasks that (1) need to happen periodically to keep Rust-Lightning
24
//! running properly, and (2) either can or should be run in the background.
35
#![cfg_attr(feature = "std", doc = "See docs for [`BackgroundProcessor`] for more details.")]

lightning/src/chain/chaininterface.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/chain/chainmonitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/chain/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/chain/package.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/chain/transaction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/async_signer_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/channel.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//
@@ -3808,7 +3810,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
38083810
if update_fee {
38093811
debug_assert!(!funding.is_outbound());
38103812
let counterparty_reserve_we_require_msat = funding.holder_selected_channel_reserve_satoshis * 1000;
3811-
if commitment_data.stats.remote_balance_before_fee_anchors_msat < commitment_data.stats.total_fee_sat * 1000 + counterparty_reserve_we_require_msat {
3813+
if commitment_data.stats.remote_balance_before_fee_anchors_msat < commitment_data.stats.total_fee_sat * 1000 + commitment_data.stats.total_anchors_sat * 1000 + counterparty_reserve_we_require_msat {
38123814
return Err(ChannelError::close("Funding remote cannot afford proposed new fee".to_owned()));
38133815
}
38143816
}
@@ -6724,7 +6726,7 @@ impl<SP: Deref> FundedChannel<SP> where
67246726
);
67256727
let buffer_fee_msat = commit_tx_fee_sat(feerate_per_kw, commitment_data.tx.nondust_htlcs().len() + htlc_stats.on_holder_tx_outbound_holding_cell_htlcs_count as usize + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as usize, self.funding.get_channel_type()) * 1000;
67266728
let holder_balance_msat = commitment_data.stats.local_balance_before_fee_anchors_msat - htlc_stats.outbound_holding_cell_msat;
6727-
if holder_balance_msat < buffer_fee_msat + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
6729+
if holder_balance_msat < buffer_fee_msat + commitment_data.stats.total_anchors_sat * 1000 + self.funding.counterparty_selected_channel_reserve_satoshis.unwrap() * 1000 {
67286730
//TODO: auto-close after a number of failures?
67296731
log_debug!(logger, "Cannot afford to send new feerate at {}", feerate_per_kw);
67306732
return None;

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/monitor_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/offers_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/onion_payment.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
//! Utilities to decode payment onions and do contextless validation of incoming payments.
24
//!
35
//! Primarily features [`peel_payment_onion`], which allows the decoding of an onion statelessly

lightning/src/ln/onion_route_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/outbound_payment.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/reload_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/reorg_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/shutdown_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/ln/update_fee_tests.rs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::ln::chan_utils::{
66
COMMITMENT_TX_WEIGHT_PER_HTLC,
77
};
88
use crate::ln::channel::{
9-
get_holder_selected_channel_reserve_satoshis, CONCURRENT_INBOUND_HTLC_FEE_BUFFER,
10-
MIN_AFFORDABLE_HTLC_COUNT,
9+
get_holder_selected_channel_reserve_satoshis, ANCHOR_OUTPUT_VALUE_SATOSHI,
10+
CONCURRENT_INBOUND_HTLC_FEE_BUFFER, MIN_AFFORDABLE_HTLC_COUNT,
1111
};
1212
use crate::ln::channelmanager::PaymentId;
1313
use crate::ln::functional_test_utils::*;
@@ -388,11 +388,22 @@ pub fn test_update_fee_vanilla() {
388388
check_added_monitors(&nodes[1], 1);
389389
}
390390

391-
#[xtest(feature = "_externalize_tests")]
392-
pub fn test_update_fee_that_funder_cannot_afford() {
391+
pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: ChannelTypeFeatures) {
393392
let chanmon_cfgs = create_chanmon_cfgs(2);
394393
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
395-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
394+
395+
let mut default_config = test_default_channel_config();
396+
if channel_type_features == ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() {
397+
default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
398+
// this setting is also needed to create an anchor channel
399+
default_config.manually_accept_inbound_channels = true;
400+
}
401+
402+
let node_chanmgrs = create_node_chanmgrs(
403+
2,
404+
&node_cfgs,
405+
&[Some(default_config.clone()), Some(default_config.clone())],
406+
);
396407
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
397408

398409
let node_a_id = nodes[0].node.get_our_node_id();
@@ -409,22 +420,26 @@ pub fn test_update_fee_that_funder_cannot_afford() {
409420
);
410421
let channel_id = chan.2;
411422
let secp_ctx = Secp256k1::new();
412-
let default_config = UserConfig::default();
413423
let bs_channel_reserve_sats =
414424
get_holder_selected_channel_reserve_satoshis(channel_value, &default_config);
415-
416-
let channel_type_features = ChannelTypeFeatures::only_static_remote_key();
425+
let (anchor_outputs_value_sats, outputs_num_no_htlcs) =
426+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
427+
(ANCHOR_OUTPUT_VALUE_SATOSHI * 2, 4)
428+
} else {
429+
(0, 2)
430+
};
417431

418432
// Calculate the maximum feerate that A can afford. Note that we don't send an update_fee
419433
// CONCURRENT_INBOUND_HTLC_FEE_BUFFER HTLCs before actually running out of local balance, so we
420434
// calculate two different feerates here - the expected local limit as well as the expected
421435
// remote limit.
422-
let feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000
423-
/ (commitment_tx_base_weight(&channel_type_features)
424-
+ CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC))
425-
as u32;
426-
let non_buffer_feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000
427-
/ commitment_tx_base_weight(&channel_type_features)) as u32;
436+
let feerate =
437+
((channel_value - bs_channel_reserve_sats - push_sats - anchor_outputs_value_sats) * 1000
438+
/ (commitment_tx_base_weight(&channel_type_features)
439+
+ CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC)) as u32;
440+
let non_buffer_feerate =
441+
((channel_value - bs_channel_reserve_sats - push_sats - anchor_outputs_value_sats) * 1000
442+
/ commitment_tx_base_weight(&channel_type_features)) as u32;
428443
{
429444
let mut feerate_lock = chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap();
430445
*feerate_lock = feerate;
@@ -441,8 +456,8 @@ pub fn test_update_fee_that_funder_cannot_afford() {
441456
{
442457
let commitment_tx = get_local_commitment_txn!(nodes[1], channel_id)[0].clone();
443458

444-
//We made sure neither party's funds are below the dust limit and there are no HTLCs here
445-
assert_eq!(commitment_tx.output.len(), 2);
459+
// We made sure neither party's funds are below the dust limit and there are no HTLCs here
460+
assert_eq!(commitment_tx.output.len(), outputs_num_no_htlcs);
446461
let total_fee: u64 = commit_tx_fee_msat(feerate, 0, &channel_type_features) / 1000;
447462
let mut actual_fee =
448463
commitment_tx.output.iter().fold(0, |acc, output| acc + output.value.to_sat());
@@ -486,8 +501,8 @@ pub fn test_update_fee_that_funder_cannot_afford() {
486501
&remote_point,
487502
push_sats,
488503
channel_value
489-
- push_sats - commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features)
490-
/ 1000,
504+
- push_sats - anchor_outputs_value_sats
505+
- commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features) / 1000,
491506
non_buffer_feerate + 4,
492507
nondust_htlcs,
493508
&local_chan.funding().channel_transaction_parameters.as_counterparty_broadcastable(),
@@ -526,6 +541,14 @@ pub fn test_update_fee_that_funder_cannot_afford() {
526541
check_closed_event!(nodes[1], 1, reason, [node_a_id], channel_value);
527542
}
528543

544+
#[xtest(feature = "_externalize_tests")]
545+
pub fn test_update_fee_that_funder_cannot_afford() {
546+
do_test_update_fee_that_funder_cannot_afford(ChannelTypeFeatures::only_static_remote_key());
547+
do_test_update_fee_that_funder_cannot_afford(
548+
ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(),
549+
);
550+
}
551+
529552
#[xtest(feature = "_externalize_tests")]
530553
pub fn test_update_fee_that_saturates_subs() {
531554
// Check that when a remote party sends us an `update_fee` message that results in a total fee

lightning/src/routing/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/routing/router.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/routing/scoring.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/routing/test_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

lightning/src/routing/utxo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
// This file is Copyright its original authors, visible in version control
24
// history.
35
//

0 commit comments

Comments
 (0)