Skip to content

Commit fc48cea

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 ae0ad19 commit fc48cea

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/ln/channelmanager.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,28 @@ impl ChannelManager {
14831483
events.append(&mut new_events);
14841484
}
14851485

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