Skip to content

Commit d7f14fc

Browse files
committed
Move pay_for_offer_human_readable to OffersMessageFlow
1 parent 609f0fb commit d7f14fc

File tree

3 files changed

+112
-68
lines changed

3 files changed

+112
-68
lines changed

lightning-dns-resolver/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ mod test {
404404
let retry = Retry::Attempts(0);
405405
let amt = 42_000;
406406
nodes[0]
407-
.node
407+
.offers_handler
408408
.pay_for_offer_from_human_readable_name(name, amt, payment_id, retry, None, resolvers)
409409
.unwrap();
410410

lightning/src/ln/channelmanager.rs

Lines changed: 31 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9203,6 +9203,13 @@ pub trait OffersMessageCommons {
92039203
/// Get pending offers messages
92049204
fn get_pending_offers_messages(&self) -> MutexGuard<'_, Vec<(OffersMessage, MessageSendInstructions)>>;
92059205

9206+
/// Get pending DNS onion messages
9207+
fn get_pending_dns_onion_messages(&self) -> MutexGuard<'_, Vec<(DNSResolverMessage, MessageSendInstructions)>>;
9208+
9209+
#[cfg(feature = "dnssec")]
9210+
/// Get hrn resolver
9211+
fn get_hrn_resolver(&self) -> &OMNameResolver;
9212+
92069213
/// Gets the node_id held by this ChannelManager
92079214
fn get_our_node_id(&self) -> PublicKey;
92089215

@@ -9315,6 +9322,13 @@ pub trait OffersMessageCommons {
93159322
/// Add new awaiting invoice
93169323
fn add_new_awaiting_invoice(&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>, retryable_invoice_request: Option<RetryableInvoiceRequest>) -> Result<(), ()>;
93179324

9325+
#[cfg(feature = "dnssec")]
9326+
/// Add new awaiting offer
9327+
fn add_new_awaiting_offer(
9328+
&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry,
9329+
max_total_routing_fee_msat: Option<u64>, amount_msats: u64,
9330+
) -> Result<(), ()>;
9331+
93189332
/// Internal pay_for_offer
93199333
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>> (
93209334
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -9339,6 +9353,15 @@ where
93399353
self.pending_offers_messages.lock().expect("Mutex is locked by other thread.")
93409354
}
93419355

9356+
fn get_pending_dns_onion_messages(&self) -> MutexGuard<'_, Vec<(DNSResolverMessage, MessageSendInstructions)>> {
9357+
self.pending_dns_onion_messages.lock().expect("Mutex is locked by other thread.")
9358+
}
9359+
9360+
#[cfg(feature = "dnssec")]
9361+
fn get_hrn_resolver(&self) -> &OMNameResolver {
9362+
&self.hrn_resolver
9363+
}
9364+
93429365
fn get_our_node_id(&self) -> PublicKey {
93439366
self.our_network_pubkey.clone()
93449367
}
@@ -9509,6 +9532,14 @@ where
95099532
)
95109533
}
95119534

9535+
#[cfg(feature = "dnssec")]
9536+
fn add_new_awaiting_offer(
9537+
&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry,
9538+
max_total_routing_fee_msat: Option<u64>, amount_msats: u64,
9539+
) -> Result<(), ()> {
9540+
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9541+
}
9542+
95129543
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
95139544
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
95149545
payer_note: Option<String>, payment_id: PaymentId,
@@ -9576,73 +9607,6 @@ where
95769607
MR::Target: MessageRouter,
95779608
L::Target: Logger,
95789609
{
9579-
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9580-
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9581-
///
9582-
/// If the wallet supports paying on-chain schemes, you should instead use
9583-
/// [`OMNameResolver::resolve_name`] and [`OMNameResolver::handle_dnssec_proof_for_uri`] (by
9584-
/// implementing [`DNSResolverMessageHandler`]) directly to look up a URI and then delegate to
9585-
/// your normal URI handling.
9586-
///
9587-
/// If `max_total_routing_fee_msat` is not specified, the default from
9588-
/// [`RouteParameters::from_payment_params_and_value`] is applied.
9589-
///
9590-
/// # Payment
9591-
///
9592-
/// The provided `payment_id` is used to ensure that only one invoice is paid for the request
9593-
/// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
9594-
/// been sent.
9595-
///
9596-
/// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
9597-
/// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
9598-
/// payment will fail with an [`Event::InvoiceRequestFailed`].
9599-
///
9600-
/// # Privacy
9601-
///
9602-
/// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
9603-
/// to construct a [`BlindedPath`] for the reply path. For further privacy implications, see the
9604-
/// docs of the parameterized [`Router`], which implements [`MessageRouter`].
9605-
///
9606-
/// # Limitations
9607-
///
9608-
/// Requires a direct connection to the given [`Destination`] as well as an introduction node in
9609-
/// [`Offer::paths`] or to [`Offer::signing_pubkey`], if empty. A similar restriction applies to
9610-
/// the responding [`Bolt12Invoice::payment_paths`].
9611-
///
9612-
/// # Errors
9613-
///
9614-
/// Errors if:
9615-
/// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9616-
///
9617-
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9618-
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9619-
#[cfg(feature = "dnssec")]
9620-
pub fn pay_for_offer_from_human_readable_name(
9621-
&self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId,
9622-
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>,
9623-
dns_resolvers: Vec<Destination>,
9624-
) -> Result<(), ()> {
9625-
let (onion_message, context) =
9626-
self.hrn_resolver.resolve_name(payment_id, name, &*self.entropy_source)?;
9627-
let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
9628-
let expiration = StaleExpiration::TimerTicks(1);
9629-
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)?;
9630-
let message_params = dns_resolvers
9631-
.iter()
9632-
.flat_map(|destination| reply_paths.iter().map(move |path| (path, destination)))
9633-
.take(OFFERS_MESSAGE_REQUEST_LIMIT);
9634-
for (reply_path, destination) in message_params {
9635-
self.pending_dns_onion_messages.lock().unwrap().push((
9636-
DNSResolverMessage::DNSSECQuery(onion_message.clone()),
9637-
MessageSendInstructions::WithSpecifiedReplyPath {
9638-
destination: destination.clone(),
9639-
reply_path: reply_path.clone(),
9640-
},
9641-
));
9642-
}
9643-
Ok(())
9644-
}
9645-
96469610
/// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
96479611
/// stored external to LDK.
96489612
///

