@@ -33,9 +33,9 @@ use bitcoin::secp256k1::Secp256k1;
3333use bitcoin::{secp256k1, Sequence, Weight};
3434
3535use crate::events::FundingInfo;
36- use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
36+ use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, MessageForwardNode, OffersContext};
3737use crate::blinded_path::NodeIdLookUp;
38- use crate::blinded_path::message::{ BlindedMessagePath, MessageForwardNode} ;
38+ use crate::blinded_path::message::BlindedMessagePath;
3939use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, ReceiveTlvs};
4040use crate::chain;
4141use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
@@ -47,7 +47,6 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
4747// construct one themselves.
4848use crate::ln::inbound_payment;
4949use crate::ln::types::ChannelId;
50- use crate::offers::offer::Offer;
5150use crate::offers::flow::OffersMessageCommons;
5251use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
5352use crate::ln::channel::{self, Channel, ChannelPhase, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext, InboundV2Channel, InteractivelyFunded as _};
@@ -66,14 +65,13 @@ use crate::ln::outbound_payment;
6665use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
6766use crate::offers::invoice::Bolt12Invoice;
6867use crate::offers::invoice::UnsignedBolt12Invoice;
69- use crate::offers::invoice_request::{ InvoiceRequest, InvoiceRequestBuilder} ;
68+ use crate::offers::invoice_request::InvoiceRequest;
7069use crate::offers::nonce::Nonce;
7170use crate::offers::parse::Bolt12SemanticError;
7271use crate::offers::signer;
7372#[cfg(async_payments)]
7473use crate::offers::static_invoice::StaticInvoice;
7574use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
76- use crate::onion_message::dns_resolution::HumanReadableName;
7775use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, MessageSendInstructions, Responder, ResponseInstruction};
7876use crate::onion_message::offers::OffersMessage;
7977use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
@@ -2590,26 +2588,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
25902588/// many peers we reject new (inbound) connections.
25912589const MAX_NO_CHANNEL_PEERS: usize = 250;
25922590
2593- /// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2594- /// short-lived, while anything with a greater expiration is considered long-lived.
2595- ///
2596- /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
2597- /// will included a [`BlindedMessagePath`] created using:
2598- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2599- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2600- ///
2601- /// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2602- /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2603- ///
2604- ///
2605- /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2606- /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2607- /// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2608- ///
2609- /// [`Offer`]: crate::offers::offer
2610- /// [`Refund`]: crate::offers::refund
2611- pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2612-
26132591/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
26142592/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
26152593#[derive(Debug, PartialEq)]
@@ -9560,6 +9538,23 @@ where
95609538 )
95619539 }
95629540
9541+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9542+ self.per_peer_state.read().unwrap()
9543+ .iter()
9544+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9545+ .filter(|(_, peer)| peer.is_connected)
9546+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9547+ .map(|(node_id, peer)| MessageForwardNode {
9548+ node_id: *node_id,
9549+ short_channel_id: peer.channel_by_id
9550+ .iter()
9551+ .filter(|(_, channel)| channel.context().is_usable())
9552+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9553+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9554+ })
9555+ .collect::<Vec<_>>()
9556+ }
9557+
95639558 fn verify_bolt12_invoice(
95649559 &self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
95659560 ) -> Result<PaymentId, ()> {
@@ -9656,19 +9651,6 @@ where
96569651 Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
96579652 }
96589653
9659- fn create_blinded_paths_using_absolute_expiry(
9660- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9661- ) -> Result<Vec<BlindedMessagePath>, ()> {
9662- let now = self.duration_since_epoch();
9663- let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9664-
9665- if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9666- self.create_compact_blinded_paths(context)
9667- } else {
9668- self.create_blinded_paths(MessageContext::Offers(context))
9669- }
9670- }
9671-
96729654 fn get_chain_hash(&self) -> ChainHash {
96739655 self.chain_hash
96749656 }
@@ -9687,53 +9669,6 @@ where
96879669 self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
96889670 }
96899671
9690- fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9691- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9692- payer_note: Option<String>, payment_id: PaymentId,
9693- human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9694- ) -> Result<(), Bolt12SemanticError> {
9695- let expanded_key = &self.inbound_payment_key;
9696- let entropy = &*self.entropy_source;
9697- let secp_ctx = &self.secp_ctx;
9698-
9699- let nonce = Nonce::from_entropy_source(entropy);
9700- let builder: InvoiceRequestBuilder<secp256k1::All> = offer
9701- .request_invoice(expanded_key, nonce, secp_ctx, payment_id)?
9702- .into();
9703- let builder = builder.chain_hash(self.chain_hash)?;
9704-
9705- let builder = match quantity {
9706- None => builder,
9707- Some(quantity) => builder.quantity(quantity)?,
9708- };
9709- let builder = match amount_msats {
9710- None => builder,
9711- Some(amount_msats) => builder.amount_msats(amount_msats)?,
9712- };
9713- let builder = match payer_note {
9714- None => builder,
9715- Some(payer_note) => builder.payer_note(payer_note),
9716- };
9717- let builder = match human_readable_name {
9718- None => builder,
9719- Some(hrn) => builder.sourced_from_human_readable_name(hrn),
9720- };
9721- let invoice_request = builder.build_and_sign()?;
9722-
9723- let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
9724- let context = MessageContext::Offers(
9725- OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
9726- );
9727- let reply_paths = self.create_blinded_paths(context)
9728- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9729-
9730- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9731-
9732- create_pending_payment(&invoice_request, nonce)?;
9733-
9734- self.enqueue_invoice_request(invoice_request, reply_paths)
9735- }
9736-
97379672 #[cfg(feature = "dnssec")]
97389673 fn amt_msats_for_payment_awaiting_offer(&self, payment_id: PaymentId) -> Result<u64, ()> {
97399674 self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id)
@@ -9745,6 +9680,11 @@ where
97459680 ) -> Result<(), ()> {
97469681 self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
97479682 }
9683+
9684+ #[cfg(not(feature = "std"))]
9685+ fn get_highest_seen_timestamp(&self) -> Duration {
9686+ Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9687+ }
97489688}
97499689
97509690/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9827,47 +9767,6 @@ where
98279767 inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
98289768 }
98299769
9830- pub(super) fn duration_since_epoch(&self) -> Duration {
9831- #[cfg(not(feature = "std"))]
9832- let now = Duration::from_secs(
9833- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9834- );
9835- #[cfg(feature = "std")]
9836- let now = std::time::SystemTime::now()
9837- .duration_since(std::time::SystemTime::UNIX_EPOCH)
9838- .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
9839-
9840- now
9841- }
9842-
9843- /// Creates a collection of blinded paths by delegating to
9844- /// [`MessageRouter::create_compact_blinded_paths`].
9845- ///
9846- /// Errors if the `MessageRouter` errors.
9847- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9848- let recipient = self.get_our_node_id();
9849- let secp_ctx = &self.secp_ctx;
9850-
9851- let peers = self.per_peer_state.read().unwrap()
9852- .iter()
9853- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9854- .filter(|(_, peer)| peer.is_connected)
9855- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9856- .map(|(node_id, peer)| MessageForwardNode {
9857- node_id: *node_id,
9858- short_channel_id: peer.channel_by_id
9859- .iter()
9860- .filter(|(_, channel)| channel.context().is_usable())
9861- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9862- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9863- })
9864- .collect::<Vec<_>>();
9865-
9866- self.message_router
9867- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9868- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9869- }
9870-
98719770 /// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
98729771 /// are used when constructing the phantom invoice's route hints.
98739772 ///
0 commit comments