Skip to content

Commit 05cd95d

Browse files
committed
Fail incoming HTLCs sent after we start shutdown, not the chan
1 parent d04d54c commit 05cd95d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/ln/channel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,12 @@ impl Channel {
15161516

15171517
//TODO: Check msg.cltv_expiry further? Do this in channel manager?
15181518

1519+
if self.channel_state & ChannelState::LocalShutdownSent as u32 != 0 {
1520+
if let PendingHTLCStatus::Forward(_) = pending_forward_state {
1521+
panic!("ChannelManager shouldn't be trying to add a forwardable HTLC after we've started closing");
1522+
}
1523+
}
1524+
15191525
// Now update local state:
15201526
self.next_remote_htlc_id += 1;
15211527
self.pending_inbound_htlcs.push(InboundHTLCOutput {

src/ln/channelmanager.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ impl ChannelManager {
19261926
//encrypted with the same key. Its not immediately obvious how to usefully exploit that,
19271927
//but we should prevent it anyway.
19281928

1929-
let (pending_forward_info, mut channel_state_lock) = self.decode_update_add_htlc_onion(msg);
1929+
let (mut pending_forward_info, mut channel_state_lock) = self.decode_update_add_htlc_onion(msg);
19301930
let channel_state = channel_state_lock.borrow_parts();
19311931

19321932
match channel_state.by_id.get_mut(&msg.channel_id) {
@@ -1936,7 +1936,16 @@ impl ChannelManager {
19361936
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
19371937
}
19381938
if !chan.is_usable() {
1939-
return Err(MsgHandleErrInternal::from_no_close(HandleError{err: "Channel not yet available for receiving HTLCs", action: Some(msgs::ErrorAction::IgnoreError)}));
1939+
// If the update_add is completely bogus, the channel will reject it outright,
1940+
// but if we've sent a shutdown but they haven't acknowledged it yet, we just
1941+
// want to reject the new HTLC.
1942+
if let PendingHTLCStatus::Forward(PendingForwardHTLCInfo { incoming_shared_secret, .. }) = pending_forward_info {
1943+
pending_forward_info = PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
1944+
channel_id: msg.channel_id,
1945+
htlc_id: msg.htlc_id,
1946+
reason: ChannelManager::build_first_hop_failure_packet(&incoming_shared_secret, 0x1000|20, &self.get_channel_update(chan).unwrap().encode_with_len()[..]),
1947+
}));
1948+
}
19401949
}
19411950
chan.update_add_htlc(&msg, pending_forward_info).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))
19421951
},

0 commit comments

Comments
 (0)