@@ -33,9 +33,9 @@ use bitcoin::secp256k1::Secp256k1;
33
33
use bitcoin::{secp256k1, Sequence};
34
34
35
35
use crate::events::FundingInfo;
36
- use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
36
+ use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, MessageForwardNode, 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, PaymentConstraints, PaymentContext, ReceiveTlvs};
40
40
use crate::chain;
41
41
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -2575,26 +2575,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
2575
2575
/// many peers we reject new (inbound) connections.
2576
2576
const MAX_NO_CHANNEL_PEERS: usize = 250;
2577
2577
2578
- /// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2579
- /// short-lived, while anything with a greater expiration is considered long-lived.
2580
- ///
2581
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
2582
- /// will included a [`BlindedMessagePath`] created using:
2583
- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2584
- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2585
- ///
2586
- /// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2587
- /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2588
- ///
2589
- ///
2590
- /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2591
- /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2592
- /// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2593
- ///
2594
- /// [`Offer`]: crate::offers::offer
2595
- /// [`Refund`]: crate::offers::refund
2596
- pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2597
-
2598
2578
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2599
2579
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2600
2580
#[derive(Debug, PartialEq)]
@@ -9255,6 +9235,9 @@ pub trait OffersMessageCommons {
9255
9235
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
9256
9236
) -> Result<Vec<BlindedPaymentPath>, ()>;
9257
9237
9238
+ /// Get the vector of peers that can be used for a blinded path
9239
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode>;
9240
+
9258
9241
/// Verify bolt12 invoice
9259
9242
fn verify_bolt12_invoice(
9260
9243
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
@@ -9291,16 +9274,6 @@ pub trait OffersMessageCommons {
9291
9274
/// Get the current time determined by highest seen timestamp
9292
9275
fn get_current_blocktime(&self) -> Duration;
9293
9276
9294
- /// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
9295
- /// the path's intended lifetime.
9296
- ///
9297
- /// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
9298
- /// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
9299
- /// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
9300
- fn create_blinded_paths_using_absolute_expiry(
9301
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9302
- ) -> Result<Vec<BlindedMessagePath>, ()>;
9303
-
9304
9277
/// Get the [`ChainHash`] of the chain
9305
9278
fn get_chain_hash(&self) -> ChainHash;
9306
9279
@@ -9394,6 +9367,23 @@ where
9394
9367
)
9395
9368
}
9396
9369
9370
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9371
+ self.per_peer_state.read().unwrap()
9372
+ .iter()
9373
+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9374
+ .filter(|(_, peer)| peer.is_connected)
9375
+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9376
+ .map(|(node_id, peer)| MessageForwardNode {
9377
+ node_id: *node_id,
9378
+ short_channel_id: peer.channel_by_id
9379
+ .iter()
9380
+ .filter(|(_, channel)| channel.context().is_usable())
9381
+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9382
+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9383
+ })
9384
+ .collect::<Vec<_>>()
9385
+ }
9386
+
9397
9387
fn verify_bolt12_invoice(
9398
9388
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9399
9389
) -> Result<PaymentId, ()> {
@@ -9498,19 +9488,6 @@ where
9498
9488
Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9499
9489
}
9500
9490
9501
- fn create_blinded_paths_using_absolute_expiry(
9502
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9503
- ) -> Result<Vec<BlindedMessagePath>, ()> {
9504
- let now = self.duration_since_epoch();
9505
- let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9506
-
9507
- if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9508
- self.create_compact_blinded_paths(context)
9509
- } else {
9510
- self.create_blinded_paths(MessageContext::Offers(context))
9511
- }
9512
- }
9513
-
9514
9491
fn get_chain_hash(&self) -> ChainHash {
9515
9492
self.chain_hash
9516
9493
}
@@ -9624,47 +9601,6 @@ where
9624
9601
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9625
9602
}
9626
9603
9627
- pub(super) fn duration_since_epoch(&self) -> Duration {
9628
- #[cfg(not(feature = "std"))]
9629
- let now = Duration::from_secs(
9630
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9631
- );
9632
- #[cfg(feature = "std")]
9633
- let now = std::time::SystemTime::now()
9634
- .duration_since(std::time::SystemTime::UNIX_EPOCH)
9635
- .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
9636
-
9637
- now
9638
- }
9639
-
9640
- /// Creates a collection of blinded paths by delegating to
9641
- /// [`MessageRouter::create_compact_blinded_paths`].
9642
- ///
9643
- /// Errors if the `MessageRouter` errors.
9644
- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9645
- let recipient = self.get_our_node_id();
9646
- let secp_ctx = &self.secp_ctx;
9647
-
9648
- let peers = self.per_peer_state.read().unwrap()
9649
- .iter()
9650
- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9651
- .filter(|(_, peer)| peer.is_connected)
9652
- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9653
- .map(|(node_id, peer)| MessageForwardNode {
9654
- node_id: *node_id,
9655
- short_channel_id: peer.channel_by_id
9656
- .iter()
9657
- .filter(|(_, channel)| channel.context().is_usable())
9658
- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9659
- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9660
- })
9661
- .collect::<Vec<_>>();
9662
-
9663
- self.message_router
9664
- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9665
- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9666
- }
9667
-
9668
9604
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
9669
9605
/// are used when constructing the phantom invoice's route hints.
9670
9606
///
0 commit comments