Skip to content

Commit 67d2463

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

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 7 additions & 0 deletions
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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParame
5353
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundOnionErr, NextPacketDetails};
5454
use crate::ln::msgs;
5555
use crate::ln::onion_utils;
56-
use crate::ln::onion_utils::HTLCFailReason;
56+
use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
5757
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
5858
#[cfg(test)]
5959
use crate::ln::outbound_payment;
@@ -2977,14 +2977,24 @@ where
29772977
msg, &self.node_signer, &self.logger, &self.secp_ctx
29782978
)?;
29792979

2980+
let is_blinded = match next_hop {
2981+
onion_utils::Hop::Forward {
2982+
next_hop_data: msgs::InboundOnionPayload::BlindedForward { .. }, ..
2983+
} => true,
2984+
_ => false, // TODO: update this when we support receiving to multi-hop blinded paths
2985+
};
2986+
29802987
macro_rules! return_err {
29812988
($msg: expr, $err_code: expr, $data: expr) => {
29822989
{
29832990
log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
2991+
let (err_code, err_data) = if is_blinded {
2992+
(INVALID_ONION_BLINDING, &[0; 32][..])
2993+
} else { ($err_code, $data) };
29842994
return Err(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
29852995
channel_id: msg.channel_id,
29862996
htlc_id: msg.htlc_id,
2987-
reason: HTLCFailReason::reason($err_code, $data.to_vec())
2997+
reason: HTLCFailReason::reason(err_code, err_data.to_vec())
29882998
.get_encrypted_failure_packet(&shared_secret, &None),
29892999
}));
29903000
}

0 commit comments

Comments
 (0)