@@ -35,7 +35,7 @@ use bitcoin::{secp256k1, Sequence};
35
35
use crate::events::FundingInfo;
36
36
use crate::blinded_path::message::{MessageContext, OffersContext};
37
37
use crate::blinded_path::NodeIdLookUp;
38
- use crate::blinded_path::message::{ BlindedMessagePath, MessageForwardNode} ;
38
+ use crate::blinded_path::message::BlindedMessagePath;
39
39
use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs};
40
40
use crate::chain;
41
41
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -1728,12 +1728,13 @@ where
1728
1728
/// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
1729
1729
/// # use lightning::ln::channelmanager::AChannelManager;
1730
1730
/// # use lightning::offers::parse::Bolt12SemanticError;
1731
+ /// # use lightning::onion_message::messenger::BlindedPathParams;
1731
1732
/// #
1732
1733
/// # fn example<T: AChannelManager>(channel_manager: T) -> Result<(), Bolt12SemanticError> {
1733
1734
/// # let channel_manager = channel_manager.get_cm();
1734
- /// # let absolute_expiry = None ;
1735
+ /// # let params = BlindedPathParams::new(false) ;
1735
1736
/// let offer = channel_manager
1736
- /// .create_offer_builder(absolute_expiry )?
1737
+ /// .create_offer_builder(Some(params) )?
1737
1738
/// # ;
1738
1739
/// # // Needed for compiling for c_bindings
1739
1740
/// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into();
@@ -1831,16 +1832,18 @@ where
1831
1832
/// # use lightning::events::{Event, EventsProvider};
1832
1833
/// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry};
1833
1834
/// # use lightning::offers::parse::Bolt12SemanticError;
1835
+ /// # use lightning::onion_message::messenger::BlindedPathParams;
1834
1836
/// #
1835
1837
/// # fn example<T: AChannelManager>(
1836
1838
/// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry,
1837
1839
/// # max_total_routing_fee_msat: Option<u64>
1838
1840
/// # ) -> Result<(), Bolt12SemanticError> {
1839
1841
/// # 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]);
1841
1844
/// let refund = channel_manager
1842
1845
/// .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
1844
1847
/// )?
1845
1848
/// # ;
1846
1849
/// # // Needed for compiling for c_bindings
@@ -8870,7 +8873,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
8870
8873
/// [`Offer`]: crate::offers::offer::Offer
8871
8874
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
8872
8875
pub fn create_offer_builder(
8873
- &$self, absolute_expiry : Option<Duration>
8876
+ &$self, params : Option<BlindedPathParams>,
8874
8877
) -> Result<$builder, Bolt12SemanticError> {
8875
8878
let node_id = $self.get_our_node_id();
8876
8879
let expanded_key = &$self.inbound_payment_key;
@@ -8879,17 +8882,16 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => {
8879
8882
8880
8883
let nonce = Nonce::from_entropy_source(entropy);
8881
8884
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);
8888
8885
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
+ }
8893
8895
8894
8896
Ok(builder.into())
8895
8897
}
@@ -8942,7 +8944,8 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8942
8944
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
8943
8945
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
8944
8946
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,
8946
8949
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>
8947
8950
) -> Result<$builder, Bolt12SemanticError> {
8948
8951
let node_id = $self.get_our_node_id();
@@ -8952,16 +8955,20 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
8952
8955
8953
8956
let nonce = Nonce::from_entropy_source(entropy);
8954
8957
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)?;
8958
8958
8959
- let builder = RefundBuilder::deriving_payer_id(
8959
+ let mut builder = RefundBuilder::deriving_payer_id(
8960
8960
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
8961
8961
)?
8962
8962
.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
+ };
8965
8972
8966
8973
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self);
8967
8974
@@ -9334,26 +9341,7 @@ where
9334
9341
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9335
9342
}
9336
9343
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)]
9357
9345
pub(super) fn duration_since_epoch(&self) -> Duration {
9358
9346
#[cfg(not(feature = "std"))]
9359
9347
let now = Duration::from_secs(
@@ -9388,34 +9376,6 @@ where
9388
9376
.and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9389
9377
}
9390
9378
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
-
9419
9379
/// Creates multi-hop blinded payment paths for the given `amount_msats` by delegating to
9420
9380
/// [`Router::create_blinded_payment_paths`].
9421
9381
fn create_blinded_payment_paths(
0 commit comments