@@ -33,7 +33,7 @@ use bitcoin::secp256k1::Secp256k1;
33
33
use bitcoin::{secp256k1, Sequence};
34
34
35
35
use crate::events::FundingInfo;
36
- use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
36
+ use crate::blinded_path::message::{MessageContext, OffersContext};
37
37
use crate::blinded_path::NodeIdLookUp;
38
38
use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode};
39
39
use crate::blinded_path::payment::{AsyncBolt12OfferContext, BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, UnauthenticatedReceiveTlvs};
@@ -74,9 +74,8 @@ use crate::offers::offer::{Offer, OfferBuilder};
74
74
use crate::offers::parse::Bolt12SemanticError;
75
75
use crate::offers::refund::{Refund, RefundBuilder};
76
76
use crate::offers::signer;
77
- use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler};
78
77
use crate::onion_message::dns_resolution::HumanReadableName;
79
- use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions};
78
+ use crate::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions};
80
79
use crate::onion_message::offers::OffersMessage;
81
80
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
82
81
use crate::sign::ecdsa::EcdsaChannelSigner;
@@ -88,6 +87,7 @@ use crate::util::ser::{BigSize, FixedLengthReader, Readable, ReadableArgs, Maybe
88
87
use crate::util::logger::{Level, Logger, WithContext};
89
88
use crate::util::errors::APIError;
90
89
#[cfg(async_payments)] use {
90
+ crate::blinded_path::message::AsyncPaymentsContext,
91
91
crate::offers::offer::Amount,
92
92
crate::offers::static_invoice::{DEFAULT_RELATIVE_EXPIRY as STATIC_INVOICE_DEFAULT_RELATIVE_EXPIRY, StaticInvoice, StaticInvoiceBuilder},
93
93
};
@@ -2553,7 +2553,10 @@ where
2553
2553
2554
2554
our_network_pubkey: PublicKey,
2555
2555
2556
- pub(super) inbound_payment_key: inbound_payment::ExpandedKey,
2556
+ /// The [`ExpandedKey`] for use in encrypting and decrypting inbound payment data.
2557
+ ///
2558
+ /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
2559
+ pub inbound_payment_key: inbound_payment::ExpandedKey,
2557
2560
2558
2561
/// LDK puts the [fake scids] that it generates into namespaces, to identify the type of an
2559
2562
/// incoming payment. To make it harder for a third-party to identify the type of a payment,
@@ -2646,7 +2649,6 @@ where
2646
2649
pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
2647
2650
#[cfg(any(test, feature = "_test_utils"))]
2648
2651
pub(crate) pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,
2649
- pending_async_payments_messages: Mutex<Vec<(AsyncPaymentsMessage, MessageSendInstructions)>>,
2650
2652
2651
2653
/// Tracks the message events that are to be broadcasted when we are connected to some peer.
2652
2654
pending_broadcast_messages: Mutex<Vec<MessageSendEvent>>,
@@ -3579,7 +3581,6 @@ where
3579
3581
funding_batch_states: Mutex::new(BTreeMap::new()),
3580
3582
3581
3583
pending_offers_messages: Mutex::new(Vec::new()),
3582
- pending_async_payments_messages: Mutex::new(Vec::new()),
3583
3584
pending_broadcast_messages: Mutex::new(Vec::new()),
3584
3585
3585
3586
last_days_feerates: Mutex::new(VecDeque::new()),
@@ -4783,45 +4784,6 @@ where
4783
4784
res
4784
4785
}
4785
4786
4786
- #[cfg(async_payments)]
4787
- fn initiate_async_payment(
4788
- &self, invoice: &StaticInvoice, payment_id: PaymentId
4789
- ) -> Result<(), Bolt12PaymentError> {
4790
-
4791
- self.handle_static_invoice_received(invoice, payment_id)?;
4792
-
4793
- let nonce = Nonce::from_entropy_source(&*self.entropy_source);
4794
- let hmac = payment_id.hmac_for_async_payment(nonce, &self.inbound_payment_key);
4795
- let reply_paths = match self.create_blinded_paths(
4796
- MessageContext::AsyncPayments(
4797
- AsyncPaymentsContext::OutboundPayment { payment_id, nonce, hmac }
4798
- )
4799
- ) {
4800
- Ok(paths) => paths,
4801
- Err(()) => {
4802
- self.abandon_payment_with_reason(payment_id, PaymentFailureReason::BlindedPathCreationFailed);
4803
- return Err(Bolt12PaymentError::BlindedPathCreationFailed);
4804
- }
4805
- };
4806
-
4807
- let mut pending_async_payments_messages = self.pending_async_payments_messages.lock().unwrap();
4808
- const HTLC_AVAILABLE_LIMIT: usize = 10;
4809
- reply_paths
4810
- .iter()
4811
- .flat_map(|reply_path| invoice.message_paths().iter().map(move |invoice_path| (invoice_path, reply_path)))
4812
- .take(HTLC_AVAILABLE_LIMIT)
4813
- .for_each(|(invoice_path, reply_path)| {
4814
- let instructions = MessageSendInstructions::WithSpecifiedReplyPath {
4815
- destination: Destination::BlindedPath(invoice_path.clone()),
4816
- reply_path: reply_path.clone(),
4817
- };
4818
- let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {});
4819
- pending_async_payments_messages.push((message, instructions));
4820
- });
4821
-
4822
- Ok(())
4823
- }
4824
-
4825
4787
#[cfg(async_payments)]
4826
4788
fn send_payment_for_static_invoice(
4827
4789
&self, payment_id: PaymentId
@@ -9999,6 +9961,18 @@ where
9999
9961
self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
10000
9962
}
10001
9963
9964
+ #[cfg(async_payments)]
9965
+ fn handle_static_invoice_received(
9966
+ &self, invoice: &StaticInvoice, payment_id: PaymentId
9967
+ ) -> Result<(), Bolt12PaymentError> {
9968
+ self.handle_static_invoice_received(invoice, payment_id)
9969
+ }
9970
+
9971
+ #[cfg(async_payments)]
9972
+ fn send_payment_for_static_invoice(&self, payment_id: PaymentId) -> Result<(), Bolt12PaymentError> {
9973
+ self.send_payment_for_static_invoice(payment_id)
9974
+ }
9975
+
10002
9976
// ----Temporary Functions----
10003
9977
// Set of functions temporarily moved to OffersMessageCommons for easier
10004
9978
// transition of code from ChannelManager to OffersMessageFlow
@@ -10018,13 +9992,6 @@ where
10018
9992
) -> Result<(), Bolt12SemanticError> {
10019
9993
self.pay_for_offer_intern(offer, quantity, amount_msats, payer_note, payment_id, human_readable_name, create_pending_payment)
10020
9994
}
10021
-
10022
- #[cfg(async_payments)]
10023
- fn initiate_async_payment(
10024
- &self, invoice: &StaticInvoice, payment_id: PaymentId
10025
- ) -> Result<(), Bolt12PaymentError> {
10026
- self.initiate_async_payment(invoice, payment_id)
10027
- }
10028
9995
}
10029
9996
10030
9997
/// Defines the maximum number of [`OffersMessage`] including different reply paths to be sent
@@ -12016,61 +11983,6 @@ where
12016
11983
}
12017
11984
}
12018
11985
12019
- impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>
12020
- AsyncPaymentsMessageHandler for ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
12021
- where
12022
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
12023
- T::Target: BroadcasterInterface,
12024
- ES::Target: EntropySource,
12025
- NS::Target: NodeSigner,
12026
- SP::Target: SignerProvider,
12027
- F::Target: FeeEstimator,
12028
- R::Target: Router,
12029
- MR::Target: MessageRouter,
12030
- L::Target: Logger,
12031
- {
12032
- fn handle_held_htlc_available(
12033
- &self, _message: HeldHtlcAvailable, _context: AsyncPaymentsContext,
12034
- _responder: Option<Responder>
12035
- ) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> {
12036
- #[cfg(async_payments)] {
12037
- match _context {
12038
- AsyncPaymentsContext::InboundPayment { nonce, hmac, path_absolute_expiry } => {
12039
- if let Err(()) = signer::verify_held_htlc_available_context(
12040
- nonce, hmac, &self.inbound_payment_key
12041
- ) { return None }
12042
- if self.duration_since_epoch() > path_absolute_expiry { return None }
12043
- },
12044
- _ => return None
12045
- }
12046
- return _responder.map(|responder| (ReleaseHeldHtlc {}, responder.respond()))
12047
- }
12048
- #[cfg(not(async_payments))]
12049
- return None
12050
- }
12051
-
12052
- fn handle_release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {
12053
- #[cfg(async_payments)] {
12054
- let (payment_id, nonce, hmac) = match _context {
12055
- AsyncPaymentsContext::OutboundPayment { payment_id, hmac, nonce } => {
12056
- (payment_id, nonce, hmac)
12057
- },
12058
- _ => return
12059
- };
12060
- if payment_id.verify_for_async_payment(hmac, nonce, &self.inbound_payment_key).is_err() { return }
12061
- if let Err(e) = self.send_payment_for_static_invoice(payment_id) {
12062
- log_trace!(
12063
- self.logger, "Failed to release held HTLC with payment id {}: {:?}", payment_id, e
12064
- );
12065
- }
12066
- }
12067
- }
12068
-
12069
- fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> {
12070
- core::mem::take(&mut self.pending_async_payments_messages.lock().unwrap())
12071
- }
12072
- }
12073
-
12074
11986
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>
12075
11987
NodeIdLookUp for ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
12076
11988
where
@@ -14025,7 +13937,6 @@ where
14025
13937
funding_batch_states: Mutex::new(BTreeMap::new()),
14026
13938
14027
13939
pending_offers_messages: Mutex::new(Vec::new()),
14028
- pending_async_payments_messages: Mutex::new(Vec::new()),
14029
13940
14030
13941
pending_broadcast_messages: Mutex::new(Vec::new()),
14031
13942
0 commit comments