@@ -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, UnauthenticatedReceiveTlvs};
40
40
use crate::chain;
41
41
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -47,7 +47,6 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
47
47
// construct one themselves.
48
48
use crate::ln::inbound_payment;
49
49
use crate::ln::types::ChannelId;
50
- use crate::offers::offer::Offer;
51
50
use crate::offers::flow::OffersMessageCommons;
52
51
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
53
52
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
@@ -68,14 +67,13 @@ use crate::ln::outbound_payment;
68
67
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
69
68
use crate::offers::invoice::Bolt12Invoice;
70
69
use crate::offers::invoice::UnsignedBolt12Invoice;
71
- use crate::offers::invoice_request::{ InvoiceRequest, InvoiceRequestBuilder} ;
70
+ use crate::offers::invoice_request::InvoiceRequest;
72
71
use crate::offers::nonce::Nonce;
73
72
use crate::offers::parse::Bolt12SemanticError;
74
73
use crate::offers::signer;
75
74
#[cfg(async_payments)]
76
75
use crate::offers::static_invoice::StaticInvoice;
77
76
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
78
- use crate::onion_message::dns_resolution::HumanReadableName;
79
77
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, MessageSendInstructions, Responder, ResponseInstruction};
80
78
use crate::onion_message::offers::OffersMessage;
81
79
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
@@ -2619,26 +2617,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
2619
2617
/// many peers we reject new (inbound) connections.
2620
2618
const MAX_NO_CHANNEL_PEERS: usize = 250;
2621
2619
2622
- /// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2623
- /// short-lived, while anything with a greater expiration is considered long-lived.
2624
- ///
2625
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
2626
- /// will included a [`BlindedMessagePath`] created using:
2627
- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2628
- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2629
- ///
2630
- /// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2631
- /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2632
- ///
2633
- ///
2634
- /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2635
- /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2636
- /// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2637
- ///
2638
- /// [`Offer`]: crate::offers::offer
2639
- /// [`Refund`]: crate::offers::refund
2640
- pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2641
-
2642
2620
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2643
2621
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2644
2622
#[derive(Debug, PartialEq)]
@@ -9624,6 +9602,23 @@ where
9624
9602
)
9625
9603
}
9626
9604
9605
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9606
+ self.per_peer_state.read().unwrap()
9607
+ .iter()
9608
+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9609
+ .filter(|(_, peer)| peer.is_connected)
9610
+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9611
+ .map(|(node_id, peer)| MessageForwardNode {
9612
+ node_id: *node_id,
9613
+ short_channel_id: peer.channel_by_id
9614
+ .iter()
9615
+ .filter(|(_, channel)| channel.context().is_usable())
9616
+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9617
+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9618
+ })
9619
+ .collect::<Vec<_>>()
9620
+ }
9621
+
9627
9622
fn verify_bolt12_invoice(
9628
9623
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9629
9624
) -> Result<PaymentId, ()> {
@@ -9780,19 +9775,6 @@ where
9780
9775
res
9781
9776
}
9782
9777
9783
- fn create_blinded_paths_using_absolute_expiry(
9784
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9785
- ) -> Result<Vec<BlindedMessagePath>, ()> {
9786
- let now = self.duration_since_epoch();
9787
- let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9788
-
9789
- if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9790
- self.create_compact_blinded_paths(context)
9791
- } else {
9792
- self.create_blinded_paths(MessageContext::Offers(context))
9793
- }
9794
- }
9795
-
9796
9778
fn get_chain_hash(&self) -> ChainHash {
9797
9779
self.chain_hash
9798
9780
}
@@ -9811,53 +9793,6 @@ where
9811
9793
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9812
9794
}
9813
9795
9814
- fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9815
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9816
- payer_note: Option<String>, payment_id: PaymentId,
9817
- human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9818
- ) -> Result<(), Bolt12SemanticError> {
9819
- let expanded_key = &self.inbound_payment_key;
9820
- let entropy = &*self.entropy_source;
9821
- let secp_ctx = &self.secp_ctx;
9822
-
9823
- let nonce = Nonce::from_entropy_source(entropy);
9824
- let builder: InvoiceRequestBuilder<secp256k1::All> = offer
9825
- .request_invoice(expanded_key, nonce, secp_ctx, payment_id)?
9826
- .into();
9827
- let builder = builder.chain_hash(self.chain_hash)?;
9828
-
9829
- let builder = match quantity {
9830
- None => builder,
9831
- Some(quantity) => builder.quantity(quantity)?,
9832
- };
9833
- let builder = match amount_msats {
9834
- None => builder,
9835
- Some(amount_msats) => builder.amount_msats(amount_msats)?,
9836
- };
9837
- let builder = match payer_note {
9838
- None => builder,
9839
- Some(payer_note) => builder.payer_note(payer_note),
9840
- };
9841
- let builder = match human_readable_name {
9842
- None => builder,
9843
- Some(hrn) => builder.sourced_from_human_readable_name(hrn),
9844
- };
9845
- let invoice_request = builder.build_and_sign()?;
9846
-
9847
- let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
9848
- let context = MessageContext::Offers(
9849
- OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
9850
- );
9851
- let reply_paths = self.create_blinded_paths(context)
9852
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9853
-
9854
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9855
-
9856
- create_pending_payment(&invoice_request, nonce)?;
9857
-
9858
- self.enqueue_invoice_request(invoice_request, reply_paths)
9859
- }
9860
-
9861
9796
#[cfg(feature = "dnssec")]
9862
9797
fn amt_msats_for_payment_awaiting_offer(&self, payment_id: PaymentId) -> Result<u64, ()> {
9863
9798
self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id)
@@ -9869,6 +9804,11 @@ where
9869
9804
) -> Result<(), ()> {
9870
9805
self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
9871
9806
}
9807
+
9808
+ #[cfg(not(feature = "std"))]
9809
+ fn get_highest_seen_timestamp(&self) -> Duration {
9810
+ Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9811
+ }
9872
9812
}
9873
9813
9874
9814
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9951,47 +9891,6 @@ where
9951
9891
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9952
9892
}
9953
9893
9954
- pub(super) fn duration_since_epoch(&self) -> Duration {
9955
- #[cfg(not(feature = "std"))]
9956
- let now = Duration::from_secs(
9957
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9958
- );
9959
- #[cfg(feature = "std")]
9960
- let now = std::time::SystemTime::now()
9961
- .duration_since(std::time::SystemTime::UNIX_EPOCH)
9962
- .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
9963
-
9964
- now
9965
- }
9966
-
9967
- /// Creates a collection of blinded paths by delegating to
9968
- /// [`MessageRouter::create_compact_blinded_paths`].
9969
- ///
9970
- /// Errors if the `MessageRouter` errors.
9971
- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9972
- let recipient = self.get_our_node_id();
9973
- let secp_ctx = &self.secp_ctx;
9974
-
9975
- let peers = self.per_peer_state.read().unwrap()
9976
- .iter()
9977
- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9978
- .filter(|(_, peer)| peer.is_connected)
9979
- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9980
- .map(|(node_id, peer)| MessageForwardNode {
9981
- node_id: *node_id,
9982
- short_channel_id: peer.channel_by_id
9983
- .iter()
9984
- .filter(|(_, channel)| channel.context().is_usable())
9985
- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9986
- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9987
- })
9988
- .collect::<Vec<_>>();
9989
-
9990
- self.message_router
9991
- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9992
- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9993
- }
9994
-
9995
9894
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
9996
9895
/// are used when constructing the phantom invoice's route hints.
9997
9896
///
0 commit comments