Skip to content

Commit a8e5da0

Browse files
f fix Matt review from 06/08 nits
1 parent 5dffe87 commit a8e5da0

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
17351735

17361736
pub fn update_add_htlc<F>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_state: PendingHTLCStatus, create_pending_htlc_status: F) -> Result<(), ChannelError>
17371737
where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus {
1738-
if !self.is_usable() {
1738+
// We can't accept HTLCs sent after we've sent a shutdown.
1739+
let local_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
1740+
if local_sent_shutdown {
17391741
// TODO: Note that |20 is defined as "channel FROM the processing
17401742
// node has been disabled" (emphasis mine), which seems to imply
17411743
// that we can't return |20 for an inbound channel being disabled.
@@ -1815,6 +1817,10 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
18151817
if !self.channel_outbound {
18161818
// `+1` for this HTLC, `2 *` and `+1` fee spike buffer we keep for the remote (this deviates from the spec
18171819
// but should help protect us from stuck channels).
1820+
// Note that when we eventually remove support for fee updates and switch to anchor output fees,
1821+
// we will drop the `2 *`, since we no longer be as sensitive to fee spikes. But, keep the extra +1
1822+
// as we should still be able to afford adding this HTLC plus one more future HTLC, regardless of
1823+
// being sensitive to fee spikes.
18181824
let remote_fee_cost_incl_stuck_buffer_msat = 2 * self.next_remote_commit_tx_fee_msat(1 + 1);
18191825
if pending_remote_value_msat - msg.amount_msat - chan_reserve_msat < remote_fee_cost_incl_stuck_buffer_msat {
18201826
// Note that if the pending_forward_state is not updated here, then it's because we're already failing

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,17 +2482,14 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
24822482
}
24832483

24842484
let create_pending_htlc_status = |chan: &Channel<ChanSigner>, pending_forward_info: PendingHTLCStatus, error_code: u16| {
2485+
// Ensure error_code has the UPDATE flag set, since by default we send a
2486+
// channel update along as part of failing the HTLC.
2487+
assert!((error_code & 0x1000) != 0);
24852488
// If the update_add is completely bogus, the call will Err and we will close,
24862489
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
24872490
// want to reject the new HTLC and fail it backwards instead of forwarding.
24882491
match pending_forward_info {
24892492
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
2490-
// The only case where we'd be unable to successfully get a channel
2491-
// update here is if the channel isn't in the fully-funded
2492-
// state yet, implying our counterparty is trying to route payments
2493-
// over the channel back to themselves (cause no one else should
2494-
// know the short_id is a lightning channel yet). We should have no
2495-
// problem just calling this unknown_next_peer, as above (0x4000|10).
24962493
let reason = if let Ok(upd) = self.get_channel_update(chan) {
24972494
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
24982495
let mut res = Vec::with_capacity(8 + 128);
@@ -2501,6 +2498,15 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
25012498
res
25022499
}[..])
25032500
} else {
2501+
// The only case where we'd be unable to
2502+
// successfully get a channel update is if the
2503+
// channel isn't in the fully-funded state yet,
2504+
// implying our counterparty is trying to route
2505+
// payments over the channel back to themselves
2506+
// (cause no one else should know the short_id
2507+
// is a lightning channel yet). We should have
2508+
// no problem just calling this
2509+
// unknown_next_peer (0x4000|10).
25042510
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[])
25052511
};
25062512
let msg = msgs::UpdateFailHTLC {

0 commit comments

Comments
 (0)