@@ -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};
@@ -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 _};
@@ -66,14 +65,13 @@ use crate::ln::outbound_payment;
66
65
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
67
66
use crate::offers::invoice::Bolt12Invoice;
68
67
use crate::offers::invoice::UnsignedBolt12Invoice;
69
- use crate::offers::invoice_request::{ InvoiceRequest, InvoiceRequestBuilder} ;
68
+ use crate::offers::invoice_request::InvoiceRequest;
70
69
use crate::offers::nonce::Nonce;
71
70
use crate::offers::parse::Bolt12SemanticError;
72
71
use crate::offers::signer;
73
72
#[cfg(async_payments)]
74
73
use crate::offers::static_invoice::StaticInvoice;
75
74
use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
76
- use crate::onion_message::dns_resolution::HumanReadableName;
77
75
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, MessageSendInstructions, Responder, ResponseInstruction};
78
76
use crate::onion_message::offers::OffersMessage;
79
77
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
@@ -2590,26 +2588,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
2590
2588
/// many peers we reject new (inbound) connections.
2591
2589
const MAX_NO_CHANNEL_PEERS: usize = 250;
2592
2590
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
-
2613
2591
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2614
2592
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2615
2593
#[derive(Debug, PartialEq)]
@@ -9560,6 +9538,23 @@ where
9560
9538
)
9561
9539
}
9562
9540
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
+
9563
9558
fn verify_bolt12_invoice(
9564
9559
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9565
9560
) -> Result<PaymentId, ()> {
@@ -9656,19 +9651,6 @@ where
9656
9651
Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9657
9652
}
9658
9653
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
-
9672
9654
fn get_chain_hash(&self) -> ChainHash {
9673
9655
self.chain_hash
9674
9656
}
@@ -9687,53 +9669,6 @@ where
9687
9669
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9688
9670
}
9689
9671
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
-
9737
9672
#[cfg(feature = "dnssec")]
9738
9673
fn amt_msats_for_payment_awaiting_offer(&self, payment_id: PaymentId) -> Result<u64, ()> {
9739
9674
self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id)
@@ -9745,6 +9680,11 @@ where
9745
9680
) -> Result<(), ()> {
9746
9681
self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
9747
9682
}
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
+ }
9748
9688
}
9749
9689
9750
9690
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9827,47 +9767,6 @@ where
9827
9767
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9828
9768
}
9829
9769
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
-
9871
9770
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
9872
9771
/// are used when constructing the phantom invoice's route hints.
9873
9772
///
0 commit comments