Skip to content

Commit f564df3

Browse files
author
Antoine Riard
committed
Add UpdateStatus in Channel to track freshness of gossiped liveness.
Added enum and method are only used in next commit.
1 parent 01ae452 commit f564df3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,20 @@ const MULTI_STATE_FLAGS: u32 = (BOTH_SIDES_SHUTDOWN_MASK | ChannelState::PeerDis
210210

211211
const INITIAL_COMMITMENT_NUMBER: u64 = (1 << 48) - 1;
212212

213+
/// Liveness is called to fluctuate given peer disconnecton/monitor failures/closing.
214+
/// If channel is public, network should have a liveness view announced by us on a
215+
/// best-effort, which means we may filter out some status transitions to avoid spam.
216+
/// See further timer_chan_freshness_every_min.
217+
#[derive(PartialEq)]
218+
enum UpdateStatus {
219+
/// Status has been gossiped.
220+
Fresh,
221+
/// Status has been changed.
222+
DisabledMarked,
223+
/// Status has been marked to be gossiped at next flush
224+
DisabledStaged,
225+
}
226+
213227
// TODO: We should refactor this to be an Inbound/OutboundChannel until initial setup handshaking
214228
// has been completed, and then turn into a Channel to get compiler-time enforcement of things like
215229
// calling channel_id() before we're set up or things like get_outbound_funding_signed on an
@@ -340,6 +354,8 @@ pub(super) struct Channel {
340354

341355
channel_monitor: ChannelMonitor,
342356

357+
network_sync: UpdateStatus,
358+
343359
logger: Arc<Logger>,
344360
}
345361

@@ -517,6 +533,8 @@ impl Channel {
517533

518534
channel_monitor: channel_monitor,
519535

536+
network_sync: UpdateStatus::Fresh,
537+
520538
logger,
521539
})
522540
}
@@ -734,6 +752,8 @@ impl Channel {
734752

735753
channel_monitor: channel_monitor,
736754

755+
network_sync: UpdateStatus::Fresh,
756+
737757
logger,
738758
};
739759

@@ -2993,6 +3013,26 @@ impl Channel {
29933013
} else { false }
29943014
}
29953015

3016+
pub fn to_disabled_staged(&mut self) {
3017+
self.network_sync = UpdateStatus::DisabledStaged;
3018+
}
3019+
3020+
pub fn to_disabled_marked(&mut self) {
3021+
self.network_sync = UpdateStatus::DisabledMarked;
3022+
}
3023+
3024+
pub fn to_fresh(&mut self) {
3025+
self.network_sync = UpdateStatus::Fresh;
3026+
}
3027+
3028+
pub fn is_disabled_staged(&self) -> bool {
3029+
self.network_sync == UpdateStatus::DisabledStaged
3030+
}
3031+
3032+
pub fn is_disabled_marked(&self) -> bool {
3033+
self.network_sync == UpdateStatus::DisabledMarked
3034+
}
3035+
29963036
/// Called by channelmanager based on chain blocks being connected.
29973037
/// Note that we only need to use this to detect funding_signed, anything else is handled by
29983038
/// the channel_monitor.
@@ -4091,6 +4131,8 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
40914131

40924132
channel_monitor,
40934133

4134+
network_sync: UpdateStatus::Fresh,
4135+
40944136
logger,
40954137
})
40964138
}

0 commit comments

Comments
 (0)