Skip to content

Commit bf9ad7a

Browse files
committed
Rename Channel::UpdateStatus to be more descriptive and update docs
1 parent c6a1893 commit bf9ad7a

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ const MULTI_STATE_FLAGS: u32 = BOTH_SIDES_SHUTDOWN_MASK | ChannelState::PeerDisc
248248

249249
pub const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
250250

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.
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.
254255
/// See implementation at [`super::channelmanager::ChannelManager::timer_tick_occurred`].
255256
#[derive(Clone, Copy, PartialEq)]
256-
pub(super) enum UpdateStatus {
257+
pub(super) enum ChannelUpdateStatus {
257258
/// We've announced the channel as enabled and are connected to our peer.
258259
Enabled,
259260
/// Our channel is no longer live, but we haven't announced the channel as disabled yet.
@@ -418,7 +419,7 @@ pub(super) struct Channel<Signer: Sign> {
418419

419420
commitment_secrets: CounterpartyCommitmentSecrets,
420421

421-
network_sync: UpdateStatus,
422+
channel_update_status: ChannelUpdateStatus,
422423

423424
// We save these values so we can make sure `next_local_commit_tx_fee_msat` and
424425
// `next_remote_commit_tx_fee_msat` properly predict what the next commitment transaction fee will
@@ -619,7 +620,7 @@ impl<Signer: Sign> Channel<Signer> {
619620

620621
commitment_secrets: CounterpartyCommitmentSecrets::new(),
621622

622-
network_sync: UpdateStatus::Enabled,
623+
channel_update_status: ChannelUpdateStatus::Enabled,
623624

624625
#[cfg(any(test, feature = "fuzztarget"))]
625626
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
@@ -860,7 +861,7 @@ impl<Signer: Sign> Channel<Signer> {
860861

861862
commitment_secrets: CounterpartyCommitmentSecrets::new(),
862863

863-
network_sync: UpdateStatus::Enabled,
864+
channel_update_status: ChannelUpdateStatus::Enabled,
864865

865866
#[cfg(any(test, feature = "fuzztarget"))]
866867
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
@@ -3497,12 +3498,12 @@ impl<Signer: Sign> Channel<Signer> {
34973498
} else { false }
34983499
}
34993500

3500-
pub fn get_update_status(&self) -> UpdateStatus {
3501-
self.network_sync
3501+
pub fn channel_update_status(&self) -> ChannelUpdateStatus {
3502+
self.channel_update_status
35023503
}
35033504

3504-
pub fn set_update_status(&mut self, status: UpdateStatus) {
3505-
self.network_sync = status;
3505+
pub fn set_channel_update_status(&mut self, status: ChannelUpdateStatus) {
3506+
self.channel_update_status = status;
35063507
}
35073508

35083509
fn check_get_funding_locked(&mut self, height: u32) -> Option<msgs::FundingLocked> {
@@ -4365,26 +4366,26 @@ impl Readable for InboundHTLCRemovalReason {
43654366
}
43664367
}
43674368

4368-
impl Writeable for UpdateStatus {
4369+
impl Writeable for ChannelUpdateStatus {
43694370
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
43704371
// We only care about writing out the current state as it was announced, ie only either
43714372
// Enabled or Disabled. In the case of DisabledStaged, we most recently announced the
43724373
// channel as enabled, so we write 0. For EnabledStaged, we similarly write a 1.
43734374
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)?,
4375+
ChannelUpdateStatus::Enabled => 0u8.write(writer)?,
4376+
ChannelUpdateStatus::DisabledStaged => 0u8.write(writer)?,
4377+
ChannelUpdateStatus::EnabledStaged => 1u8.write(writer)?,
4378+
ChannelUpdateStatus::Disabled => 1u8.write(writer)?,
43784379
}
43794380
Ok(())
43804381
}
43814382
}
43824383

4383-
impl Readable for UpdateStatus {
4384+
impl Readable for ChannelUpdateStatus {
43844385
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
43854386
Ok(match <u8 as Readable>::read(reader)? {
4386-
0 => UpdateStatus::Enabled,
4387-
1 => UpdateStatus::Disabled,
4387+
0 => ChannelUpdateStatus::Enabled,
4388+
1 => ChannelUpdateStatus::Disabled,
43884389
_ => return Err(DecodeError::InvalidValue),
43894390
})
43904391
}
@@ -4584,7 +4585,7 @@ impl<Signer: Sign> Writeable for Channel<Signer> {
45844585

45854586
self.commitment_secrets.write(writer)?;
45864587

4587-
self.network_sync.write(writer)?;
4588+
self.channel_update_status.write(writer)?;
45884589
Ok(())
45894590
}
45904591
}
@@ -4757,7 +4758,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
47574758
let counterparty_shutdown_scriptpubkey = Readable::read(reader)?;
47584759
let commitment_secrets = Readable::read(reader)?;
47594760

4760-
let network_sync = Readable::read(reader)?;
4761+
let channel_update_status = Readable::read(reader)?;
47614762

47624763
let mut secp_ctx = Secp256k1::new();
47634764
secp_ctx.seeded_randomize(&keys_source.get_secure_random_bytes());
@@ -4833,7 +4834,7 @@ impl<'a, Signer: Sign, K: Deref> ReadableArgs<&'a K> for Channel<Signer>
48334834

48344835
commitment_secrets,
48354836

4836-
network_sync,
4837+
channel_update_status,
48374838

48384839
#[cfg(any(test, feature = "fuzztarget"))]
48394840
next_local_commitment_tx_fee_info_cached: Mutex::new(None),

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use chain::transaction::{OutPoint, TransactionData};
4545
// construct one themselves.
4646
use ln::{PaymentHash, PaymentPreimage, PaymentSecret};
4747
pub use ln::channel::CounterpartyForwardingInfo;
48-
use ln::channel::{Channel, ChannelError, UpdateStatus};
48+
use ln::channel::{Channel, ChannelError, ChannelUpdateStatus};
4949
use ln::features::{InitFeatures, NodeFeatures};
5050
use routing::router::{Route, RouteHop};
5151
use ln::msgs;
@@ -2147,28 +2147,28 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21472147
let mut channel_state_lock = self.channel_state.lock().unwrap();
21482148
let channel_state = &mut *channel_state_lock;
21492149
for (_, chan) in channel_state.by_id.iter_mut() {
2150-
match chan.get_update_status() {
2151-
UpdateStatus::Enabled if !chan.is_live() => chan.set_update_status(UpdateStatus::DisabledStaged),
2152-
UpdateStatus::Disabled if chan.is_live() => chan.set_update_status(UpdateStatus::EnabledStaged),
2153-
UpdateStatus::DisabledStaged if chan.is_live() => chan.set_update_status(UpdateStatus::Enabled),
2154-
UpdateStatus::EnabledStaged if !chan.is_live() => chan.set_update_status(UpdateStatus::Disabled),
2155-
UpdateStatus::DisabledStaged if !chan.is_live() => {
2150+
match chan.channel_update_status() {
2151+
ChannelUpdateStatus::Enabled if !chan.is_live() => chan.set_channel_update_status(ChannelUpdateStatus::DisabledStaged),
2152+
ChannelUpdateStatus::Disabled if chan.is_live() => chan.set_channel_update_status(ChannelUpdateStatus::EnabledStaged),
2153+
ChannelUpdateStatus::DisabledStaged if chan.is_live() => chan.set_channel_update_status(ChannelUpdateStatus::Enabled),
2154+
ChannelUpdateStatus::EnabledStaged if !chan.is_live() => chan.set_channel_update_status(ChannelUpdateStatus::Disabled),
2155+
ChannelUpdateStatus::DisabledStaged if !chan.is_live() => {
21562156
if let Ok(update) = self.get_channel_update(&chan) {
21572157
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
21582158
msg: update
21592159
});
21602160
}
21612161
should_persist = PersistenceGuardOption::DoPersist;
2162-
chan.set_update_status(UpdateStatus::Disabled);
2162+
chan.set_channel_update_status(ChannelUpdateStatus::Disabled);
21632163
},
2164-
UpdateStatus::EnabledStaged if chan.is_live() => {
2164+
ChannelUpdateStatus::EnabledStaged if chan.is_live() => {
21652165
if let Ok(update) = self.get_channel_update(&chan) {
21662166
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
21672167
msg: update
21682168
});
21692169
}
21702170
should_persist = PersistenceGuardOption::DoPersist;
2171-
chan.set_update_status(UpdateStatus::Enabled);
2171+
chan.set_channel_update_status(ChannelUpdateStatus::Enabled);
21722172
},
21732173
_ => {},
21742174
}

0 commit comments

Comments
 (0)