@@ -33,9 +33,9 @@ use bitcoin::secp256k1::Secp256k1;
33
33
use bitcoin::{secp256k1, Sequence, Weight};
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};
@@ -2588,26 +2588,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
2588
2588
/// many peers we reject new (inbound) connections.
2589
2589
const MAX_NO_CHANNEL_PEERS: usize = 250;
2590
2590
2591
- /// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2592
- /// short-lived, while anything with a greater expiration is considered long-lived.
2593
- ///
2594
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
2595
- /// will included a [`BlindedMessagePath`] created using:
2596
- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2597
- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2598
- ///
2599
- /// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2600
- /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2601
- ///
2602
- ///
2603
- /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2604
- /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2605
- /// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2606
- ///
2607
- /// [`Offer`]: crate::offers::offer
2608
- /// [`Refund`]: crate::offers::refund
2609
- pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2610
-
2611
2591
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2612
2592
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2613
2593
#[derive(Debug, PartialEq)]
@@ -9566,6 +9546,9 @@ pub trait OffersMessageCommons {
9566
9546
&self, amount_msats: u64, payment_secret: PaymentSecret, payment_context: PaymentContext
9567
9547
) -> Result<Vec<BlindedPaymentPath>, ()>;
9568
9548
9549
+ /// Get the vector of peers that can be used for a blinded path
9550
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode>;
9551
+
9569
9552
/// Verify bolt12 invoice
9570
9553
fn verify_bolt12_invoice(
9571
9554
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
@@ -9602,16 +9585,6 @@ pub trait OffersMessageCommons {
9602
9585
/// Get the current time determined by highest seen timestamp
9603
9586
fn get_current_blocktime(&self) -> Duration;
9604
9587
9605
- /// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on
9606
- /// the path's intended lifetime.
9607
- ///
9608
- /// Whether or not the path is compact depends on whether the path is short-lived or long-lived,
9609
- /// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See
9610
- /// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`].
9611
- fn create_blinded_paths_using_absolute_expiry(
9612
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9613
- ) -> Result<Vec<BlindedMessagePath>, ()>;
9614
-
9615
9588
/// Get the [`ChainHash`] of the chain
9616
9589
fn get_chain_hash(&self) -> ChainHash;
9617
9590
@@ -9705,6 +9678,23 @@ where
9705
9678
)
9706
9679
}
9707
9680
9681
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9682
+ self.per_peer_state.read().unwrap()
9683
+ .iter()
9684
+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9685
+ .filter(|(_, peer)| peer.is_connected)
9686
+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9687
+ .map(|(node_id, peer)| MessageForwardNode {
9688
+ node_id: *node_id,
9689
+ short_channel_id: peer.channel_by_id
9690
+ .iter()
9691
+ .filter(|(_, channel)| channel.context().is_usable())
9692
+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9693
+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9694
+ })
9695
+ .collect::<Vec<_>>()
9696
+ }
9697
+
9708
9698
fn verify_bolt12_invoice(
9709
9699
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9710
9700
) -> Result<PaymentId, ()> {
@@ -9809,19 +9799,6 @@ where
9809
9799
Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9810
9800
}
9811
9801
9812
- fn create_blinded_paths_using_absolute_expiry(
9813
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9814
- ) -> Result<Vec<BlindedMessagePath>, ()> {
9815
- let now = self.duration_since_epoch();
9816
- let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9817
-
9818
- if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9819
- self.create_compact_blinded_paths(context)
9820
- } else {
9821
- self.create_blinded_paths(MessageContext::Offers(context))
9822
- }
9823
- }
9824
-
9825
9802
fn get_chain_hash(&self) -> ChainHash {
9826
9803
self.chain_hash
9827
9804
}
@@ -9935,47 +9912,6 @@ where
9935
9912
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9936
9913
}
9937
9914
9938
- pub(super) fn duration_since_epoch(&self) -> Duration {
9939
- #[cfg(not(feature = "std"))]
9940
- let now = Duration::from_secs(
9941
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9942
- );
9943
- #[cfg(feature = "std")]
9944
- let now = std::time::SystemTime::now()
9945
- .duration_since(std::time::SystemTime::UNIX_EPOCH)
9946
- .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
9947
-
9948
- now
9949
- }
9950
-
9951
- /// Creates a collection of blinded paths by delegating to
9952
- /// [`MessageRouter::create_compact_blinded_paths`].
9953
- ///
9954
- /// Errors if the `MessageRouter` errors.
9955
- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9956
- let recipient = self.get_our_node_id();
9957
- let secp_ctx = &self.secp_ctx;
9958
-
9959
- let peers = self.per_peer_state.read().unwrap()
9960
- .iter()
9961
- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9962
- .filter(|(_, peer)| peer.is_connected)
9963
- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9964
- .map(|(node_id, peer)| MessageForwardNode {
9965
- node_id: *node_id,
9966
- short_channel_id: peer.channel_by_id
9967
- .iter()
9968
- .filter(|(_, channel)| channel.context().is_usable())
9969
- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9970
- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9971
- })
9972
- .collect::<Vec<_>>();
9973
-
9974
- self.message_router
9975
- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9976
- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9977
- }
9978
-
9979
9915
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
9980
9916
/// are used when constructing the phantom invoice's route hints.
9981
9917
///
0 commit comments