Skip to content

Commit bd3ee0a

Browse files
committed
Fail with PERM|8 (permanent_channel_failure)
This affects the htlc_fail_async_shutdown test.
1 parent a6749d5 commit bd3ee0a

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ impl<Signer: Sign> Channel<Signer> {
21782178
// We can't accept HTLCs sent after we've sent a shutdown.
21792179
let local_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
21802180
if local_sent_shutdown {
2181-
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|20);
2181+
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x4000|8);
21822182
}
21832183
// If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
21842184
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
@@ -3519,33 +3519,34 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
35193519
}
35203520

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

lightning/src/ln/shutdown_tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ fn htlc_fail_async_shutdown() {
197197
let msg_events = nodes[0].node.get_and_clear_pending_msg_events();
198198
assert_eq!(msg_events.len(), 2);
199199
match msg_events[0] {
200-
MessageSendEvent::PaymentFailureNetworkUpdate { update: msgs::HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg }} => {
201-
assert_eq!(msg.contents.short_channel_id, chan_1.0.contents.short_channel_id);
200+
MessageSendEvent::PaymentFailureNetworkUpdate { update: msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id, is_permanent }} => {
201+
assert_eq!(short_channel_id, chan_2.0.contents.short_channel_id);
202+
assert!(is_permanent);
202203
},
203204
_ => panic!("Unexpected event"),
204205
}

0 commit comments

Comments
 (0)