From db94d930f0260298806b399b1eb41e6bf7bb674e Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Mon, 19 Aug 2024 15:08:20 -0400 Subject: [PATCH] Move BlindedPayInfo into blinded_path::payment module. --- fuzz/src/router.rs | 3 +- lightning/src/blinded_path/payment.rs | 39 +++++++++++++++- .../src/ln/max_payment_path_len_tests.rs | 3 +- lightning/src/offers/invoice.rs | 46 ++----------------- lightning/src/offers/test_utils.rs | 3 +- lightning/src/routing/router.rs | 7 ++- 6 files changed, 48 insertions(+), 53 deletions(-) diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index c315f58e2..cc28f5ae9 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -12,7 +12,7 @@ use bitcoin::constants::ChainHash; use bitcoin::script::Builder; use bitcoin::transaction::TxOut; -use lightning::blinded_path::payment::BlindedPaymentPath; +use lightning::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath}; use lightning::blinded_path::BlindedHop; use lightning::chain::transaction::OutPoint; use lightning::ln::channel_state::{ChannelCounterparty, ChannelDetails, ChannelShutdownState}; @@ -20,7 +20,6 @@ use lightning::ln::channelmanager; use lightning::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures}; use lightning::ln::msgs; use lightning::ln::types::ChannelId; -use lightning::offers::invoice::BlindedPayInfo; use lightning::routing::gossip::{NetworkGraph, RoutingFees}; use lightning::routing::router::{ find_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters, diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index 4c7066b9a..e128e6675 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -21,7 +21,6 @@ use crate::ln::channel_state::CounterpartyForwardingInfo; use crate::ln::features::BlindedHopFeatures; use crate::ln::msgs::DecodeError; use crate::ln::onion_utils; -use crate::offers::invoice::BlindedPayInfo; use crate::offers::invoice_request::InvoiceRequestFields; use crate::offers::offer::OfferId; use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph}; @@ -34,6 +33,44 @@ use core::ops::Deref; #[allow(unused_imports)] use crate::prelude::*; +/// Information needed to route a payment across a [`BlindedPaymentPath`]. +#[derive(Clone, Debug, Hash, Eq, PartialEq)] +pub struct BlindedPayInfo { + /// Base fee charged (in millisatoshi) for the entire blinded path. + pub fee_base_msat: u32, + + /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path + /// (i.e., 10,000 is 1%). + pub fee_proportional_millionths: u32, + + /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded + /// path. + pub cltv_expiry_delta: u16, + + /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the + /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as + /// seen by the recipient. + pub htlc_minimum_msat: u64, + + /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the + /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as + /// seen by the recipient. + pub htlc_maximum_msat: u64, + + /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an + /// onion payload. + pub features: BlindedHopFeatures, +} + +impl_writeable!(BlindedPayInfo, { + fee_base_msat, + fee_proportional_millionths, + cltv_expiry_delta, + htlc_minimum_msat, + htlc_maximum_msat, + features +}); + /// A blinded path to be used for sending or receiving a payment, hiding the identity of the /// recipient. #[derive(Clone, Debug, Hash, PartialEq, Eq)] diff --git a/lightning/src/ln/max_payment_path_len_tests.rs b/lightning/src/ln/max_payment_path_len_tests.rs index a22d7d164..69ae3cd76 100644 --- a/lightning/src/ln/max_payment_path_len_tests.rs +++ b/lightning/src/ln/max_payment_path_len_tests.rs @@ -12,7 +12,7 @@ use bitcoin::secp256k1::{Secp256k1, PublicKey}; use crate::blinded_path::BlindedHop; -use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, ReceiveTlvs}; +use crate::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath, PaymentConstraints, PaymentContext, ReceiveTlvs}; use crate::events::{Event, MessageSendEventsProvider}; use crate::ln::PaymentSecret; use crate::ln::blinded_payment_tests::get_blinded_route_parameters; @@ -24,7 +24,6 @@ use crate::ln::msgs::OnionMessageHandler; use crate::ln::onion_utils; use crate::ln::onion_utils::MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY; use crate::ln::outbound_payment::{RecipientOnionFields, Retry, RetryableSendFailure}; -use crate::offers::invoice::BlindedPayInfo; use crate::prelude::*; use crate::routing::router::{DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, PaymentParameters, RouteParameters}; use crate::util::errors::APIError; diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 693e8e00f..40ee40090 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -29,8 +29,8 @@ //! use lightning::util::ser::Writeable; //! //! # use lightning::ln::types::PaymentHash; -//! # use lightning::offers::invoice::{BlindedPayInfo, ExplicitSigningPubkey, InvoiceBuilder}; -//! # use lightning::blinded_path::payment::BlindedPaymentPath; +//! # use lightning::offers::invoice::{ExplicitSigningPubkey, InvoiceBuilder}; +//! # use lightning::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath}; //! # //! # fn create_payment_paths() -> Vec { unimplemented!() } //! # fn create_payment_hash() -> PaymentHash { unimplemented!() } @@ -112,10 +112,10 @@ use core::hash::{Hash, Hasher}; use crate::io; use crate::blinded_path::BlindedPath; use crate::blinded_path::message::BlindedMessagePath; -use crate::blinded_path::payment::BlindedPaymentPath; +use crate::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath}; use crate::ln::types::PaymentHash; use crate::ln::channelmanager::PaymentId; -use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures}; +use crate::ln::features::{Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures}; use crate::ln::inbound_payment::{ExpandedKey, IV_LEN}; use crate::ln::msgs::DecodeError; use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common}; @@ -1216,44 +1216,6 @@ pub(super) type BlindedPayInfoIter<'a> = core::iter::Map< for<'r> fn(&'r BlindedPaymentPath) -> &'r BlindedPayInfo, >; -/// Information needed to route a payment across a [`BlindedPaymentPath`]. -#[derive(Clone, Debug, Hash, Eq, PartialEq)] -pub struct BlindedPayInfo { - /// Base fee charged (in millisatoshi) for the entire blinded path. - pub fee_base_msat: u32, - - /// Liquidity fee charged (in millionths of the amount transferred) for the entire blinded path - /// (i.e., 10,000 is 1%). - pub fee_proportional_millionths: u32, - - /// Number of blocks subtracted from an incoming HTLC's `cltv_expiry` for the entire blinded - /// path. - pub cltv_expiry_delta: u16, - - /// The minimum HTLC value (in millisatoshi) that is acceptable to all channel peers on the - /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as - /// seen by the recipient. - pub htlc_minimum_msat: u64, - - /// The maximum HTLC value (in millisatoshi) that is acceptable to all channel peers on the - /// blinded path from the introduction node to the recipient, accounting for any fees, i.e., as - /// seen by the recipient. - pub htlc_maximum_msat: u64, - - /// Features set in `encrypted_data_tlv` for the `encrypted_recipient_data` TLV record in an - /// onion payload. - pub features: BlindedHopFeatures, -} - -impl_writeable!(BlindedPayInfo, { - fee_base_msat, - fee_proportional_millionths, - cltv_expiry_delta, - htlc_minimum_msat, - htlc_maximum_msat, - features -}); - /// Wire representation for an on-chain fallback address. #[derive(Clone, Debug, PartialEq)] pub(super) struct FallbackAddress { diff --git a/lightning/src/offers/test_utils.rs b/lightning/src/offers/test_utils.rs index d815338d7..735354cb8 100644 --- a/lightning/src/offers/test_utils.rs +++ b/lightning/src/offers/test_utils.rs @@ -14,11 +14,10 @@ use bitcoin::secp256k1::schnorr::Signature; use core::time::Duration; use crate::blinded_path::BlindedHop; -use crate::blinded_path::payment::BlindedPaymentPath; +use crate::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath}; use crate::sign::EntropySource; use crate::ln::types::PaymentHash; use crate::ln::features::BlindedHopFeatures; -use crate::offers::invoice::BlindedPayInfo; use crate::offers::merkle::TaggedHash; #[allow(unused_imports)] diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 495ff30a9..c40e6ab31 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -1282,7 +1282,7 @@ pub struct OneHopBlindedPathCandidate<'a> { /// /// This is not exported to bindings users as lifetimes are not expressible in most languages. /// - /// [`BlindedPayInfo`]: crate::offers::invoice::BlindedPayInfo + /// [`BlindedPayInfo`]: crate::blinded_path::payment::BlindedPayInfo pub hint: &'a BlindedPaymentPath, /// Index of the hint in the original list of blinded hints. /// @@ -1334,7 +1334,7 @@ pub enum CandidateRouteHop<'a> { /// This primarily exists to track that we need to included a blinded path at the end of our /// [`Route`], even though it doesn't actually add an additional hop in the payment. /// - /// [`BlindedPayInfo`]: crate::offers::invoice::BlindedPayInfo + /// [`BlindedPayInfo`]: crate::blinded_path::payment::BlindedPayInfo OneHopBlinded(OneHopBlindedPathCandidate<'a>), } @@ -3553,7 +3553,7 @@ fn build_route_from_hops_internal( #[cfg(test)] mod tests { use crate::blinded_path::BlindedHop; - use crate::blinded_path::payment::BlindedPaymentPath; + use crate::blinded_path::payment::{BlindedPayInfo, BlindedPaymentPath}; use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity}; use crate::routing::utxo::UtxoResult; use crate::routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features, @@ -3567,7 +3567,6 @@ mod tests { use crate::ln::features::{BlindedHopFeatures, ChannelFeatures, InitFeatures, NodeFeatures}; use crate::ln::msgs::{ErrorAction, LightningError, UnsignedChannelUpdate, MAX_VALUE_MSAT}; use crate::ln::channelmanager; - use crate::offers::invoice::BlindedPayInfo; use crate::util::config::UserConfig; use crate::util::test_utils as ln_test_utils; use crate::crypto::chacha20::ChaCha20; -- 2.39.5