]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Cfg-gate async payments module and public enum variants.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 13 Jun 2024 18:09:12 +0000 (14:09 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Thu, 20 Jun 2024 18:24:09 +0000 (14:24 -0400)
ci/check-cfg-flags.py
ci/ci-tests.sh
lightning/src/ln/channelmanager.rs
lightning/src/ln/offers_tests.rs
lightning/src/offers/mod.rs
lightning/src/offers/offer.rs
lightning/src/onion_message/messenger.rs
lightning/src/onion_message/offers.rs
lightning/src/onion_message/packet.rs

index c33e8aa3a15015fb7e7c470def921d633cb2ceb9..d73bf50a1f6cf4a483d7e1b2d237062b4c3f1e3e 100755 (executable)
@@ -104,6 +104,8 @@ def check_cfg_tag(cfg):
         pass
     elif cfg == "splicing":
         pass
+    elif cfg == "async_payments":
+        pass
     else:
         print("Bad cfg tag: " + cfg)
         assert False
index 0dc654d8bedca04688e5cf5e8afcd248b4cc3587..d0ba7c7fe9e581292fc36816582e1884dedc7607 100755 (executable)
@@ -179,3 +179,5 @@ RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
 RUSTFLAGS="--cfg=dual_funding" cargo test --verbose --color always -p lightning
 [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
 RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
+[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
+RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
index f189aee04cf75b2933a5f1508ec065b4b1356104..fe3320a136029fa4a4504ccf906c1f8a2642150e 100644 (file)
@@ -10337,6 +10337,7 @@ where
                                        },
                                }
                        },
+                       #[cfg(async_payments)]
                        OffersMessage::StaticInvoice(_invoice) => {
                                match responder {
                                        Some(responder) => {
index 10ebd599bde528a1882f2fd975107f088e542ae4..e174dfc1cb4d3ef57ea0888cc6b7c4d97d86c773 100644 (file)
@@ -192,9 +192,11 @@ fn extract_invoice_request<'a, 'b, 'c>(
                        ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
                                OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path.unwrap()),
                                OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
+                               #[cfg(async_payments)]
                                OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
                                OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
                        },
+                       #[cfg(async_payments)]
                        ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
                        ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
                },
@@ -209,9 +211,11 @@ fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage)
                        ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
                                OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
                                OffersMessage::Invoice(invoice) => invoice,
+                               #[cfg(async_payments)]
                                OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
                                OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
                        },
+                       #[cfg(async_payments)]
                        ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
                        ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
                },
@@ -228,9 +232,11 @@ fn extract_invoice_error<'a, 'b, 'c>(
                        ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
                                OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
                                OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
+                               #[cfg(async_payments)]
                                OffersMessage::StaticInvoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
                                OffersMessage::InvoiceError(error) => error,
                        },
+                       #[cfg(async_payments)]
                        ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
                        ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
                },
index b77eec1611906789182c4a1da8cf6694b24ef55b..e5e894e2a128fe395a51ca71fb6e38fa1125aaff 100644 (file)
@@ -24,7 +24,7 @@ pub mod parse;
 mod payer;
 pub mod refund;
 pub(crate) mod signer;
-#[allow(unused)]
-pub(crate) mod static_invoice;
+#[cfg(async_payments)]
+pub mod static_invoice;
 #[cfg(test)]
 pub(crate) mod test_utils;
index dd58c75cec27e600e803122d72d92036665b0976..253de8652bbdb8bbe70792988fa676a9b52bcbc6 100644 (file)
@@ -665,6 +665,7 @@ impl Offer {
                self.contents.expects_quantity()
        }
 
