Skip to content

Run rustfmt on chain/transaction, chain/chaininterface, max_payment_path_len_tests, and chanmon_update_fail_tests #3783

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 12 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
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
);
}
}
29 changes: 15 additions & 14 deletions lightning/src/chain/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ impl OutPoint {
/// This is not exported to bindings users as the same type is used universally in the C bindings
/// for all outpoints
pub fn into_bitcoin_outpoint(self) -> BitcoinOutPoint {
BitcoinOutPoint {
txid: self.txid,
vout: self.index as u32,
}
BitcoinOutPoint { txid: self.txid, vout: self.index as u32 }
}
}

Expand All @@ -90,20 +87,24 @@ mod tests {
use crate::chain::transaction::OutPoint;
use crate::ln::types::ChannelId;

use bitcoin::transaction::Transaction;
use bitcoin::consensus::encode;
use bitcoin::hex::FromHex;
use bitcoin::transaction::Transaction;

#[test]
fn test_channel_id_calculation() {
let tx: Transaction = encode::deserialize(&<Vec<u8>>::from_hex("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint {
txid: tx.compute_txid(),
index: 0
}).0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e").unwrap()[..]);
assert_eq!(&ChannelId::v1_from_funding_outpoint(OutPoint {
txid: tx.compute_txid(),
index: 1
}).0[..], &<Vec<u8>>::from_hex("3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f").unwrap()[..]);
let tx_hex = "020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000";
let tx: Transaction =
encode::deserialize(&<Vec<u8>>::from_hex(tx_hex).unwrap()[..]).unwrap();

let txid = tx.compute_txid();

let id_0 = ChannelId::v1_from_funding_outpoint(OutPoint { txid, index: 0 });
let expected_0 = "3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25e";
assert_eq!(&id_0.0[..], &Vec::<u8>::from_hex(expected_0).unwrap()[..]);

let id_1 = ChannelId::v1_from_funding_outpoint(OutPoint { txid, index: 1 });
let expected_1 = "3e88dd7165faf7be58b3c5bb2c9c452aebef682807ea57080f62e6f6e113c25f";
assert_eq!(&id_1.0[..], &Vec::<u8>::from_hex(expected_1).unwrap()[..]);
}
}
Loading
Loading