Skip to content

Commit 548ad7a

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 429f070 commit 548ad7a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,32 @@ 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+
if chan.is_staged() && !chan.is_live() {
1501+
if let Ok(update) = self.get_channel_update(&chan) {
1502+
channel_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelUpdate {
1503+
msg: update
1504+
});
1505+
}
1506+
chan.to_fresh();
1507+
} else if chan.is_staged() && chan.is_live() {
1508+
chan.to_fresh();
1509+
} else if chan.is_dirty() {
1510+
chan.to_staged();
1511+
}
1512+
}
1513+
}
1514+
}
1515+
14901516
/// Indicates that the preimage for payment_hash is unknown or the received amount is incorrect
14911517
/// after a PaymentReceived event, failing the HTLC back to its origin and freeing resources
14921518
/// along the path (including in our own channel on which we received it).
@@ -2795,8 +2821,8 @@ impl<'a> ChannelMessageHandler for ChannelManager<'a> {
27952821
log_debug!(self, "Marking channels with {} disconnected and generating channel_updates", log_pubkey!(their_node_id));
27962822
channel_state.by_id.retain(|_, chan| {
27972823
if chan.get_their_node_id() == *their_node_id {
2798-
//TODO: mark channel disabled (and maybe announce such after a timeout).
27992824
let failed_adds = chan.remove_uncommitted_htlcs_and_mark_paused();
2825+
chan.to_dirty();
28002826
if !failed_adds.is_empty() {
28012827
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
28022828
failed_payments.push((chan_update, failed_adds));

0 commit comments

Comments
 (0)