@@ -1002,16 +1002,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1002
1002
}
1003
1003
}
1004
1004
1005
- fn force_close_channel_with_peer ( & self , channel_id : & [ u8 ; 32 ] , peer_node_id : Option < & PublicKey > ) -> Result < ( ) , APIError > {
1005
+ fn force_close_channel_with_peer ( & self , channel_id : & [ u8 ; 32 ] , peer_node_id : Option < & PublicKey > ) -> Result < PublicKey , APIError > {
1006
1006
let mut chan = {
1007
1007
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
1008
1008
let channel_state = & mut * channel_state_lock;
1009
1009
if let hash_map:: Entry :: Occupied ( chan) = channel_state. by_id . entry ( channel_id. clone ( ) ) {
1010
1010
if let Some ( node_id) = peer_node_id {
1011
1011
if chan. get ( ) . get_counterparty_node_id ( ) != * node_id {
1012
- // Error or Ok here doesn't matter - the result is only exposed publicly
1013
- // when peer_node_id is None anyway.
1014
- return Ok ( ( ) ) ;
1012
+ return Err ( APIError :: ChannelUnavailable { err : "No such channel" . to_owned ( ) } ) ;
1015
1013
}
1016
1014
}
1017
1015
if let Some ( short_id) = chan. get ( ) . get_short_channel_id ( ) {
@@ -1031,14 +1029,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1031
1029
} ) ;
1032
1030
}
1033
1031
1034
- Ok ( ( ) )
1032
+ Ok ( chan . get_counterparty_node_id ( ) )
1035
1033
}
1036
1034
1037
1035
/// Force closes a channel, immediately broadcasting the latest local commitment transaction to
1038
1036
/// the chain and rejecting new HTLCs on the given channel. Fails if channel_id is unknown to the manager.
1039
1037
pub fn force_close_channel ( & self , channel_id : & [ u8 ; 32 ] ) -> Result < ( ) , APIError > {
1040
1038
let _persistence_guard = PersistenceNotifierGuard :: new ( & self . total_consistency_lock , & self . persistence_notifier ) ;
1041
- self . force_close_channel_with_peer ( channel_id, None )
1039
+ match self . force_close_channel_with_peer ( channel_id, None ) {
1040
+ Ok ( pk) => {
1041
+ self . channel_state . lock ( ) . unwrap ( ) . pending_msg_events . push (
1042
+ events:: MessageSendEvent :: HandleError {
1043
+ node_id : pk,
1044
+ action : msgs:: ErrorAction :: SendErrorMessage {
1045
+ msg : msgs:: ErrorMessage { channel_id : * channel_id, data : "Channel force-closed" . to_owned ( ) }
1046
+ } ,
1047
+ }
1048
+ ) ;
1049
+ Ok ( ( ) )
1050
+ } ,
1051
+ Err ( e) => Err ( e)
1052
+ }
1042
1053
}
1043
1054
1044
1055
/// Force close all channels, immediately broadcasting the latest local commitment transaction
@@ -3194,6 +3205,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3194
3205
msg : update
3195
3206
} ) ;
3196
3207
}
3208
+ pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3209
+ node_id : chan. get_counterparty_node_id ( ) ,
3210
+ action : msgs:: ErrorAction :: SendErrorMessage {
3211
+ msg : msgs:: ErrorMessage { channel_id : chan. channel_id ( ) , data : "Channel force-closed" . to_owned ( ) }
3212
+ } ,
3213
+ } ) ;
3197
3214
}
3198
3215
} ,
3199
3216
}
@@ -3364,6 +3381,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3364
3381
msg : update
3365
3382
} ) ;
3366
3383
}
3384
+ pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3385
+ node_id : channel. get_counterparty_node_id ( ) ,
3386
+ action : msgs:: ErrorAction :: SendErrorMessage {
3387
+ msg : msgs:: ErrorMessage { channel_id : channel. channel_id ( ) , data : "Commitment transaction was confirmed on chain." . to_owned ( ) }
3388
+ } ,
3389
+ } ) ;
3367
3390
return false ;
3368
3391
}
3369
3392
}
@@ -3433,7 +3456,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3433
3456
let channel_state = & mut * channel_lock;
3434
3457
let short_to_id = & mut channel_state. short_to_id ;
3435
3458
let pending_msg_events = & mut channel_state. pending_msg_events ;
3436
- channel_state. by_id . retain ( |_ , v| {
3459
+ channel_state. by_id . retain ( |channel_id , v| {
3437
3460
if v. block_disconnected ( header, new_height) {
3438
3461
if let Some ( short_id) = v. get_short_channel_id ( ) {
3439
3462
short_to_id. remove ( & short_id) ;
@@ -3444,6 +3467,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3444
3467
msg : update
3445
3468
} ) ;
3446
3469
}
3470
+ pending_msg_events. push ( events:: MessageSendEvent :: HandleError {
3471
+ node_id : v. get_counterparty_node_id ( ) ,
3472
+ action : msgs:: ErrorAction :: SendErrorMessage {
3473
+ msg : msgs:: ErrorMessage { channel_id : * channel_id, data : "Funding transaction was un-confirmed." . to_owned ( ) }
3474
+ } ,
3475
+ } ) ;
3447
3476
false
3448
3477
} else {
3449
3478
true
0 commit comments