Skip to content

Commit 5bfa529

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 d009eeb commit 5bfa529

File tree

4 files changed

+144
-134
lines changed

4 files changed

+144
-134
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use bitcoin::{secp256k1, Sequence};
3535
use crate::events::FundingInfo;
3636
use crate::blinded_path::message::{MessageContext, OffersContext};
3737
use crate::blinded_path::NodeIdLookUp;
38-
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode};
38+
use crate::blinded_path::message::BlindedMessagePath;
3939
use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
4040
use crate::chain;
4141
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -1728,12 +1728,13 @@ 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::new(false);
17351736
/// let offer = channel_manager
1736-
/// .create_offer_builder(absolute_expiry)?
1737+
/// .create_offer_builder(Some(params))?
17371738
/// # ;
17381739
/// # // Needed for compiling for c_bindings
17391740
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
@@ -1831,16 +1832,18 @@ where
18311832
/// # use lightning::events::{Event, EventsProvider};
18321833
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
18331834
/// # use lightning::offers::parse::Bolt12SemanticError;
1835+
/// # use lightning::onion_message::messenger::BlindedPathParams;
18341836
/// #
18351837
/// # fn example<T: AChannelManager>(
18361838
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
18371839
/// # max_total_routing_fee_msat: Option<u64>
18381840
/// # ) -> Result<(), Bolt12SemanticError> {
18391841
/// # let channel_manager = channel_manager.get_cm();
1840-
/// let payment_id = PaymentId([42; 32]);
1842+
/// # let params = BlindedPathParams::new(false);
1843+
/// # let payment_id = PaymentId([42; 32]);
18411844
/// let refund = channel_manager
18421845
/// .create_refund_builder(
1843-
/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
1846+
/// Some(params), amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat
18441847
/// )?
18451848
/// # ;
18461849
/// # // Needed for compiling for c_bindings
@@ -8870,7 +8873,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
88708873
/// [`Offer`]: crate::offers::offer::Offer
88718874
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
88728875
pub fn create_offer_builder(
8873-
&$self, absolute_expiry: Option<Duration>
8876+
&$self, params: Option<BlindedPathParams>,
88748877
) -> Result<$builder, Bolt12SemanticError> {
88758878
let node_id = $self.get_our_node_id();
88768879
let expanded_key = &$self.inbound_payment_key;
@@ -8879,17 +8882,16 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
88798882

88808883
let nonce = Nonce::from_entropy_source(entropy);
88818884
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);
88888885

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

88948896
Ok(builder.into())
88958897
}
@@ -8942,7 +8944,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
89428944
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
89438945
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
89448946
pub fn create_refund_builder(
8945-
&$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId,
8947+
&$self, params: Option<BlindedPathParams>, amount_msats: u64,
8948+
absolute_expiry: Duration, payment_id: PaymentId,
89468949
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
89478950
) -> Result<$builder, Bolt12SemanticError> {
89488951
let node_id = $self.get_our_node_id();
@@ -8952,16 +8955,20 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
89528955

89538956
let nonce = Nonce::from_entropy_source(entropy);
89548957
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)?;
89588958

8959-
let builder = RefundBuilder::deriving_payer_id(
8959+
let mut builder = RefundBuilder::deriving_payer_id(
89608960
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
89618961
)?
89628962
.chain_hash($self.chain_hash)
8963-
.absolute_expiry(absolute_expiry)
8964-
.path(path);
8963+
.absolute_expiry(absolute_expiry);
8964+
8965+
if let Some(params) = params {
8966+
let path = $self.create_blinded_paths(params, context)
8967+
.and_then(|paths| paths.into_iter().next().ok_or(()))
8968+
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
8969+
8970+
builder = builder.path(path);
8971+
};
89658972

89668973
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
89678974

@@ -9334,26 +9341,7 @@ where
93349341
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
93359342
}
93369343

9337-
/// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
9338-
/// the path's intended lifetime.
9339-
///
9340-
/// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
9341-
/// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
9342-
/// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
9343-
fn create_blinded_paths_using_absolute_expiry(
9344-
&self, context: OffersContext, absolute_expiry: Option<Duration>,
9345-
) -> Result<Vec<BlindedMessagePath>, ()> {
9346-
let now = self.duration_since_epoch();
9347-
let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9348-
9349-
if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9350-
self.create_compact_blinded_paths(context)
9351-
} else {
9352-
let params = BlindedPathParams::new(false);
9353-
self.create_blinded_paths(params, context)
9354-
}
9355-
}
9356-
9344+
#[cfg(test)]
93579345
pub(super) fn duration_since_epoch(&self) -> Duration {
93589346
#[cfg(not(feature = "std"))]
93599347
let now = Duration::from_secs(
@@ -9388,34 +9376,6 @@ where
93889376
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
93899377
}
93909378

9391-
/// Creates a collection of blinded paths by delegating to
9392-
/// [`MessageRouter::create_compact_blinded_paths`].
9393-
///
9394-
/// Errors if the `MessageRouter` errors.
9395-
fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9396-
let recipient = self.get_our_node_id();
9397-
let secp_ctx = &self.secp_ctx;
9398-
9399-
let peers = self.per_peer_state.read().unwrap()
9400-
.iter()
9401-
.map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9402-
.filter(|(_, peer)| peer.is_connected)
9403-
.filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9404-
.map(|(node_id, peer)| MessageForwardNode {
9405-
node_id: *node_id,
9406-
short_channel_id: peer.channel_by_id
9407-
.iter()
9408-
.filter(|(_, channel)| channel.context().is_usable())
9409-
.min_by_key(|(_, channel)| channel.context().channel_creation_height)
9410-
.and_then(|(_, channel)| channel.context().get_short_channel_id()),
9411-
})
9412-
.collect::<Vec<_>>();
9413-
9414-
self.router
9415-
.create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9416-
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9417-
}
9418-
94199379
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
94209380
/// [`Router::create_blinded_payment_paths`].
94219381
fn create_blinded_payment_paths(

lightning/src/ln/max_payment_path_len_tests.rs

Lines changed: 3 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;
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,8 @@ 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::new(false);
382+
let offer = nodes[1].node.create_offer_builder(Some(params)).unwrap().build().unwrap();
381383
let payment_id = PaymentId([1; 32]);
382384
nodes[0].node.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), None).unwrap();
383385
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)