Skip to content

Commit c078155

Browse files
committed
Remove create_blinded_path_using_absolute_expiry
1. This function was initially introduced in commit `8012c2b213127372bdad150cdc354920d971087d` to allow using compact or full-length blinded paths based on the lifetime of Offers and Refunds. 2. With the introduction of `BlindedPathParams`, users can now explicitly specify the type of blinded path to be used, rendering this functionality redundant. 3. As a result, the corresponding `create_blinded_path` variant is removed. 4. The params parameter is introduced as an option, that allows the user to create Offers and Refund without BlindedPath if needed.
1 parent 318b72e commit c078155

File tree

3 files changed

+264
-106
lines changed

3 files changed

+264
-106
lines changed

lightning/src/ln/channelmanager.rs

+35-44
Original file line numberDiff line numberDiff line change
@@ -1704,12 +1704,16 @@ where
17041704
/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
17051705
/// # use lightning::ln::channelmanager::AChannelManager;
17061706
/// # use lightning::offers::parse::Bolt12SemanticError;
1707+
/// # use lightning::onion_message::messenger::BlindedPathParams;
17071708
/// #
17081709
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
17091710
/// # let channel_manager = channel_manager.get_cm();
1710-
/// # let absolute_expiry = None;
1711+
/// # let params = BlindedPathParams {
1712+
/// # paths: 0,
1713+
/// # is_compact: false,
1714+
/// # };
17111715
/// let offer = channel_manager
1712-
/// .create_offer_builder(absolute_expiry)?
1716+
/// .create_offer_builder(Some(params))?
17131717
/// # ;
17141718
/// # // Needed for compiling for c_bindings
17151719
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
@@ -1807,16 +1811,21 @@ where
18071811
/// # use lightning::events::{Event, EventsProvider};
18081812
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
18091813
/// # use lightning::offers::parse::Bolt12SemanticError;
1814+
/// # use lightning::onion_message::messenger::BlindedPathParams;
18101815
/// #
18111816
/// # fn example<T: AChannelManager>(
18121817
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
18131818
/// # max_total_routing_fee_msat: Option<u64>
18141819
/// # ) -> Result<(), Bolt12SemanticError> {
18151820
/// # let channel_manager = channel_manager.get_cm();
1816-
/// let payment_id = PaymentId([42; 32]);
1821+
/// # let params = BlindedPathParams {
1822+
/// # paths: 0,
1823+
/// # is_compact: false,
1824+
/// # };
1825+
/// # let payment_id = PaymentId([42; 32]);
18171826
/// let refund = channel_manager
18181827
/// .create_refund_builder(
1819-
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
1828+
/// Some(params), amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
18201829
/// )?
18211830
/// # ;
18221831
/// # // Needed for compiling for c_bindings
@@ -8808,7 +8817,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
88088817
/// [`Offer`]: crate::offers::offer::Offer
88098818
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
88108819
pub fn create_offer_builder(
8811-
&$self, absolute_expiry: Option<Duration>
8820+
&$self, params: Option<BlindedPathParams>,
88128821
) -> Result<$builder, Bolt12SemanticError> {
88138822
let node_id = $self.get_our_node_id();
88148823
let expanded_key = &$self.inbound_payment_key;
@@ -8817,17 +8826,15 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
88178826

88188827
let nonce = Nonce::from_entropy_source(entropy);
88198828
let context = OffersContext::InvoiceRequest { nonce };
8820-
let path = $self.create_blinded_paths_using_absolute_expiry(context, absolute_expiry)
8829+
let mut builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
8830+
.chain_hash($self.chain_hash);
8831+
if let Some(params) = params {
8832+
let path = $self.create_blinded_paths(params, context)
88218833
.and_then(|paths| paths.into_iter().next().ok_or(()))
88228834
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8823-
let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
8824-
.chain_hash($self.chain_hash)
8825-
.path(path);
8826-
8827-
let builder = match absolute_expiry {
8828-
None => builder,
8829-
Some(absolute_expiry) => builder.absolute_expiry(absolute_expiry),
8830-
};
8835+
8836+
builder = builder.path(path);
8837+
}
88318838

88328839
Ok(builder.into())
88338840
}
@@ -8880,7 +8887,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
88808887
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
88818888
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
88828889
pub fn create_refund_builder(
8883-
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
8890+
&$self, params: Option<BlindedPathParams>, amount_msats: u64,
8891+
absolute_expiry: Duration, payment_id: PaymentId,
88848892
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
88858893
) -> Result<$builder, Bolt12SemanticError> {
88868894
let node_id = $self.get_our_node_id();
@@ -8891,15 +8899,19 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
88918899
let nonce = Nonce::from_entropy_source(entropy);
88928900
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
88938901

8894-
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
8895-
.and_then(|paths| paths.into_iter().next().ok_or(()))
8896-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8897-
let builder = RefundBuilder::deriving_payer_id(
8902+
let mut builder = RefundBuilder::deriving_payer_id(
88988903
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
88998904
)?
89008905
.chain_hash($self.chain_hash)
8901-
.absolute_expiry(absolute_expiry)
8902-
.path(path);
8906+
.absolute_expiry(absolute_expiry);
8907+
8908+
if let Some(params) = params {
8909+
let path = $self.create_blinded_paths(params, context)
8910+
.and_then(|paths| paths.into_iter().next().ok_or(()))
8911+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8912+
8913+
builder = builder.path(path);
8914+
};
89038915

89048916
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
89058917

@@ -9273,29 +9285,7 @@ where
92739285
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
92749286
}
92759287

9276-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
9277-
/// the path's intended lifetime.
9278-
///
9279-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
9280-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
9281-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
9282-
fn create_blinded_paths_using_absolute_expiry(
9283-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
9284-
) -> Result<Vec<BlindedMessagePath>, ()> {
9285-
let now = self.duration_since_epoch();
9286-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9287-
9288-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9289-
self.create_compact_blinded_paths(context)
9290-
} else {
9291-
let params = BlindedPathParams {
9292-
paths: PATHS_PLACEHOLDER,
9293-
is_compact: false
9294-
};
9295-
self.create_blinded_paths(params, context)
9296-
}
9297-
}
9298-
9288+
#[cfg(test)]
92999289
pub(super) fn duration_since_epoch(&self) -> Duration {
93009290
#[cfg(not(feature = "std"))]
93019291
let now = Duration::from_secs(
@@ -9334,6 +9324,7 @@ where
93349324
/// [`MessageRouter::create_compact_blinded_paths`].
93359325
///
93369326
/// Errors if the `MessageRouter` errors.
9327+
#[allow(unused)]
93379328
fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
93389329
let recipient = self.get_our_node_id();
93399330
let secp_ctx = &self.secp_ctx;

lightning/src/ln/max_payment_path_len_tests.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::ln::onion_utils;
2525
use crate::ln::onion_utils::MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
2626
use crate::ln::outbound_payment::{RecipientOnionFields, Retry, RetryableSendFailure};
2727
use crate::offers::invoice::BlindedPayInfo;
28+
use crate::onion_message::messenger::{BlindedPathParams, PATHS_PLACEHOLDER};
2829
use crate::prelude::*;
2930
use crate::routing::router::{DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, PaymentParameters, RouteParameters};
3031
use crate::util::errors::APIError;
@@ -378,7 +379,11 @@ fn bolt12_invoice_too_large_blinded_paths() {
378379
)
379380
)]);
380381

381-
let offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap();
382+
let params = BlindedPathParams {
383+
paths: PATHS_PLACEHOLDER,
384+
is_compact: false,
385+
};
386+
let offer = nodes[1].node.create_offer_builder(Some(params)).unwrap().build().unwrap();
382387
let payment_id = PaymentId([1; 32]);
383388
nodes[0].node.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), None).unwrap();
384389
let invreq_om = nodes[0].onion_messenger.next_onion_message_for_peer(nodes[1].node.get_our_node_id()).unwrap();

0 commit comments

Comments
 (0)