Skip to content

Commit 5c7af8c

Browse files
Cfg-gate async payments module and public enum variants.
1 parent f20bd3d commit 5c7af8c

File tree

9 files changed

+37
-5
lines changed

9 files changed

+37
-5
lines changed

ci/check-cfg-flags.py

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def check_cfg_tag(cfg):
104104
pass
105105
elif cfg == "splicing":
106106
pass
107+
elif cfg == "async_payments":
108+
pass
107109
else:
108110
print("Bad cfg tag: " + cfg)
109111
assert False

ci/ci-tests.sh

+2
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,5 @@ RUSTFLAGS="--cfg=async_signing" cargo test --verbose --color always -p lightning
179179
RUSTFLAGS="--cfg=dual_funding" cargo test --verbose --color always -p lightning
180180
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
181181
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
182+
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
183+
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning

lightning/src/ln/channelmanager.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10337,6 +10337,7 @@ where
1033710337
},
1033810338
}
1033910339
},
10340+
#[cfg(async_payments)]
1034010341
OffersMessage::StaticInvoice(_invoice) => {
1034110342
match responder {
1034210343
Some(responder) => {

lightning/src/ln/offers_tests.rs

+6
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ fn extract_invoice_request<'a, 'b, 'c>(
192192
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
193193
OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path.unwrap()),
194194
OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
195+
#[cfg(async_payments)]
195196
OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
196197
OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
197198
},
199+
#[cfg(async_payments)]
198200
ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
199201
ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
200202
},
@@ -209,9 +211,11 @@ fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage)
209211
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
210212
OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
211213
OffersMessage::Invoice(invoice) => invoice,
214+
#[cfg(async_payments)]
212215
OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
213216
OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
214217
},
218+
#[cfg(async_payments)]
215219
ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
216220
ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
217221
},
@@ -228,9 +232,11 @@ fn extract_invoice_error<'a, 'b, 'c>(
228232
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
229233
OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
230234
OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
235+
#[cfg(async_payments)]
231236
OffersMessage::StaticInvoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
232237
OffersMessage::InvoiceError(error) => error,
233238
},
239+
#[cfg(async_payments)]
234240
ParsedOnionMessageContents::AsyncPayments(message) => panic!("Unexpected async payments message: {:?}", message),
235241
ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
236242
},

lightning/src/offers/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub mod parse;
2424
mod payer;
2525
pub mod refund;
2626
pub(crate) mod signer;
27-
#[allow(unused)]
28-
pub(crate) mod static_invoice;
27+
#[cfg(async_payments)]
28+
pub mod static_invoice;
2929
#[cfg(test)]
3030
pub(crate) mod test_utils;

lightning/src/offers/offer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ impl Offer {
665665
self.contents.expects_quantity()
666666
}
667667

668+
#[cfg(async_payments)]
668669
pub(super) fn verify<T: secp256k1::Signing>(
669670
&self, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
670671
) -> Result<(OfferId, Option<Keypair>), ()> {

lightning/src/onion_message/messenger.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::ln::features::{InitFeatures, NodeFeatures};
2424
use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
2525
use crate::ln::onion_utils;
2626
use crate::routing::gossip::{NetworkGraph, NodeId, ReadOnlyNetworkGraph};
27-
use super::async_payments::{AsyncPaymentsMessage, AsyncPaymentsMessageHandler};
27+
use super::async_payments::AsyncPaymentsMessageHandler;
28+
#[cfg(async_payments)]
29+
use super::async_payments::AsyncPaymentsMessage;
2830
use super::packet::OnionMessageContents;
2931
use super::packet::ParsedOnionMessageContents;
3032
use super::offers::OffersMessageHandler;
@@ -254,6 +256,7 @@ pub struct OnionMessenger<
254256
node_id_lookup: NL,
255257
message_router: MR,
256258
offers_handler: OMH,
259+
#[allow(unused)]
257260
async_payments_handler: APH,
258261
custom_handler: CMH,
259262
intercept_messages_for_offline_peers: bool,
@@ -1444,12 +1447,14 @@ where
14441447
let response_instructions = self.offers_handler.handle_message(msg, responder);
14451448
let _ = self.handle_onion_message_response(response_instructions);
14461449
},
1450+
#[cfg(async_payments)]
14471451
ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::HeldHtlcAvailable(msg)) => {
14481452
let response_instructions = self.async_payments_handler.held_htlc_available(
14491453
msg, responder
14501454
);
14511455
let _ = self.handle_onion_message_response(response_instructions);
14521456
},
1457+
#[cfg(async_payments)]
14531458
ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::ReleaseHeldHtlc(msg)) => {
14541459
self.async_payments_handler.release_held_htlc(msg);
14551460
},

