@@ -5458,38 +5458,48 @@ where
5458
5458
} ) ?;
5459
5459
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
5460
5460
let peer_state = & mut * peer_state_lock;
5461
- match peer_state. channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5462
- hash_map:: Entry :: Occupied ( mut chan_entry) => {
5461
+ if let hash_map:: Entry :: Occupied ( chan_entry) = peer_state. outbound_v1_channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5462
+ log_error ! ( self . logger, "Force-closing channel {}" , log_bytes!( & msg. channel_id[ ..] ) ) ;
5463
+ self . issue_channel_close_events ( & chan_entry. get ( ) . context , ClosureReason :: HolderForceClosed ) ;
5464
+ let mut chan = remove_channel ! ( self , chan_entry) ;
5465
+ self . finish_force_close_channel ( chan. context . force_shutdown ( false ) ) ;
5466
+ return Ok ( ( ) ) ;
5467
+ } else if let hash_map:: Entry :: Occupied ( chan_entry) = peer_state. inbound_v1_channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5468
+ log_error ! ( self . logger, "Force-closing channel {}" , log_bytes!( & msg. channel_id[ ..] ) ) ;
5469
+ self . issue_channel_close_events ( & chan_entry. get ( ) . context , ClosureReason :: HolderForceClosed ) ;
5470
+ let mut chan = remove_channel ! ( self , chan_entry) ;
5471
+ self . finish_force_close_channel ( chan. context . force_shutdown ( false ) ) ;
5472
+ return Ok ( ( ) ) ;
5473
+ } else if let hash_map:: Entry :: Occupied ( mut chan_entry) = peer_state. channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5474
+ if !chan_entry. get ( ) . received_shutdown ( ) {
5475
+ log_info ! ( self . logger, "Received a shutdown message from our counterparty for channel {}{}." ,
5476
+ log_bytes!( msg. channel_id) ,
5477
+ if chan_entry. get( ) . sent_shutdown( ) { " after we initiated shutdown" } else { "" } ) ;
5478
+ }
5463
5479
5464
- if !chan_entry. get ( ) . received_shutdown ( ) {
5465
- log_info ! ( self . logger, "Received a shutdown message from our counterparty for channel {}{}." ,
5466
- log_bytes!( msg. channel_id) ,
5467
- if chan_entry. get( ) . sent_shutdown( ) { " after we initiated shutdown" } else { "" } ) ;
5468
- }
5480
+ let funding_txo_opt = chan_entry. get ( ) . context . get_funding_txo ( ) ;
5481
+ let ( shutdown, monitor_update_opt, htlcs) = try_chan_entry ! ( self ,
5482
+ chan_entry. get_mut( ) . shutdown( & self . signer_provider, & peer_state. latest_features, & msg) , chan_entry) ;
5483
+ dropped_htlcs = htlcs;
5469
5484
5470
- let funding_txo_opt = chan_entry. get ( ) . context . get_funding_txo ( ) ;
5471
- let ( shutdown, monitor_update_opt, htlcs) = try_chan_entry ! ( self ,
5472
- chan_entry. get_mut( ) . shutdown( & self . signer_provider, & peer_state. latest_features, & msg) , chan_entry) ;
5473
- dropped_htlcs = htlcs;
5474
-
5475
- if let Some ( msg) = shutdown {
5476
- // We can send the `shutdown` message before updating the `ChannelMonitor`
5477
- // here as we don't need the monitor update to complete until we send a
5478
- // `shutdown_signed`, which we'll delay if we're pending a monitor update.
5479
- peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
5480
- node_id : * counterparty_node_id,
5481
- msg,
5482
- } ) ;
5483
- }
5485
+ if let Some ( msg) = shutdown {
5486
+ // We can send the `shutdown` message before updating the `ChannelMonitor`
5487
+ // here as we don't need the monitor update to complete until we send a
5488
+ // `shutdown_signed`, which we'll delay if we're pending a monitor update.
5489
+ peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
5490
+ node_id : * counterparty_node_id,
5491
+ msg,
5492
+ } ) ;
5493
+ }
5484
5494
5485
- // Update the monitor with the shutdown script if necessary.
5486
- if let Some ( monitor_update) = monitor_update_opt {
5487
- break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update,
5488
- peer_state_lock, peer_state, per_peer_state, chan_entry) . map ( |_| ( ) ) ;
5489
- }
5490
- break Ok ( ( ) ) ;
5491
- } ,
5492
- hash_map :: Entry :: Vacant ( _ ) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}" , counterparty_node_id) , msg. channel_id ) )
5495
+ // Update the monitor with the shutdown script if necessary.
5496
+ if let Some ( monitor_update) = monitor_update_opt {
5497
+ break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update,
5498
+ peer_state_lock, peer_state, per_peer_state, chan_entry) . map ( |_| ( ) ) ;
5499
+ }
5500
+ break Ok ( ( ) ) ;
5501
+ } else {
5502
+ return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( format ! ( "Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}" , counterparty_node_id) , msg. channel_id ) )
5493
5503
}
5494
5504
} ;
5495
5505
for htlc_source in dropped_htlcs. drain ( ..) {
0 commit comments