+       #[cfg(async_payments)]
        pub(super) fn verify<T: secp256k1::Signing>(
                &self, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
        ) -> Result<(OfferId, Option<Keypair>), ()> {
index 4182fdf030735710533c146b9b7113f4bfe68558..c7da29307bc5d44c08036bd4b8deb5eef6e6f70f 100644 (file)
@@ -24,7 +24,9 @@ use crate::ln::features::{InitFeatures, NodeFeatures};
 use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
 use crate::ln::onion_utils;
 use crate::routing::gossip::{NetworkGraph, NodeId, ReadOnlyNetworkGraph};
-use super::async_payments::{AsyncPaymentsMessage, AsyncPaymentsMessageHandler};
+use super::async_payments::AsyncPaymentsMessageHandler;
+#[cfg(async_payments)]
+use super::async_payments::AsyncPaymentsMessage;
 use super::packet::OnionMessageContents;
 use super::packet::ParsedOnionMessageContents;
 use super::offers::OffersMessageHandler;
@@ -254,6 +256,7 @@ pub struct OnionMessenger<
        node_id_lookup: NL,
        message_router: MR,
        offers_handler: OMH,
+       #[allow(unused)]
        async_payments_handler: APH,
        custom_handler: CMH,
        intercept_messages_for_offline_peers: bool,
@@ -1444,12 +1447,14 @@ where
                                                let response_instructions = self.offers_handler.handle_message(msg, responder);
                                                let _ = self.handle_onion_message_response(response_instructions);
                                        },
+                                       #[cfg(async_payments)]
                                        ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::HeldHtlcAvailable(msg)) => {
                                                let response_instructions = self.async_payments_handler.held_htlc_available(
                                                        msg, responder
                                                );
                                                let _ = self.handle_onion_message_response(response_instructions);
                                        },
+                                       #[cfg(async_payments)]
                                        ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::ReleaseHeldHtlc(msg)) => {
                                                self.async_payments_handler.release_held_htlc(msg);
                                        },
index 52dacd84e3d4a9d15dadc881c6dcb18b0e0a8651..397f4b8a72b7a827b8bb0543f78a076cd9eb2210 100644 (file)
@@ -16,6 +16,7 @@ use crate::offers::invoice_error::InvoiceError;
 use crate::offers::invoice_request::InvoiceRequest;
 use crate::offers::invoice::Bolt12Invoice;
 use crate::offers::parse::Bolt12ParseError;
+#[cfg(async_payments)]
 use crate::offers::static_invoice::StaticInvoice;
 use crate::onion_message::packet::OnionMessageContents;
 use crate::util::logger::Logger;
@@ -30,6 +31,7 @@ use crate::prelude::*;
 const INVOICE_REQUEST_TLV_TYPE: u64 = 64;
 const INVOICE_TLV_TYPE: u64 = 66;
 const INVOICE_ERROR_TLV_TYPE: u64 = 68;
+#[cfg(async_payments)]
 const STATIC_INVOICE_TLV_TYPE: u64 = 70;
 
 /// A handler for an [`OnionMessage`] containing a BOLT 12 Offers message as its payload.
