/// Liveness is called to fluctuate given peer disconnecton/monitor failures/closing.
/// If channel is public, network should have a liveness view announced by us on a
/// best-effort, which means we may filter out some status transitions to avoid spam.
-/// See further timer_tick_occurred.
-#[derive(PartialEq)]
-enum UpdateStatus {
- /// Status has been gossiped.
- Fresh,
- /// Status has been changed.
- DisabledMarked,
- /// Status has been marked to be gossiped at next flush
+/// See implementation at [`super::channelmanager::ChannelManager::timer_tick_occurred`].
+#[derive(Clone, Copy, PartialEq)]
+pub(super) enum UpdateStatus {
+ /// We've announced the channel as enabled and are connected to our peer.
+ Enabled,
+ /// Our channel is no longer live, but we haven't announced the channel as disabled yet.
DisabledStaged,
+ /// Our channel is live again, but we haven't announced the channel as enabled yet.
+ EnabledStaged,
+ /// We've announced the channel as disabled.
+ Disabled,
}
/// An enum indicating whether the local or remote side offered a given HTLC.
commitment_secrets: CounterpartyCommitmentSecrets::new(),
- network_sync: UpdateStatus::Fresh,
+ network_sync: UpdateStatus::Enabled,
#[cfg(any(test, feature = "fuzztarget"))]
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
commitment_secrets: CounterpartyCommitmentSecrets::new(),
- network_sync: UpdateStatus::Fresh,
+ network_sync: UpdateStatus::Enabled,
#[cfg(any(test, feature = "fuzztarget"))]
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
} else { false }
}
- pub fn to_disabled_staged(&mut self) {
- self.network_sync = UpdateStatus::DisabledStaged;
+ pub fn get_update_status(&self) -> UpdateStatus {
+ self.network_sync
}
- pub fn to_disabled_marked(&mut self) {
- self.network_sync = UpdateStatus::DisabledMarked;
- }
-
- pub fn to_fresh(&mut self) {
- self.network_sync = UpdateStatus::Fresh;
- }
-
- pub fn is_disabled_staged(&self) -> bool {
- self.network_sync == UpdateStatus::DisabledStaged
- }
-
- pub fn is_disabled_marked(&self) -> bool {
- self.network_sync == UpdateStatus::DisabledMarked
+ pub fn set_update_status(&mut self, status: UpdateStatus) {
+ self.network_sync = status;
}
fn check_get_funding_locked(&mut self, height: u32) -> Option<msgs::FundingLocked> {
}
}
+impl Writeable for UpdateStatus {
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
+ // We only care about writing out the current state as it was announced, ie only either
+ // Enabled or Disabled. In the case of DisabledStaged, we most recently announced the
+ // channel as enabled, so we write 0. For EnabledStaged, we similarly write a 1.
+ match self {
+ UpdateStatus::Enabled => 0u8.write(writer)?,
+ UpdateStatus::DisabledStaged => 0u8.write(writer)?,
+ UpdateStatus::EnabledStaged => 1u8.write(writer)?,
+ UpdateStatus::Disabled => 1u8.write(writer)?,
+ }
+ Ok(())
+ }
+}
+
+impl Readable for UpdateStatus {
+ fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+ Ok(match <u8 as Readable>::read(reader)? {
+ 0 => UpdateStatus::Enabled,
+ 1 => UpdateStatus::Disabled,
+ _ => return Err(DecodeError::InvalidValue),
+ })
+ }
+}
+
impl<Signer: Sign> Writeable for Channel<Signer> {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
// Note that we write out as if remove_uncommitted_htlcs_and_mark_paused had just been
self.counterparty_shutdown_scriptpubkey.write(writer)?;
self.commitment_secrets.write(writer)?;
+
+ self.network_sync.write(writer)?;
Ok(())
}
}
let counterparty_shutdown_scriptpubkey = Readable::read(reader)?;
let commitment_secrets = Readable::read(reader)?;
+ let network_sync = Readable::read(reader)?;
+
let mut secp_ctx = Secp256k1::new();
secp_ctx.seeded_randomize(&keys_source.get_secure_random_bytes());
commitment_secrets,
- network_sync: UpdateStatus::Fresh,
+ network_sync,
#[cfg(any(test, feature = "fuzztarget"))]
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
// construct one themselves.
use ln::{PaymentHash, PaymentPreimage, PaymentSecret};
pub use ln::channel::CounterpartyForwardingInfo;
-use ln::channel::{Channel, ChannelError};
+use ln::channel::{Channel, ChannelError, UpdateStatus};
use ln::features::{InitFeatures, NodeFeatures};
use routing::router::{Route, RouteHop};
use ln::msgs;
let mut channel_state_lock = self.channel_state.lock().unwrap();
let channel_state = &mut *channel_state_lock;
for (_, chan) in channel_state.by_id.iter_mut() {
- if chan.is_disabled_staged() && !chan.is_live() {
- if let Ok(update) = self.get_channel_update(&chan) {
- channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
- msg: update
- });
- }
- chan.to_fresh();
- } else if chan.is_disabled_staged() && chan.is_live() {
- chan.to_fresh();
- } else if chan.is_disabled_marked() {
- chan.to_disabled_staged();
+ match chan.get_update_status() {
+ UpdateStatus::Enabled if !chan.is_live() => chan.set_update_status(UpdateStatus::DisabledStaged),
+ UpdateStatus::Disabled if chan.is_live() => chan.set_update_status(UpdateStatus::EnabledStaged),
+ UpdateStatus::DisabledStaged if chan.is_live() => chan.set_update_status(UpdateStatus::Enabled),
+ UpdateStatus::EnabledStaged if !chan.is_live() => chan.set_update_status(UpdateStatus::Disabled),
+ UpdateStatus::DisabledStaged if !chan.is_live() => {
+ if let Ok(update) = self.get_channel_update(&chan) {
+ channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
+ msg: update
+ });
+ }
+ chan.set_update_status(UpdateStatus::Disabled);
+ },
+ UpdateStatus::EnabledStaged if chan.is_live() => {
+ if let Ok(update) = self.get_channel_update(&chan) {
+ channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
+ msg: update
+ });
+ }
+ chan.set_update_status(UpdateStatus::Enabled);
+ },
+ _ => {},
}
}
}
// on peer disconnect here, there will need to be corresponding changes in
// reestablish logic.
let failed_adds = chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
- chan.to_disabled_marked();
if !failed_adds.is_empty() {
let chan_update = self.get_channel_update(&chan).map(|u| u.encode_with_len()).unwrap(); // Cannot add/recv HTLCs before we have a short_id so unwrap is safe
failed_payments.push((chan_update, failed_adds));