@@ -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};
@@ -2585,26 +2583,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
2585
2583
/// many peers we reject new (inbound) connections.
2586
2584
const MAX_NO_CHANNEL_PEERS: usize = 250;
2587
2585
2588
- /// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2589
- /// short-lived, while anything with a greater expiration is considered long-lived.
2590
- ///
2591
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
2592
- /// will included a [`BlindedMessagePath`] created using:
2593
- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2594
- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2595
- ///
2596
- /// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2597
- /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2598
- ///
2599
- ///
2600
- /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2601
- /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2602
- /// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2603
- ///
2604
- /// [`Offer`]: crate::offers::offer
2605
- /// [`Refund`]: crate::offers::refund
2606
- pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2607
-
2608
2586
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2609
2587
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2610
2588
#[derive(Debug, PartialEq)]
@@ -9495,6 +9473,23 @@ where
9495
9473
)
9496
9474
}
9497
9475
9476
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9477
+ self.per_peer_state.read().unwrap()
9478
+ .iter()
9479
+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9480
+ .filter(|(_, peer)| peer.is_connected)
9481
+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9482
+ .map(|(node_id, peer)| MessageForwardNode {
9483
+ node_id: *node_id,
9484
+ short_channel_id: peer.channel_by_id
9485
+ .iter()
9486
+ .filter(|(_, channel)| channel.context().is_usable())
9487
+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9488
+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9489
+ })
9490
+ .collect::<Vec<_>>()
9491
+ }
9492
+
9498
9493
fn verify_bolt12_invoice(
9499
9494
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9500
9495
) -> Result<PaymentId, ()> {
@@ -9651,19 +9646,6 @@ where
9651
9646
res
9652
9647
}
9653
9648
9654
- fn create_blinded_paths_using_absolute_expiry(
9655
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9656
- ) -> Result<Vec<BlindedMessagePath>, ()> {
9657
- let now = self.duration_since_epoch();
9658
- let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9659
-
9660
- if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9661
- self.create_compact_blinded_paths(context)
9662
- } else {
9663
- self.create_blinded_paths(MessageContext::Offers(context))
9664
- }
9665
- }
9666
-
9667
9649
fn get_chain_hash(&self) -> ChainHash {
9668
9650
self.chain_hash
9669
9651
}
@@ -9682,53 +9664,6 @@ where
9682
9664
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9683
9665
}
9684
9666
9685
- fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9686
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9687
- payer_note: Option<String>, payment_id: PaymentId,
9688
- human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9689
- ) -> Result<(), Bolt12SemanticError> {
9690
- let expanded_key = &self.inbound_payment_key;
9691
- let entropy = &*self.entropy_source;
9692
- let secp_ctx = &self.secp_ctx;
9693
-
9694
- let nonce = Nonce::from_entropy_source(entropy);
9695
- let builder: InvoiceRequestBuilder<secp256k1::All> = offer
9696
- .request_invoice(expanded_key, nonce, secp_ctx, payment_id)?
9697
- .into();
9698
- let builder = builder.chain_hash(self.chain_hash)?;
9699
-
9700
- let builder = match quantity {
9701
- None => builder,
9702
- Some(quantity) => builder.quantity(quantity)?,
9703
- };
9704
- let builder = match amount_msats {
9705
- None => builder,
9706
- Some(amount_msats) => builder.amount_msats(amount_msats)?,
9707
- };
9708
- let builder = match payer_note {
9709
- None => builder,
9710
- Some(payer_note) => builder.payer_note(payer_note),
9711
- };
9712
- let builder = match human_readable_name {
9713
- None => builder,
9714
- Some(hrn) => builder.sourced_from_human_readable_name(hrn),
9715
- };
9716
- let invoice_request = builder.build_and_sign()?;
9717
-
9718
- let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
9719
- let context = MessageContext::Offers(
9720
- OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
9721
- );
9722
- let reply_paths = self.create_blinded_paths(context)
9723
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9724
-
9725
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9726
-
9727
- create_pending_payment(&invoice_request, nonce)?;
9728
-
9729
- self.enqueue_invoice_request(invoice_request, reply_paths)
9730
- }
9731
-
9732
9667
#[cfg(feature = "dnssec")]
9733
9668
fn amt_msats_for_payment_awaiting_offer(&self, payment_id: PaymentId) -> Result<u64, ()> {
9734
9669
self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id)
@@ -9740,6 +9675,11 @@ where
9740
9675
) -> Result<(), ()> {
9741
9676
self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
9742
9677
}
9678
+
9679
+ #[cfg(not(feature = "std"))]
9680
+ fn get_highest_seen_timestamp(&self) -> Duration {
9681
+ Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9682
+ }
9743
9683
}
9744
9684
9745
9685
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9822,47 +9762,6 @@ where
9822
9762
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9823
9763
}
9824
9764
9825
- pub(super) fn duration_since_epoch(&self) -> Duration {
9826
- #[cfg(not(feature = "std"))]
9827
- let now = Duration::from_secs(
9828
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9829
- );
9830
- #[cfg(feature = "std")]
9831
- let now = std::time::SystemTime::now()
9832
- .duration_since(std::time::SystemTime::UNIX_EPOCH)
9833
- .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
9834
-
9835
- now
9836
- }
9837
-
9838
- /// Creates a collection of blinded paths by delegating to
9839
- /// [`MessageRouter::create_compact_blinded_paths`].
9840
- ///
9841
- /// Errors if the `MessageRouter` errors.
9842
- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9843
- let recipient = self.get_our_node_id();
9844
- let secp_ctx = &self.secp_ctx;
9845
-
9846
- let peers = self.per_peer_state.read().unwrap()
9847
- .iter()
9848
- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9849
- .filter(|(_, peer)| peer.is_connected)
9850
- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9851
- .map(|(node_id, peer)| MessageForwardNode {
9852
- node_id: *node_id,
9853
- short_channel_id: peer.channel_by_id
9854
- .iter()
9855
- .filter(|(_, channel)| channel.context().is_usable())
9856
- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9857
- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9858
- })
9859
- .collect::<Vec<_>>();
9860
-
9861
- self.message_router
9862
- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9863
- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9864
- }
9865
-
9866
9765
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
9867
9766
/// are used when constructing the phantom invoice's route hints.
9868
9767
///
0 commit comments