Skip to content

Commit

Permalink
rustfmt: apply fn_single_line to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Jan 8, 2020
1 parent 38ee5c5 commit 4cd92bf
Show file tree
Hide file tree
Showing 18 changed files with 150 additions and 360 deletions.
8 changes: 2 additions & 6 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,8 @@ impl peer_handler::SocketDescriptor for SocketDescriptor {
}
impl Eq for SocketDescriptor {}
impl PartialEq for SocketDescriptor {
fn eq(&self, o: &Self) -> bool {
self.id == o.id
}
fn eq(&self, o: &Self) -> bool { self.id == o.id }
}
impl Hash for SocketDescriptor {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { self.id.hash(state); }
}
4 changes: 1 addition & 3 deletions lightning/src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
(matched, matched_index)
}

fn reentered(&self) -> usize {
self.reentered.load(Ordering::Relaxed)
}
fn reentered(&self) -> usize { self.reentered.load(Ordering::Relaxed) }
}

impl ChainWatchInterfaceUtil {
Expand Down
36 changes: 9 additions & 27 deletions lightning/src/chain/keysinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,12 @@ pub struct InMemoryChannelKeys {
}

impl ChannelKeys for InMemoryChannelKeys {
fn funding_key(&self) -> &SecretKey {
&self.funding_key
}
fn revocation_base_key(&self) -> &SecretKey {
&self.revocation_base_key
}
fn payment_base_key(&self) -> &SecretKey {
&self.payment_base_key
}
fn delayed_payment_base_key(&self) -> &SecretKey {
&self.delayed_payment_base_key
}
fn htlc_base_key(&self) -> &SecretKey {
&self.htlc_base_key
}
fn commitment_seed(&self) -> &[u8; 32] {
&self.commitment_seed
}
fn funding_key(&self) -> &SecretKey { &self.funding_key }
fn revocation_base_key(&self) -> &SecretKey { &self.revocation_base_key }
fn payment_base_key(&self) -> &SecretKey { &self.payment_base_key }
fn delayed_payment_base_key(&self) -> &SecretKey { &self.delayed_payment_base_key }
fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key }
fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed }

