Skip to content

Commit 47077a6

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 88ecbe2 commit 47077a6

File tree

3 files changed

+266
-107
lines changed

3 files changed

+266
-107
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,12 +1728,16 @@ where
17281728
/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
17291729
/// # use lightning::ln::channelmanager::AChannelManager;
17301730
/// # use lightning::offers::parse::Bolt12SemanticError;
1731+
/// # use lightning::onion_message::messenger::BlindedPathParams;
17311732
/// #
17321733
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
17331734
/// # let channel_manager = channel_manager.get_cm();
1734-
/// # let absolute_expiry = None;
1735+
/// # let params = BlindedPathParams {
1736+
/// # paths: 0,
1737+
/// # is_compact: false,
1738+
/// # };
17351739
/// let offer = channel_manager
1736-
/// .create_offer_builder(absolute_expiry)?
1740+
/// .create_offer_builder(Some(params))?
17371741
/// # ;
17381742
/// # // Needed for compiling for c_bindings
17391743
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
@@ -1831,16 +1835,21 @@ where
18311835
/// # use lightning::events::{Event, EventsProvider};
18321836
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
18331837
/// # use lightning::offers::parse::Bolt12SemanticError;
1838+
/// # use lightning::onion_message::messenger::BlindedPathParams;
18341839
/// #
18351840
/// # fn example<T: AChannelManager>(
18361841
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
18371842
/// # max_total_routing_fee_msat: Option<u64>
18381843
/// # ) -> Result<(), Bolt12SemanticError> {
18391844
/// # let channel_manager = channel_manager.get_cm();
1840-
/// let payment_id = PaymentId([42; 32]);
1845+
/// # let params = BlindedPathParams {
1846+
/// # paths: 0,
1847+
/// # is_compact: false,
1848+
/// # };
1849+
/// # let payment_id = PaymentId([42; 32]);
18411850
/// let refund = channel_manager
18421851
/// .create_refund_builder(
1843-
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
1852+
/// Some(params), amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
18441853
/// )?
18451854
/// # ;
18461855
/// # // Needed for compiling for c_bindings
@@ -8870,7 +8879,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
88708879
/// [`Offer`]: crate::offers::offer::Offer
88718880
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
88728881
pub fn create_offer_builder(
8873-
&$self, absolute_expiry: Option<Duration>
8882+
&$self, params: Option<BlindedPathParams>,
88748883
) -> Result<$builder, Bolt12SemanticError> {
88758884
let node_id = $self.get_our_node_id();
88768885
let expanded_key = &$self.inbound_payment_key;
@@ -8879,17 +8888,16 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
88798888

88808889
let nonce = Nonce::from_entropy_source(entropy);
88818890
let context = OffersContext::InvoiceRequest { nonce };
8882-
let path = $self.create_blinded_paths_using_absolute_expiry(context, absolute_expiry)
8883-
.and_then(|paths| paths.into_iter().next().ok_or(()))
8884-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8885-
let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
8886-
.chain_hash($self.chain_hash)
8887-
.path(path);
88888891

8889-
let builder = match absolute_expiry {
8890-
None => builder,
8891-
Some(absolute_expiry) => builder.absolute_expiry(absolute_expiry),
8892-
};
8892+
let mut builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
8893+
.chain_hash($self.chain_hash);
8894+
if let Some(params) = params {
8895+
let path = $self.create_blinded_paths(params, context)
8896+
.and_then(|paths| paths.into_iter().next().ok_or(()))
8897+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8898+
8899+
builder = builder.path(path);
8900+
}
88938901

88948902
Ok(builder.into())
88958903
}
@@ -8942,7 +8950,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
89428950
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
89438951
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
89448952
pub fn create_refund_builder(
8945-
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
8953+
&$self, params: Option<BlindedPathParams>, amount_msats: u64,
8954+
absolute_expiry: Duration, payment_id: PaymentId,
89468955
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
89478956
) -> Result<$builder, Bolt12SemanticError> {
89488957
let node_id = $self.get_our_node_id();
@@ -8952,16 +8961,20 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
89528961

89538962
let nonce = Nonce::from_entropy_source(entropy);
89548963
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
8955-
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
8956-
.and_then(|paths| paths.into_iter().next().ok_or(()))
8957-
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
89588964

8959-
let builder = RefundBuilder::deriving_payer_id(
8965+
let mut builder = RefundBuilder::deriving_payer_id(
89608966
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
89618967
)?
89628968
.chain_hash($self.chain_hash)
8963-
.absolute_expiry(absolute_expiry)
8964-
.path(path);
8969+
.absolute_expiry(absolute_expiry);
8970+
8971+
if let Some(params) = params {
8972+
let path = $self.create_blinded_paths(params, context)
8973+
.and_then(|paths| paths.into_iter().next().ok_or(()))
8974+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8975+
8976+
builder = builder.path(path);
8977+
};
89658978

89668979
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
89678980

@@ -9336,29 +9349,7 @@ where
93369349
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
93379350
}
93389351

9339-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
9340-
/// the path's intended lifetime.
9341-
///
9342-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
9343-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
9344-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
9345-
fn create_blinded_paths_using_absolute_expiry(
9346-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
9347-
) -> Result<Vec<BlindedMessagePath>, ()> {
9348-
let now = self.duration_since_epoch();
9349-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9350-
9351-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9352-
self.create_compact_blinded_paths(context)
9353-
} else {
9354-
let params = BlindedPathParams {
9355-
paths: PATHS_PLACEHOLDER,
9356-
is_compact: false
9357-
};
9358-
self.create_blinded_paths(params, context)
9359-
}
9360-
}
9361-
9352+
#[cfg(test)]
93629353
pub(super) fn duration_since_epoch(&self) -> Duration {
93639354
#[cfg(not(feature = "std"))]
93649355
let now = Duration::from_secs(
@@ -9397,6 +9388,7 @@ where
93979388
/// [`MessageRouter::create_compact_blinded_paths`].
93989389
///
93999390
/// Errors if the `MessageRouter` errors.
9391+
#[allow(unused)]
94009392
fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
94019393
let recipient = self.get_our_node_id();
94029394
let secp_ctx = &self.secp_ctx;

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::ln::msgs::OnionMessageHandler;
2424
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};
27+
use crate::onion_message::messenger::{BlindedPathParams, PATHS_PLACEHOLDER};
2728
use crate::prelude::*;
2829
use crate::routing::router::{DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, PaymentParameters, RouteParameters};
2930
use crate::util::errors::APIError;
@@ -377,7 +378,11 @@ fn bolt12_invoice_too_large_blinded_paths() {
377378
)
378379
]);
379380

380-
let offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap();
381+
let params = BlindedPathParams {
382+
paths: PATHS_PLACEHOLDER,
383+
is_compact: false,
384+
};
385+
let offer = nodes[1].node.create_offer_builder(Some(params)).unwrap().build().unwrap();
381386
let payment_id = PaymentId([1; 32]);
382387
nodes[0].node.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), None).unwrap();
383388
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)