From 1bfd19e24389299a09f3e4e4a68722684ad43534 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Wed, 12 Jun 2024 11:05:18 -0400 Subject: [PATCH] Rename StaticInvoice::message_paths to be more specific. --- lightning/src/offers/invoice.rs | 18 ++++----- lightning/src/offers/static_invoice.rs | 52 +++++++++++++++----------- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index ca4a2b671f0..5fbc0e19348 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -1102,7 +1102,7 @@ impl InvoiceFields { fallbacks: self.fallbacks.as_ref(), features, node_id: Some(&self.signing_pubkey), - message_paths: None, + async_receive_message_paths: None, } } } @@ -1171,7 +1171,7 @@ tlv_stream!(InvoiceTlvStream, InvoiceTlvStreamRef, 160..240, { (174, features: (Bolt12InvoiceFeatures, WithoutLength)), (176, node_id: PublicKey), // Only present in `StaticInvoice`s. - (238, message_paths: (Vec, WithoutLength)), + (238, async_receive_message_paths: (Vec, WithoutLength)), }); pub(super) type BlindedPathIter<'a> = core::iter::Map< @@ -1309,11 +1309,11 @@ impl TryFrom for InvoiceContents { invoice_request_tlv_stream, InvoiceTlvStream { paths, blindedpay, created_at, relative_expiry, payment_hash, amount, fallbacks, - features, node_id, message_paths, + features, node_id, async_receive_message_paths, }, ) = tlv_stream; - if message_paths.is_some() { return Err(Bolt12SemanticError::UnexpectedPaths) } + if async_receive_message_paths.is_some() { return Err(Bolt12SemanticError::UnexpectedPaths) } let payment_paths = construct_payment_paths(blindedpay, paths)?; @@ -1580,7 +1580,7 @@ mod tests { fallbacks: None, features: None, node_id: Some(&recipient_pubkey()), - message_paths: None, + async_receive_message_paths: None, }, SignatureTlvStreamRef { signature: Some(&invoice.signature()) }, ), @@ -1672,7 +1672,7 @@ mod tests { fallbacks: None, features: None, node_id: Some(&recipient_pubkey()), - message_paths: None, + async_receive_message_paths: None, }, SignatureTlvStreamRef { signature: Some(&invoice.signature()) }, ), @@ -2445,7 +2445,7 @@ mod tests { } #[test] - fn fails_parsing_invoice_with_message_paths() { + fn fails_parsing_invoice_with_async_receive_message_paths() { let invoice = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap() @@ -2466,8 +2466,8 @@ mod tests { }; let mut tlv_stream = invoice.as_tlv_stream(); - let message_paths = vec![blinded_path]; - tlv_stream.3.message_paths = Some(&message_paths); + let async_receive_message_paths = vec![blinded_path]; + tlv_stream.3.async_receive_message_paths = Some(&async_receive_message_paths); match Bolt12Invoice::try_from(tlv_stream.to_bytes()) { Ok(_) => panic!("expected error"), diff --git a/lightning/src/offers/static_invoice.rs b/lightning/src/offers/static_invoice.rs index 39e74c67767..91e52f819c2 100644 --- a/lightning/src/offers/static_invoice.rs +++ b/lightning/src/offers/static_invoice.rs @@ -77,7 +77,7 @@ struct InvoiceContents { fallbacks: Option>, features: Bolt12InvoiceFeatures, signing_pubkey: PublicKey, - message_paths: Vec, + async_receive_message_paths: Vec, } /// Builds a [`StaticInvoice`] from an [`Offer`]. @@ -98,14 +98,17 @@ impl<'a> StaticInvoiceBuilder<'a> { /// after `created_at`. pub fn for_offer_using_derived_keys( offer: &'a Offer, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, - message_paths: Vec, created_at: Duration, expanded_key: &ExpandedKey, - secp_ctx: &Secp256k1, + async_receive_message_paths: Vec, created_at: Duration, + expanded_key: &ExpandedKey, secp_ctx: &Secp256k1, ) -> Result { if offer.chains().len() > 1 { return Err(Bolt12SemanticError::UnexpectedChain); } - if payment_paths.is_empty() || message_paths.is_empty() || offer.paths().is_empty() { + if payment_paths.is_empty() + || async_receive_message_paths.is_empty() + || offer.paths().is_empty() + { return Err(Bolt12SemanticError::MissingPaths); } @@ -123,8 +126,13 @@ impl<'a> StaticInvoiceBuilder<'a> { return Err(Bolt12SemanticError::InvalidSigningPubkey); } - let invoice = - InvoiceContents::new(offer, payment_paths, message_paths, created_at, signing_pubkey); + let invoice = InvoiceContents::new( + offer, + payment_paths, + async_receive_message_paths, + created_at, + signing_pubkey, + ); Ok(Self { offer_bytes: &offer.bytes, invoice, keys }) } @@ -230,8 +238,8 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { /// Paths to the recipient for indicating that a held HTLC is available to claim when they next /// come online. - pub fn message_paths(&$self) -> &[BlindedPath] { - $contents.message_paths() + pub fn async_receive_message_paths(&$self) -> &[BlindedPath] { + $contents.async_receive_message_paths() } /// The quantity of items supported, from [`Offer::supported_quantity`]. @@ -327,12 +335,13 @@ impl InvoiceContents { fn new( offer: &Offer, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, - message_paths: Vec, created_at: Duration, signing_pubkey: PublicKey, + async_receive_message_paths: Vec, created_at: Duration, + signing_pubkey: PublicKey, ) -> Self { Self { offer: offer.contents.clone(), payment_paths, - message_paths, + async_receive_message_paths, created_at, relative_expiry: None, fallbacks: None, @@ -352,7 +361,7 @@ impl InvoiceContents { let invoice = InvoiceTlvStreamRef { paths: Some(Iterable(self.payment_paths.iter().map(|(_, path)| path))), - message_paths: Some(self.message_paths.as_ref()), + async_receive_message_paths: Some(self.async_receive_message_paths.as_ref()), blindedpay: Some(Iterable(self.payment_paths.iter().map(|(payinfo, _)| payinfo))), created_at: Some(self.created_at.as_secs()), relative_expiry: self.relative_expiry.map(|duration| duration.as_secs() as u32), @@ -399,8 +408,8 @@ impl InvoiceContents { self.offer.paths() } - fn message_paths(&self) -> &[BlindedPath] { - &self.message_paths[..] + fn async_receive_message_paths(&self) -> &[BlindedPath] { + &self.async_receive_message_paths[..] } fn supported_quantity(&self) -> Quantity { @@ -510,7 +519,7 @@ impl TryFrom for InvoiceContents { fallbacks, features, node_id, - message_paths, + async_receive_message_paths, payment_hash, amount, }, @@ -524,7 +533,8 @@ impl TryFrom for InvoiceContents { } let payment_paths = construct_payment_paths(blindedpay, paths)?; - let message_paths = message_paths.ok_or(Bolt12SemanticError::MissingPaths)?; + let async_receive_message_paths = + async_receive_message_paths.ok_or(Bolt12SemanticError::MissingPaths)?; let created_at = match created_at { None => return Err(Bolt12SemanticError::MissingCreationTime), @@ -548,7 +558,7 @@ impl TryFrom for InvoiceContents { Ok(InvoiceContents { offer: OfferContents::try_from(offer_tlv_stream)?, payment_paths, - message_paths, + async_receive_message_paths, created_at, relative_expiry, fallbacks, @@ -679,7 +689,7 @@ mod tests { assert_eq!(invoice.offer_features(), &OfferFeatures::empty()); assert_eq!(invoice.absolute_expiry(), None); assert_eq!(invoice.request_paths(), &[blinded_path()]); - assert_eq!(invoice.message_paths(), &[blinded_path()]); + assert_eq!(invoice.async_receive_message_paths(), &[blinded_path()]); assert_eq!(invoice.issuer(), None); assert_eq!(invoice.supported_quantity(), Quantity::One); assert_ne!(invoice.signing_pubkey(), recipient_pubkey()); @@ -726,7 +736,7 @@ mod tests { fallbacks: None, features: None, node_id: Some(&offer_signing_pubkey), - message_paths: Some(&paths), + async_receive_message_paths: Some(&paths), }, SignatureTlvStreamRef { signature: Some(&invoice.signature()) }, ) @@ -1055,9 +1065,9 @@ mod tests { } // Error if message paths are missing. - let missing_message_paths_invoice = invoice(); - let mut tlv_stream = missing_message_paths_invoice.as_tlv_stream(); - tlv_stream.1.message_paths = None; + let missing_async_receive_message_paths_invoice = invoice(); + let mut tlv_stream = missing_async_receive_message_paths_invoice.as_tlv_stream(); + tlv_stream.1.async_receive_message_paths = None; match StaticInvoice::try_from(tlv_stream_to_bytes(&tlv_stream)) { Ok(_) => panic!("expected error"), Err(e) => {