Skip to content

Commit 777636c

Browse files
committed
Adds check for pending funding transaction broadcasts
1 parent ffda105 commit 777636c

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,12 @@ impl<Signer: Sign> Channel<Signer> {
19011901
Ok(())
19021902
}
19031903

1904+
/// Returns true if we have a pending funding transaction that is yet to broadcast
1905+
pub fn is_funding_pending(&self) -> bool {
1906+
self.funding_transaction.is_some() &&
1907+
self.channel_state & (ChannelState::FundingCreated as u32) != 0
1908+
}
1909+
19041910
/// Returns a HTLCStats about inbound pending htlcs
19051911
fn get_inbound_pending_htlc_stats(&self) -> HTLCStats {
19061912
let mut stats = HTLCStats {

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
13291329
/// Helper function that issues the channel close events
13301330
fn issue_channel_close_events(&self, channel: &Channel<Signer>, closure_reason: ClosureReason) {
13311331
let mut pending_events_lock = self.pending_events.lock().unwrap();
1332+
if channel.is_funding_pending() {
1333+
pending_events_lock.push(events::Event::DiscardFunding { channel_id: channel.channel_id(), transaction: channel.channel_transaction_parameters.funding_outpoint});
1334+
}
13321335
pending_events_lock.push(events::Event::ChannelClosed { channel_id: channel.channel_id(), reason: closure_reason });
13331336
}
13341337

lightning/src/ln/functional_test_utils.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,21 +763,32 @@ macro_rules! check_closed_broadcast {
763763
}}
764764
}
765765

766-
/// Check that a channel's closing channel event has been issued
766+
/// Check that a channel's closing channel events has been issued
767767
#[macro_export]
768768
macro_rules! check_closed_event {
769-
($node: expr, $events: expr, $reason: expr) => {{
769+
($node: expr, $events: expr, $reason: expr) => {
770+
check_closed_event!($node, $events, $reason, false);
771+
};
772+
($node: expr, $events: expr, $reason: expr, $is_check_discard_funding: expr) => {{
770773
let events = $node.node.get_and_clear_pending_events();
771774
assert_eq!(events.len(), $events);
772775
let expected_reason = $reason;
776+
let mut issues_discard_funding = false;
773777
for event in events {
774778
match event {
775779
Event::ChannelClosed { ref reason, .. } => {
776780
assert_eq!(*reason, expected_reason);
777781
},
782+
Event::DiscardFunding { .. } => {
783+
issues_discard_funding = true;
784+
}
778785
_ => panic!("Unexpected event"),
779786
}
780787
}
788+
789+
if $is_check_discard_funding {
790+
assert!(issues_discard_funding);
791+
}
781792
}}
782793
}
783794

lightning/src/ln/functional_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8632,7 +8632,7 @@ fn test_pre_lockin_no_chan_closed_update() {
86328632
let channel_id = ::chain::transaction::OutPoint { txid: funding_created_msg.funding_txid, index: funding_created_msg.funding_output_index }.to_channel_id();
86338633
nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id, data: "Hi".to_owned() });
86348634
assert!(nodes[0].chain_monitor.added_monitors.lock().unwrap().is_empty());
8635-
check_closed_event!(nodes[0], 1, ClosureReason::CounterpartyForceClosed { peer_msg: "Hi".to_string() });
8635+
check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: "Hi".to_string() }, true);
86368636
}
86378637

86388638
#[test]

0 commit comments

Comments
 (0)