Skip to content

Commit d5ea8e8

Browse files
committed
f - Fix htlc_fail_async_shutdown
DO NOT MERGE - NEED TO BACKPORT FIXUP
1 parent ce12955 commit d5ea8e8

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

lightning/src/ln/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,7 @@ impl<Signer: Sign> Channel<Signer> {
21642164
// We can't accept HTLCs sent after we've sent a shutdown.
21652165
let local_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
21662166
if local_sent_shutdown {
2167-
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|20);
2167+
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x4000|8);
21682168
}
21692169
// If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
21702170
let remote_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);

lightning/src/ln/channelmanager.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -3461,33 +3461,34 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
34613461
}
34623462

34633463
let create_pending_htlc_status = |chan: &Channel<Signer>, pending_forward_info: PendingHTLCStatus, error_code: u16| {
3464-
// Ensure error_code has the UPDATE flag set, since by default we send a
3465-
// channel update along as part of failing the HTLC.
3466-
assert!((error_code & 0x1000) != 0);
34673464
// If the update_add is completely bogus, the call will Err and we will close,
34683465
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
34693466
// want to reject the new HTLC and fail it backwards instead of forwarding.
34703467
match pending_forward_info {
34713468
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
3472-
let reason = if let Ok(upd) = self.get_channel_update_for_unicast(chan) {
3473-
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
3474-
let mut res = Vec::with_capacity(8 + 128);
3475-
// TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3476-
res.extend_from_slice(&byte_utils::be16_to_array(0));
3477-
res.extend_from_slice(&upd.encode_with_len()[..]);
3478-
res
3479-
}[..])
3469+
let reason = if (error_code & 0x1000) != 0 {
3470+
if let Ok(upd) = self.get_channel_update_for_unicast(chan) {
3471+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
3472+
let mut res = Vec::with_capacity(8 + 128);
3473+
// TODO: underspecified, follow https://github.com/lightningnetwork/lightning-rfc/issues/791
3474+
res.extend_from_slice(&byte_utils::be16_to_array(0));
3475+
res.extend_from_slice(&upd.encode_with_len()[..]);
3476+
res
3477+
}[..])
3478+
} else {
3479+
// The only case where we'd be unable to
3480+
// successfully get a channel update is if the
3481+
// channel isn't in the fully-funded state yet,
3482+
// implying our counterparty is trying to route
3483+
// payments over the channel back to themselves
3484+
// (cause no one else should know the short_id
3485+
// is a lightning channel yet). We should have
3486+
// no problem just calling this
3487+
// unknown_next_peer (0x4000|10).
3488+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[])
3489+
}
34803490
} else {
3481-
// The only case where we'd be unable to
3482-
// successfully get a channel update is if the
3483-
// channel isn't in the fully-funded state yet,
3484-
// implying our counterparty is trying to route
3485-
// payments over the channel back to themselves
3486-
// (cause no one else should know the short_id
3487-
// is a lightning channel yet). We should have
3488-
// no problem just calling this
3489-
// unknown_next_peer (0x4000|10).
3490-
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[])
3491+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &[])
34913492
};
34923493
let msg = msgs::UpdateFailHTLC {
34933494
channel_id: msg.channel_id,

lightning/src/ln/functional_test_utils.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,7 @@ macro_rules! expect_payment_failed_with_update {
10361036
match network_update {
10371037
&Some(NetworkUpdate::ChannelUpdateMessage { ref msg }) if !$chan_closed => {
10381038
assert_eq!(msg.contents.short_channel_id, $scid);
1039-
// TODO: Fails for htlc_fail_async_shutdown
1040-
//assert_eq!(msg.contents.flags & 2, 0);
1039+
assert_eq!(msg.contents.flags & 2, 0);
10411040
},
10421041
&Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent }) if $chan_closed => {
10431042
assert_eq!(short_channel_id, $scid);

lightning/src/ln/functional_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ fn htlc_fail_async_shutdown() {
10061006
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fail_htlcs[0]);
10071007
commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true);
10081008

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

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

0 commit comments

Comments
 (0)