@@ -1384,6 +1384,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1384
1384
self . list_channels_with_filter ( |& ( _, ref channel) | channel. is_live ( ) )
1385
1385
}
1386
1386
1387
+ /// Helper function that issues the channel close events
1388
+ fn issue_channel_close_events ( & self , channel : & Channel < Signer > , closure_reason : ClosureReason ) {
1389
+ let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
1390
+ match channel. unbroadcasted_funding ( ) {
1391
+ Some ( transaction) => {
1392
+ pending_events_lock. push ( events:: Event :: DiscardFunding { channel_id : channel. channel_id ( ) , transaction } )
1393
+ } ,
1394
+ None => { } ,
1395
+ }
1396
+ pending_events_lock. push ( events:: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : closure_reason } ) ;
1397
+ }
1398
+
1387
1399
fn close_channel_internal ( & self , channel_id : & [ u8 ; 32 ] , target_feerate_sats_per_1000_weight : Option < u32 > ) -> Result < ( ) , APIError > {
1388
1400
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1389
1401
@@ -1430,12 +1442,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1430
1442
msg : channel_update
1431
1443
} ) ;
1432
1444
}
1433
- if let Ok ( mut pending_events_lock) = self . pending_events . lock ( ) {
1434
- pending_events_lock. push ( events:: Event :: ChannelClosed {
1435
- channel_id : * channel_id,
1436
- reason : ClosureReason :: HolderForceClosed
1437
- } ) ;
1438
- }
1445
+ self . issue_channel_close_events ( & channel, ClosureReason :: HolderForceClosed ) ;
1439
1446
}
1440
1447
break Ok ( ( ) ) ;
1441
1448
} ,
@@ -1526,13 +1533,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1526
1533
if let Some ( short_id) = chan. get ( ) . get_short_channel_id ( ) {
1527
1534
channel_state. short_to_id . remove ( & short_id) ;
1528
1535
}
1529
- let mut pending_events_lock = self . pending_events . lock ( ) . unwrap ( ) ;
1530
1536
if peer_node_id. is_some ( ) {
1531
1537
if let Some ( peer_msg) = peer_msg {
1532
- pending_events_lock . push ( events :: Event :: ChannelClosed { channel_id : * channel_id , reason : ClosureReason :: CounterpartyForceClosed { peer_msg : peer_msg. to_string ( ) } } ) ;
1538
+ self . issue_channel_close_events ( chan . get ( ) , ClosureReason :: CounterpartyForceClosed { peer_msg : peer_msg. to_string ( ) } ) ;
1533
1539
}
1534
1540
} else {
1535
- pending_events_lock . push ( events :: Event :: ChannelClosed { channel_id : * channel_id , reason : ClosureReason :: HolderForceClosed } ) ;
1541
+ self . issue_channel_close_events ( chan . get ( ) , ClosureReason :: HolderForceClosed ) ;
1536
1542
}
1537
1543
chan. remove_entry ( ) . 1
1538
1544
} else {
@@ -3705,7 +3711,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3705
3711
msg : update
3706
3712
} ) ;
3707
3713
}
3708
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : msg . channel_id , reason : ClosureReason :: CooperativeClosure } ) ;
3714
+ self . issue_channel_close_events ( & chan , ClosureReason :: CooperativeClosure ) ;
3709
3715
}
3710
3716
Ok ( ( ) )
3711
3717
}
@@ -4117,7 +4123,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4117
4123
msg : update
4118
4124
} ) ;
4119
4125
}
4120
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: CommitmentTxConfirmed } ) ;
4126
+ self . issue_channel_close_events ( & chan, ClosureReason :: CommitmentTxConfirmed ) ;
4121
4127
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4122
4128
node_id : chan. get_counterparty_node_id ( ) ,
4123
4129
action : msgs:: ErrorAction :: SendErrorMessage {
@@ -4233,12 +4239,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
4233
4239
} ) ;
4234
4240
}
4235
4241
4236
- if let Ok ( mut pending_events_lock) = self . pending_events . lock ( ) {
4237
- pending_events_lock. push ( events:: Event :: ChannelClosed {
4238
- channel_id : * channel_id,
4239
- reason : ClosureReason :: CooperativeClosure
4240
- } ) ;
4241
- }
4242
+ self . issue_channel_close_events ( chan, ClosureReason :: CooperativeClosure ) ;
4242
4243
4243
4244
log_info ! ( self . logger, "Broadcasting {}" , log_tx!( tx) ) ;
4244
4245
self . tx_broadcaster . broadcast_transaction ( & tx) ;
@@ -4675,7 +4676,7 @@ where
4675
4676
msg : update
4676
4677
} ) ;
4677
4678
}
4678
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : channel. channel_id ( ) , reason : ClosureReason :: CommitmentTxConfirmed } ) ;
4679
+ self . issue_channel_close_events ( channel, ClosureReason :: CommitmentTxConfirmed ) ;
4679
4680
pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
4680
4681
node_id : channel. get_counterparty_node_id ( ) ,
4681
4682
action : msgs:: ErrorAction :: SendErrorMessage { msg : e } ,
@@ -4866,7 +4867,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4866
4867
msg : update
4867
4868
} ) ;
4868
4869
}
4869
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4870
+ self . issue_channel_close_events ( chan, ClosureReason :: DisconnectedPeer ) ;
4870
4871
false
4871
4872
} else {
4872
4873
true
@@ -4881,7 +4882,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4881
4882
if let Some ( short_id) = chan. get_short_channel_id ( ) {
4882
4883
short_to_id. remove ( & short_id) ;
4883
4884
}
4884
- self . pending_events . lock ( ) . unwrap ( ) . push ( events :: Event :: ChannelClosed { channel_id : chan. channel_id ( ) , reason : ClosureReason :: DisconnectedPeer } ) ;
4885
+ self . issue_channel_close_events ( chan, ClosureReason :: DisconnectedPeer ) ;
4885
4886
return false ;
4886
4887
} else {
4887
4888
no_channels_remain = false ;
0 commit comments