From 50c850fdd08eab678558c70c7c9d6c369fe918e8 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 26 Oct 2023 14:24:10 -0400 Subject: [PATCH] Set update_add blinding point on HTLC forward Used by the next hop to decode their blinded onion payload. --- lightning/src/ln/channelmanager.rs | 12 ++++++++++-- lightning/src/ln/onion_utils.rs | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index b3994e977..de1260842 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; @@ -4262,9 +4262,17 @@ where phantom_shared_secret: None, blinded_failure: blinded.map(|_| BlindedFailure::FromIntroductionNode), }); + let next_blinding_point = blinded.and_then(|b| { + let encrypted_tlvs_ss = self.node_signer.ecdh( + Recipient::Node, &b.inbound_blinding_point, None + ).unwrap().secret_bytes(); + onion_utils::next_hop_pubkey( + &self.secp_ctx, b.inbound_blinding_point, &encrypted_tlvs_ss + ).ok() + }); if let Err(e) = chan.queue_add_htlc(outgoing_amt_msat, payment_hash, outgoing_cltv_value, htlc_source.clone(), - onion_packet, skimmed_fee_msat, None, &self.fee_estimator, + onion_packet, skimmed_fee_msat, next_blinding_point, &self.fee_estimator, &self.logger) { if let ChannelError::Ignore(msg) = e { diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 605080c7b..88f0efe9a 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -242,6 +242,8 @@ pub(super) fn build_onion_payloads(path: &Path, total_msat: u64, mut recipient_o /// the hops can be of variable length. pub(crate) const ONION_DATA_LEN: usize = 20*65; +pub(super) const INVALID_ONION_BLINDING: u16 = 0x8000 | 0x4000 | 24; + #[inline] fn shift_slice_right(arr: &mut [u8], amt: usize) { for i in (amt..arr.len()).rev() { -- 2.39.5