Remove InvoiceRequestFields::features
authorJeffrey Czyz <jkczyz@gmail.com>
Fri, 26 Apr 2024 17:13:12 +0000 (12:13 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Mon, 29 Apr 2024 17:27:39 +0000 (12:27 -0500)
InvoiceRequestFeatures may contain a large, odd bit. Including this in
InvoiceRequestFields, which is in each BlindedPath of a Bolt12Invoice,
could cause the invoice's onion message to exceed the maximum size. The
features are already checked before sending an invoice.

lightning/src/ln/offers_tests.rs
lightning/src/offers/invoice_request.rs

index 5a6285373846f1e3cf92a306b71cb67a4ebdb3b0..c480cf5b8a83bc0070646ecfa083839b3f1bf9b2 100644 (file)
@@ -46,7 +46,6 @@ use crate::blinded_path::{BlindedPath, IntroductionNode};
 use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext};
 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
-use crate::ln::features::InvoiceRequestFeatures;
 use crate::ln::functional_test_utils::*;
 use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
 use crate::offers::invoice::Bolt12Invoice;
@@ -412,7 +411,6 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
                offer_id: offer.id(),
                invoice_request: InvoiceRequestFields {
                        payer_id: invoice_request.payer_id(),
-                       features: InvoiceRequestFeatures::empty(),
                        quantity: None,
                        payer_note_truncated: None,
                },
@@ -564,7 +562,6 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
                offer_id: offer.id(),
                invoice_request: InvoiceRequestFields {
                        payer_id: invoice_request.payer_id(),
-                       features: InvoiceRequestFeatures::empty(),
                        quantity: None,
                        payer_note_truncated: None,
                },
@@ -685,7 +682,6 @@ fn pays_for_offer_without_blinded_paths() {
                offer_id: offer.id(),
                invoice_request: InvoiceRequestFields {
                        payer_id: invoice_request.payer_id(),
-                       features: InvoiceRequestFeatures::empty(),
                        quantity: None,
                        payer_note_truncated: None,
                },
index e1256b71ac10f36a4536a61a40ac8f86a8d94182..357b85c5cf07b89a06cb591278e6e61ed8ac4245 100644 (file)
@@ -877,13 +877,12 @@ impl VerifiedInvoiceRequest {
                let InvoiceRequestContents {
                        payer_id,
                        inner: InvoiceRequestContentsWithoutPayerId {
-                               payer: _, offer: _, chain: _, amount_msats: _, features, quantity, payer_note
+                               payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note
                        },
                } = &self.inner.contents;
 
                InvoiceRequestFields {
                        payer_id: *payer_id,
-                       features: features.clone(),
                        quantity: *quantity,
                        payer_note_truncated: payer_note.clone()
                                .map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
@@ -1125,9 +1124,6 @@ pub struct InvoiceRequestFields {
        /// A possibly transient pubkey used to sign the invoice request.
        pub payer_id: PublicKey,
 
-       /// Features pertaining to requesting an invoice.
-       pub features: InvoiceRequestFeatures,
-
        /// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
        pub quantity: Option<u64>,
 
@@ -1143,9 +1139,8 @@ impl Writeable for InvoiceRequestFields {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                write_tlv_fields!(writer, {
                        (0, self.payer_id, required),
-                       (2, WithoutLength(&self.features), required),
-                       (4, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
-                       (6, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
+                       (2, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
+                       (4, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
                });
                Ok(())
        }
@@ -1155,14 +1150,13 @@ impl Readable for InvoiceRequestFields {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, payer_id, required),
-                       (2, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))),
-                       (4, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
-                       (6, payer_note_truncated, (option, encoding: (String, WithoutLength))),
+                       (2, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
+                       (4, payer_note_truncated, (option, encoding: (String, WithoutLength))),
                });
-               let features = features.unwrap_or(InvoiceRequestFeatures::empty());
 
                Ok(InvoiceRequestFields {
-                       payer_id: payer_id.0.unwrap(), features, quantity,
+                       payer_id: payer_id.0.unwrap(),
+                       quantity,
                        payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)),
                })
        }
@@ -2267,7 +2261,6 @@ mod tests {
                                        fields,
                                        InvoiceRequestFields {
                                                payer_id: payer_pubkey(),
-                                               features: InvoiceRequestFeatures::empty(),
                                                quantity: Some(1),
                                                payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),
                                        }