@@ -1598,6 +1598,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1598
1598
action : msgs:: ErrorAction :: IgnoreError
1599
1599
} ) ;
1600
1600
}
1601
+ log_trace ! ( self . logger, "Attempting to generate broadcast channel update for channel {}" , log_bytes!( chan. channel_id( ) ) ) ;
1601
1602
self . get_channel_update_for_unicast ( chan)
1602
1603
}
1603
1604
@@ -1607,6 +1608,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
1607
1608
/// provided evidence that they know about the existence of the channel.
1608
1609
/// May be called with channel_state already locked!
1609
1610
fn get_channel_update_for_unicast ( & self , chan : & Channel < Signer > ) -> Result < msgs:: ChannelUpdate , LightningError > {
1611
+ log_trace ! ( self . logger, "Attempting to generate channel update for channel {}" , log_bytes!( chan. channel_id( ) ) ) ;
1610
1612
let short_channel_id = match chan. get_short_channel_id ( ) {
1611
1613
None => return Err ( LightningError { err : "Channel not yet established" . to_owned ( ) , action : msgs:: ErrorAction :: IgnoreError } ) ,
1612
1614
Some ( id) => id,
@@ -2789,7 +2791,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2789
2791
pub fn channel_monitor_updated ( & self , funding_txo : & OutPoint , highest_applied_update_id : u64 ) {
2790
2792
let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
2791
2793
2792
- let ( mut pending_failures, chan_restoration_res) = {
2794
+ let chan_restoration_res;
2795
+ let mut pending_failures = {
2793
2796
let mut channel_lock = self . channel_state . lock ( ) . unwrap ( ) ;
2794
2797
let channel_state = & mut * channel_lock;
2795
2798
let mut channel = match channel_state. by_id . entry ( funding_txo. to_channel_id ( ) ) {
@@ -2801,7 +2804,21 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2801
2804
}
2802
2805
2803
2806
let ( raa, commitment_update, order, pending_forwards, pending_failures, funding_broadcastable, funding_locked) = channel. get_mut ( ) . monitor_updating_restored ( & self . logger ) ;
2804
- ( pending_failures, handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, None , pending_forwards, funding_broadcastable, funding_locked) )
2807
+ let channel_update = if funding_locked. is_some ( ) && channel. get ( ) . is_usable ( ) && !channel. get ( ) . should_announce ( ) {
2808
+ // We only send a channel_update in the case where we are just now sending a
2809
+ // funding_locked and the channel is in a usable state. Further, we rely on the
2810
+ // normal announcement_signatures process to send a channel_update for public
2811
+ // channels, only generating a unicast channel_update if this is a private channel.
2812
+ Some ( events:: MessageSendEvent :: SendChannelUpdate {
2813
+ node_id : channel. get ( ) . get_counterparty_node_id ( ) ,
2814
+ msg : self . get_channel_update_for_unicast ( channel. get ( ) ) . unwrap ( ) ,
2815
+ } )
2816
+ } else { None } ;
2817
+ chan_restoration_res = handle_chan_restoration_locked ! ( self , channel_lock, channel_state, channel, raa, commitment_update, order, None , pending_forwards, funding_broadcastable, funding_locked) ;
2818
+ if let Some ( upd) = channel_update {
2819
+ channel_state. pending_msg_events . push ( upd) ;
2820
+ }
2821
+ pending_failures
2805
2822
} ;
2806
2823
post_handle_chan_restoration ! ( self , chan_restoration_res) ;
2807
2824
for failure in pending_failures. drain ( ..) {
@@ -2964,6 +2981,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2964
2981
node_id : counterparty_node_id. clone ( ) ,
2965
2982
msg : announcement_sigs,
2966
2983
} ) ;
2984
+ } else if chan. get ( ) . is_usable ( ) {
2985
+ channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendChannelUpdate {
2986
+ node_id : counterparty_node_id. clone ( ) ,
2987
+ msg : self . get_channel_update_for_unicast ( chan. get ( ) ) . unwrap ( ) ,
2988
+ } ) ;
2967
2989
}
2968
2990
Ok ( ( ) )
2969
2991
} ,
@@ -3394,7 +3416,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3394
3416
}
3395
3417
3396
3418
fn internal_channel_reestablish ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , MsgHandleErrInternal > {
3397
- let ( htlcs_failed_forward, need_lnd_workaround, chan_restoration_res) = {
3419
+ let chan_restoration_res;
3420
+ let ( htlcs_failed_forward, need_lnd_workaround) = {
3398
3421
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3399
3422
let channel_state = & mut * channel_state_lock;
3400
3423
@@ -3409,15 +3432,27 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3409
3432
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
3410
3433
let ( funding_locked, revoke_and_ack, commitment_update, monitor_update_opt, order, htlcs_failed_forward, shutdown) =
3411
3434
try_chan_entry ! ( self , chan. get_mut( ) . channel_reestablish( msg, & self . logger) , channel_state, chan) ;
3435
+ let mut channel_update = None ;
3412
3436
if let Some ( msg) = shutdown {
3413
3437
channel_state. pending_msg_events . push ( events:: MessageSendEvent :: SendShutdown {
3414
3438
node_id : counterparty_node_id. clone ( ) ,
3415
3439
msg,
3416
3440
} ) ;
3441
+ } else if chan. get ( ) . is_usable ( ) {
3442
+ // If the channel is in a usable state (ie the channel is not being shut
3443
+ // down), send a unicast channel_update to our counterparty to make sure
3444
+ // they have the latest channel parameters.
3445
+ channel_update = Some ( events:: MessageSendEvent :: SendChannelUpdate {
3446
+ node_id : chan. get ( ) . get_counterparty_node_id ( ) ,
3447
+ msg : self . get_channel_update_for_unicast ( chan. get ( ) ) . unwrap ( ) ,
3448
+ } ) ;
3417
3449
}
3418
3450
let need_lnd_workaround = chan. get_mut ( ) . workaround_lnd_bug_4006 . take ( ) ;
3419
- ( htlcs_failed_forward, need_lnd_workaround,
3420
- 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) )
3451
+ 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) ;
3452
+ if let Some ( upd) = channel_update {
3453
+ channel_state. pending_msg_events . push ( upd) ;
3454
+ }
3455
+ ( htlcs_failed_forward, need_lnd_workaround)
3421
3456
} ,
3422
3457
hash_map:: Entry :: Vacant ( _) => return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Failed to find corresponding channel" . to_owned ( ) , msg. channel_id ) )
3423
3458
}
@@ -3970,6 +4005,12 @@ where
3970
4005
node_id : channel. get_counterparty_node_id ( ) ,
3971
4006
msg : announcement_sigs,
3972
4007
} ) ;
4008
+ } else if channel. is_usable ( ) {
4009
+ log_trace ! ( self . logger, "Sending funding_locked WITHOUT announcement_signatures but with private channel_update for our counterparty on channel {}" , log_bytes!( channel. channel_id( ) ) ) ;
4010
+ pending_msg_events. push ( events:: MessageSendEvent :: SendChannelUpdate {
4011
+ node_id : channel. get_counterparty_node_id ( ) ,
4012
+ msg : self . get_channel_update_for_unicast ( channel) . unwrap ( ) ,
4013
+ } ) ;
3973
4014
} else {
3974
4015
log_trace ! ( self . logger, "Sending funding_locked WITHOUT announcement_signatures for {}" , log_bytes!( channel. channel_id( ) ) ) ;
3975
4016
}
@@ -4209,6 +4250,7 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4209
4250
& events:: MessageSendEvent :: BroadcastChannelAnnouncement { .. } => true ,
4210
4251
& events:: MessageSendEvent :: BroadcastNodeAnnouncement { .. } => true ,
4211
4252
& events:: MessageSendEvent :: BroadcastChannelUpdate { .. } => true ,
4253
+ & events:: MessageSendEvent :: SendChannelUpdate { ref node_id, .. } => node_id != counterparty_node_id,
4212
4254
& events:: MessageSendEvent :: HandleError { ref node_id, .. } => node_id != counterparty_node_id,
4213
4255
& events:: MessageSendEvent :: PaymentFailureNetworkUpdate { .. } => true ,
4214
4256
& events:: MessageSendEvent :: SendChannelRangeQuery { .. } => false ,
@@ -5042,7 +5084,19 @@ pub mod bench {
5042
5084
Listen :: block_connected ( & node_b, & block, 1 ) ;
5043
5085
5044
5086
node_a. handle_funding_locked ( & node_b. get_our_node_id ( ) , & get_event_msg ! ( node_b_holder, MessageSendEvent :: SendFundingLocked , node_a. get_our_node_id( ) ) ) ;
5045
- node_b. handle_funding_locked ( & node_a. get_our_node_id ( ) , & get_event_msg ! ( node_a_holder, MessageSendEvent :: SendFundingLocked , node_b. get_our_node_id( ) ) ) ;
5087
+ let msg_events = node_a. get_and_clear_pending_msg_events ( ) ;
5088
+ assert_eq ! ( msg_events. len( ) , 2 ) ;
5089
+ match msg_events[ 0 ] {
5090
+ MessageSendEvent :: SendFundingLocked { ref msg, .. } => {
5091
+ node_b. handle_funding_locked ( & node_a. get_our_node_id ( ) , msg) ;
5092
+ get_event_msg ! ( node_b_holder, MessageSendEvent :: SendChannelUpdate , node_a. get_our_node_id( ) ) ;
5093
+ } ,
5094
+ _ => panic ! ( ) ,
5095
+ }
5096
+ match msg_events[ 1 ] {
5097
+ MessageSendEvent :: SendChannelUpdate { .. } => { } ,
5098
+ _ => panic ! ( ) ,
5099
+ }
5046
5100
5047
5101
let dummy_graph = NetworkGraph :: new ( genesis_hash) ;
5048
5102
0 commit comments