Skip to content

Commit 33acee1

Browse files
committed
Drop channels on disconnection if we haven't funded them yet
1 parent b8677a6 commit 33acee1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/ln/channel.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,13 @@ impl Channel {
17711771
/// Returns the set of PendingHTLCStatuses from remote uncommitted HTLCs (which we're
17721772
/// implicitly dropping) and the payment_hashes of HTLCs we tried to add but are dropping.
17731773
pub fn remove_uncommitted_htlcs(&mut self) -> Vec<(HTLCSource, [u8; 32])> {
1774+
let mut outbound_drops = Vec::new();
1775+
1776+
if self.channel_state < ChannelState::FundingSent as u32 {
1777+
self.channel_state = ChannelState::ShutdownComplete as u32;
1778+
return outbound_drops;
1779+
}
1780+
17741781
self.pending_inbound_htlcs.retain(|htlc| {
17751782
match htlc.state {
17761783
InboundHTLCState::RemoteAnnounced => {
@@ -1806,7 +1813,6 @@ impl Channel {
18061813
}
18071814
}
18081815

1809-
let mut outbound_drops = Vec::new();
18101816
self.holding_cell_htlc_updates.retain(|htlc_update| {
18111817
match htlc_update {
18121818
&HTLCUpdateAwaitingACK::AddHTLC { ref payment_hash, ref source, .. } => {

src/ln/channelmanager.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,16 +2149,23 @@ impl ChannelMessageHandler for ChannelManager {
21492149
}
21502150
});
21512151
} else {
2152-
for chan in channel_state.by_id {
2153-
if chan.1.get_their_node_id() == *their_node_id {
2152+
channel_state.by_id.retain(|_, chan| {
2153+
if chan.get_their_node_id() == *their_node_id {
21542154
//TODO: mark channel disabled (and maybe announce such after a timeout).
2155-
let failed_adds = chan.1.remove_uncommitted_htlcs();
2155+
let failed_adds = chan.remove_uncommitted_htlcs();
21562156
if !failed_adds.is_empty() {
2157-
let chan_update = self.get_channel_update(&chan.1).map(|u| u.encode_with_len()).unwrap(); // Cannot add/recv HTLCs before we have a short_id so unwrap is safe
2157+
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
21582158
failed_payments.push((chan_update, failed_adds));
21592159
}
2160+
if chan.is_shutdown() {
2161+
if let Some(short_id) = chan.get_short_channel_id() {
2162+
short_to_id.remove(&short_id);
2163+
}
2164+
return false;
2165+
}
21602166
}
2161-
}
2167+
true
2168+
})
21622169
}
21632170
}
21642171
for failure in failed_channels.drain(..) {

0 commit comments

Comments
 (0)