lightning/src/offers/flow.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ use {
4747
crate::offers::refund::RefundMaybeWithDerivedMetadataBuilder,
4848
};
4949

50+
#[cfg(feature = "dnssec")]
51+
use crate::onion_message::dns_resolution::{DNSResolverMessage, HumanReadableName};
52+
5053
/// A trivial trait which describes any [`OffersMessageFlow`].
5154
///
5255
/// This is not exported to bindings users as general cover traits aren't useful in other
@@ -1067,4 +1070,81 @@ where
10671070
Err(()) => Err(Bolt12SemanticError::InvalidAmount),
10681071
}
10691072
}
1073+
1074+
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
1075+
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
1076+
///
1077+
/// If the wallet supports paying on-chain schemes, you should instead use
1078+
/// [`OMNameResolver::resolve_name`] and [`OMNameResolver::handle_dnssec_proof_for_uri`] (by
1079+
/// implementing [`DNSResolverMessageHandler`]) directly to look up a URI and then delegate to
1080+
/// your normal URI handling.
1081+
///
1082+
/// If `max_total_routing_fee_msat` is not specified, the default from
1083+
/// [`RouteParameters::from_payment_params_and_value`] is applied.
1084+
///
1085+
/// # Payment
1086+
///
1087+
/// The provided `payment_id` is used to ensure that only one invoice is paid for the request
1088+
/// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
1089+
/// been sent.
1090+
///
1091+
/// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
1092+
/// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
1093+
/// payment will fail with an [`Event::InvoiceRequestFailed`].
1094+
///
1095+
/// # Privacy
1096+
///
1097+
/// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
1098+
/// to construct a [`BlindedPath`] for the reply path. For further privacy implications, see the
1099+
/// docs of the parameterized [`Router`], which implements [`MessageRouter`].
1100+
///
1101+
/// # Limitations
1102+
///
1103+
/// Requires a direct connection to the given [`Destination`] as well as an introduction node in
1104+
/// [`Offer::paths`] or to [`Offer::signing_pubkey`], if empty. A similar restriction applies to
1105+
/// the responding [`Bolt12Invoice::payment_paths`].
1106+
///
1107+
/// # Errors
1108+
///
1109+
/// Errors if:
1110+
/// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
1111+
///
1112+
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
1113+
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
1114+
#[cfg(feature = "dnssec")]
1115+
pub fn pay_for_offer_from_human_readable_name(
1116+
&self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId,
1117+
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>,
1118+
dns_resolvers: Vec<Destination>,
1119+
) -> Result<(), ()> {
1120+
let (onion_message, context) = self.commons.get_hrn_resolver().resolve_name(
1121+
payment_id,
1122+
name,
1123+
&*self.entropy_source,
1124+
)?;
1125+
let reply_paths =
1126+
self.commons.create_blinded_paths(MessageContext::DNSResolver(context))?;
1127+
let expiration = StaleExpiration::TimerTicks(1);
1128+
self.commons.add_new_awaiting_offer(
1129+
payment_id,
1130+
expiration,
1131+
retry_strategy,
1132+
max_total_routing_fee_msat,
1133+
amount_msats,
1134+
)?;
1135+
let message_params = dns_resolvers
1136+
.iter()
1137+
.flat_map(|destination| reply_paths.iter().map(move |path| (path, destination)))
1138+
.take(OFFERS_MESSAGE_REQUEST_LIMIT);
1139+
for (reply_path, destination) in message_params {
1140+
self.commons.get_pending_dns_onion_messages().push((
1141+
DNSResolverMessage::DNSSECQuery(onion_message.clone()),
1142+
MessageSendInstructions::WithSpecifiedReplyPath {
1143+
destination: destination.clone(),
1144+
reply_path: reply_path.clone(),
1145+
},
1146+
));
1147+
}
1148+
Ok(())
1149+
}
10701150
}

0 commit comments

Comments
 (0)