From: Valentine Wallace Date: Fri, 15 Sep 2023 22:21:28 +0000 (-0400) Subject: Correctly fail back on outbound channel check for blinded HTLC X-Git-Tag: v0.0.119~36^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=67d24633aeb02ed2288171bd1cee5af815a770f7;p=rust-lightning Correctly fail back on outbound channel check for blinded HTLC Forwarding intro nodes should always fail with 0x8000|0x4000|24. --- diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index e20464cb9..e26da7922 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -120,12 +120,15 @@ enum ForwardCheckFail { InboundOnionCheck, // The forwarding node's payload is encoded as a receive, i.e. the next hop HMAC is [0; 32]. ForwardPayloadEncodedAsReceive, + // Fail a check on the outbound channel. In this case, our next-hop peer is offline. + OutboundChannelCheck, } #[test] fn forward_checks_failure() { do_forward_checks_failure(ForwardCheckFail::InboundOnionCheck); do_forward_checks_failure(ForwardCheckFail::ForwardPayloadEncodedAsReceive); + do_forward_checks_failure(ForwardCheckFail::OutboundChannelCheck); } fn do_forward_checks_failure(check: ForwardCheckFail) { @@ -200,6 +203,10 @@ fn do_forward_checks_failure(check: ForwardCheckFail) { onion_payloads.pop(); update_add.onion_routing_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap(); }, + ForwardCheckFail::OutboundChannelCheck => { + // The intro node will see that the next-hop peer is disconnected and fail the HTLC backwards. + nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id()); + }, } nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index d56d13492..5a6694fe5 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -53,7 +53,7 @@ use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParame 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}; use crate::ln::msgs; use crate::ln::onion_utils; -use crate::ln::onion_utils::HTLCFailReason; +use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING}; use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError}; #[cfg(test)] use crate::ln::outbound_payment; @@ -2977,14 +2977,24 @@ where msg, &self.node_signer, &self.logger, &self.secp_ctx )?; + let is_blinded = match next_hop { + onion_utils::Hop::Forward { + next_hop_data: msgs::InboundOnionPayload::BlindedForward { .. }, .. + } => true, + _ => false, // TODO: update this when we support receiving to multi-hop blinded paths + }; + macro_rules! return_err { ($msg: expr, $err_code: expr, $data: expr) => { { log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg); + let (err_code, err_data) = if is_blinded { + (INVALID_ONION_BLINDING, &[0; 32][..]) + } else { ($err_code, $data) }; return Err(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC { channel_id: msg.channel_id, htlc_id: msg.htlc_id, - reason: HTLCFailReason::reason($err_code, $data.to_vec()) + reason: HTLCFailReason::reason(err_code, err_data.to_vec()) .get_encrypted_failure_packet(&shared_secret, &None), })); }