@@ -36,7 +36,7 @@ use crate::events::FundingInfo;
3636use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
3737use crate::blinded_path::NodeIdLookUp;
3838use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode};
39- use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12RefundContext, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
39+ use crate::blinded_path::payment::{BlindedPaymentPath, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
4040use crate::chain;
4141use crate::chain::{Confirm, ChannelMonitorUpdateStatus, Watch, BestBlock};
4242use crate::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator};
@@ -66,11 +66,11 @@ use crate::ln::msgs::{ChannelMessageHandler, CommitmentUpdate, DecodeError, Ligh
6666#[cfg(test)]
6767use crate::ln::outbound_payment;
6868use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration};
69- use crate::offers::invoice::{Bolt12Invoice, DerivedSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice, DEFAULT_RELATIVE_EXPIRY};
69+ use crate::offers::invoice::Bolt12Invoice;
70+ use crate::offers::invoice::UnsignedBolt12Invoice;
7071use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestBuilder};
7172use crate::offers::nonce::Nonce;
7273use crate::offers::parse::Bolt12SemanticError;
73- use crate::offers::refund::Refund;
7474use crate::offers::signer;
7575use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
7676use crate::onion_message::dns_resolution::HumanReadableName;
@@ -2059,53 +2059,8 @@ where
20592059///
20602060/// For more information on creating refunds, see [`create_refund_builder`].
20612061///
2062- /// Use [`request_refund_payment`] to send a [`Bolt12Invoice`] for receiving the refund. Similar to
2063- /// *creating* an [`Offer`], this is stateless as it represents an inbound payment.
2064- ///
2065- /// ```
2066- /// # use lightning::events::{Event, EventsProvider, PaymentPurpose};
2067- /// # use lightning::ln::channelmanager::AChannelManager;
2068- /// # use lightning::offers::flow::OffersMessageCommons;
2069- /// # use lightning::offers::refund::Refund;
2070- /// #
2071- /// # fn example<T: AChannelManager>(channel_manager: T, refund: &Refund) {
2072- /// # let channel_manager = channel_manager.get_cm();
2073- /// let known_payment_hash = match channel_manager.request_refund_payment(refund) {
2074- /// Ok(invoice) => {
2075- /// let payment_hash = invoice.payment_hash();
2076- /// println!("Requesting refund payment {}", payment_hash);
2077- /// payment_hash
2078- /// },
2079- /// Err(e) => panic!("Unable to request payment for refund: {:?}", e),
2080- /// };
2081- ///
2082- /// // On the event processing thread
2083- /// channel_manager.process_pending_events(&|event| {
2084- /// match event {
2085- /// Event::PaymentClaimable { payment_hash, purpose, .. } => match purpose {
2086- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: Some(payment_preimage), .. } => {
2087- /// assert_eq!(payment_hash, known_payment_hash);
2088- /// println!("Claiming payment {}", payment_hash);
2089- /// channel_manager.claim_funds(payment_preimage);
2090- /// },
2091- /// PaymentPurpose::Bolt12RefundPayment { payment_preimage: None, .. } => {
2092- /// println!("Unknown payment hash: {}", payment_hash);
2093- /// },
2094- /// // ...
2095- /// # _ => {},
2096- /// },
2097- /// Event::PaymentClaimed { payment_hash, amount_msat, .. } => {
2098- /// assert_eq!(payment_hash, known_payment_hash);
2099- /// println!("Claimed {} msats", amount_msat);
2100- /// },
2101- /// // ...
2102- /// # _ => {},
2103- /// }
2104- /// Ok(())
2105- /// });
2106- /// # }
2107- /// ```
2108- ///
2062+ /// For requesting refund payments, see [`request_refund_payment`].
2063+ ///
21092064/// # Persistence
21102065///
21112066/// Implements [`Writeable`] to write out all channel state to disk. Implies [`peer_disconnected`] for
@@ -2186,7 +2141,7 @@ where
21862141/// [`offers`]: crate::offers
21872142/// [`Offer`]: crate::offers::offer
21882143/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
2189- /// [`request_refund_payment`]: Self ::request_refund_payment
2144+ /// [`request_refund_payment`]: crate::offers::flow::OffersMessageFlow ::request_refund_payment
21902145/// [`peer_disconnected`]: msgs::ChannelMessageHandler::peer_disconnected
21912146/// [`funding_created`]: msgs::FundingCreated
21922147/// [`funding_transaction_generated`]: Self::funding_transaction_generated
@@ -2706,6 +2661,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250;
27062661/// become invalid over time as channels are closed. Thus, they are only suitable for short-term use.
27072662///
27082663/// [`Offer`]: crate::offers::offer
2664+ /// [`Refund`]: crate::offers::refund
27092665pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 60 * 24);
27102666
27112667/// Used by [`ChannelManager::list_recent_payments`] to express the status of recent payments.
@@ -9629,7 +9585,7 @@ where
96299585/// Sending multiple requests increases the chances of successful delivery in case some
96309586/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
96319587/// even if multiple invoices are received.
9632- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
9588+ pub const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
96339589
96349590impl<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>
96359591where
@@ -9726,106 +9682,6 @@ where
97269682 Ok(())
97279683 }
97289684
9729- /// Creates a [`Bolt12Invoice`] for a [`Refund`] and enqueues it to be sent via an onion
9730- /// message.
9731- ///
9732- /// The resulting invoice uses a [`PaymentHash`] recognized by the [`ChannelManager`] and a
9733- /// [`BlindedPaymentPath`] containing the [`PaymentSecret`] needed to reconstruct the
9734- /// corresponding [`PaymentPreimage`]. It is returned purely for informational purposes.
9735- ///
9736- /// # Limitations
9737- ///
9738- /// Requires a direct connection to an introduction node in [`Refund::paths`] or to
9739- /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be
9740- /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they
9741- /// will be received and no retries will be made.
9742- ///
9743- /// # Errors
9744- ///
9745- /// Errors if:
9746- /// - the refund is for an unsupported chain, or
9747- /// - the parameterized [`Router`] is unable to create a blinded payment path or reply path for
9748- /// the invoice.
9749- ///
9750- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
9751- pub fn request_refund_payment(
9752- &self, refund: &Refund
9753- ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
9754- let expanded_key = &self.inbound_payment_key;
9755- let entropy = &*self.entropy_source;
9756- let secp_ctx = &self.secp_ctx;
9757-
9758- let amount_msats = refund.amount_msats();
9759- let relative_expiry = DEFAULT_RELATIVE_EXPIRY.as_secs() as u32;
9760-
9761- if refund.chain() != self.chain_hash {
9762- return Err(Bolt12SemanticError::UnsupportedChain);
9763- }
9764-
9765- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
9766-
9767- match self.create_inbound_payment(Some(amount_msats), relative_expiry, None) {
9768- Ok((payment_hash, payment_secret)) => {
9769- let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
9770- let payment_paths = self.create_blinded_payment_paths(
9771- Some(amount_msats), payment_secret, payment_context, relative_expiry,
9772- )
9773- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9774-
9775- #[cfg(feature = "std")]
9776- let builder = refund.respond_using_derived_keys(
9777- payment_paths, payment_hash, expanded_key, entropy
9778- )?;
9779- #[cfg(not(feature = "std"))]
9780- let created_at = Duration::from_secs(
9781- self.highest_seen_timestamp.load(Ordering::Acquire) as u64
9782- );
9783- #[cfg(not(feature = "std"))]
9784- let builder = refund.respond_using_derived_keys_no_std(
9785- payment_paths, payment_hash, created_at, expanded_key, entropy
9786- )?;
9787- let builder: InvoiceBuilder<DerivedSigningPubkey> = builder.into();
9788- let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
9789-
9790- let nonce = Nonce::from_entropy_source(entropy);
9791- let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
9792- let context = MessageContext::Offers(OffersContext::InboundPayment {
9793- payment_hash: invoice.payment_hash(), nonce, hmac
9794- });
9795- let reply_paths = self.create_blinded_paths(context)
9796- .map_err(|_| Bolt12SemanticError::MissingPaths)?;
9797-
9798- let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap();
9799- if refund.paths().is_empty() {
9800- for reply_path in reply_paths {
9801- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9802- destination: Destination::Node(refund.payer_signing_pubkey()),
9803- reply_path,
9804- };
9805- let message = OffersMessage::Invoice(invoice.clone());
9806- pending_offers_messages.push((message, instructions));
9807- }
9808- } else {
9809- reply_paths
9810- .iter()
9811- .flat_map(|reply_path| refund.paths().iter().map(move |path| (path, reply_path)))
9812- .take(OFFERS_MESSAGE_REQUEST_LIMIT)
9813- .for_each(|(path, reply_path)| {
9814- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
9815- destination: Destination::BlindedPath(path.clone()),
9816- reply_path: reply_path.clone(),
9817- };
9818- let message = OffersMessage::Invoice(invoice.clone());
9819- pending_offers_messages.push((message, instructions));
9820- });
9821- }
9822-
9823- Ok(invoice)
9824- },
9825- Err(()) => Err(Bolt12SemanticError::InvalidAmount),
9826- }
9827- }
9828-
98299685 /// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
98309686 /// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
98319687 ///
@@ -12422,6 +12278,7 @@ where
1242212278 /// [`Refund`]s, and any reply paths.
1242312279 ///
1242412280 /// [`Offer`]: crate::offers::offer
12281+ /// [`Refund`]: crate::offers::refund
1242512282 pub message_router: MR,
1242612283 /// The Logger for use in the ChannelManager and which may be used to log information during
1242712284 /// deserialization.
0 commit comments