@@ -93,9 +93,7 @@ use crate::util::errors::APIError;
93
93
};
94
94
95
95
#[cfg(feature = "dnssec")]
96
- use crate::blinded_path::message::DNSResolverContext;
97
- #[cfg(feature = "dnssec")]
98
- use crate::onion_message::dns_resolution::{DNSResolverMessage, DNSResolverMessageHandler, DNSSECQuery, DNSSECProof, OMNameResolver};
96
+ use crate::onion_message::dns_resolution::OMNameResolver;
99
97
100
98
#[cfg(not(c_bindings))]
101
99
use {
@@ -2670,16 +2668,6 @@ where
2670
2668
2671
2669
#[cfg(feature = "dnssec")]
2672
2670
hrn_resolver: OMNameResolver,
2673
- #[cfg(feature = "dnssec")]
2674
- pending_dns_onion_messages: Mutex<Vec<(DNSResolverMessage, MessageSendInstructions)>>,
2675
-
2676
- #[cfg(feature = "_test_utils")]
2677
- /// In testing, it is useful be able to forge a name -> offer mapping so that we can pay an
2678
- /// offer generated in the test.
2679
- ///
2680
- /// This allows for doing so, validating proofs as normal, but, if they pass, replacing the
2681
- /// offer they resolve to to the given one.
2682
- pub testing_dnssec_proof_offer_resolution_override: Mutex<HashMap<HumanReadableName, Offer>>,
2683
2671
2684
2672
#[cfg(test)]
2685
2673
pub(super) entropy_source: ES,
@@ -3604,11 +3592,6 @@ where
3604
3592
3605
3593
#[cfg(feature = "dnssec")]
3606
3594
hrn_resolver: OMNameResolver::new(current_timestamp, params.best_block.height),
3607
- #[cfg(feature = "dnssec")]
3608
- pending_dns_onion_messages: Mutex::new(Vec::new()),
3609
-
3610
- #[cfg(feature = "_test_utils")]
3611
- testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()),
3612
3595
}
3613
3596
}
3614
3597
@@ -9937,6 +9920,11 @@ where
9937
9920
Duration::from_secs(self.highest_seen_timestamp.load(Ordering::Acquire) as u64)
9938
9921
}
9939
9922
9923
+ #[cfg(feature = "dnssec")]
9924
+ fn get_hrn_resolver(&self) -> &OMNameResolver {
9925
+ &self.hrn_resolver
9926
+ }
9927
+
9940
9928
fn get_peer_for_blinded_path(&self) -> Vec<MessageForwardNode> {
9941
9929
self.per_peer_state.read().unwrap()
9942
9930
.iter()
@@ -9983,6 +9971,26 @@ where
9983
9971
self.abandon_payment_with_reason(payment_id, reason);
9984
9972
}
9985
9973
9974
+ #[cfg(feature = "dnssec")]
9975
+ fn add_new_awaiting_offer(
9976
+ &self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry,
9977
+ max_total_routing_fee_msat: Option<u64>, amount_msats: u64,
9978
+ ) -> Result<(), ()> {
9979
+ self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9980
+ }
9981
+
9982
+ #[cfg(feature = "dnssec")]
9983
+ fn amt_msats_for_payment_awaiting_offer(&self, payment_id: PaymentId) -> Result<u64, ()> {
9984
+ self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id)
9985
+ }
9986
+
9987
+ #[cfg(feature = "dnssec")]
9988
+ fn received_offer(
9989
+ &self, payment_id: PaymentId, retryable_invoice_request: Option<RetryableInvoiceRequest>,
9990
+ ) -> Result<(), ()> {
9991
+ self.pending_outbound_payments.received_offer(payment_id, retryable_invoice_request)
9992
+ }
9993
+
9986
9994
// ----Temporary Functions----
9987
9995
// Set of functions temporarily moved to OffersMessageCommons for easier
9988
9996
// transition of code from ChannelManager to OffersMessageFlow
@@ -9995,6 +10003,14 @@ where
9995
10003
self.enqueue_invoice_request(invoice_request, reply_paths)
9996
10004
}
9997
10005
10006
+ fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
10007
+ &self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
10008
+ payer_note: Option<String>, payment_id: PaymentId,
10009
+ human_readable_name: Option<HumanReadableName>, create_pending_payment: CPP,
10010
+ ) -> Result<(), Bolt12SemanticError> {
10011
+ self.pay_for_offer_intern(offer, quantity, amount_msats, payer_note, payment_id, human_readable_name, create_pending_payment)
10012
+ }
10013
+
9998
10014
#[cfg(async_payments)]
9999
10015
fn initiate_async_payment(
10000
10016
&self, invoice: &StaticInvoice, payment_id: PaymentId
@@ -10008,7 +10024,7 @@ where
10008
10024
/// Sending multiple requests increases the chances of successful delivery in case some
10009
10025
/// paths are unavailable. However, only one invoice for a given [`PaymentId`] will be paid,
10010
10026
/// even if multiple invoices are received.
10011
- const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
10027
+ pub(crate) const OFFERS_MESSAGE_REQUEST_LIMIT: usize = 10;
10012
10028
10013
10029
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>
10014
10030
where
@@ -10229,7 +10245,8 @@ where
10229
10245
let reply_paths = self.create_blinded_paths(context)
10230
10246
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
10231
10247
10232
- let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
10248
+ // Temporarily removing this to find the best way to integrate the guard
10249
+ // let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
10233
10250
10234
10251
create_pending_payment(&invoice_request, nonce)?;
10235
10252
@@ -10372,73 +10389,6 @@ where
10372
10389
}
10373
10390
}
10374
10391
10375
- /// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
10376
- /// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
10377
- ///
10378
- /// If the wallet supports paying on-chain schemes, you should instead use
10379
- /// [`OMNameResolver::resolve_name`] and [`OMNameResolver::handle_dnssec_proof_for_uri`] (by
10380
- /// implementing [`DNSResolverMessageHandler`]) directly to look up a URI and then delegate to
10381
- /// your normal URI handling.
10382
- ///
10383
- /// If `max_total_routing_fee_msat` is not specified, the default from
10384
- /// [`RouteParameters::from_payment_params_and_value`] is applied.
10385
- ///
10386
- /// # Payment
10387
- ///
10388
- /// The provided `payment_id` is used to ensure that only one invoice is paid for the request
10389
- /// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
10390
- /// been sent.
10391
- ///
10392
- /// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
10393
- /// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
10394
- /// payment will fail with an [`Event::InvoiceRequestFailed`].
10395
- ///
10396
- /// # Privacy
10397
- ///
10398
- /// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
10399
- /// to construct a [`BlindedPath`] for the reply path. For further privacy implications, see the
10400
- /// docs of the parameterized [`Router`], which implements [`MessageRouter`].
10401
- ///
10402
- /// # Limitations
10403
- ///
10404
- /// Requires a direct connection to the given [`Destination`] as well as an introduction node in
10405
- /// [`Offer::paths`] or to [`Offer::signing_pubkey`], if empty. A similar restriction applies to
10406
- /// the responding [`Bolt12Invoice::payment_paths`].
10407
- ///
10408
- /// # Errors
10409
- ///
10410
- /// Errors if:
10411
- /// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
10412
- ///
10413
- /// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
10414
- /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
10415
- #[cfg(feature = "dnssec")]
10416
- pub fn pay_for_offer_from_human_readable_name(
10417
- &self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId,
10418
- retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>,
10419
- dns_resolvers: Vec<Destination>,
10420
- ) -> Result<(), ()> {
10421
- let (onion_message, context) =
10422
- self.hrn_resolver.resolve_name(payment_id, name, &*self.entropy_source)?;
10423
- let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
10424
- let expiration = StaleExpiration::TimerTicks(1);
10425
- self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)?;
10426
- let message_params = dns_resolvers
10427
- .iter()
10428
- .flat_map(|destination| reply_paths.iter().map(move |path| (path, destination)))
10429
- .take(OFFERS_MESSAGE_REQUEST_LIMIT);
10430
- for (reply_path, destination) in message_params {
10431
- self.pending_dns_onion_messages.lock().unwrap().push((
10432
- DNSResolverMessage::DNSSECQuery(onion_message.clone()),
10433
- MessageSendInstructions::WithSpecifiedReplyPath {
10434
- destination: destination.clone(),
10435
- reply_path: reply_path.clone(),
10436
- },
10437
- ));
10438
- }
10439
- Ok(())
10440
- }
10441
-
10442
10392
/// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
10443
10393
/// to pay us.
10444
10394
///
@@ -12113,70 +12063,6 @@ where
12113
12063
}
12114
12064
}
12115
12065
12116
- #[cfg(feature = "dnssec")]
12117
- impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>
12118
- DNSResolverMessageHandler for ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
12119
- where
12120
- M::Target: chain::Watch<<SP::Target as SignerProvider>::EcdsaSigner>,
12121
- T::Target: BroadcasterInterface,
12122
- ES::Target: EntropySource,
12123
- NS::Target: NodeSigner,
12124
- SP::Target: SignerProvider,
12125
- F::Target: FeeEstimator,
12126
- R::Target: Router,
12127
- MR::Target: MessageRouter,
12128
- L::Target: Logger,
12129
- {
12130
- fn handle_dnssec_query(
12131
- &self, _message: DNSSECQuery, _responder: Option<Responder>,
12132
- ) -> Option<(DNSResolverMessage, ResponseInstruction)> {
12133
- None
12134
- }
12135
-
12136
- fn handle_dnssec_proof(&self, message: DNSSECProof, context: DNSResolverContext) {
12137
- let offer_opt = self.hrn_resolver.handle_dnssec_proof_for_offer(message, context);
12138
- #[cfg_attr(not(feature = "_test_utils"), allow(unused_mut))]
12139
- if let Some((completed_requests, mut offer)) = offer_opt {
12140
- for (name, payment_id) in completed_requests {
12141
- #[cfg(feature = "_test_utils")]
12142
- if let Some(replacement_offer) = self.testing_dnssec_proof_offer_resolution_override.lock().unwrap().remove(&name) {
12143
- // If we have multiple pending requests we may end up over-using the override
12144
- // offer, but tests can deal with that.
12145
- offer = replacement_offer;
12146
- }
12147
- if let Ok(amt_msats) = self.pending_outbound_payments.amt_msats_for_payment_awaiting_offer(payment_id) {
12148
- let offer_pay_res =
12149
- self.pay_for_offer_intern(&offer, None, Some(amt_msats), None, payment_id, Some(name),
12150
- |invoice_request, nonce| {
12151
- let retryable_invoice_request = RetryableInvoiceRequest {
12152
- invoice_request: invoice_request.clone(),
12153
- nonce,
12154
- needs_retry: true,
12155
- };
12156
- self.pending_outbound_payments
12157
- .received_offer(payment_id, Some(retryable_invoice_request))
12158
- .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)
12159
- });
12160
- if offer_pay_res.is_err() {
12161
- // The offer we tried to pay is the canonical current offer for the name we
12162
- // wanted to pay. If we can't pay it, there's no way to recover so fail the
12163
- // payment.
12164
- // Note that the PaymentFailureReason should be ignored for an
12165
- // AwaitingInvoice payment.
12166
- self.pending_outbound_payments.abandon_payment(
12167
- payment_id, PaymentFailureReason::RouteNotFound, &self.pending_events,
12168
- );
12169
- }
12170
- }
12171
- }
12172
- }
12173
- }
12174
-
12175
- fn release_pending_messages(&self) -> Vec<(DNSResolverMessage, MessageSendInstructions)> {
12176
- core::mem::take(&mut self.pending_dns_onion_messages.lock().unwrap())
12177
- }
12178
- }
12179
-
12180
12066
impl<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, MR: Deref, L: Deref>
12181
12067
NodeIdLookUp for ChannelManager<M, T, ES, NS, SP, F, R, MR, L>
12182
12068
where
@@ -14146,11 +14032,6 @@ where
14146
14032
14147
14033
#[cfg(feature = "dnssec")]
14148
14034
hrn_resolver: OMNameResolver::new(highest_seen_timestamp, best_block_height),
14149
- #[cfg(feature = "dnssec")]
14150
- pending_dns_onion_messages: Mutex::new(Vec::new()),
14151
-
14152
- #[cfg(feature = "_test_utils")]
14153
- testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()),
14154
14035
};
14155
14036
14156
14037
let mut processed_claims: HashSet<Vec<MPPClaimHTLCSource>> = new_hash_set();
0 commit comments