@@ -947,11 +947,6 @@ macro_rules! handle_chan_restoration_locked {
947
947
node_id: counterparty_node_id,
948
948
msg: announcement_sigs,
949
949
} ) ;
950
- } else if $channel_entry. get( ) . is_usable( ) {
951
- $channel_state. pending_msg_events. push( events:: MessageSendEvent :: SendChannelUpdate {
952
- node_id: counterparty_node_id,
953
- msg: $self. get_channel_update_for_unicast( $channel_entry. get( ) ) . unwrap( ) ,
954
- } ) ;
955
950
}
956
951
$channel_state. short_to_id. insert( $channel_entry. get( ) . get_short_channel_id( ) . unwrap( ) , $channel_entry. get( ) . channel_id( ) ) ;
957
952
}
@@ -2791,7 +2786,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2791
2786
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2792
2787
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2793
2788
2794
- let ( mut pending_failures, chan_restoration_res) = {
2789
+ let chan_restoration_res;
2790
+ let mut pending_failures = {
2795
2791
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2796
2792
let channel_state = & mut * channel_lock;
2797
2793
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2803,7 +2799,22 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2803
2799
}
2804
2800
2805
2801
let ( raa, commitment_update, order, pending_forwards, pending_failures, funding_broadcastable, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2806
- ( pending_failures, handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, None , pending_forwards, funding_broadcastable, funding_locked) )
2802
+ let channel_update = if funding_locked. is_some ( ) && channel. get ( ) . is_usable ( ) {
2803
+ Some ( events:: MessageSendEvent :: SendChannelUpdate {
2804
+ node_id : channel. get ( ) . get_counterparty_node_id ( ) ,
2805
+ msg : self . get_channel_update_for_unicast ( channel. get ( ) ) . unwrap ( ) ,
2806
+ } )
2807
+ } else { None } ;
2808
+ chan_restoration_res = handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, None , pending_forwards, funding_broadcastable, funding_locked) ;
2809
+ if let Some ( upd) = channel_update {
2810
+ // If we closed the channel due to a failed monitor update in
2811
+ // handle_chan_restoration_locked this will send a bogus channel_update immediately
2812
+ // after closure, but our direct peer should be fine with that, given they know the
2813
+ // channel state as well. Further, we'll broadcast a channel_disabled channel_update
2814
+ // in post_handle_chan_restoration below for public channels.
2815
+ channel_state. pending_msg_events . push ( upd) ;
2816
+ }
2817
+ pending_failures
2807
2818
} ;
2808
2819
post_handle_chan_restoration ! ( self , chan_restoration_res) ;
2809
2820
for failure in pending_failures. drain ( ..) {
@@ -3395,7 +3406,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3395
3406
}
3396
3407
3397
3408
fn internal_channel_reestablish ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , MsgHandleErrInternal > {
3398
- let ( htlcs_failed_forward, chan_restoration_res) = {
3409
+ let chan_restoration_res;
3410
+ let htlcs_failed_forward = {
3399
3411
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3400
3412
let channel_state = & mut * channel_state_lock;
3401
3413
@@ -3410,13 +3422,28 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3410
3422
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
3411
3423
let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, order, htlcs_failed_forward, shutdown) =
3412
3424
try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
3425
+ let mut channel_update = None ;
3413
3426
if let Some ( msg) = shutdown {
3414
3427
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
3415
3428
node_id : counterparty_node_id. clone ( ) ,
3416
3429
msg,
3417
3430
} ) ;
3431
+ } else if chan. get ( ) . is_usable ( ) {
3432
+ channel_update = Some ( events:: MessageSendEvent :: SendChannelUpdate {
3433
+ node_id : chan. get ( ) . get_counterparty_node_id ( ) ,
3434
+ msg : self . get_channel_update_for_unicast ( chan. get ( ) ) . unwrap ( ) ,
3435
+ } ) ;
3436
+ }
3437
+ chan_restoration_res = handle_chan_restoration_locked ! ( self , channel_state_lock, channel_state, chan, revoke_and_ack, commitment_update, order, monitor_update_opt, Vec :: new( ) , None , funding_locked) ;
3438
+ if let Some ( upd) = channel_update {
3439
+ // If we closed the channel due to a failed monitor update in
3440
+ // handle_chan_restoration_locked this will send a bogus channel_update immediately
3441
+ // after closure, but our direct peer should be fine with that, given they know the
3442
+ // channel state as well. Further, we'll broadcast a channel_disabled channel_update
3443
+ // in post_handle_chan_restoration below for public channels.
3444
+ channel_state. pending_msg_events . push ( upd) ;
3418
3445
}
3419
- ( htlcs_failed_forward, handle_chan_restoration_locked ! ( self , channel_state_lock , channel_state , chan , revoke_and_ack , commitment_update , order , monitor_update_opt , Vec :: new ( ) , None , funding_locked ) )
3446
+ htlcs_failed_forward
3420
3447
} ,
3421
3448
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
3422
3449
}
0 commit comments