Skip to content

Rustfmt Maximalism #3749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions ci/rustfmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,4 @@ VERS=""
[ "$(which rustup)" != "" ] && VERS="+1.63.0"

# Run fmt
TMP_FILE=$(mktemp)
git ls-files | grep '.rs$' | sort >"$TMP_FILE"
for file in $(comm -23 "$TMP_FILE" rustfmt_excluded_files); do
echo "Checking formatting of $file"
rustfmt $VERS --edition 2021 --check "$file"
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONTRIBUTING.md needs update to remove reference to contrib/run-rustfmt.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one, will fix after rebase

cargo $VERS fmt --check
21 changes: 0 additions & 21 deletions contrib/run-rustfmt.sh

This file was deleted.

30 changes: 20 additions & 10 deletions lightning/src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,29 @@ pub const FEERATE_FLOOR_SATS_PER_KW: u32 = 253;
///
/// Note that this does *not* implement [`FeeEstimator`] to make it harder to accidentally mix the
/// two.
pub(crate) struct LowerBoundedFeeEstimator<F: Deref>(pub F) where F::Target: FeeEstimator;

impl<F: Deref> LowerBoundedFeeEstimator<F> where F::Target: FeeEstimator {
pub(crate) struct LowerBoundedFeeEstimator<F: Deref>(pub F)
where
F::Target: FeeEstimator;

impl<F: Deref> LowerBoundedFeeEstimator<F>
where
F::Target: FeeEstimator,
{
/// Creates a new `LowerBoundedFeeEstimator` which wraps the provided fee_estimator
pub fn new(fee_estimator: F) -> Self {
LowerBoundedFeeEstimator(fee_estimator)
}

pub fn bounded_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
cmp::max(
self.0.get_est_sat_per_1000_weight(confirmation_target),
FEERATE_FLOOR_SATS_PER_KW,
)
cmp::max(self.0.get_est_sat_per_1000_weight(confirmation_target), FEERATE_FLOOR_SATS_PER_KW)
}
}

#[cfg(test)]
mod tests {
use super::{FEERATE_FLOOR_SATS_PER_KW, LowerBoundedFeeEstimator, ConfirmationTarget, FeeEstimator};
use super::{
ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator, FEERATE_FLOOR_SATS_PER_KW,
};

struct TestFeeEstimator {
sat_per_kw: u32,
Expand All @@ -223,7 +227,10 @@ mod tests {
let test_fee_estimator = &TestFeeEstimator { sat_per_kw };
let fee_estimator = LowerBoundedFeeEstimator::new(test_fee_estimator);

assert_eq!(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee), FEERATE_FLOOR_SATS_PER_KW);
assert_eq!(
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee),
FEERATE_FLOOR_SATS_PER_KW
);
}

#[test]
Expand All @@ -232,6 +239,9 @@ mod tests {
let test_fee_estimator = &TestFeeEstimator { sat_per_kw };
let fee_estimator = LowerBoundedFeeEstimator::new(test_fee_estimator);

assert_eq!(fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee), sat_per_kw);
assert_eq!(
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee),
sat_per_kw
);
}
}
Loading
Loading