@@ -251,15 +251,17 @@ pub const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
251
251
/// Liveness is called to fluctuate given peer disconnecton/monitor failures/closing.
252
252
/// If channel is public, network should have a liveness view announced by us on a
253
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
254
+ /// See implementation at [`ChannelManager::timer_tick_occurred`].
255
+ #[ derive( Clone , Copy , PartialEq ) ]
256
+ pub ( super ) enum UpdateStatus {
257
+ /// We've announced the channel as enabled and are connected to our peer.
258
+ Enabled ,
259
+ /// Our channel is no longer live, but we haven't announced the channel as disabled yet.
262
260
DisabledStaged ,
261
+ /// Our channel is live again, but we haven't announced the channel as enabled yet.
262
+ EnabledStaged ,
263
+ /// We've announced the channel as disabled.
264
+ Disabled ,
263
265
}
264
266
265
267
/// An enum indicating whether the local or remote side offered a given HTLC.
@@ -617,7 +619,7 @@ impl<Signer: Sign> Channel<Signer> {
617
619
618
620
commitment_secrets : CounterpartyCommitmentSecrets :: new ( ) ,
619
621
620
- network_sync : UpdateStatus :: Fresh ,
622
+ network_sync : UpdateStatus :: Enabled ,
621
623
622
624
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
623
625
next_local_commitment_tx_fee_info_cached : Mutex :: new ( None ) ,
@@ -858,7 +860,7 @@ impl<Signer: Sign> Channel<Signer> {
858
860
859
861
commitment_secrets : CounterpartyCommitmentSecrets :: new ( ) ,
860
862
861
- network_sync : UpdateStatus :: Fresh ,
863
+ network_sync : UpdateStatus :: Enabled ,
862
864
863
865
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
864
866
next_local_commitment_tx_fee_info_cached : Mutex :: new ( None ) ,
@@ -3495,24 +3497,12 @@ impl<Signer: Sign> Channel<Signer> {
3495
3497
} else { false }
3496
3498
}
3497
3499
3498
- pub fn to_disabled_staged ( & mut self ) {
3499
- self . network_sync = UpdateStatus :: DisabledStaged ;
3500
+ pub fn get_update_status ( & self ) -> UpdateStatus {
3501
+ self . network_sync
3500
3502
}
3501
3503
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
3504
+ pub fn set_update_status ( & mut self , status : UpdateStatus ) {
3505
+ self . network_sync = status;
3516
3506
}
3517
3507
3518
3508
fn check_get_funding_locked ( & mut self , height : u32 ) -> Option < msgs:: FundingLocked > {
@@ -4375,6 +4365,31 @@ impl Readable for InboundHTLCRemovalReason {
4375
4365
}
4376
4366
}
4377
4367
4368
+ impl Writeable for UpdateStatus {
4369
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4370
+ // We only care about writing out the current state as it was announced, ie only either
4371
+ // Enabled or Disabled. In the case of DisabledStaged, we most recently announced the
4372
+ // channel as enabled, so we write 0. For EnabledStaged, we similarly write a 1.
4373
+ match self {
4374
+ UpdateStatus :: Enabled => 0u8 . write ( writer) ?,
4375
+ UpdateStatus :: DisabledStaged => 0u8 . write ( writer) ?,
4376
+ UpdateStatus :: EnabledStaged => 1u8 . write ( writer) ?,
4377
+ UpdateStatus :: Disabled => 1u8 . write ( writer) ?,
4378
+ }
4379
+ Ok ( ( ) )
4380
+ }
4381
+ }
4382
+
4383
+ impl Readable for UpdateStatus {
4384
+ fn read < R : :: std:: io:: Read > ( reader : & mut R ) -> Result < Self , DecodeError > {
4385
+ Ok ( match <u8 as Readable >:: read ( reader) ? {
4386
+ 0 => UpdateStatus :: Enabled ,
4387
+ 1 => UpdateStatus :: Disabled ,
4388
+ _ => return Err ( DecodeError :: InvalidValue ) ,
4389
+ } )
4390
+ }
4391
+ }
4392
+
4378
4393
impl < Signer : Sign > Writeable for Channel < Signer > {
4379
4394
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: std:: io:: Error > {
4380
4395
// Note that we write out as if remove_uncommitted_htlcs_and_mark_paused had just been
@@ -4568,6 +4583,8 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
4568
4583
self . counterparty_shutdown_scriptpubkey . write ( writer) ?;
4569
4584
4570
4585
self . commitment_secrets . write ( writer) ?;
4586
+
4587
+ self . network_sync . write ( writer) ?;
4571
4588
Ok ( ( ) )
4572
4589
}
4573
4590
}
@@ -4740,6 +4757,8 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4740
4757
let counterparty_shutdown_scriptpubkey = Readable :: read ( reader) ?;
4741
4758
let commitment_secrets = Readable :: read ( reader) ?;
4742
4759
4760
+ let network_sync = Readable :: read ( reader) ?;
4761
+
4743
4762
let mut secp_ctx = Secp256k1 :: new ( ) ;
4744
4763
secp_ctx. seeded_randomize ( & keys_source. get_secure_random_bytes ( ) ) ;
4745
4764
@@ -4814,7 +4833,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
4814
4833
4815
4834
commitment_secrets,
4816
4835
4817
- network_sync : UpdateStatus :: Fresh ,
4836
+ network_sync,
4818
4837
4819
4838
#[ cfg( any( test, feature = "fuzztarget" ) ) ]
4820
4839
next_local_commitment_tx_fee_info_cached : Mutex :: new ( None ) ,
0 commit comments