From be134d11c93eaaf594c8ccb35f3d1a8bcff753aa Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 10 Jan 2024 10:55:55 -0500 Subject: [PATCH 01/11] Remove trailing whitespace. --- lightning/src/ln/channelmanager.rs | 2 +- lightning/src/ln/outbound_payment.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index e04a3cd1a34..55b201ed961 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -6037,7 +6037,7 @@ where APIError::ChannelUnavailable { err: err_str } }) } - _ => { + _ => { let err_str = "No such channel awaiting to be accepted.".to_owned(); log_error!(logger, "{}", err_str); diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index e1748dca7f2..f5396046177 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -243,7 +243,7 @@ impl PendingOutboundPayment { if insert_res { if let PendingOutboundPayment::Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, - ref mut remaining_max_total_routing_fee_msat, .. + ref mut remaining_max_total_routing_fee_msat, .. } = self { *pending_amt_msat += path.final_value_msat(); let path_fee_msat = path.fee_msat(); From 95a5ab96fc9b5fc8159cdf035cb8137e396b8efa Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 12 Dec 2023 17:39:10 -0500 Subject: [PATCH 02/11] Rename InboundOnionErr to InboundHTLCErr. The prior name seems to reference onion decode errors specifically, when in fact the error contents are generic failure codes for any error that occurs during HTLC receipt. --- lightning/src/ln/channelmanager.rs | 14 ++++++------ lightning/src/ln/onion_payment.rs | 36 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 55b201ed961..8ba0b52e8a9 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -48,7 +48,7 @@ use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFea #[cfg(any(feature = "_test_utils", test))] use crate::ln::features::Bolt11InvoiceFeatures; use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router}; -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::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails}; use crate::ln::msgs; use crate::ln::onion_utils; use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING}; @@ -3245,14 +3245,14 @@ where // delay) once they've send us a commitment_signed! PendingHTLCStatus::Forward(info) }, - Err(InboundOnionErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data) + Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data) } }, onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => { match create_fwd_pending_htlc_info(msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret, next_packet_pubkey_opt) { Ok(info) => PendingHTLCStatus::Forward(info), - Err(InboundOnionErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data) + Err(InboundHTLCErr { err_code, err_data, msg }) => return_err!(msg, err_code, &err_data) } } } @@ -4309,7 +4309,7 @@ where current_height, self.default_configuration.accept_mpp_keysend) { Ok(info) => phantom_receives.push((prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id, vec![(info, prev_htlc_id)])), - Err(InboundOnionErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret)) + Err(InboundHTLCErr { err_code, err_data, msg }) => failed_payment!(msg, err_code, err_data, Some(phantom_shared_secret)) } }, _ => panic!(), @@ -6011,10 +6011,10 @@ where let per_peer_state = self.per_peer_state.read().unwrap(); let peer_state_mutex = per_peer_state.get(counterparty_node_id) .ok_or_else(|| { - let err_str = format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id); + let err_str = format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id); log_error!(logger, "{}", err_str); - APIError::ChannelUnavailable { err: err_str } + APIError::ChannelUnavailable { err: err_str } })?; let mut peer_state_lock = peer_state_mutex.lock().unwrap(); let peer_state = &mut *peer_state_lock; @@ -12139,7 +12139,7 @@ mod tests { // Check that if the amount we received + the penultimate hop extra fee is less than the sender // intended amount, we fail the payment. let current_height: u32 = node[0].node.best_block.read().unwrap().height(); - if let Err(crate::ln::channelmanager::InboundOnionErr { err_code, .. }) = + if let Err(crate::ln::channelmanager::InboundHTLCErr { err_code, .. }) = create_recv_pending_htlc_info(hop_data, [0; 32], PaymentHash([0; 32]), sender_intended_amt_msat - extra_fee_msat - 1, 42, None, true, Some(extra_fee_msat), current_height, node[0].node.default_configuration.accept_mpp_keysend) diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 5966dce9103..31ecc6ddd23 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -25,7 +25,7 @@ use core::ops::Deref; /// Invalid inbound onion payment. #[derive(Debug)] -pub struct InboundOnionErr { +pub struct InboundHTLCErr { /// BOLT 4 error code. pub err_code: u16, /// Data attached to this error. @@ -63,7 +63,7 @@ pub(super) fn create_fwd_pending_htlc_info( msg: &msgs::UpdateAddHTLC, hop_data: msgs::InboundOnionPayload, hop_hmac: [u8; 32], new_packet_bytes: [u8; onion_utils::ONION_DATA_LEN], shared_secret: [u8; 32], next_packet_pubkey_opt: Option> -) -> Result { +) -> Result { debug_assert!(next_packet_pubkey_opt.is_some()); let outgoing_packet = msgs::OnionPacket { version: 0, @@ -85,7 +85,7 @@ pub(super) fn create_fwd_pending_htlc_info( ).map_err(|()| { // We should be returning malformed here if `msg.blinding_point` is set, but this is // unreachable right now since we checked it in `decode_update_add_htlc_onion`. - InboundOnionErr { + InboundHTLCErr { msg: "Underflow calculating outbound amount or cltv value for blinded forward", err_code: INVALID_ONION_BLINDING, err_data: vec![0; 32], @@ -94,7 +94,7 @@ pub(super) fn create_fwd_pending_htlc_info( (short_channel_id, amt_to_forward, outgoing_cltv_value, Some(intro_node_blinding_point)) }, msgs::InboundOnionPayload::Receive { .. } | msgs::InboundOnionPayload::BlindedReceive { .. } => - return Err(InboundOnionErr { + return Err(InboundHTLCErr { msg: "Final Node OnionHopData provided for us as an intermediary node", err_code: 0x4000 | 22, err_data: Vec::new(), @@ -120,7 +120,7 @@ pub(super) fn create_recv_pending_htlc_info( hop_data: msgs::InboundOnionPayload, shared_secret: [u8; 32], payment_hash: PaymentHash, amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>, allow_underpay: bool, counterparty_skimmed_fee_msat: Option, current_height: u32, accept_mpp_keysend: bool, -) -> Result { +) -> Result { let ( payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, outgoing_cltv_value, payment_metadata, requires_blinded_error @@ -136,7 +136,7 @@ pub(super) fn create_recv_pending_htlc_info( } => { check_blinded_payment_constraints(amt_msat, cltv_expiry, &payment_constraints) .map_err(|()| { - InboundOnionErr { + InboundHTLCErr { err_code: INVALID_ONION_BLINDING, err_data: vec![0; 32], msg: "Amount or cltv_expiry violated blinded payment constraints", @@ -147,14 +147,14 @@ pub(super) fn create_recv_pending_htlc_info( intro_node_blinding_point.is_none()) } msgs::InboundOnionPayload::Forward { .. } => { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: 0x4000|22, err_data: Vec::new(), msg: "Got non final data with an HMAC of 0", }) }, msgs::InboundOnionPayload::BlindedForward { .. } => { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: INVALID_ONION_BLINDING, err_data: vec![0; 32], msg: "Got blinded non final data with an HMAC of 0", @@ -163,7 +163,7 @@ pub(super) fn create_recv_pending_htlc_info( }; // final_incorrect_cltv_expiry if outgoing_cltv_value > cltv_expiry { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { msg: "Upstream node set CLTV to less than the CLTV set by the sender", err_code: 18, err_data: cltv_expiry.to_be_bytes().to_vec() @@ -180,7 +180,7 @@ pub(super) fn create_recv_pending_htlc_info( let mut err_data = Vec::with_capacity(12); err_data.extend_from_slice(&amt_msat.to_be_bytes()); err_data.extend_from_slice(¤t_height.to_be_bytes()); - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: 0x4000 | 15, err_data, msg: "The final CLTV expiry is too soon to handle", }); @@ -189,7 +189,7 @@ pub(super) fn create_recv_pending_htlc_info( (allow_underpay && onion_amt_msat > amt_msat.saturating_add(counterparty_skimmed_fee_msat.unwrap_or(0))) { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: 19, err_data: amt_msat.to_be_bytes().to_vec(), msg: "Upstream node sent less than we were supposed to receive in payment", @@ -204,14 +204,14 @@ pub(super) fn create_recv_pending_htlc_info( // time discrepancies due to a hash collision with X. let hashed_preimage = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array()); if hashed_preimage != payment_hash { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: 0x4000|22, err_data: Vec::new(), msg: "Payment preimage didn't match payment hash", }); } if !accept_mpp_keysend && payment_data.is_some() { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: 0x4000|22, err_data: Vec::new(), msg: "We don't support MPP keysend payments", @@ -234,7 +234,7 @@ pub(super) fn create_recv_pending_htlc_info( requires_blinded_error, } } else { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { err_code: 0x4000|0x2000|3, err_data: Vec::new(), msg: "We require payment_secrets", @@ -263,7 +263,7 @@ pub(super) fn create_recv_pending_htlc_info( pub fn peel_payment_onion( msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1, cur_height: u32, accept_mpp_keysend: bool, allow_skimmed_fees: bool, -) -> Result +) -> Result where NS::Target: NodeSigner, L::Target: Logger, @@ -276,7 +276,7 @@ where HTLCFailureMsg::Relay(r) => (0x4000 | 22, r.reason.data), }; let msg = "Failed to decode update add htlc onion"; - InboundOnionErr { msg, err_code, err_data } + InboundHTLCErr { msg, err_code, err_data } })?; Ok(match hop { onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => { @@ -285,7 +285,7 @@ where } = match next_packet_details_opt { Some(next_packet_details) => next_packet_details, // Forward should always include the next hop details - None => return Err(InboundOnionErr { + None => return Err(InboundHTLCErr { msg: "Failed to decode update add htlc onion", err_code: 0x4000 | 22, err_data: Vec::new(), @@ -295,7 +295,7 @@ where if let Err((err_msg, code)) = check_incoming_htlc_cltv( cur_height, outgoing_cltv_value, msg.cltv_expiry ) { - return Err(InboundOnionErr { + return Err(InboundHTLCErr { msg: err_msg, err_code: code, err_data: Vec::new(), From cadea5dae5ee4cbb8e98675ba6e686143764e754 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 12 Dec 2023 17:59:41 -0500 Subject: [PATCH 03/11] Rename outgoing_cltv_value internal var. There is no outgoing CLTV for received HTLCs, so this new var makes more sense. --- lightning/src/ln/onion_payment.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 31ecc6ddd23..b04b78f6554 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -122,7 +122,7 @@ pub(super) fn create_recv_pending_htlc_info( counterparty_skimmed_fee_msat: Option, current_height: u32, accept_mpp_keysend: bool, ) -> Result { let ( - payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, outgoing_cltv_value, + payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry, payment_metadata, requires_blinded_error ) = match hop_data { msgs::InboundOnionPayload::Receive { @@ -162,7 +162,7 @@ pub(super) fn create_recv_pending_htlc_info( } }; // final_incorrect_cltv_expiry - if outgoing_cltv_value > cltv_expiry { + if onion_cltv_expiry > cltv_expiry { return Err(InboundHTLCErr { msg: "Upstream node set CLTV to less than the CLTV set by the sender", err_code: 18, @@ -221,14 +221,14 @@ pub(super) fn create_recv_pending_htlc_info( payment_data, payment_preimage, payment_metadata, - incoming_cltv_expiry: outgoing_cltv_value, + incoming_cltv_expiry: onion_cltv_expiry, custom_tlvs, } } else if let Some(data) = payment_data { PendingHTLCRouting::Receive { payment_data: data, payment_metadata, - incoming_cltv_expiry: outgoing_cltv_value, + incoming_cltv_expiry: onion_cltv_expiry, phantom_shared_secret, custom_tlvs, requires_blinded_error, @@ -246,7 +246,7 @@ pub(super) fn create_recv_pending_htlc_info( incoming_shared_secret: shared_secret, incoming_amt_msat: Some(amt_msat), outgoing_amt_msat: onion_amt_msat, - outgoing_cltv_value, + outgoing_cltv_value: onion_cltv_expiry, skimmed_fee_msat: counterparty_skimmed_fee_msat, }) } From b8fa547c6693e98a842441157fe64a575f5b7d97 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Tue, 12 Dec 2023 17:45:46 -0500 Subject: [PATCH 04/11] Rename InboundOnionPayload::Receive::outgoing_cltv_value .. since there is no outgoing cltv for received HTLCs. --- lightning/src/ln/channelmanager.rs | 6 +++--- lightning/src/ln/msgs.rs | 14 +++++++------- lightning/src/ln/onion_payment.rs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 8ba0b52e8a9..5fe0ad3d694 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -12128,7 +12128,7 @@ mod tests { let extra_fee_msat = 10; let hop_data = msgs::InboundOnionPayload::Receive { amt_msat: 100, - outgoing_cltv_value: 42, + cltv_expiry_height: 42, payment_metadata: None, keysend_preimage: None, payment_data: Some(msgs::FinalOnionHopData { @@ -12150,7 +12150,7 @@ mod tests { // If amt_received + extra_fee is equal to the sender intended amount, we're fine. let hop_data = msgs::InboundOnionPayload::Receive { // This is the same payload as above, InboundOnionPayload doesn't implement Clone amt_msat: 100, - outgoing_cltv_value: 42, + cltv_expiry_height: 42, payment_metadata: None, keysend_preimage: None, payment_data: Some(msgs::FinalOnionHopData { @@ -12174,7 +12174,7 @@ mod tests { let current_height: u32 = node[0].node.best_block.read().unwrap().height(); let result = create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive { amt_msat: 100, - outgoing_cltv_value: 22, + cltv_expiry_height: 22, payment_metadata: None, keysend_preimage: None, payment_data: Some(msgs::FinalOnionHopData { diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 2e56e2fc2c0..574f1b7cf05 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1707,7 +1707,7 @@ mod fuzzy_internal_msgs { keysend_preimage: Option, custom_tlvs: Vec<(u64, Vec)>, amt_msat: u64, - outgoing_cltv_value: u32, + cltv_expiry_height: u32, }, BlindedForward { short_channel_id: u64, @@ -2433,7 +2433,7 @@ impl ReadableArgs<(Option, &NS)> for InboundOnionPayload w payment_metadata: payment_metadata.map(|w| w.0), keysend_preimage, amt_msat: amt.ok_or(DecodeError::InvalidValue)?, - outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?, + cltv_expiry_height: cltv_value.ok_or(DecodeError::InvalidValue)?, custom_tlvs, }) } @@ -4030,10 +4030,10 @@ mod tests { let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet); let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &&node_signer)).unwrap(); if let msgs::InboundOnionPayload::Receive { - payment_data: None, amt_msat, outgoing_cltv_value, .. + payment_data: None, amt_msat, cltv_expiry_height, .. } = inbound_msg { assert_eq!(amt_msat, 0x0badf00d01020304); - assert_eq!(outgoing_cltv_value, 0xffffffff); + assert_eq!(cltv_expiry_height, 0xffffffff); } else { panic!(); } } @@ -4062,14 +4062,14 @@ mod tests { payment_secret, total_msat: 0x1badca1f }), - amt_msat, outgoing_cltv_value, + amt_msat, cltv_expiry_height, payment_metadata: None, keysend_preimage: None, custom_tlvs, } = inbound_msg { assert_eq!(payment_secret, expected_payment_secret); assert_eq!(amt_msat, 0x0badf00d01020304); - assert_eq!(outgoing_cltv_value, 0xffffffff); + assert_eq!(cltv_expiry_height, 0xffffffff); assert_eq!(custom_tlvs, vec![]); } else { panic!(); } } @@ -4133,7 +4133,7 @@ mod tests { keysend_preimage: None, custom_tlvs, amt_msat, - outgoing_cltv_value, + cltv_expiry_height: outgoing_cltv_value, .. } = inbound_msg { assert_eq!(custom_tlvs, expected_custom_tlvs); diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index b04b78f6554..ae602fb1103 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -126,9 +126,9 @@ pub(super) fn create_recv_pending_htlc_info( payment_metadata, requires_blinded_error ) = match hop_data { msgs::InboundOnionPayload::Receive { - payment_data, keysend_preimage, custom_tlvs, amt_msat, outgoing_cltv_value, payment_metadata, .. + payment_data, keysend_preimage, custom_tlvs, amt_msat, cltv_expiry_height, payment_metadata, .. } => - (payment_data, keysend_preimage, custom_tlvs, amt_msat, outgoing_cltv_value, payment_metadata, + (payment_data, keysend_preimage, custom_tlvs, amt_msat, cltv_expiry_height, payment_metadata, false), msgs::InboundOnionPayload::BlindedReceive { amt_msat, total_msat, outgoing_cltv_value, payment_secret, intro_node_blinding_point, From 7c3ef195c4380cc49dbaa4ce896a33099bbded22 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 13 Dec 2023 16:43:27 -0500 Subject: [PATCH 05/11] Rename InboundOnionPayload::BlindedReceive::outgoing_cltv_value. There is no outgoing HTLC for received HTLCs, so rename to be more accurate. --- lightning/src/ln/msgs.rs | 4 ++-- lightning/src/ln/onion_payment.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 574f1b7cf05..d9b5cda4bcb 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1719,7 +1719,7 @@ mod fuzzy_internal_msgs { BlindedReceive { amt_msat: u64, total_msat: u64, - outgoing_cltv_value: u32, + cltv_expiry_height: u32, payment_secret: PaymentSecret, payment_constraints: PaymentConstraints, intro_node_blinding_point: Option, @@ -2403,7 +2403,7 @@ impl ReadableArgs<(Option, &NS)> for InboundOnionPayload w Ok(Self::BlindedReceive { amt_msat: amt.ok_or(DecodeError::InvalidValue)?, total_msat: total_msat.ok_or(DecodeError::InvalidValue)?, - outgoing_cltv_value: cltv_value.ok_or(DecodeError::InvalidValue)?, + cltv_expiry_height: cltv_value.ok_or(DecodeError::InvalidValue)?, payment_secret, payment_constraints, intro_node_blinding_point, diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index ae602fb1103..cba3ef0fb3d 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -131,7 +131,7 @@ pub(super) fn create_recv_pending_htlc_info( (payment_data, keysend_preimage, custom_tlvs, amt_msat, cltv_expiry_height, payment_metadata, false), msgs::InboundOnionPayload::BlindedReceive { - amt_msat, total_msat, outgoing_cltv_value, payment_secret, intro_node_blinding_point, + amt_msat, total_msat, cltv_expiry_height, payment_secret, intro_node_blinding_point, payment_constraints, .. } => { check_blinded_payment_constraints(amt_msat, cltv_expiry, &payment_constraints) @@ -143,7 +143,7 @@ pub(super) fn create_recv_pending_htlc_info( } })?; let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat }; - (Some(payment_data), None, Vec::new(), amt_msat, outgoing_cltv_value, None, + (Some(payment_data), None, Vec::new(), amt_msat, cltv_expiry_height, None, intro_node_blinding_point.is_none()) } msgs::InboundOnionPayload::Forward { .. } => { From 4d38ee65c3f38f71eaa2adc10b08bc33ed1cb3c0 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 13 Dec 2023 17:18:56 -0500 Subject: [PATCH 06/11] Rename OutboundOnionPayload::Receive::outgoing_cltv_value. There is no outgoing HTLC for received HTLCs, so rename to be more accurate. --- lightning/src/ln/msgs.rs | 16 ++++++++-------- lightning/src/ln/onion_utils.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index d9b5cda4bcb..c0d19df53c4 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1739,7 +1739,7 @@ mod fuzzy_internal_msgs { keysend_preimage: Option, custom_tlvs: Vec<(u64, Vec)>, amt_msat: u64, - outgoing_cltv_value: u32, + cltv_expiry_height: u32, }, BlindedForward { encrypted_tlvs: Vec, @@ -2289,8 +2289,8 @@ impl Writeable for OutboundOnionPayload { }); }, Self::Receive { - ref payment_data, ref payment_metadata, ref keysend_preimage, amt_msat, - outgoing_cltv_value, ref custom_tlvs, + ref payment_data, ref payment_metadata, ref keysend_preimage, amt_msat, cltv_expiry_height, + ref custom_tlvs, } => { // We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`] // to reject any reserved types in the experimental range if new ones are ever @@ -2300,7 +2300,7 @@ impl Writeable for OutboundOnionPayload { custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ); _encode_varint_length_prefixed_tlv!(w, { (2, HighZeroBytesDroppedBigSize(*amt_msat), required), - (4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required), + (4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required), (8, payment_data, option), (16, payment_metadata.as_ref().map(|m| WithoutLength(m)), option) }, custom_tlvs.iter()); @@ -4020,7 +4020,7 @@ mod tests { payment_metadata: None, keysend_preimage: None, amt_msat: 0x0badf00d01020304, - outgoing_cltv_value: 0xffffffff, + cltv_expiry_height: 0xffffffff, custom_tlvs: vec![], }; let encoded_value = outbound_msg.encode(); @@ -4048,7 +4048,7 @@ mod tests { payment_metadata: None, keysend_preimage: None, amt_msat: 0x0badf00d01020304, - outgoing_cltv_value: 0xffffffff, + cltv_expiry_height: 0xffffffff, custom_tlvs: vec![], }; let encoded_value = outbound_msg.encode(); @@ -4088,7 +4088,7 @@ mod tests { keysend_preimage: None, custom_tlvs: bad_type_range_tlvs, amt_msat: 0x0badf00d01020304, - outgoing_cltv_value: 0xffffffff, + cltv_expiry_height: 0xffffffff, }; let encoded_value = msg.encode(); let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet); @@ -4120,7 +4120,7 @@ mod tests { keysend_preimage: None, custom_tlvs: expected_custom_tlvs.clone(), amt_msat: 0x0badf00d01020304, - outgoing_cltv_value: 0xffffffff, + cltv_expiry_height: 0xffffffff, }; let encoded_value = msg.encode(); let target_value = >::from_hex("2e02080badf00d010203040404ffffffffff0000000146c6616b021234ff0000000146c6616f084242424242424242").unwrap(); diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 99e3e965a9a..840ada4d137 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -215,7 +215,7 @@ pub(super) fn build_onion_payloads(path: &Path, total_msat: u64, mut recipient_o keysend_preimage: *keysend_preimage, custom_tlvs: recipient_onion.custom_tlvs.clone(), amt_msat: value_msat, - outgoing_cltv_value: cltv, + cltv_expiry_height: cltv, }); } } else { From aace2d3e24600049eb26f3e18a150f5fa63a21cc Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 13 Dec 2023 17:22:50 -0500 Subject: [PATCH 07/11] Rename OutboundOnionPayload::BlindedReceive::outgoing_cltv_value. There is no outgoing HTLC for received HTLCs, so rename to be more accurate. --- lightning/src/ln/msgs.rs | 7 +++---- lightning/src/ln/onion_utils.rs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index c0d19df53c4..78702a3b8ed 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1748,7 +1748,7 @@ mod fuzzy_internal_msgs { BlindedReceive { amt_msat: u64, total_msat: u64, - outgoing_cltv_value: u32, + cltv_expiry_height: u32, encrypted_tlvs: Vec, intro_node_blinding_point: Option, // Set if the introduction node of the blinded path is the final node } @@ -2312,12 +2312,11 @@ impl Writeable for OutboundOnionPayload { }); }, Self::BlindedReceive { - amt_msat, total_msat, outgoing_cltv_value, encrypted_tlvs, - intro_node_blinding_point, + amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs, intro_node_blinding_point, } => { _encode_varint_length_prefixed_tlv!(w, { (2, HighZeroBytesDroppedBigSize(*amt_msat), required), - (4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required), + (4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required), (10, *encrypted_tlvs, required_vec), (12, intro_node_blinding_point, option), (18, HighZeroBytesDroppedBigSize(*total_msat), required) diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 840ada4d137..a83f9dc5a64 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -192,7 +192,7 @@ pub(super) fn build_onion_payloads(path: &Path, total_msat: u64, mut recipient_o res.push(msgs::OutboundOnionPayload::BlindedReceive { amt_msat: *final_value_msat, total_msat, - outgoing_cltv_value: cltv, + cltv_expiry_height: cltv, encrypted_tlvs: blinded_hop.encrypted_payload.clone(), intro_node_blinding_point: blinding_point.take(), }); From 2d58297b40d32afe4cfbcea825b0e5c37b40835a Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 14 Dec 2023 15:15:41 -0500 Subject: [PATCH 08/11] Rename InboundOnionPayload::Receive::amt_msat to be more descriptive. --- lightning/src/ln/channelmanager.rs | 6 +++--- lightning/src/ln/msgs.rs | 14 +++++++------- lightning/src/ln/onion_payment.rs | 7 ++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 5fe0ad3d694..06138dc1637 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -12127,7 +12127,7 @@ mod tests { let sender_intended_amt_msat = 100; let extra_fee_msat = 10; let hop_data = msgs::InboundOnionPayload::Receive { - amt_msat: 100, + sender_intended_htlc_amt_msat: 100, cltv_expiry_height: 42, payment_metadata: None, keysend_preimage: None, @@ -12149,7 +12149,7 @@ mod tests { // If amt_received + extra_fee is equal to the sender intended amount, we're fine. let hop_data = msgs::InboundOnionPayload::Receive { // This is the same payload as above, InboundOnionPayload doesn't implement Clone - amt_msat: 100, + sender_intended_htlc_amt_msat: 100, cltv_expiry_height: 42, payment_metadata: None, keysend_preimage: None, @@ -12173,7 +12173,7 @@ mod tests { let current_height: u32 = node[0].node.best_block.read().unwrap().height(); let result = create_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive { - amt_msat: 100, + sender_intended_htlc_amt_msat: 100, cltv_expiry_height: 22, payment_metadata: None, keysend_preimage: None, diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 78702a3b8ed..2b6a9ee105d 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1706,7 +1706,7 @@ mod fuzzy_internal_msgs { payment_metadata: Option>, keysend_preimage: Option, custom_tlvs: Vec<(u64, Vec)>, - amt_msat: u64, + sender_intended_htlc_amt_msat: u64, cltv_expiry_height: u32, }, BlindedForward { @@ -2431,7 +2431,7 @@ impl ReadableArgs<(Option, &NS)> for InboundOnionPayload w payment_data, payment_metadata: payment_metadata.map(|w| w.0), keysend_preimage, - amt_msat: amt.ok_or(DecodeError::InvalidValue)?, + sender_intended_htlc_amt_msat: amt.ok_or(DecodeError::InvalidValue)?, cltv_expiry_height: cltv_value.ok_or(DecodeError::InvalidValue)?, custom_tlvs, }) @@ -4029,9 +4029,9 @@ mod tests { let node_signer = test_utils::TestKeysInterface::new(&[42; 32], Network::Testnet); let inbound_msg = ReadableArgs::read(&mut Cursor::new(&target_value[..]), (None, &&node_signer)).unwrap(); if let msgs::InboundOnionPayload::Receive { - payment_data: None, amt_msat, cltv_expiry_height, .. + payment_data: None, sender_intended_htlc_amt_msat, cltv_expiry_height, .. } = inbound_msg { - assert_eq!(amt_msat, 0x0badf00d01020304); + assert_eq!(sender_intended_htlc_amt_msat, 0x0badf00d01020304); assert_eq!(cltv_expiry_height, 0xffffffff); } else { panic!(); } } @@ -4061,13 +4061,13 @@ mod tests { payment_secret, total_msat: 0x1badca1f }), - amt_msat, cltv_expiry_height, + sender_intended_htlc_amt_msat, cltv_expiry_height, payment_metadata: None, keysend_preimage: None, custom_tlvs, } = inbound_msg { assert_eq!(payment_secret, expected_payment_secret); - assert_eq!(amt_msat, 0x0badf00d01020304); + assert_eq!(sender_intended_htlc_amt_msat, 0x0badf00d01020304); assert_eq!(cltv_expiry_height, 0xffffffff); assert_eq!(custom_tlvs, vec![]); } else { panic!(); } @@ -4131,7 +4131,7 @@ mod tests { payment_metadata: None, keysend_preimage: None, custom_tlvs, - amt_msat, + sender_intended_htlc_amt_msat: amt_msat, cltv_expiry_height: outgoing_cltv_value, .. } = inbound_msg { diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index cba3ef0fb3d..875e530337e 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -126,10 +126,11 @@ pub(super) fn create_recv_pending_htlc_info( payment_metadata, requires_blinded_error ) = match hop_data { msgs::InboundOnionPayload::Receive { - payment_data, keysend_preimage, custom_tlvs, amt_msat, cltv_expiry_height, payment_metadata, .. + payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat, + cltv_expiry_height, payment_metadata, .. } => - (payment_data, keysend_preimage, custom_tlvs, amt_msat, cltv_expiry_height, payment_metadata, - false), + (payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat, + cltv_expiry_height, payment_metadata, false), msgs::InboundOnionPayload::BlindedReceive { amt_msat, total_msat, cltv_expiry_height, payment_secret, intro_node_blinding_point, payment_constraints, .. From 2b1c9945121884ebb536afa00f4027cebe53adf4 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 14 Dec 2023 15:21:15 -0500 Subject: [PATCH 09/11] Rename InboundOnionPayload::BlindedReceive::amt_msat to be more descriptive. --- lightning/src/ln/msgs.rs | 4 ++-- lightning/src/ln/onion_payment.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 2b6a9ee105d..39a2b2afa2c 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1717,7 +1717,7 @@ mod fuzzy_internal_msgs { intro_node_blinding_point: PublicKey, }, BlindedReceive { - amt_msat: u64, + sender_intended_htlc_amt_msat: u64, total_msat: u64, cltv_expiry_height: u32, payment_secret: PaymentSecret, @@ -2400,7 +2400,7 @@ impl ReadableArgs<(Option, &NS)> for InboundOnionPayload w })} => { if total_msat.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) } Ok(Self::BlindedReceive { - amt_msat: amt.ok_or(DecodeError::InvalidValue)?, + sender_intended_htlc_amt_msat: amt.ok_or(DecodeError::InvalidValue)?, total_msat: total_msat.ok_or(DecodeError::InvalidValue)?, cltv_expiry_height: cltv_value.ok_or(DecodeError::InvalidValue)?, payment_secret, diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 875e530337e..c552bf13b8e 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -132,10 +132,12 @@ pub(super) fn create_recv_pending_htlc_info( (payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat, cltv_expiry_height, payment_metadata, false), msgs::InboundOnionPayload::BlindedReceive { - amt_msat, total_msat, cltv_expiry_height, payment_secret, intro_node_blinding_point, - payment_constraints, .. + sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, payment_secret, + intro_node_blinding_point, payment_constraints, .. } => { - check_blinded_payment_constraints(amt_msat, cltv_expiry, &payment_constraints) + check_blinded_payment_constraints( + sender_intended_htlc_amt_msat, cltv_expiry, &payment_constraints + ) .map_err(|()| { InboundHTLCErr { err_code: INVALID_ONION_BLINDING, @@ -144,8 +146,8 @@ pub(super) fn create_recv_pending_htlc_info( } })?; let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat }; - (Some(payment_data), None, Vec::new(), amt_msat, cltv_expiry_height, None, - intro_node_blinding_point.is_none()) + (Some(payment_data), None, Vec::new(), sender_intended_htlc_amt_msat, cltv_expiry_height, + None, intro_node_blinding_point.is_none()) } msgs::InboundOnionPayload::Forward { .. } => { return Err(InboundHTLCErr { From c76d74a4c12db5c1b041e00f181598d7e0e4410b Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 14 Dec 2023 15:32:34 -0500 Subject: [PATCH 10/11] Rename OutboundOnionPayload::Receive::amt_msat to be more descriptive. --- lightning/src/ln/functional_tests.rs | 6 ++++-- lightning/src/ln/msgs.rs | 20 ++++++++++---------- lightning/src/ln/onion_utils.rs | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 2ad53faa8b2..07a635588e2 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -8216,8 +8216,10 @@ fn test_onion_value_mpp_set_calculation() { RecipientOnionFields::secret_only(our_payment_secret), height + 1, &None).unwrap(); // Edit amt_to_forward to simulate the sender having set // the final amount and the routing node taking less fee - if let msgs::OutboundOnionPayload::Receive { ref mut amt_msat, .. } = onion_payloads[1] { - *amt_msat = 99_000; + if let msgs::OutboundOnionPayload::Receive { + ref mut sender_intended_htlc_amt_msat, .. + } = onion_payloads[1] { + *sender_intended_htlc_amt_msat = 99_000; } else { panic!() } let new_onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &our_payment_hash).unwrap(); payment_event.msgs[0].onion_routing_packet = new_onion_packet; diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index 39a2b2afa2c..ff9d2c19585 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1738,7 +1738,7 @@ mod fuzzy_internal_msgs { payment_metadata: Option>, keysend_preimage: Option, custom_tlvs: Vec<(u64, Vec)>, - amt_msat: u64, + sender_intended_htlc_amt_msat: u64, cltv_expiry_height: u32, }, BlindedForward { @@ -2289,8 +2289,8 @@ impl Writeable for OutboundOnionPayload { }); }, Self::Receive { - ref payment_data, ref payment_metadata, ref keysend_preimage, amt_msat, cltv_expiry_height, - ref custom_tlvs, + ref payment_data, ref payment_metadata, ref keysend_preimage, sender_intended_htlc_amt_msat, + cltv_expiry_height, ref custom_tlvs, } => { // We need to update [`ln::outbound_payment::RecipientOnionFields::with_custom_tlvs`] // to reject any reserved types in the experimental range if new ones are ever @@ -2299,7 +2299,7 @@ impl Writeable for OutboundOnionPayload { let mut custom_tlvs: Vec<&(u64, Vec)> = custom_tlvs.iter().chain(keysend_tlv.iter()).collect(); custom_tlvs.sort_unstable_by_key(|(typ, _)| *typ); _encode_varint_length_prefixed_tlv!(w, { - (2, HighZeroBytesDroppedBigSize(*amt_msat), required), + (2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required), (4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required), (8, payment_data, option), (16, payment_metadata.as_ref().map(|m| WithoutLength(m)), option) @@ -4018,7 +4018,7 @@ mod tests { payment_data: None, payment_metadata: None, keysend_preimage: None, - amt_msat: 0x0badf00d01020304, + sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, custom_tlvs: vec![], }; @@ -4046,7 +4046,7 @@ mod tests { }), payment_metadata: None, keysend_preimage: None, - amt_msat: 0x0badf00d01020304, + sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, custom_tlvs: vec![], }; @@ -4086,7 +4086,7 @@ mod tests { payment_metadata: None, keysend_preimage: None, custom_tlvs: bad_type_range_tlvs, - amt_msat: 0x0badf00d01020304, + sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, }; let encoded_value = msg.encode(); @@ -4118,7 +4118,7 @@ mod tests { payment_metadata: None, keysend_preimage: None, custom_tlvs: expected_custom_tlvs.clone(), - amt_msat: 0x0badf00d01020304, + sender_intended_htlc_amt_msat: 0x0badf00d01020304, cltv_expiry_height: 0xffffffff, }; let encoded_value = msg.encode(); @@ -4131,12 +4131,12 @@ mod tests { payment_metadata: None, keysend_preimage: None, custom_tlvs, - sender_intended_htlc_amt_msat: amt_msat, + sender_intended_htlc_amt_msat, cltv_expiry_height: outgoing_cltv_value, .. } = inbound_msg { assert_eq!(custom_tlvs, expected_custom_tlvs); - assert_eq!(amt_msat, 0x0badf00d01020304); + assert_eq!(sender_intended_htlc_amt_msat, 0x0badf00d01020304); assert_eq!(outgoing_cltv_value, 0xffffffff); } else { panic!(); } } diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index a83f9dc5a64..f3112c207e6 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -214,7 +214,7 @@ pub(super) fn build_onion_payloads(path: &Path, total_msat: u64, mut recipient_o payment_metadata: recipient_onion.payment_metadata.take(), keysend_preimage: *keysend_preimage, custom_tlvs: recipient_onion.custom_tlvs.clone(), - amt_msat: value_msat, + sender_intended_htlc_amt_msat: value_msat, cltv_expiry_height: cltv, }); } From b20a9ad2703e0bcc066e05142ea23c162d0ad6d7 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 14 Dec 2023 15:34:51 -0500 Subject: [PATCH 11/11] Rename OutboundOnionPayload::BlindedReceive::amt_msat to be more descriptive. --- lightning/src/ln/msgs.rs | 7 ++++--- lightning/src/ln/onion_utils.rs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index ff9d2c19585..41d8974f29c 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -1746,7 +1746,7 @@ mod fuzzy_internal_msgs { intro_node_blinding_point: Option, }, BlindedReceive { - amt_msat: u64, + sender_intended_htlc_amt_msat: u64, total_msat: u64, cltv_expiry_height: u32, encrypted_tlvs: Vec, @@ -2312,10 +2312,11 @@ impl Writeable for OutboundOnionPayload { }); }, Self::BlindedReceive { - amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs, intro_node_blinding_point, + sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs, + intro_node_blinding_point, } => { _encode_varint_length_prefixed_tlv!(w, { - (2, HighZeroBytesDroppedBigSize(*amt_msat), required), + (2, HighZeroBytesDroppedBigSize(*sender_intended_htlc_amt_msat), required), (4, HighZeroBytesDroppedBigSize(*cltv_expiry_height), required), (10, *encrypted_tlvs, required_vec), (12, intro_node_blinding_point, option), diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index f3112c207e6..ac0bb6189c6 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -190,7 +190,7 @@ pub(super) fn build_onion_payloads(path: &Path, total_msat: u64, mut recipient_o cur_value_msat += final_value_msat; cur_cltv += excess_final_cltv_expiry_delta; res.push(msgs::OutboundOnionPayload::BlindedReceive { - amt_msat: *final_value_msat, + sender_intended_htlc_amt_msat: *final_value_msat, total_msat, cltv_expiry_height: cltv, encrypted_tlvs: blinded_hop.encrypted_payload.clone(),