@@ -1373,12 +1373,39 @@ impl ChannelManager {
1373
1373
let ( commitment_msg, monitor) = match chan. get_mut ( ) . send_commitment ( ) {
1374
1374
Ok ( res) => res,
1375
1375
Err ( e) => {
1376
- if let ChannelError :: Ignore ( _) = e {
1377
- panic ! ( "Stated return value requirements in send_commitment() were not met" ) ;
1376
+ // We surely failed send_commitment due to bad keys, in that case
1377
+ // close channel and then send error message to peer.
1378
+ let their_node_id = chan. get ( ) . get_their_node_id ( ) ;
1379
+ let err: Result < ( ) , _ > = match e {
1380
+ ChannelError :: Ignore ( _) => {
1381
+ panic ! ( "Stated return value requirements in send_commitment() were not met" ) ;
1382
+ } ,
1383
+ ChannelError :: Close ( msg) => {
1384
+ log_trace ! ( self , "Closing channel {} due to Close-required error: {}" , log_bytes!( chan. key( ) [ ..] ) , msg) ;
1385
+ let ( channel_id, mut channel) = chan. remove_entry ( ) ;
1386
+ if let Some ( short_id) = channel. get_short_channel_id ( ) {
1387
+ channel_state. short_to_id . remove ( & short_id) ;
1388
+ }
1389
+ Err ( MsgHandleErrInternal :: from_finish_shutdown ( msg, channel_id, channel. force_shutdown ( ) , self . get_channel_update ( & channel) . ok ( ) ) )
1390
+ } ,
1391
+ ChannelError :: CloseDelayBroadcast { .. } => { panic ! ( "Wait is only generated on receipt of channel_reestablish, which is handled by try_chan_entry, we don't bother to support it here" ) ; }
1392
+ } ;
1393
+ match handle_error ! ( self , err) {
1394
+ Ok ( _) => unreachable ! ( ) ,
1395
+ Err ( e) => {
1396
+ if let Some ( msgs:: ErrorAction :: IgnoreError ) = e. action {
1397
+ } else {
1398
+ log_error ! ( self , "Got bad keys: {}!" , e. err) ;
1399
+ let mut channel_state = self . channel_state . lock ( ) . unwrap ( ) ;
1400
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: HandleError {
1401
+ node_id : their_node_id,
1402
+ action : e. action ,
1403
+ } ) ;
1404
+ }
1405
+ continue ;
1406
+ } ,
1378
1407
}
1379
- //TODO: Handle...this is bad!
1380
- continue ;
1381
- } ,
1408
+ }
1382
1409
} ;
1383
1410
if let Err ( e) = self . monitor . add_update_monitor ( monitor. get_funding_txo ( ) . unwrap ( ) , monitor) {
1384
1411
handle_errors. push ( ( chan. get ( ) . get_their_node_id ( ) , handle_monitor_err ! ( self , e, channel_state, chan, RAACommitmentOrder :: CommitmentFirst , false , true ) ) ) ;
0 commit comments