Skip to content

Commit c5adee6

Browse files
Correctly fail back on outbound channel check for blinded HTLC
Forwarding intro nodes should always fail with 0x8000|0x4000|24.
1 parent cc4f8e4 commit c5adee6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lightning/src/ln/blinded_payment_tests.rs

+7
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ enum ForwardCheckFail {
120120
InboundOnionCheck,
121121
// The forwarding node's payload is encoded as a receive, i.e. the next hop HMAC is [0; 32].
122122
ForwardPayloadEncodedAsReceive,
123+
// Fail a check on the outbound channel. In this case, our next-hop peer is offline.
124+
OutboundChannelCheck,
123125
}
124126

125127
#[test]
126128
fn forward_checks_failure() {
127129
do_forward_checks_failure(ForwardCheckFail::InboundOnionCheck);
128130
do_forward_checks_failure(ForwardCheckFail::ForwardPayloadEncodedAsReceive);
131+
do_forward_checks_failure(ForwardCheckFail::OutboundChannelCheck);
129132
}
130133

131134
fn do_forward_checks_failure(check: ForwardCheckFail) {
@@ -200,6 +203,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail) {
200203
onion_payloads.pop();
201204
update_add.onion_routing_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
202205
},
206+
ForwardCheckFail::OutboundChannelCheck => {
207+
// The intro node will see that the next-hop peer is disconnected and fail the HTLC backwards.
208+
nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id());
209+
},
203210
}
204211
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
205212
check_added_monitors!(nodes[1], 0);

lightning/src/ln/channelmanager.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -3178,15 +3178,17 @@ where
31783178
return_err!(err_msg, err_code, &[0; 0]);
31793179
},
31803180
};
3181-
let (outgoing_scid, outgoing_amt_msat, outgoing_cltv_value, next_packet_pk_opt) = match next_hop {
3181+
let (
3182+
outgoing_scid, outgoing_amt_msat, outgoing_cltv_value, next_packet_pk_opt, is_blinded
3183+
) = match next_hop {
31823184
onion_utils::Hop::Forward {
31833185
next_hop_data: msgs::InboundOnionPayload::Forward {
31843186
short_channel_id, amt_to_forward, outgoing_cltv_value
31853187
}, ..
31863188
} => {
31873189
let next_packet_pk = onion_utils::next_hop_pubkey(&self.secp_ctx,
31883190
msg.onion_routing_packet.public_key.unwrap(), &shared_secret);
3189-
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(next_packet_pk))
3191+
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(next_packet_pk), false)
31903192
},
31913193
onion_utils::Hop::Forward {
31923194
next_hop_data: msgs::InboundOnionPayload::BlindedForward {
@@ -3204,7 +3206,7 @@ where
32043206
};
32053207
let next_packet_pk = onion_utils::next_hop_pubkey(&self.secp_ctx,
32063208
msg.onion_routing_packet.public_key.unwrap(), &shared_secret);
3207-
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(next_packet_pk))
3209+
(short_channel_id, amt_to_forward, outgoing_cltv_value, Some(next_packet_pk), true)
32083210
},
32093211
// We'll do receive checks in [`Self::construct_pending_htlc_info`] so we have access to the
32103212
// inbound channel's state.
@@ -3327,6 +3329,7 @@ where
33273329
break None;
33283330
}
33293331
{
3332+
if is_blinded { return_err!(err, INVALID_ONION_BLINDING, vec![0; 32]); }
33303333
let mut res = VecWriter(Vec::with_capacity(chan_update.serialized_length() + 2 + 8 + 2));
33313334
if let Some(chan_update) = chan_update {
33323335
if code == 0x1000 | 11 || code == 0x1000 | 12 {

0 commit comments

Comments
 (0)