Skip to content

Commit

Permalink
Refactor funding pending check to return transaction if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
1nF0rmed committed Oct 6, 2021
1 parent 6a546dd commit bfe1f39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,10 +1306,6 @@ impl<Signer: Sign> Channel<Signer> {
self.channel_transaction_parameters.funding_outpoint.unwrap()
}

pub(crate) fn funding_transaction(&self) -> Option<Transaction> {
self.funding_transaction.clone()
}

#[inline]
/// Creates a set of keys for build_commitment_transaction to generate a transaction which our
/// counterparty will sign (ie DO NOT send signatures over a transaction created by this to
Expand Down Expand Up @@ -1905,10 +1901,14 @@ impl<Signer: Sign> Channel<Signer> {
Ok(())
}

/// Returns true if we have a pending funding transaction that is yet to broadcast
pub fn is_funding_pending(&self) -> bool {
self.funding_transaction.is_some() &&
self.channel_state & (ChannelState::FundingCreated as u32) != 0
/// Returns transaction if there is pending funding transaction that is yet to broadcast
pub fn has_funding_pending(&self) -> Option<Transaction> {
if self.funding_transaction.is_some() &&
self.channel_state & (ChannelState::FundingCreated as u32) != 0 {
self.funding_transaction.clone()
} else {
None
}
}

/// Returns a HTLCStats about inbound pending htlcs
Expand Down
7 changes: 5 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,8 +1329,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
/// Helper function that issues the channel close events
fn issue_channel_close_events(&self, channel: &Channel<Signer>, closure_reason: ClosureReason) {
let mut pending_events_lock = self.pending_events.lock().unwrap();
if channel.is_funding_pending() {
pending_events_lock.push(events::Event::DiscardFunding { channel_id: channel.channel_id(), transaction: channel.funding_transaction() });
match channel.has_funding_pending() {
Some(transaction) => {
pending_events_lock.push(events::Event::DiscardFunding { channel_id: channel.channel_id(), transaction })
},
None => {},
}
pending_events_lock.push(events::Event::ChannelClosed { channel_id: channel.channel_id(), reason: closure_reason });
}
Expand Down

0 comments on commit bfe1f39

Please sign in to comment.