fn sign_remote_commitment<T: secp256k1::Signing>(&self,
channel_value_satoshis: u64,
Expand Down Expand Up @@ -418,17 +406,11 @@ impl KeysManager {
impl KeysInterface for KeysManager {
type ChanKeySigner = InMemoryChannelKeys;

fn get_node_secret(&self) -> SecretKey {
self.node_secret.clone()
}
fn get_node_secret(&self) -> SecretKey { self.node_secret.clone() }

fn get_destination_script(&self) -> Script {
self.destination_script.clone()
}
fn get_destination_script(&self) -> Script { self.destination_script.clone() }

fn get_shutdown_pubkey(&self) -> PublicKey {
self.shutdown_pubkey.clone()
}
fn get_shutdown_pubkey(&self) -> PublicKey { self.shutdown_pubkey.clone() }

fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys {
// We only seriously intend to rely on the channel_master_key for true secure
Expand Down
4 changes: 1 addition & 3 deletions lightning/src/chain/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ pub struct OutPoint {

impl OutPoint {
/// Creates a new `OutPoint` from the txid and the index.
pub fn new(txid: Sha256dHash, index: u16) -> OutPoint {
OutPoint { txid, index }
}
pub fn new(txid: Sha256dHash, index: u16) -> OutPoint { OutPoint { txid, index } }

/// Convert an `OutPoint` to a lightning channel id.
pub fn to_channel_id(&self) -> [u8; 32] {
Expand Down
12 changes: 3 additions & 9 deletions lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ impl LocalCommitmentTransaction {
Self { tx }
}

pub fn txid(&self) -> Sha256dHash {
self.tx.txid()
}
pub fn txid(&self) -> Sha256dHash { self.tx.txid() }

pub fn has_local_sig(&self) -> bool {
if self.tx.input.len() != 1 {
Expand Down Expand Up @@ -471,19 +469,15 @@ impl LocalCommitmentTransaction {
self.tx.input[0].witness.push(funding_redeemscript.as_bytes().to_vec());
}

pub fn without_valid_witness(&self) -> &Transaction {
&self.tx
}
pub fn without_valid_witness(&self) -> &Transaction { &self.tx }
pub fn with_valid_witness(&self) -> &Transaction {
assert!(self.has_local_sig());
&self.tx
}
}
impl PartialEq for LocalCommitmentTransaction {
// We dont care whether we are signed in equality comparison
fn eq(&self, o: &Self) -> bool {
self.txid() == o.txid()
}
fn eq(&self, o: &Self) -> bool { self.txid() == o.txid() }
}
impl Writeable for LocalCommitmentTransaction {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
Expand Down
96 changes: 24 additions & 72 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3595,15 +3595,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {

// Public utilities:

pub fn channel_id(&self) -> [u8; 32] {
self.channel_id
}
pub fn channel_id(&self) -> [u8; 32] { self.channel_id }

/// Gets the "user_id" value passed into the construction of this channel. It has no special
/// meaning and exists only to allow users to have a persistent identifier of a channel.
pub fn get_user_id(&self) -> u64 {
self.user_id
}
pub fn get_user_id(&self) -> u64 { self.user_id }

/// May only be called after funding has been initiated (ie is_funding_initiated() is true)
pub fn channel_monitor(&mut self) -> &mut ChannelMonitor {
Expand All @@ -3616,43 +3612,27 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
/// Guaranteed to be Some after both FundingLocked messages have been exchanged (and, thus,
/// is_usable() returns true).
/// Allowed in any state (including after shutdown)
pub fn get_short_channel_id(&self) -> Option<u64> {
self.short_channel_id
}
pub fn get_short_channel_id(&self) -> Option<u64> { self.short_channel_id }

/// Returns the funding_txo we either got from our peer, or were given by
/// get_outbound_funding_created.
pub fn get_funding_txo(&self) -> Option<OutPoint> {
self.channel_monitor.get_funding_txo()
}
pub fn get_funding_txo(&self) -> Option<OutPoint> { self.channel_monitor.get_funding_txo() }

/// Allowed in any state (including after shutdown)
pub fn get_their_node_id(&self) -> PublicKey {
self.their_node_id
}
pub fn get_their_node_id(&self) -> PublicKey { self.their_node_id }

/// Allowed in any state (including after shutdown)
pub fn get_our_htlc_minimum_msat(&self) -> u64 {
self.our_htlc_minimum_msat
}
pub fn get_our_htlc_minimum_msat(&self) -> u64 { self.our_htlc_minimum_msat }

/// Allowed in any state (including after shutdown)
pub fn get_their_htlc_minimum_msat(&self) -> u64 {
self.our_htlc_minimum_msat
}
pub fn get_their_htlc_minimum_msat(&self) -> u64 { self.our_htlc_minimum_msat }

pub fn get_value_satoshis(&self) -> u64 {
self.channel_value_satoshis
}
pub fn get_value_satoshis(&self) -> u64 { self.channel_value_satoshis }

pub fn get_fee_proportional_millionths(&self) -> u32 {
self.config.fee_proportional_millionths
}
pub fn get_fee_proportional_millionths(&self) -> u32 { self.config.fee_proportional_millionths }

#[cfg(test)]
pub fn get_feerate(&self) -> u64 {
self.feerate_per_kw
}
pub fn get_feerate(&self) -> u64 { self.feerate_per_kw }

pub fn get_cur_local_commitment_transaction_number(&self) -> u64 {
self.cur_local_commitment_transaction_number + 1
Expand All @@ -3672,9 +3652,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}

#[cfg(test)]
pub fn get_local_keys(&self) -> &ChanSigner {
&self.local_keys
}
pub fn get_local_keys(&self) -> &ChanSigner { &self.local_keys }

#[cfg(test)]
pub fn get_value_stat(&self) -> ChannelValueStat {
Expand Down Expand Up @@ -3705,17 +3683,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}

/// Allowed in any state (including after shutdown)
pub fn get_channel_update_count(&self) -> u32 {
self.channel_update_count
}
pub fn get_channel_update_count(&self) -> u32 { self.channel_update_count }

pub fn should_announce(&self) -> bool {
self.config.announced_channel
}
pub fn should_announce(&self) -> bool { self.config.announced_channel }

pub fn is_outbound(&self) -> bool {
self.channel_outbound
}
pub fn is_outbound(&self) -> bool { self.channel_outbound }

/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
/// Allowed in any state (including after shutdown)
Expand All @@ -3740,9 +3712,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}

/// Returns true if we've ever received a message from the remote end for this Channel
pub fn have_received_message(&self) -> bool {
self.channel_state > (ChannelState::OurInitSent as u32)
}
pub fn have_received_message(&self) -> bool { self.channel_state > (ChannelState::OurInitSent as u32) }

/// Returns true if this channel is fully established and not known to be closing.
/// Allowed in any state (including after shutdown)
Expand All @@ -3767,9 +3737,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}

/// Returns true if funding_created was sent/received.
pub fn is_funding_initiated(&self) -> bool {
self.channel_state >= ChannelState::FundingCreated as u32
}
pub fn is_funding_initiated(&self) -> bool { self.channel_state >= ChannelState::FundingCreated as u32 }

/// Returns true if this channel is fully shut down. True here implies that no further actions
/// may/will be taken on this channel, and thus this object should be freed. Any future changes
Expand All @@ -3783,25 +3751,15 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}
}

pub fn to_disabled_staged(&mut self) {
self.network_sync = UpdateStatus::DisabledStaged;
}
pub fn to_disabled_staged(&mut self) { self.network_sync = UpdateStatus::DisabledStaged; }

pub fn to_disabled_marked(&mut self) {
self.network_sync = UpdateStatus::DisabledMarked;
}
pub fn to_disabled_marked(&mut self) { self.network_sync = UpdateStatus::DisabledMarked; }

pub fn to_fresh(&mut self) {
self.network_sync = UpdateStatus::Fresh;
}
pub fn to_fresh(&mut self) { self.network_sync = UpdateStatus::Fresh; }

pub fn is_disabled_staged(&self) -> bool {
self.network_sync == UpdateStatus::DisabledStaged
}
pub fn is_disabled_staged(&self) -> bool { self.network_sync == UpdateStatus::DisabledStaged }

pub fn is_disabled_marked(&self) -> bool {
self.network_sync == UpdateStatus::DisabledMarked
}
pub fn is_disabled_marked(&self) -> bool { self.network_sync == UpdateStatus::DisabledMarked }

/// Called by channelmanager based on chain blocks being connected.
/// Note that we only need to use this to detect funding_signed, anything else is handled by
Expand Down Expand Up @@ -5116,9 +5074,7 @@ mod tests {
fee_est: u64,
}
impl FeeEstimator for TestFeeEstimator {
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 {
self.fee_est
}
fn get_est_sat_per_1000_weight(&self, _: ConfirmationTarget) -> u64 { self.fee_est }
}

#[test]
Expand Down Expand Up @@ -5160,15 +5116,11 @@ mod tests {
PublicKey::from_secret_key(&secp_ctx, &channel_close_key)
}

fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys {
self.chan_keys.clone()
}
fn get_channel_keys(&self, _inbound: bool) -> InMemoryChannelKeys { self.chan_keys.clone() }
fn get_onion_rand(&self) -> (SecretKey, [u8; 32]) {
panic!();
}
fn get_channel_id(&self) -> [u8; 32] {
[0; 32]
}
fn get_channel_id(&self) -> [u8; 32] { [0; 32] }
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2012,9 +2012,7 @@ impl<ChanSigner: ChannelKeys> ChannelManager<ChanSigner> {
}

/// Gets the node_id held by this ChannelManager
pub fn get_our_node_id(&self) -> PublicKey {
PublicKey::from_secret_key(&self.secp_ctx, &self.our_network_key)
}
pub fn get_our_node_id(&self) -> PublicKey { PublicKey::from_secret_key(&self.secp_ctx, &self.our_network_key) }

/// Used to restore channels to normal operation after a
/// ChannelMonitorUpdateErr::TemporaryFailure was returned from a channel monitor update
Expand Down
8 changes: 2 additions & 6 deletions lightning/src/ln/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,7 @@ impl ChannelMonitor {
/// the "reorg path" (ie not just starting at the same height but starting at the highest
/// common block that appears on your best chain as well as on the chain which contains the
/// last block hash returned) upon deserializing the object!
pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
self.write(writer, true)
}
pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> { self.write(writer, true) }

/// Encodes this monitor into the given writer, suitable for sending to a remote watchtower
///
Expand Down Expand Up @@ -1484,9 +1482,7 @@ impl ChannelMonitor {
min
}

pub(super) fn get_cur_remote_commitment_number(&self) -> u64 {
self.current_remote_commitment_number
}
pub(super) fn get_cur_remote_commitment_number(&self) -> u64 { self.current_remote_commitment_number }

pub(super) fn get_cur_local_commitment_number(&self) -> u64 {
if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx {
Expand Down
8 changes: 2 additions & 6 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6579,14 +6579,10 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
}

#[test]
fn test_fail_backwards_latest_remote_announce_a() {
do_test_fail_backwards_unrevoked_remote_announce(false, true);
}
fn test_fail_backwards_latest_remote_announce_a() { do_test_fail_backwards_unrevoked_remote_announce(false, true); }

#[test]
fn test_fail_backwards_latest_remote_announce_b() {
do_test_fail_backwards_unrevoked_remote_announce(true, true);
}
fn test_fail_backwards_latest_remote_announce_b() { do_test_fail_backwards_unrevoked_remote_announce(true, true); }

#[test]
fn test_fail_backwards_previous_remote_announce() {
Expand Down
Loading

0 comments on commit 4cd92bf

Please sign in to comment.