Skip to content

Commit 70a10a9

Browse files
author
Antoine Riard
committed
Add timer_chan_freshness_every_min
Latency/peer disconnection may trigger us to mark as disabled some of our channels. After some time, if channels are still disabled we need to broadcast ChannelUpdate to inform other network peers about the uselessness of these channels.
1 parent 01ae452 commit 70a10a9

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,28 @@ impl<'a> ChannelManager<'a> {
14871487
events.append(&mut new_events);
14881488
}
14891489

1490+
/// Latency/peer disconnection may trigger us to mark as disabled some
1491+
/// of our channels. After some time, if channels are still disabled
1492+
/// we need to broadcast ChannelUpdate to inform other network peers
1493+
/// about the uselessness of this channels.
1494+
pub fn timer_chan_freshness_every_min(&self) {
1495+
let _ = self.total_consistency_lock.read().unwrap();
1496+
{
1497+
let mut channel_state_lock = self.channel_state.lock().unwrap();
1498+
let channel_state = channel_state_lock.borrow_parts();
1499+
for (_, chan) in channel_state.by_id {
1500+
// Check if channel is still disabled
1501+
if !chan.is_live() {
1502+
if let Ok(update) = self.get_channel_update(&chan) {
1503+
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
1504+
msg: update
1505+
});
1506+
}
1507+
}
1508+
}
1509+
}
1510+
}
1511+
14901512
/// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
14911513
/// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
14921514
/// along the path (including in our own channel on which we received it).
@@ -2795,7 +2817,6 @@ impl<'a> ChannelMessageHandler for ChannelManager<'a> {
27952817
log_debug!(self, "Marking channels with {} disconnected and generating channel_updates", log_pubkey!(their_node_id));
27962818
channel_state.by_id.retain(|_, chan| {
27972819
if chan.get_their_node_id() == *their_node_id {
2798-
//TODO: mark channel disabled (and maybe announce such after a timeout).
27992820
let failed_adds = chan.remove_uncommitted_htlcs_and_mark_paused();
28002821
if !failed_adds.is_empty() {
28012822
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

0 commit comments

Comments
 (0)