diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 62ce7dec186..7cadde1ab5e 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -260,6 +260,8 @@ pub struct ReceiveTlvs { pub payment_constraints: PaymentConstraints, /// Context for the receiver of this payment. pub payment_context: PaymentContext, + /// Custom Tlvs + pub custom_tlvs: Vec, } /// Data to construct a [`BlindedHop`] for sending a payment over. @@ -404,7 +406,8 @@ impl Writeable for ReceiveTlvs { encode_tlv_stream!(w, { (12, self.payment_constraints, required), (65536, self.payment_secret, required), - (65537, self.payment_context, required) + (65537, self.payment_context, required), + (65539, self.custom_tlvs, (default_value, Vec::new())), }); Ok(()) } @@ -432,6 +435,7 @@ impl Readable for BlindedPaymentTlvs { (14, features, (option, encoding: (BlindedHopFeatures, WithoutLength))), (65536, payment_secret, option), (65537, payment_context, (default_value, PaymentContext::unknown())), + (65539, custom_tlvs, (default_value, Vec::new())) }); let _padding: Option = _padding; @@ -452,6 +456,7 @@ impl Readable for BlindedPaymentTlvs { payment_secret: payment_secret.ok_or(DecodeError::InvalidValue)?, payment_constraints: payment_constraints.0.unwrap(), payment_context: payment_context.0.unwrap(), + custom_tlvs: custom_tlvs.0.unwrap(), })) } } @@ -683,6 +688,7 @@ mod tests { htlc_minimum_msat: 1, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let htlc_maximum_msat = 100_000; let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, 12).unwrap(); @@ -702,6 +708,7 @@ mod tests { htlc_minimum_msat: 1, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let blinded_payinfo = super::compute_payinfo(&[], &recv_tlvs, 4242, TEST_FINAL_CLTV as u16).unwrap(); assert_eq!(blinded_payinfo.fee_base_msat, 0); @@ -758,6 +765,7 @@ mod tests { htlc_minimum_msat: 3, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let htlc_maximum_msat = 100_000; let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_maximum_msat, TEST_FINAL_CLTV as u16).unwrap(); @@ -811,6 +819,7 @@ mod tests { htlc_minimum_msat: 1, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let htlc_minimum_msat = 3798; assert!(super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, htlc_minimum_msat - 1, TEST_FINAL_CLTV as u16).is_err()); @@ -868,6 +877,7 @@ mod tests { htlc_minimum_msat: 1, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new() }; let blinded_payinfo = super::compute_payinfo(&intermediate_nodes[..], &recv_tlvs, 10_000, TEST_FINAL_CLTV as u16).unwrap(); diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index 9deedd19829..439b29d2d31 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -74,6 +74,7 @@ fn blinded_payment_path( intro_node_min_htlc_opt.unwrap_or_else(|| channel_upds.last().unwrap().htlc_minimum_msat), }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let mut secp_ctx = Secp256k1::new(); BlindedPaymentPath::new( @@ -120,6 +121,7 @@ fn do_one_hop_blinded_path(success: bool) { htlc_minimum_msat: chan_upd.htlc_minimum_msat, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let mut secp_ctx = Secp256k1::new(); let blinded_path = BlindedPaymentPath::new( @@ -164,6 +166,7 @@ fn mpp_to_one_hop_blinded_path() { htlc_minimum_msat: chan_upd_1_3.htlc_minimum_msat, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let blinded_path = BlindedPaymentPath::new( &[], nodes[3].node.get_our_node_id(), payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16, @@ -1310,6 +1313,7 @@ fn custom_tlvs_to_blinded_path() { htlc_minimum_msat: chan_upd.htlc_minimum_msat, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let mut secp_ctx = Secp256k1::new(); let blinded_path = BlindedPaymentPath::new( diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index ec7b2845ef3..0b65fa54871 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -9445,7 +9445,7 @@ where Ok((payment_hash, payment_secret)) => { let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {}); let payment_paths = self.create_blinded_payment_paths( - amount_msats, payment_secret, payment_context + amount_msats, payment_secret, payment_context, None ) .map_err(|_| Bolt12SemanticError::MissingPaths)?; @@ -9685,7 +9685,7 @@ where /// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to /// [`Router::create_blinded_payment_paths`]. fn create_blinded_payment_paths( - &self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext + &self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext, custom_tlvs: Option> ) -> Result, ()> { let secp_ctx = &self.secp_ctx; @@ -9700,6 +9700,7 @@ where htlc_minimum_msat: 1, }, payment_context, + custom_tlvs: custom_tlvs.unwrap_or_default() }; self.router.create_blinded_payment_paths( payee_node_id, first_hops, payee_tlvs, amount_msats, secp_ctx @@ -11190,7 +11191,7 @@ where invoice_request: invoice_request.fields(), }); let payment_paths = match self.create_blinded_payment_paths( - amount_msats, payment_secret, payment_context + amount_msats, payment_secret, payment_context, custom_tlvs.clone() ) { Ok(payment_paths) => payment_paths, Err(()) => { diff --git a/lightning/src/ln/max_payment_path_len_tests.rs b/lightning/src/ln/max_payment_path_len_tests.rs index 2bfa40b30d6..f53318df014 100644 --- a/lightning/src/ln/max_payment_path_len_tests.rs +++ b/lightning/src/ln/max_payment_path_len_tests.rs @@ -167,6 +167,7 @@ fn one_hop_blinded_path_with_custom_tlv() { htlc_minimum_msat: chan_upd_1_2.htlc_minimum_msat, }, payment_context: PaymentContext::unknown(), + custom_tlvs: Vec::new(), }; let mut secp_ctx = Secp256k1::new(); let blinded_path = BlindedPaymentPath::new( diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 42baf6d5bc6..9ecc605bdeb 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -2909,8 +2909,9 @@ impl ReadableArgs<(Option, NS)> for InboundOnionPayload wh next_blinding_override, }) }, + // Note: The custom tlvs in the receive tlvs is not used here. ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(ReceiveTlvs { - payment_secret, payment_constraints, payment_context + payment_secret, payment_constraints, payment_context, custom_tlvs: user_custom_tlvs })} => { if total_msat.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) } Ok(Self::BlindedReceive { @@ -2923,7 +2924,7 @@ impl ReadableArgs<(Option, NS)> for InboundOnionPayload wh intro_node_blinding_point, keysend_preimage, sender_custom_tlvs, - user_custom_tlvs: Vec::new(), + user_custom_tlvs, }) }, }