@@ -1070,6 +1070,14 @@ pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
10701070/// [`OutboundPayments::remove_stale_resolved_payments`].
10711071pub ( crate ) const IDEMPOTENCY_TIMEOUT_TICKS : u8 = 7 ;
10721072
1073+ /// The number of ticks of [`ChannelManager::timer_tick_occurred`] where a peer is disconnected
1074+ /// until we mark the channel disabled and gossip the update.
1075+ pub ( crate ) const DISABLE_GOSSIP_TICKS : u8 = 10 ;
1076+
1077+ /// The number of ticks of [`ChannelManager::timer_tick_occurred`] where a peer is connected until
1078+ /// we mark the channel enabled and gossip the update.
1079+ pub ( crate ) const ENABLE_GOSSIP_TICKS : u8 = 5 ;
1080+
10731081/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
10741082/// (inbound) ones. The number of peers with unfunded channels is limited separately in
10751083/// [`MAX_UNFUNDED_CHANNEL_PEERS`].
@@ -2457,7 +2465,14 @@ where
24572465 // hopefully an attacker trying to path-trace payments cannot make this occur
24582466 // on a small/per-node/per-channel scale.
24592467 if !chan. is_live ( ) { // channel_disabled
2460- break Some ( ( "Forwarding channel is not in a ready state." , 0x1000 | 20 , chan_update_opt) ) ;
2468+ // If the channel_update we're going to return is disabled (i.e. the
2469+ // peer has been disabled for some time), return `channel_disabled`,
2470+ // otherwise return `temporary_channel_failure`.
2471+ if chan_update_opt. as_ref ( ) . map ( |u| u. contents . flags & 2 == 2 ) . unwrap_or ( false ) {
2472+ break Some ( ( "Forwarding channel has been disconnected for some time." , 0x1000 | 20 , chan_update_opt) ) ;
2473+ } else {
2474+ break Some ( ( "Forwarding channel is not in a ready state." , 0x1000 | 7 , chan_update_opt) ) ;
2475+ }
24612476 }
24622477 if * outgoing_amt_msat < chan. get_counterparty_htlc_minimum_msat ( ) { // amount_below_minimum
24632478 break Some ( ( "HTLC amount was below the htlc_minimum_msat" , 0x1000 | 11 , chan_update_opt) ) ;
@@ -2582,11 +2597,18 @@ where
25822597 log_trace ! ( self . logger, "Generating channel update for channel {}" , log_bytes!( chan. channel_id( ) ) ) ;
25832598 let were_node_one = self . our_network_pubkey . serialize ( ) [ ..] < chan. get_counterparty_node_id ( ) . serialize ( ) [ ..] ;
25842599
2600+ let enabled = chan. is_usable ( ) && match chan. channel_update_status ( ) {
2601+ ChannelUpdateStatus :: Enabled => true ,
2602+ ChannelUpdateStatus :: DisabledStaged ( _) => true ,
2603+ ChannelUpdateStatus :: Disabled => false ,
2604+ ChannelUpdateStatus :: EnabledStaged ( _) => false ,
2605+ } ;
2606+
25852607 let unsigned = msgs:: UnsignedChannelUpdate {
25862608 chain_hash : self . genesis_hash ,
25872609 short_channel_id,
25882610 timestamp : chan. get_update_time_counter ( ) ,
2589- flags : ( !were_node_one) as u8 | ( ( !chan . is_live ( ) as u8 ) << 1 ) ,
2611+ flags : ( !were_node_one) as u8 | ( ( !enabled as u8 ) << 1 ) ,
25902612 cltv_expiry_delta : chan. get_cltv_expiry_delta ( ) ,
25912613 htlc_minimum_msat : chan. get_counterparty_htlc_minimum_msat ( ) ,
25922614 htlc_maximum_msat : chan. get_announced_htlc_max_msat ( ) ,
@@ -3736,27 +3758,39 @@ where
37363758 }
37373759
37383760 match chan. channel_update_status ( ) {
3739- ChannelUpdateStatus :: Enabled if !chan. is_live ( ) => chan. set_channel_update_status ( ChannelUpdateStatus :: DisabledStaged ) ,
3740- ChannelUpdateStatus :: Disabled if chan. is_live ( ) => chan. set_channel_update_status ( ChannelUpdateStatus :: EnabledStaged ) ,
3741- ChannelUpdateStatus :: DisabledStaged if chan. is_live ( ) => chan. set_channel_update_status ( ChannelUpdateStatus :: Enabled ) ,
3742- ChannelUpdateStatus :: EnabledStaged if !chan. is_live ( ) => chan. set_channel_update_status ( ChannelUpdateStatus :: Disabled ) ,
3743- ChannelUpdateStatus :: DisabledStaged if !chan. is_live ( ) => {
3744- if let Ok ( update) = self . get_channel_update_for_broadcast ( & chan) {
3745- pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3746- msg : update
3747- } ) ;
3761+ ChannelUpdateStatus :: Enabled if !chan. is_live ( ) => chan. set_channel_update_status ( ChannelUpdateStatus :: DisabledStaged ( 0 ) ) ,
3762+ ChannelUpdateStatus :: Disabled if chan. is_live ( ) => chan. set_channel_update_status ( ChannelUpdateStatus :: EnabledStaged ( 0 ) ) ,
3763+ ChannelUpdateStatus :: DisabledStaged ( _) if chan. is_live ( )
3764+ => chan. set_channel_update_status ( ChannelUpdateStatus :: Enabled ) ,
3765+ ChannelUpdateStatus :: EnabledStaged ( _) if !chan. is_live ( )
3766+ => chan. set_channel_update_status ( ChannelUpdateStatus :: Disabled ) ,
3767+ ChannelUpdateStatus :: DisabledStaged ( mut n) if !chan. is_live ( ) => {
3768+ n += 1 ;
3769+ if n >= DISABLE_GOSSIP_TICKS {
3770+ chan. set_channel_update_status ( ChannelUpdateStatus :: Disabled ) ;
3771+ if let Ok ( update) = self . get_channel_update_for_broadcast ( & chan) {
3772+ pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3773+ msg : update
3774+ } ) ;
3775+ }
3776+ should_persist = NotifyOption :: DoPersist ;
3777+ } else {
3778+ chan. set_channel_update_status ( ChannelUpdateStatus :: DisabledStaged ( n) ) ;
37483779 }
3749- should_persist = NotifyOption :: DoPersist ;
3750- chan. set_channel_update_status ( ChannelUpdateStatus :: Disabled ) ;
37513780 } ,
3752- ChannelUpdateStatus :: EnabledStaged if chan. is_live ( ) => {
3753- if let Ok ( update) = self . get_channel_update_for_broadcast ( & chan) {
3754- pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3755- msg : update
3756- } ) ;
3781+ ChannelUpdateStatus :: EnabledStaged ( mut n) if chan. is_live ( ) => {
3782+ n += 1 ;
3783+ if n >= ENABLE_GOSSIP_TICKS {
3784+ chan. set_channel_update_status ( ChannelUpdateStatus :: Enabled ) ;
3785+ if let Ok ( update) = self . get_channel_update_for_broadcast ( & chan) {
3786+ pending_msg_events. push ( events:: MessageSendEvent :: BroadcastChannelUpdate {
3787+ msg : update
3788+ } ) ;
3789+ }
3790+ should_persist = NotifyOption :: DoPersist ;
3791+ } else {
3792+ chan. set_channel_update_status ( ChannelUpdateStatus :: EnabledStaged ( n) ) ;
37573793 }
3758- should_persist = NotifyOption :: DoPersist ;
3759- chan. set_channel_update_status ( ChannelUpdateStatus :: Enabled ) ;
37603794 } ,
37613795 _ => { } ,
37623796 }
0 commit comments