@@ -5524,38 +5524,48 @@ where
5524
5524
} ) ?;
5525
5525
let mut peer_state_lock = peer_state_mutex. lock ( ) . unwrap ( ) ;
5526
5526
let peer_state = & mut * peer_state_lock;
5527
- match peer_state. channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5528
- hash_map:: Entry :: Occupied ( mut chan_entry) => {
5527
+ if let hash_map:: Entry :: Occupied ( chan_entry) = peer_state. outbound_v1_channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5528
+ log_error ! ( self . logger, "Force-closing channel {}" , log_bytes!( & msg. channel_id[ ..] ) ) ;
5529
+ self . issue_channel_close_events ( & chan_entry. get ( ) . context , ClosureReason :: HolderForceClosed ) ;
5530
+ let mut chan = remove_channel ! ( self , chan_entry) ;
5531
+ self . finish_force_close_channel ( chan. context . force_shutdown ( false ) ) ;
5532
+ return Ok ( ( ) ) ;
5533
+ } else if let hash_map:: Entry :: Occupied ( chan_entry) = peer_state. inbound_v1_channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5534
+ log_error ! ( self . logger, "Force-closing channel {}" , log_bytes!( & msg. channel_id[ ..] ) ) ;
5535
+ self . issue_channel_close_events ( & chan_entry. get ( ) . context , ClosureReason :: HolderForceClosed ) ;
5536
+ let mut chan = remove_channel ! ( self , chan_entry) ;
5537
+ self . finish_force_close_channel ( chan. context . force_shutdown ( false ) ) ;
5538
+ return Ok ( ( ) ) ;
5539
+ } else if let hash_map:: Entry :: Occupied ( mut chan_entry) = peer_state. channel_by_id . entry ( msg. channel_id . clone ( ) ) {
5540
+ if !chan_entry. get ( ) . received_shutdown ( ) {
5541
+ log_info ! ( self . logger, "Received a shutdown message from our counterparty for channel {}{}." ,
5542
+ log_bytes!( msg. channel_id) ,
5543
+ if chan_entry. get( ) . sent_shutdown( ) { " after we initiated shutdown" } else { "" } ) ;
5544
+ }
5529
5545
5530
- if !chan_entry. get ( ) . received_shutdown ( ) {
5531
- log_info ! ( self . logger, "Received a shutdown message from our counterparty for channel {}{}." ,
5532
- log_bytes!( msg. channel_id) ,
5533
- if chan_entry. get( ) . sent_shutdown( ) { " after we initiated shutdown" } else { "" } ) ;
5534
- }
5546
+ let funding_txo_opt = chan_entry. get ( ) . context . get_funding_txo ( ) ;
5547
+ let ( shutdown, monitor_update_opt, htlcs) = try_chan_entry ! ( self ,
5548
+ chan_entry. get_mut( ) . shutdown( & self . signer_provider, & peer_state. latest_features, & msg) , chan_entry) ;
5549
+ dropped_htlcs = htlcs;
5535
5550
5536
- let funding_txo_opt = chan_entry. get ( ) . context . get_funding_txo ( ) ;
5537
- let ( shutdown, monitor_update_opt, htlcs) = try_chan_entry ! ( self ,
5538
- chan_entry. get_mut( ) . shutdown( & self . signer_provider, & peer_state. latest_features, & msg) , chan_entry) ;
5539
- dropped_htlcs = htlcs;
5540
-
5541
- if let Some ( msg) = shutdown {
5542
- // We can send the `shutdown` message before updating the `ChannelMonitor`
5543
- // here as we don't need the monitor update to complete until we send a
5544
- // `shutdown_signed`, which we'll delay if we're pending a monitor update.
5545
- peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
5546
- node_id : * counterparty_node_id,
5547
- msg,
5548
- } ) ;
5549
- }
5551
+ if let Some ( msg) = shutdown {
5552
+ // We can send the `shutdown` message before updating the `ChannelMonitor`
5553
+ // here as we don't need the monitor update to complete until we send a
5554
+ // `shutdown_signed`, which we'll delay if we're pending a monitor update.
5555
+ peer_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
5556
+ node_id : * counterparty_node_id,
5557
+ msg,
5558
+ } ) ;
5559
+ }
5550
5560
5551
- // Update the monitor with the shutdown script if necessary.
5552
- if let Some ( monitor_update) = monitor_update_opt {
5553
- break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update,
5554
- peer_state_lock, peer_state, per_peer_state, chan_entry) . map ( |_| ( ) ) ;
5555
- }
5556
- break Ok ( ( ) ) ;
5557
- } ,
5558
- 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 ) )
5561
+ // Update the monitor with the shutdown script if necessary.
5562
+ if let Some ( monitor_update) = monitor_update_opt {
5563
+ break handle_new_monitor_update ! ( self , funding_txo_opt. unwrap( ) , monitor_update,
5564
+ peer_state_lock, peer_state, per_peer_state, chan_entry) . map ( |_| ( ) ) ;
5565
+ }
5566
+ break Ok ( ( ) ) ;
5567
+ } else {
5568
+ 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 ) )
5559
5569
}
5560
5570
} ;
5561
5571
for htlc_source in dropped_htlcs. drain ( ..) {
0 commit comments