@@ -248,18 +248,21 @@ const MULTI_STATE_FLAGS: u32 = BOTH_SIDES_SHUTDOWN_MASK | ChannelState::PeerDisc
248
248
249
249
pub const INITIAL_COMMITMENT_NUMBER : u64 = ( 1 << 48 ) - 1 ;
250
250
251
- /// Liveness is called to fluctuate given peer disconnecton/monitor failures/closing.
252
- /// If channel is public, network should have a liveness view announced by us on a
253
- /// best-effort, which means we may filter out some status transitions to avoid spam.
254
- /// See further timer_tick_occurred.
255
- #[ derive( PartialEq ) ]
256
- enum UpdateStatus {
257
- /// Status has been gossiped.
258
- Fresh ,
259
- /// Status has been changed.
260
- DisabledMarked ,
261
- /// Status has been marked to be gossiped at next flush
251
+ /// The "channel disabled" bit in channel_update must be set based on whether we are connected to
252
+ /// our counterparty or not. However, we don't want to announce updates right away to avoid
253
+ /// spamming the network with updates if the connection is flapping. Instead, we "stage" updates to
254
+ /// our channel_update message and track the current state here.
255
+ /// See implementation at [`super::channelmanager::ChannelManager::timer_tick_occurred`].
256
+ #[ derive( Clone , Copy , PartialEq ) ]
257
+ pub ( super ) enum ChannelUpdateStatus {
258
+ /// We've announced the channel as enabled and are connected to our peer.
259
+ Enabled ,
260
+ /// Our channel is no longer live, but we haven't announced the channel as disabled yet.
262
261
DisabledStaged ,
262
+ /// Our channel is live again, but we haven't announced the channel as enabled yet.
263
+ EnabledStaged ,
264
+ /// We've announced the channel as disabled.
265
+ Disabled ,
263
266
}
264
267
265
268
/// An enum indicating whether the local or remote side offered a given HTLC.
@@ -416,7 +419,7 @@ pub(super) struct Channel<Signer: Sign> {
416
419
417
420
commitment_secrets : CounterpartyCommitmentSecrets ,
418
421
419
- network_sync : UpdateStatus ,
422
+ channel_update_status : ChannelUpdateStatus ,
420
423
421
424
// We save these values so we can make sure `next_local_commit_tx_fee_msat` and
422
425
// `next_remote_commit_tx_fee_msat` properly predict what the next commitment transaction fee will
@@ -617,7 +620,7 @@ impl<Signer: Sign> Channel<Signer> {
617
620
618
621
commitment_secrets : CounterpartyCommitmentSecrets :: new ( ) ,
619
622
620
- network_sync : UpdateStatus :: Fresh ,
623
+ channel_update_status : ChannelUpdateStatus :: Enabled ,
621
624
622
625
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
623
626
next_local_commitment_tx_fee_info_cached : Mutex :: new ( None ) ,
@@ -858,7 +861,7 @@ impl<Signer: Sign> Channel<Signer> {
858
861
859
862
commitment_secrets : CounterpartyCommitmentSecrets :: new ( ) ,
860
863
861
- network_sync : UpdateStatus :: Fresh ,
864
+ channel_update_status : ChannelUpdateStatus :: Enabled ,
862
865
863
866
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
864
867
next_local_commitment_tx_fee_info_cached : Mutex :: new ( None ) ,
@@ -3495,24 +3498,12 @@ impl<Signer: Sign> Channel<Signer> {
3495
3498
} else { false }
3496
3499
}
3497
3500
3498
- pub fn to_disabled_staged ( & mut self ) {
3499
- self . network_sync = UpdateStatus :: DisabledStaged ;
3501
+ pub fn channel_update_status ( & self ) -> ChannelUpdateStatus {
3502
+ self . channel_update_status
3500
3503
}
3501
3504
3502
- pub fn to_disabled_marked ( & mut self ) {
3503
- self . network_sync = UpdateStatus :: DisabledMarked ;
3504
- }
3505
-
3506
- pub fn to_fresh ( & mut self ) {
3507
- self . network_sync = UpdateStatus :: Fresh ;
3508
- }
3509
-
3510
- pub fn is_disabled_staged ( & self ) -> bool {
3511
- self . network_sync == UpdateStatus :: DisabledStaged
3512
- }
3513
-
3514
- pub fn is_disabled_marked ( & self ) -> bool {
3515
- self . network_sync == UpdateStatus :: DisabledMarked
3505
+ pub fn set_channel_update_status ( & mut self , status : ChannelUpdateStatus ) {
3506
+ self . channel_update_status = status;
3516
3507
}
3517
3508
3518
3509
fn check_get_funding_locked ( & mut self , height : u32 ) -> Option < msgs:: FundingLocked > {
@@ -4375,6 +4366,31 @@ impl Readable for InboundHTLCRemovalReason {
4375
4366
}
4376
4367
}
4377
4368
4369
+ impl Writeable for ChannelUpdateStatus {
4370
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4371
+ // We only care about writing out the current state as it was announced, ie only either
4372
+ // Enabled or Disabled. In the case of DisabledStaged, we most recently announced the
4373
+ // channel as enabled, so we write 0. For EnabledStaged, we similarly write a 1.
4374
+ match self {
4375
+ ChannelUpdateStatus :: Enabled => 0u8 . write ( writer) ?,
4376
+ ChannelUpdateStatus :: DisabledStaged => 0u8 . write ( writer) ?,
4377
+ ChannelUpdateStatus :: EnabledStaged => 1u8 . write ( writer) ?,
4378
+ ChannelUpdateStatus :: Disabled => 1u8 . write ( writer) ?,
4379
+ }
4380
+ Ok ( ( ) )
4381
+ }
4382
+ }
4383
+
4384
+ impl Readable for ChannelUpdateStatus {
4385
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
4386
+ Ok ( match <u8 as Readable >:: read ( reader) ? {
4387
+ 0 => ChannelUpdateStatus :: Enabled ,
4388
+ 1 => ChannelUpdateStatus :: Disabled ,
4389
+ _ => return Err ( DecodeError :: InvalidValue ) ,
4390
+ } )
4391
+ }
4392
+ }
4393
+
4378
4394
impl < Signer : Sign > Writeable for Channel < Signer > {
4379
4395
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4380
4396
// Note that we write out as if remove_uncommitted_htlcs_and_mark_paused had just been
@@ -4568,6 +4584,8 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4568
4584
self . counterparty_shutdown_scriptpubkey . write ( writer) ?;
4569
4585
4570
4586
self . commitment_secrets . write ( writer) ?;
4587
+
4588
+ self . channel_update_status . write ( writer) ?;
4571
4589
Ok ( ( ) )
4572
4590
}
4573
4591
}
@@ -4740,6 +4758,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4740
4758
let counterparty_shutdown_scriptpubkey = Readable :: read ( reader) ?;
4741
4759
let commitment_secrets = Readable :: read ( reader) ?;
4742
4760
4761
+ let channel_update_status = Readable :: read ( reader) ?;
4762
+
4743
4763
let mut secp_ctx = Secp256k1 :: new ( ) ;
4744
4764
secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
4745
4765
@@ -4814,7 +4834,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4814
4834
4815
4835
commitment_secrets,
4816
4836
4817
- network_sync : UpdateStatus :: Fresh ,
4837
+ channel_update_status ,
4818
4838
4819
4839
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
4820
4840
next_local_commitment_tx_fee_info_cached : Mutex :: new ( None ) ,
0 commit comments