@@ -33,10 +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::{MessageContext, OffersContext};
37
36
use crate::blinded_path::NodeIdLookUp;
38
- use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode} ;
39
- use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12RefundContext, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
37
+ use crate::blinded_path::message::MessageForwardNode;
38
+ use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
40
39
use crate::chain;
41
40
use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
42
41
use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -48,6 +47,7 @@ use crate::events::{self, Event, EventHandler, EventsProvider, InboundChannelFun
48
47
use crate::ln::inbound_payment;
49
48
use crate::ln::types::ChannelId;
50
49
use crate::offers::flow::OffersMessageCommons;
50
+ use crate::sign::ecdsa::EcdsaChannelSigner;
51
51
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
52
52
use crate::ln::channel::{self, Channel, ChannelError, ChannelUpdateStatus, FundedChannel, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, ReconnectionMsg, InboundV1Channel, WithChannelContext};
53
53
#[cfg(any(dual_funding, splicing))]
@@ -65,15 +65,11 @@ use crate::ln::msgs::{ChannelMessageHandler, CommitmentUpdate, DecodeError, Ligh
65
65
#[cfg(test)]
66
66
use crate::ln::outbound_payment;
67
67
use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
68
- use crate::offers::invoice::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
68
+ use crate::offers::invoice::{Bolt12Invoice, UnsignedBolt12Invoice};
69
69
use crate::offers::nonce::Nonce;
70
- use crate::offers::parse::Bolt12SemanticError;
71
- use crate::offers::refund::Refund;
72
70
use crate::offers::signer;
73
- use crate::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions};
74
- use crate::onion_message::offers::OffersMessage;
71
+ use crate::onion_message::messenger::MessageRouter;
75
72
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
76
- use crate::sign::ecdsa::EcdsaChannelSigner;
77
73
use crate::util::config::{UserConfig, ChannelConfig, ChannelConfigUpdate};
78
74
use crate::util::wakers::{Future, Notifier};
79
75
use crate::util::scid_utils::fake_scid;
@@ -107,7 +103,7 @@ use core::{cmp, mem};
107
103
use core::borrow::Borrow;
108
104
use core::cell::RefCell;
109
105
use crate::io::Read;
110
- use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, MutexGuard, RwLock, RwLockReadGuard};
106
+ use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, RwLock, RwLockReadGuard};
111
107
use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering};
112
108
use core::time::Duration;
113
109
use core::ops::Deref;
@@ -458,11 +454,15 @@ impl Ord for ClaimableHTLC {
458
454
pub trait Verification {
459
455
/// Constructs an HMAC to include in [`OffersContext`] for the data along with the given
460
456
/// [`Nonce`].
457
+ ///
458
+ /// [`OffersContext`]: crate::blinded_path::message::OffersContext
461
459
fn hmac_for_offer_payment(
462
460
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
463
461
) -> Hmac<Sha256>;
464
462
465
463
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
464
+ ///
465
+ /// [`OffersContext`]: crate::blinded_path::message::OffersContext
466
466
fn verify_for_offer_payment(
467
467
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
468
468
) -> Result<(), ()>;
@@ -471,6 +471,8 @@ pub trait Verification {
471
471
impl Verification for PaymentHash {
472
472
/// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash
473
473
/// along with the given [`Nonce`].
474
+ ///
475
+ /// [`OffersContext::InboundPayment`]: crate::blinded_path::message::OffersContext::InboundPayment
474
476
fn hmac_for_offer_payment(
475
477
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
476
478
) -> Hmac<Sha256> {
@@ -479,6 +481,8 @@ impl Verification for PaymentHash {
479
481
480
482
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
481
483
/// [`OffersContext::InboundPayment`].
484
+ ///
485
+ /// [`OffersContext::InboundPayment`]: crate::blinded_path::message::OffersContext::InboundPayment
482
486
fn verify_for_offer_payment(
483
487
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
484
488
) -> Result<(), ()> {
@@ -533,6 +537,8 @@ impl PaymentId {
533
537
impl Verification for PaymentId {
534
538
/// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
535
539
/// along with the given [`Nonce`].
540
+ ///
541
+ /// [`OffersContext::OutboundPayment`]: crate::blinded_path::message::OffersContext::OutboundPayment
536
542
fn hmac_for_offer_payment(
537
543
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
538
544
) -> Hmac<Sha256> {
@@ -541,6 +547,8 @@ impl Verification for PaymentId {
541
547
542
548
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
543
549
/// [`OffersContext::OutboundPayment`].
550
+ ///
551
+ /// [`OffersContext::OutboundPayment`]: crate::blinded_path::message::OffersContext::OutboundPayment
544
552
fn verify_for_offer_payment(
545
553
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
546
554
) -> Result<(), ()> {
@@ -2051,51 +2059,7 @@ where
2051
2059
///
2052
2060
/// For more information on creating refunds, see [`create_refund_builder`].
2053
2061
///
2054
- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2055
- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2056
- ///
2057
- /// ```
2058
- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2059
- /// # use lightning::ln::channelmanager::AChannelManager;
2060
- /// # use lightning::offers::refund::Refund;
2061
- /// #
2062
- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2063
- /// # let channel_manager = channel_manager.get_cm();
2064
- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2065
- /// Ok(invoice) => {
2066
- /// let payment_hash = invoice.payment_hash();
2067
- /// println!("Requesting refund payment {}", payment_hash);
2068
- /// payment_hash
2069
- /// },
2070
- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2071
- /// };
2072
- ///
2073
- /// // On the event processing thread
2074
- /// channel_manager.process_pending_events(&|event| {
2075
- /// match event {
2076
- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2077
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2078
- /// assert_eq!(payment_hash, known_payment_hash);
2079
- /// println!("Claiming payment {}", payment_hash);
2080
- /// channel_manager.claim_funds(payment_preimage);
2081
- /// },
2082
- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2083
- /// println!("Unknown payment hash: {}", payment_hash);
2084
- /// },
2085
- /// // ...
2086
- /// # _ => {},
2087
- /// },
2088
- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2089
- /// assert_eq!(payment_hash, known_payment_hash);
2090
- /// println!("Claimed {} msats", amount_msat);
2091
- /// },
2092
- /// // ...
2093
- /// # _ => {},
2094
- /// }
2095
- /// Ok(())
2096
- /// });
2097
- /// # }
2098
- /// ```
2062
+ /// For requesting refund payments, see [`request_refund_payment`].
2099
2063
///
2100
2064
/// # Persistence
2101
2065
///
@@ -2179,7 +2143,7 @@ where
2179
2143
/// [`create_offer_builder`]: crate::offers::flow::OffersMessageFlow::create_offer_builder
2180
2144
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2181
2145
/// [`create_refund_builder`]: crate::offers::flow::OffersMessageFlow::create_refund_builder
2182
- /// [`request_refund_payment`]: Self ::request_refund_payment
2146
+ /// [`request_refund_payment`]: crate::offers::flow::OffersMessageFlow ::request_refund_payment
2183
2147
/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
2184
2148
/// [`funding_created`]: msgs::FundingCreated
2185
2149
/// [`funding_transaction_generated`]: Self::funding_transaction_generated
@@ -2450,11 +2414,6 @@ where
2450
2414
event_persist_notifier: Notifier,
2451
2415
needs_persist_flag: AtomicBool,
2452
2416
2453
- #[cfg(not(any(test, feature = "_test_utils")))]
2454
- pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
2455
- #[cfg(any(test, feature = "_test_utils"))]
2456
- pub(crate) pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
2457
-
2458
2417
/// Tracks the message events that are to be broadcasted when we are connected to some peer.
2459
2418
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
2460
2419
@@ -3374,7 +3333,6 @@ where
3374
3333
needs_persist_flag: AtomicBool::new(false),
3375
3334
funding_batch_states: Mutex::new(BTreeMap::new()),
3376
3335
3377
- pending_offers_messages: Mutex::new(Vec::new()),
3378
3336
pending_broadcast_messages: Mutex::new(Vec::new()),
3379
3337
3380
3338
last_days_feerates: Mutex::new(VecDeque::new()),
@@ -9573,23 +9531,8 @@ where
9573
9531
fn send_payment_for_static_invoice(&self, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
9574
9532
self.send_payment_for_static_invoice(payment_id)
9575
9533
}
9576
-
9577
- // ----Temporary Functions----
9578
- // Set of functions temporarily moved to OffersMessageCommons for easier
9579
- // transition of code from ChannelManager to OffersMessageFlow
9580
-
9581
- fn get_pending_offers_messages(&self) -> MutexGuard<'_, Vec<(OffersMessage, MessageSendInstructions)>> {
9582
- self.pending_offers_messages.lock().expect("Mutex is locked by other thread.")
9583
- }
9584
9534
}
9585
9535
9586
- /// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
9587
- /// along different paths.
9588
- /// Sending multiple requests increases the chances of successful delivery in case some
9589
- /// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
9590
- /// even if multiple invoices are received.
9591
- pub(crate) const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9592
-
9593
9536
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref> ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
9594
9537
where
9595
9538
M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
@@ -9602,106 +9545,6 @@ where
9602
9545
MR::Target: MessageRouter,
9603
9546
L::Target: Logger,
9604
9547
{
9605
- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9606
- /// message.
9607
- ///
9608
- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9609
- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9610
- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9611
- ///
9612
- /// # Limitations
9613
- ///
9614
- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9615
- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9616
- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9617
- /// will be received and no retries will be made.
9618
- ///
9619
- /// # Errors
9620
- ///
9621
- /// Errors if:
9622
- /// - the refund is for an unsupported chain, or
9623
- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9624
- /// the invoice.
9625
- ///
9626
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9627
- pub fn request_refund_payment(
9628
- &self, refund: &Refund
9629
- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9630
- let expanded_key = &self.inbound_payment_key;
9631
- let entropy = &*self.entropy_source;
9632
- let secp_ctx = &self.secp_ctx;
9633
-
9634
- let amount_msats = refund.amount_msats();
9635
- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9636
-
9637
- if refund.chain() != self.chain_hash {
9638
- return Err(Bolt12SemanticError::UnsupportedChain);
9639
- }
9640
-
9641
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9642
-
9643
- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9644
- Ok((payment_hash, payment_secret)) => {
9645
- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9646
- let payment_paths = self.create_blinded_payment_paths(
9647
- Some(amount_msats), payment_secret, payment_context, relative_expiry,
9648
- )
9649
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9650
-
9651
- #[cfg(feature = "std")]
9652
- let builder = refund.respond_using_derived_keys(
9653
- payment_paths, payment_hash, expanded_key, entropy
9654
- )?;
9655
- #[cfg(not(feature = "std"))]
9656
- let created_at = Duration::from_secs(
9657
- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9658
- );
9659
- #[cfg(not(feature = "std"))]
9660
- let builder = refund.respond_using_derived_keys_no_std(
9661
- payment_paths, payment_hash, created_at, expanded_key, entropy
9662
- )?;
9663
- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9664
- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9665
-
9666
- let nonce = Nonce::from_entropy_source(entropy);
9667
- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9668
- let context = MessageContext::Offers(OffersContext::InboundPayment {
9669
- payment_hash: invoice.payment_hash(), nonce, hmac
9670
- });
9671
- let reply_paths = self.create_blinded_paths(context)
9672
- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9673
-
9674
- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9675
- if refund.paths().is_empty() {
9676
- for reply_path in reply_paths {
9677
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9678
- destination: Destination::Node(refund.payer_signing_pubkey()),
9679
- reply_path,
9680
- };
9681
- let message = OffersMessage::Invoice(invoice.clone());
9682
- pending_offers_messages.push((message, instructions));
9683
- }
9684
- } else {
9685
- reply_paths
9686
- .iter()
9687
- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9688
- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9689
- .for_each(|(path, reply_path)| {
9690
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9691
- destination: Destination::BlindedPath(path.clone()),
9692
- reply_path: reply_path.clone(),
9693
- };
9694
- let message = OffersMessage::Invoice(invoice.clone());
9695
- pending_offers_messages.push((message, instructions));
9696
- });
9697
- }
9698
-
9699
- Ok(invoice)
9700
- },
9701
- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9702
- }
9703
- }
9704
-
9705
9548
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
9706
9549
/// to pay us.
9707
9550
///
@@ -9800,27 +9643,6 @@ where
9800
9643
inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key)
9801
9644
}
9802
9645
9803
- /// Creates a collection of blinded paths by delegating to
9804
- /// [`MessageRouter::create_blinded_paths`].
9805
- ///
9806
- /// Errors if the `MessageRouter` errors.
9807
- fn create_blinded_paths(&self, context: MessageContext) -> Result<Vec<BlindedMessagePath>, ()> {
9808
- let recipient = self.get_our_node_id();
9809
- let secp_ctx = &self.secp_ctx;
9810
-
9811
- let peers = self.per_peer_state.read().unwrap()
9812
- .iter()
9813
- .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap()))
9814
- .filter(|(_, peer)| peer.is_connected)
9815
- .filter(|(_, peer)| peer.latest_features.supports_onion_messages())
9816
- .map(|(node_id, _)| *node_id)
9817
- .collect::<Vec<_>>();
9818
-
9819
- self.message_router
9820
- .create_blinded_paths(recipient, context, peers, secp_ctx)
9821
- .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(()))
9822
- }
9823
-
9824
9646
#[cfg(async_payments)]
9825
9647
pub(super) fn duration_since_epoch(&self) -> Duration {
9826
9648
#[cfg(not(feature = "std"))]
@@ -12078,7 +11900,9 @@ where
12078
11900
/// The [`MessageRouter`] used for constructing [`BlindedMessagePath`]s for [`Offer`]s,
12079
11901
/// [`Refund`]s, and any reply paths.
12080
11902
///
11903
+ /// [`BlindedMessagePath`]: crate::blinded_path::message::BlindedMessagePath
12081
11904
/// [`Offer`]: crate::offers::offer::Offer
11905
+ /// [`Refund`]: crate::offers::refund::Refund
12082
11906
pub message_router: MR,
12083
11907
/// The Logger for use in the ChannelManager and which may be used to log information during
12084
11908
/// deserialization.
@@ -13181,8 +13005,6 @@ where
13181
13005
13182
13006
funding_batch_states: Mutex::new(BTreeMap::new()),
13183
13007
13184
- pending_offers_messages: Mutex::new(Vec::new()),
13185
-
13186
13008
pending_broadcast_messages: Mutex::new(Vec::new()),
13187
13009
13188
13010
entropy_source: args.entropy_source,
0 commit comments