@@ -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 _};
@@ -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};
@@ -2605,26 +2603,6 @@ const MAX_UNFUNDED_CHANNEL_PEERS: usize = 50;
2605
2603
/// many peers we reject new (inbound) connections.
2606
2604
const MAX_NO_CHANNEL_PEERS: usize = 250;
2607
2605
2608
- /// The maximum expiration from the current time where an [`Offer`] or [`Refund`] is considered
2609
- /// short-lived, while anything with a greater expiration is considered long-lived.
2610
- ///
2611
- /// Using [`OffersMessageFlow::create_offer_builder`] or [`OffersMessageFlow::create_refund_builder`],
2612
- /// will included a [`BlindedMessagePath`] created using:
2613
- /// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and
2614
- /// - [`MessageRouter::create_blinded_paths`] when long-lived.
2615
- ///
2616
- /// [`OffersMessageFlow::create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2617
- /// [`OffersMessageFlow::create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2618
- ///
2619
- ///
2620
- /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select
2621
- /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to
2622
- /// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
2623
- ///
2624
- /// [`Offer`]: crate::offers::offer
2625
- /// [`Refund`]: crate::offers::refund
2626
- pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
2627
-
2628
2606
/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
2629
2607
/// These include payments that have yet to find a successful path, or have unresolved HTLCs.
2630
2608
#[derive(Debug, PartialEq)]
@@ -9573,6 +9551,23 @@ where
9573
9551
)
9574
9552
}
9575
9553
9554
+ fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9555
+ self.per_peer_state.read().unwrap()
9556
+ .iter()
9557
+ .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9558
+ .filter(|(_, peer)| peer.is_connected)
9559
+ .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9560
+ .map(|(node_id, peer)| MessageForwardNode {
9561
+ node_id: *node_id,
9562
+ short_channel_id: peer.channel_by_id
9563
+ .iter()
9564
+ .filter(|(_, channel)| channel.context().is_usable())
9565
+ .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9566
+ .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9567
+ })
9568
+ .collect::<Vec<_>>()
9569
+ }
9570
+
9576
9571
fn verify_bolt12_invoice(
9577
9572
&self, invoice: &Bolt12Invoice, context: Option<&OffersContext>,
9578
9573
) -> Result<PaymentId, ()> {
@@ -9729,19 +9724,6 @@ where
9729
9724
res
9730
9725
}
9731
9726
9732
- fn create_blinded_paths_using_absolute_expiry(
9733
- &self, context: OffersContext, absolute_expiry: Option<Duration>,
9734
- ) -> Result<Vec<BlindedMessagePath>, ()> {
9735
- let now = self.duration_since_epoch();
9736
- let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY);
9737
-
9738
- if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry {
9739
- self.create_compact_blinded_paths(context)
9740
- } else {
9741
- self.create_blinded_paths(MessageContext::Offers(context))
9742
- }
9743
- }
9744
-
9745
9727
fn get_chain_hash(&self) -> ChainHash {
9746
9728
self.chain_hash
9747
9729
}
@@ -9760,53 +9742,6 @@ where
9760
9742
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9761
9743
}
9762
9744
9763
- fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
9764
- &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
9765
- payer_note: Option<String>, payment_id: PaymentId,
9766
- human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
9767
- ) -> Result<(), Bolt12SemanticError> {
9768
- let expanded_key = &self.inbound_payment_key;
9769
- let entropy = &*self.entropy_source;
9770
- let secp_ctx = &self.secp_ctx;
9771
-
9772
- let nonce = Nonce::from_entropy_source(entropy);
9773
- let builder: InvoiceRequestBuilder<secp256k1::All> = offer
9774
- .request_invoice(expanded_key, nonce, secp_ctx, payment_id)?
9775
- .into();
9776
- let builder = builder.chain_hash(self.chain_hash)?;
9777
-
9778
- let builder = match quantity {
9779
- None => builder,
9780
- Some(quantity) => builder.quantity(quantity)?,
9781
- };
9782
- let builder = match amount_msats {
9783
- None => builder,
9784
- Some(amount_msats) => builder.amount_msats(amount_msats)?,
9785
- };
9786
- let builder = match payer_note {
9787
- None => builder,
9788
- Some(payer_note) => builder.payer_note(payer_note),
9789
- };
9790
- let builder = match human_readable_name {
9791
- None => builder,
9792
- Some(hrn) => builder.sourced_from_human_readable_name(hrn),
9793
- };
9794
- let invoice_request = builder.build_and_sign()?;
9795
-
9796
- let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
9797
- let context = MessageContext::Offers(
9798
- OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
9799
- );
9800
- let reply_paths = self.create_blinded_paths(context)
9801
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9802
-
9803
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9804
-
9805
- create_pending_payment(&invoice_request, nonce)?;
9806
-
9807
- self.enqueue_invoice_request(invoice_request, reply_paths)
9808
- }
9809
-
9810
9745
#[cfg(feature = "dnssec")]
9811
9746
fn amt_msats_for_payment_awaiting_offer(&self, payment_id: PaymentId) -> Result<u64, ()> {
9812
9747
self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id)
@@ -9818,6 +9753,11 @@ where
9818
9753
) -> Result<(), ()> {
9819
9754
self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
9820
9755
}
9756
+
9757
+ #[cfg(not(feature = "std"))]
9758
+ fn get_highest_seen_timestamp(&self) -> Duration {
9759
+ Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9760
+ }
9821
9761
}
9822
9762
9823
9763
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -9900,47 +9840,6 @@ where
9900
9840
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9901
9841
}
9902
9842
9903
- pub(super) fn duration_since_epoch(&self) -> Duration {
9904
- #[cfg(not(feature = "std"))]
9905
- let now = Duration::from_secs(
9906
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9907
- );
9908
- #[cfg(feature = "std")]
9909
- let now = std::time::SystemTime::now()
9910
- .duration_since(std::time::SystemTime::UNIX_EPOCH)
9911
- .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
9912
-
9913
- now
9914
- }
9915
-
9916
- /// Creates a collection of blinded paths by delegating to
9917
- /// [`MessageRouter::create_compact_blinded_paths`].
9918
- ///
9919
- /// Errors if the `MessageRouter` errors.
9920
- fn create_compact_blinded_paths(&self, context: OffersContext) -> Result<Vec<BlindedMessagePath>, ()> {
9921
- let recipient = self.get_our_node_id();
9922
- let secp_ctx = &self.secp_ctx;
9923
-
9924
- let peers = self.per_peer_state.read().unwrap()
9925
- .iter()
9926
- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9927
- .filter(|(_, peer)| peer.is_connected)
9928
- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9929
- .map(|(node_id, peer)| MessageForwardNode {
9930
- node_id: *node_id,
9931
- short_channel_id: peer.channel_by_id
9932
- .iter()
9933
- .filter(|(_, channel)| channel.context().is_usable())
9934
- .min_by_key(|(_, channel)| channel.context().channel_creation_height)
9935
- .and_then(|(_, channel)| channel.context().get_short_channel_id()),
9936
- })
9937
- .collect::<Vec<_>>();
9938
-
9939
- self.message_router
9940
- .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx)
9941
- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9942
- }
9943
-
9944
9843
/// Gets a fake short channel id for use in receiving [phantom node payments]. These fake scids
9945
9844
/// are used when constructing the phantom invoice's route hints.
9946
9845
///
0 commit comments