@@ -1070,6 +1070,14 @@ pub(crate) const MPP_TIMEOUT_TICKS: u8 = 3;
1070
1070
/// [`OutboundPayments::remove_stale_resolved_payments`].
1071
1071
pub ( crate ) const IDEMPOTENCY_TIMEOUT_TICKS : u8 = 7 ;
1072
1072
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
+
1073
1081
/// The maximum number of unfunded channels we can have per-peer before we start rejecting new
1074
1082
/// (inbound) ones. The number of peers with unfunded channels is limited separately in
1075
1083
/// [`MAX_UNFUNDED_CHANNEL_PEERS`].
@@ -2457,7 +2465,14 @@ where
2457
2465
// hopefully an attacker trying to path-trace payments cannot make this occur
2458
2466
// on a small/per-node/per-channel scale.
2459
2467
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
+ }
2461
2476
}
2462
2477
if * outgoing_amt_msat < chan. get_counterparty_htlc_minimum_msat ( ) { // amount_below_minimum
2463
2478
break Some ( ( "HTLC amount was below the htlc_minimum_msat" , 0x1000 | 11 , chan_update_opt) ) ;
@@ -2582,11 +2597,18 @@ where
2582
2597
log_trace ! ( self . logger, "Generating channel update for channel {}" , log_bytes!( chan. channel_id( ) ) ) ;
2583
2598
let were_node_one = self . our_network_pubkey . serialize ( ) [ ..] < chan. get_counterparty_node_id ( ) . serialize ( ) [ ..] ;
2584
2599
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
+
2585
2607
let unsigned = msgs:: UnsignedChannelUpdate {
2586
2608
chain_hash : self . genesis_hash ,
2587
2609
short_channel_id,
2588
2610
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 ) ,
2590
2612
cltv_expiry_delta : chan. get_cltv_expiry_delta ( ) ,
2591
2613
htlc_minimum_msat : chan. get_counterparty_htlc_minimum_msat ( ) ,
2592
2614
htlc_maximum_msat : chan. get_announced_htlc_max_msat ( ) ,
@@ -3736,27 +3758,39 @@ where
3736
3758
}
3737
3759
3738
3760
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) ) ;
3748
3779
}
3749
- should_persist = NotifyOption :: DoPersist ;
3750
- chan. set_channel_update_status ( ChannelUpdateStatus :: Disabled ) ;
3751
3780
} ,
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) ) ;
3757
3793
}
3758
- should_persist = NotifyOption :: DoPersist ;
3759
- chan. set_channel_update_status ( ChannelUpdateStatus :: Enabled ) ;
3760
3794
} ,
3761
3795
_ => { } ,
3762
3796
}
0 commit comments