lightning/src/onion_message/offers.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::offers::invoice_error::InvoiceError;
1616
use crate::offers::invoice_request::InvoiceRequest;
1717
use crate::offers::invoice::Bolt12Invoice;
1818
use crate::offers::parse::Bolt12ParseError;
19+
#[cfg(async_payments)]
1920
use crate::offers::static_invoice::StaticInvoice;
2021
use crate::onion_message::packet::OnionMessageContents;
2122
use crate::util::logger::Logger;
@@ -30,6 +31,7 @@ use crate::prelude::*;
3031
const INVOICE_REQUEST_TLV_TYPE: u64 = 64;
3132
const INVOICE_TLV_TYPE: u64 = 66;
3233
const INVOICE_ERROR_TLV_TYPE: u64 = 68;
34+
#[cfg(async_payments)]
3335
const STATIC_INVOICE_TLV_TYPE: u64 = 70;
3436

3537
/// A handler for an [`OnionMessage`] containing a BOLT 12 Offers message as its payload.
@@ -74,7 +76,8 @@ pub enum OffersMessage {
7476
/// [`Refund`]: crate::offers::refund::Refund
7577
Invoice(Bolt12Invoice),
7678

77-
/// A `StaticInvoice` sent in response to an [`InvoiceRequest`].
79+
#[cfg(async_payments)]
80+
/// A [`StaticInvoice`] sent in response to an [`InvoiceRequest`].
7881
StaticInvoice(StaticInvoice),
7982

8083
/// An error from handling an [`OffersMessage`].
@@ -87,8 +90,9 @@ impl OffersMessage {
8790
match tlv_type {
8891
INVOICE_REQUEST_TLV_TYPE
8992
| INVOICE_TLV_TYPE
90-
| STATIC_INVOICE_TLV_TYPE
9193
| INVOICE_ERROR_TLV_TYPE => true,
94+
#[cfg(async_payments)]
95+
STATIC_INVOICE_TLV_TYPE => true,
9296
_ => false,
9397
}
9498
}
@@ -97,6 +101,7 @@ impl OffersMessage {
97101
match tlv_type {
98102
INVOICE_REQUEST_TLV_TYPE => Ok(Self::InvoiceRequest(InvoiceRequest::try_from(bytes)?)),
99103
INVOICE_TLV_TYPE => Ok(Self::Invoice(Bolt12Invoice::try_from(bytes)?)),
104+
#[cfg(async_payments)]
100105
STATIC_INVOICE_TLV_TYPE => Ok(Self::StaticInvoice(StaticInvoice::try_from(bytes)?)),
101106
_ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
102107
}
@@ -112,6 +117,7 @@ impl fmt::Debug for OffersMessage {
112117
OffersMessage::Invoice(message) => {
113118
write!(f, "{:?}", message.as_tlv_stream())
114119
}
120+
#[cfg(async_payments)]
115121
OffersMessage::StaticInvoice(message) => {
116122
write!(f, "{:?}", message)
117123
}
@@ -127,6 +133,7 @@ impl OnionMessageContents for OffersMessage {
127133
match self {
128134
OffersMessage::InvoiceRequest(_) => INVOICE_REQUEST_TLV_TYPE,
129135
OffersMessage::Invoice(_) => INVOICE_TLV_TYPE,
136+
#[cfg(async_payments)]
130137
OffersMessage::StaticInvoice(_) => STATIC_INVOICE_TLV_TYPE,
131138
OffersMessage::InvoiceError(_) => INVOICE_ERROR_TLV_TYPE,
132139
}
@@ -135,6 +142,7 @@ impl OnionMessageContents for OffersMessage {
135142
match &self {
136143
OffersMessage::InvoiceRequest(_) => "Invoice Request",
137144
OffersMessage::Invoice(_) => "Invoice",
145+
#[cfg(async_payments)]
138146
OffersMessage::StaticInvoice(_) => "Static Invoice",
139147
OffersMessage::InvoiceError(_) => "Invoice Error",
140148
}
@@ -146,6 +154,7 @@ impl Writeable for OffersMessage {
146154
match self {
147155
OffersMessage::InvoiceRequest(message) => message.write(w),
148156
OffersMessage::Invoice(message) => message.write(w),
157+
#[cfg(async_payments)]
149158
OffersMessage::StaticInvoice(message) => message.write(w),
150159
OffersMessage::InvoiceError(message) => message.write(w),
151160
}

lightning/src/onion_message/packet.rs

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::blinded_path::message::{ForwardTlvs, ReceiveTlvs};
1717
use crate::blinded_path::utils::Padding;
1818
use crate::ln::msgs::DecodeError;
1919
use crate::ln::onion_utils;
20+
#[cfg(async_payments)]
2021
use super::async_payments::AsyncPaymentsMessage;
2122
use super::messenger::CustomOnionMessageHandler;
2223
use super::offers::OffersMessage;
@@ -130,6 +131,7 @@ pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
130131
/// A message related to BOLT 12 Offers.
131132
Offers(OffersMessage),
132133
/// A message related to async payments.
134+
#[cfg(async_payments)]
133135
AsyncPayments(AsyncPaymentsMessage),
134136
/// A custom onion message specified by the user.
135137
Custom(T),
@@ -142,13 +144,15 @@ impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContent
142144
fn tlv_type(&self) -> u64 {
143145
match self {
144146
&ParsedOnionMessageContents::Offers(ref msg) => msg.tlv_type(),
147+
#[cfg(async_payments)]
145148
&ParsedOnionMessageContents::AsyncPayments(ref msg) => msg.tlv_type(),
146149
&ParsedOnionMessageContents::Custom(ref msg) => msg.tlv_type(),
147150
}
148151
}
149152
fn msg_type(&self) -> &'static str {
150153
match self {
151154
ParsedOnionMessageContents::Offers(ref msg) => msg.msg_type(),
155+
#[cfg(async_payments)]
152156
ParsedOnionMessageContents::AsyncPayments(ref msg) => msg.msg_type(),
153157
ParsedOnionMessageContents::Custom(ref msg) => msg.msg_type(),
154158
}
@@ -159,6 +163,7 @@ impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
159163
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
160164
match self {
161165
ParsedOnionMessageContents::Offers(msg) => Ok(msg.write(w)?),
166+
#[cfg(async_payments)]
162167
ParsedOnionMessageContents::AsyncPayments(msg) => Ok(msg.write(w)?),
163168
ParsedOnionMessageContents::Custom(msg) => Ok(msg.write(w)?),
164169
}
@@ -261,6 +266,7 @@ for Payload<ParsedOnionMessageContents<<H as CustomOnionMessageHandler>::CustomM
261266
message = Some(ParsedOnionMessageContents::Offers(msg));
262267
Ok(true)
263268
},
269+
#[cfg(async_payments)]
264270
tlv_type if AsyncPaymentsMessage::is_known_type(tlv_type) => {
265271
let msg = AsyncPaymentsMessage::read(msg_reader, tlv_type)?;
266272
message = Some(ParsedOnionMessageContents::AsyncPayments(msg));

0 commit comments

Comments
 (0)