Skip to content

Commit 9828dcc

Browse files
committed
f - Fix htlc_fail_async_shutdown
DO NOT MERGE - NEED TO BACKPORT FIXUP
1 parent d5a6b6a commit 9828dcc

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ impl<Signer: Sign> Channel<Signer> {
21922192
// We can't accept HTLCs sent after we've sent a shutdown.
21932193
let local_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
21942194
if local_sent_shutdown {
2195-
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|20);
2195+
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x4000|8);
21962196
}
21972197
// If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
21982198
let remote_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,33 +3515,34 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
35153515
}
35163516

35173517
let create_pending_htlc_status = |chan: &Channel<Signer>, pending_forward_info: PendingHTLCStatus, error_code: u16| {
3518-
// Ensure error_code has the UPDATE flag set, since by default we send a
3519-
// channel update along as part of failing the HTLC.
3520-
assert!((error_code & 0x1000) != 0);
35213518
// If the update_add is completely bogus, the call will Err and we will close,
35223519
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
35233520
// want to reject the new HTLC and fail it backwards instead of forwarding.
35243521
match pending_forward_info {
35253522
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
3526-
let reason = if let Ok(upd) = self.get_channel_update_for_unicast(chan) {
3527-
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
3528-
let mut res = Vec::with_capacity(8 + 128);
3529-
// TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3530-
res.extend_from_slice(&byte_utils::be16_to_array(0));
3531-
res.extend_from_slice(&upd.encode_with_len()[..]);
3532-
res
3533-
}[..])
3523+
let reason = if (error_code & 0x1000) != 0 {
3524+
if let Ok(upd) = self.get_channel_update_for_unicast(chan) {
3525+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
3526+
let mut res = Vec::with_capacity(8 + 128);
3527+
// TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3528+
res.extend_from_slice(&byte_utils::be16_to_array(0));
3529+
res.extend_from_slice(&upd.encode_with_len()[..]);
3530+
res
3531+
}[..])
3532+
} else {
3533+
// The only case where we'd be unable to
3534+
// successfully get a channel update is if the
3535+
// channel isn't in the fully-funded state yet,
3536+
// implying our counterparty is trying to route
3537+
// payments over the channel back to themselves
3538+
// (cause no one else should know the short_id
3539+
// is a lightning channel yet). We should have
3540+
// no problem just calling this
3541+
// unknown_next_peer (0x4000|10).
3542+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[])
3543+
}
35343544
} else {
3535-
// The only case where we'd be unable to
3536-
// successfully get a channel update is if the
3537-
// channel isn't in the fully-funded state yet,
3538-
// implying our counterparty is trying to route
3539-
// payments over the channel back to themselves
3540-
// (cause no one else should know the short_id
3541-
// is a lightning channel yet). We should have
3542-
// no problem just calling this
3543-
// unknown_next_peer (0x4000|10).
3544-
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[])
3545+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &[])
35453546
};
35463547
let msg = msgs::UpdateFailHTLC {
35473548
channel_id: msg.channel_id,

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,7 @@ macro_rules! expect_payment_failed_with_update {
10501050
match network_update {
10511051
&Some(NetworkUpdate::ChannelUpdateMessage { ref msg }) if !$chan_closed => {
10521052
assert_eq!(msg.contents.short_channel_id, $scid);
1053-
// TODO: Fails for htlc_fail_async_shutdown
1054-
//assert_eq!(msg.contents.flags & 2, 0);
1053+
assert_eq!(msg.contents.flags & 2, 0);
10551054
},
10561055
&Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent }) if $chan_closed => {
10571056
assert_eq!(short_channel_id, $scid);

lightning/src/ln/shutdown_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn htlc_fail_async_shutdown() {
193193
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fail_htlcs[0]);
194194
commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true);
195195

196-
expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, chan_1.0.contents.short_channel_id, false);
196+
expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, chan_2.0.contents.short_channel_id, true);
197197

198198
let msg_events = nodes[0].node.get_and_clear_pending_msg_events();
199199
assert_eq!(msg_events.len(), 1);

0 commit comments

Comments
 (0)