@@ -74,7 +76,8 @@ pub enum OffersMessage {
        /// [`Refund`]: crate::offers::refund::Refund
        Invoice(Bolt12Invoice),
 
-       /// A `StaticInvoice` sent in response to an [`InvoiceRequest`].
+       #[cfg(async_payments)]
+       /// A [`StaticInvoice`] sent in response to an [`InvoiceRequest`].
        StaticInvoice(StaticInvoice),
 
        /// An error from handling an [`OffersMessage`].
@@ -87,8 +90,9 @@ impl OffersMessage {
                match tlv_type {
                        INVOICE_REQUEST_TLV_TYPE
                        | INVOICE_TLV_TYPE
-                       | STATIC_INVOICE_TLV_TYPE
                        | INVOICE_ERROR_TLV_TYPE => true,
+                       #[cfg(async_payments)]
+                       STATIC_INVOICE_TLV_TYPE => true,
                        _ => false,
                }
        }
@@ -97,6 +101,7 @@ impl OffersMessage {
                match tlv_type {
                        INVOICE_REQUEST_TLV_TYPE => Ok(Self::InvoiceRequest(InvoiceRequest::try_from(bytes)?)),
                        INVOICE_TLV_TYPE => Ok(Self::Invoice(Bolt12Invoice::try_from(bytes)?)),
+                       #[cfg(async_payments)]
                        STATIC_INVOICE_TLV_TYPE => Ok(Self::StaticInvoice(StaticInvoice::try_from(bytes)?)),
                        _ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
@@ -112,6 +117,7 @@ impl fmt::Debug for OffersMessage {
                        OffersMessage::Invoice(message) => {
                                write!(f, "{:?}", message.as_tlv_stream())
                        }
+                       #[cfg(async_payments)]
                        OffersMessage::StaticInvoice(message) => {
                                write!(f, "{:?}", message)
                        }
@@ -127,6 +133,7 @@ impl OnionMessageContents for OffersMessage {
                match self {
                        OffersMessage::InvoiceRequest(_) => INVOICE_REQUEST_TLV_TYPE,
                        OffersMessage::Invoice(_) => INVOICE_TLV_TYPE,
+                       #[cfg(async_payments)]
                        OffersMessage::StaticInvoice(_) => STATIC_INVOICE_TLV_TYPE,
                        OffersMessage::InvoiceError(_) => INVOICE_ERROR_TLV_TYPE,
                }
@@ -135,6 +142,7 @@ impl OnionMessageContents for OffersMessage {
                match &self {
                        OffersMessage::InvoiceRequest(_) => "Invoice Request",
                        OffersMessage::Invoice(_) => "Invoice",
+                       #[cfg(async_payments)]
                        OffersMessage::StaticInvoice(_) => "Static Invoice",
                        OffersMessage::InvoiceError(_) => "Invoice Error",
                }
@@ -146,6 +154,7 @@ impl Writeable for OffersMessage {
                match self {
                        OffersMessage::InvoiceRequest(message) => message.write(w),
                        OffersMessage::Invoice(message) => message.write(w),
+                       #[cfg(async_payments)]
                        OffersMessage::StaticInvoice(message) => message.write(w),
                        OffersMessage::InvoiceError(message) => message.write(w),
                }
index 47b1a0313d791a43c5d52c286b919bba2f151b1a..fca7dd6a91ac6a1eda39e5519822c1c9101df78c 100644 (file)
@@ -17,6 +17,7 @@ use crate::blinded_path::message::{ForwardTlvs, ReceiveTlvs};
 use crate::blinded_path::utils::Padding;
 use crate::ln::msgs::DecodeError;
 use crate::ln::onion_utils;
+#[cfg(async_payments)]
 use super::async_payments::AsyncPaymentsMessage;
 use super::messenger::CustomOnionMessageHandler;
 use super::offers::OffersMessage;
@@ -130,6 +131,7 @@ pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
        /// A message related to BOLT 12 Offers.
        Offers(OffersMessage),
        /// A message related to async payments.
+       #[cfg(async_payments)]
        AsyncPayments(AsyncPaymentsMessage),
        /// A custom onion message specified by the user.
        Custom(T),
@@ -142,6 +144,7 @@ impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContent
        fn tlv_type(&self) -> u64 {
                match self {
                        &ParsedOnionMessageContents::Offers(ref msg) => msg.tlv_type(),
+                       #[cfg(async_payments)]
                        &ParsedOnionMessageContents::AsyncPayments(ref msg) => msg.tlv_type(),
                        &ParsedOnionMessageContents::Custom(ref msg) => msg.tlv_type(),
                }
@@ -149,6 +152,7 @@ impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContent
        fn msg_type(&self) -> &'static str {
                match self {
                        ParsedOnionMessageContents::Offers(ref msg) => msg.msg_type(),
+                       #[cfg(async_payments)]
                        ParsedOnionMessageContents::AsyncPayments(ref msg) => msg.msg_type(),
                        ParsedOnionMessageContents::Custom(ref msg) => msg.msg_type(),
                }
@@ -159,6 +163,7 @@ impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                match self {
                        ParsedOnionMessageContents::Offers(msg) => Ok(msg.write(w)?),
+                       #[cfg(async_payments)]
                        ParsedOnionMessageContents::AsyncPayments(msg) => Ok(msg.write(w)?),
                        ParsedOnionMessageContents::Custom(msg) => Ok(msg.write(w)?),
                }
@@ -261,6 +266,7 @@ for Payload<ParsedOnionMessageContents<<H as CustomOnionMessageHandler>::CustomM
                                        message = Some(ParsedOnionMessageContents::Offers(msg));
                                        Ok(true)
                                },
+                               #[cfg(async_payments)]
                                tlv_type if AsyncPaymentsMessage::is_known_type(tlv_type) => {
                                        let msg = AsyncPaymentsMessage::read(msg_reader, tlv_type)?;
                                        message = Some(ParsedOnionMessageContents::AsyncPayments(msg));