Skip to content

Commit bbe104f

Browse files
committed
Move pay_for_offer_human_readable to OffersMessageFlow
1 parent dc7f355 commit bbe104f

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
@@ -9514,6 +9514,13 @@ pub trait OffersMessageCommons {
95149514
/// Get pending offers messages
95159515
fn get_pending_offers_messages(&self) -> MutexGuard<'_, Vec<(OffersMessage, MessageSendInstructions)>>;
95169516

9517+
/// Get pending DNS onion messages
9518+
fn get_pending_dns_onion_messages(&self) -> MutexGuard<'_, Vec<(DNSResolverMessage, MessageSendInstructions)>>;
9519+
9520+
#[cfg(feature = "dnssec")]
9521+
/// Get hrn resolver
9522+
fn get_hrn_resolver(&self) -> &OMNameResolver;
9523+
95179524
/// Gets the node_id held by this ChannelManager
95189525
fn get_our_node_id(&self) -> PublicKey;
95199526

@@ -9626,6 +9633,13 @@ pub trait OffersMessageCommons {
96269633
/// Add new awaiting invoice
96279634
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<(), ()>;
96289635

9636+
#[cfg(feature = "dnssec")]
9637+
/// Add new awaiting offer
9638+
fn add_new_awaiting_offer(
9639+
&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry,
9640+
max_total_routing_fee_msat: Option<u64>, amount_msats: u64,
9641+
) -> Result<(), ()>;
9642+
96299643
/// Internal pay_for_offer
96309644
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>> (
96319645
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
@@ -9650,6 +9664,15 @@ where
96509664
self.pending_offers_messages.lock().expect("Mutex is locked by other thread.")
96519665
}
96529666

9667+
fn get_pending_dns_onion_messages(&self) -> MutexGuard<'_, Vec<(DNSResolverMessage, MessageSendInstructions)>> {
9668+
self.pending_dns_onion_messages.lock().expect("Mutex is locked by other thread.")
9669+
}
9670+
9671+
#[cfg(feature = "dnssec")]
9672+
fn get_hrn_resolver(&self) -> &OMNameResolver {
9673+
&self.hrn_resolver
9674+
}
9675+
96539676
fn get_our_node_id(&self) -> PublicKey {
96549677
self.our_network_pubkey
96559678
}
@@ -9820,6 +9843,14 @@ where
98209843
)
98219844
}
98229845

9846+
#[cfg(feature = "dnssec")]
9847+
fn add_new_awaiting_offer(
9848+
&self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry,
9849+
max_total_routing_fee_msat: Option<u64>, amount_msats: u64,
9850+
) -> Result<(), ()> {
9851+
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)
9852+
}
9853+
98239854
fn pay_for_offer_intern<CPP: FnOnce(&InvoiceRequest, Nonce) -> Result<(), Bolt12SemanticError>>(
98249855
&self, offer: &Offer, quantity: Option<u64>, amount_msats: Option<u64>,
98259856
payer_note: Option<String>, payment_id: PaymentId,
@@ -9887,73 +9918,6 @@ where
98879918
MR::Target: MessageRouter,
98889919
L::Target: Logger,
98899920
{
9890-
/// Pays for an [`Offer`] looked up using [BIP 353] Human Readable Names resolved by the DNS
9891-
/// resolver(s) at `dns_resolvers` which resolve names according to bLIP 32.
9892-
///
9893-
/// If the wallet supports paying on-chain schemes, you should instead use
9894-
/// [`OMNameResolver::resolve_name`] and [`OMNameResolver::handle_dnssec_proof_for_uri`] (by
9895-
/// implementing [`DNSResolverMessageHandler`]) directly to look up a URI and then delegate to
9896-
/// your normal URI handling.
9897-
///
9898-
/// If `max_total_routing_fee_msat` is not specified, the default from
9899-
/// [`RouteParameters::from_payment_params_and_value`] is applied.
9900-
///
9901-
/// # Payment
9902-
///
9903-
/// The provided `payment_id` is used to ensure that only one invoice is paid for the request
9904-
/// when received. See [Avoiding Duplicate Payments] for other requirements once the payment has
9905-
/// been sent.
9906-
///
9907-
/// To revoke the request, use [`ChannelManager::abandon_payment`] prior to receiving the
9908-
/// invoice. If abandoned, or an invoice isn't received in a reasonable amount of time, the
9909-
/// payment will fail with an [`Event::InvoiceRequestFailed`].
9910-
///
9911-
/// # Privacy
9912-
///
9913-
/// For payer privacy, uses a derived payer id and uses [`MessageRouter::create_blinded_paths`]
9914-
/// to construct a [`BlindedPath`] for the reply path. For further privacy implications, see the
9915-
/// docs of the parameterized [`Router`], which implements [`MessageRouter`].
9916-
///
9917-
/// # Limitations
9918-
///
9919-
/// Requires a direct connection to the given [`Destination`] as well as an introduction node in
9920-
/// [`Offer::paths`] or to [`Offer::signing_pubkey`], if empty. A similar restriction applies to
9921-
/// the responding [`Bolt12Invoice::payment_paths`].
9922-
///
9923-
/// # Errors
9924-
///
9925-
/// Errors if:
9926-
/// - a duplicate `payment_id` is provided given the caveats in the aforementioned link,
9927-
///
9928-
/// [`Bolt12Invoice::payment_paths`]: crate::offers::invoice::Bolt12Invoice::payment_paths
9929-
/// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments
9930-
#[cfg(feature = "dnssec")]
9931-
pub fn pay_for_offer_from_human_readable_name(
9932-
&self, name: HumanReadableName, amount_msats: u64, payment_id: PaymentId,
9933-
retry_strategy: Retry, max_total_routing_fee_msat: Option<u64>,
9934-
dns_resolvers: Vec<Destination>,
9935-
) -> Result<(), ()> {
9936-
let (onion_message, context) =
9937-
self.hrn_resolver.resolve_name(payment_id, name, &*self.entropy_source)?;
9938-
let reply_paths = self.create_blinded_paths(MessageContext::DNSResolver(context))?;
9939-
let expiration = StaleExpiration::TimerTicks(1);
9940-
self.pending_outbound_payments.add_new_awaiting_offer(payment_id, expiration, retry_strategy, max_total_routing_fee_msat, amount_msats)?;
9941-
let message_params = dns_resolvers
9942-
.iter()
9943-
.flat_map(|destination| reply_paths.iter().map(move |path| (path, destination)))
9944-
.take(OFFERS_MESSAGE_REQUEST_LIMIT);
9945-
for (reply_path, destination) in message_params {
9946-
self.pending_dns_onion_messages.lock().unwrap().push((
9947-
DNSResolverMessage::DNSSECQuery(onion_message.clone()),
9948-
MessageSendInstructions::WithSpecifiedReplyPath {
9949-
destination: destination.clone(),
9950-
reply_path: reply_path.clone(),
9951-
},
9952-
));
9953-
}
9954-
Ok(())
9955-
}
9956-
99579921
/// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
99589922
/// stored external to LDK.
99599923
///

lightning/src/offers/flow.rs

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

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

0 commit comments

Comments
 (0)