Skip to content

Commit 242e6ae

Browse files
authored
Merge pull request lightningdevkit#2642 from Sharmalm/2346
logging every sent receive onion message
2 parents 12c2086 + ff5e522 commit 242e6ae

File tree

8 files changed

+38
-17
lines changed

8 files changed

+38
-17
lines changed

fuzz/src/onion_message.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl OffersMessageHandler for TestOffersMessageHandler {
9191
}
9292
}
9393

94+
#[derive(Debug)]
9495
struct TestCustomMessage {}
9596

9697
const CUSTOM_MESSAGE_TYPE: u64 = 4242;
@@ -265,9 +266,10 @@ mod tests {
265266
{
266267
let log_entries = logger.lines.lock().unwrap();
267268
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
268-
"Received an onion message with path_id None and a reply_path".to_string())), Some(&1));
269+
"Received an onion message with path_id None and a reply_path: Custom(TestCustomMessage)"
270+
.to_string())), Some(&1));
269271
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
270-
"Sending onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
272+
"Sending onion message: TestCustomMessage".to_string())), Some(&1));
271273
}
272274

273275
let two_unblinded_hops_om = "\

lightning/src/offers/invoice.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,7 @@ impl Bolt12Invoice {
720720
self.contents.verify(TlvStream::new(&self.bytes), key, secp_ctx)
721721
}
722722

723-
#[cfg(test)]
724-
pub(super) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
723+
pub(crate) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
725724
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream) =
726725
self.contents.as_tlv_stream();
727726
let signature_tlv_stream = SignatureTlvStreamRef {
@@ -1143,7 +1142,6 @@ impl_writeable!(FallbackAddress, { version, program });
11431142
type FullInvoiceTlvStream =
11441143
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, InvoiceTlvStream, SignatureTlvStream);
11451144

1146-
#[cfg(test)]
11471145
type FullInvoiceTlvStreamRef<'a> = (
11481146
PayerTlvStreamRef<'a>,
11491147
OfferTlvStreamRef<'a>,

lightning/src/offers/invoice_request.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,7 @@ impl InvoiceRequest {
608608
})
609609
}
610610

611-
#[cfg(test)]
612-
fn as_tlv_stream(&self) -> FullInvoiceRequestTlvStreamRef {
611+
pub(crate) fn as_tlv_stream(&self) -> FullInvoiceRequestTlvStreamRef {
613612
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream) =
614613
self.contents.as_tlv_stream();
615614
let signature_tlv_stream = SignatureTlvStreamRef {
@@ -811,7 +810,6 @@ tlv_stream!(InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef, INVOICE_REQUEST
811810
type FullInvoiceRequestTlvStream =
812811
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, SignatureTlvStream);
813812

814-
#[cfg(test)]
815813
type FullInvoiceRequestTlvStreamRef<'a> = (
816814
PayerTlvStreamRef<'a>,
817815
OfferTlvStreamRef<'a>,

lightning/src/onion_message/functional_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ fn reply_path() {
381381
fn invalid_custom_message_type() {
382382
let nodes = create_nodes(2);
383383

384+
#[derive(Debug)]
384385
struct InvalidCustomMessage{}
385386
impl OnionMessageContents for InvalidCustomMessage {
386387
fn tlv_type(&self) -> u64 {

lightning/src/onion_message/messenger.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use crate::prelude::*;
7171
/// # use std::sync::Arc;
7272
/// # struct FakeLogger;
7373
/// # impl Logger for FakeLogger {
74-
/// # fn log(&self, record: Record) { unimplemented!() }
74+
/// # fn log(&self, record: Record) { println!("{:?}" , record); }
7575
/// # }
7676
/// # struct FakeMessageRouter {}
7777
/// # impl MessageRouter for FakeMessageRouter {
@@ -97,7 +97,8 @@ use crate::prelude::*;
9797
/// &keys_manager, &keys_manager, logger, message_router, &offers_message_handler,
9898
/// &custom_message_handler
9999
/// );
100-
///
100+
101+
/// # #[derive(Debug)]
101102
/// # struct YourCustomMessage {}
102103
/// impl Writeable for YourCustomMessage {
103104
/// fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
@@ -517,6 +518,9 @@ where
517518
pub fn send_onion_message<T: OnionMessageContents>(
518519
&self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>
519520
) -> Result<(), SendError> {
521+
522+
log_trace!(self.logger, "Sending onion message: {:?}", contents);
523+
520524
let (first_node_id, onion_msg) = create_onion_message(
521525
&self.entropy_source, &self.node_signer, &self.secp_ctx, path, contents, reply_path
522526
)?;
@@ -570,7 +574,7 @@ where
570574
},
571575
};
572576

573-
log_trace!(self.logger, "Sending onion message {}", log_suffix);
577+
log_trace!(self.logger, "Sending onion message {}: {:?}", log_suffix, contents);
574578

575579
if let Err(e) = self.send_onion_message(path, contents, reply_path) {
576580
log_trace!(self.logger, "Failed sending onion message {}: {:?}", log_suffix, e);
@@ -629,9 +633,10 @@ where
629633
msg, &self.secp_ctx, &*self.node_signer, &*self.logger, &*self.custom_handler
630634
) {
631635
Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
632-
log_trace!(self.logger,
633-
"Received an onion message with path_id {:02x?} and {} reply_path",
634-
path_id, if reply_path.is_some() { "a" } else { "no" });
636+
log_trace!(
637+
self.logger,
638+
"Received an onion message with path_id {:02x?} and {} reply_path: {:?}",
639+
path_id, if reply_path.is_some() { "a" } else { "no" }, message);
635640

636641
match message {
637642
ParsedOnionMessageContents::Offers(msg) => {

lightning/src/onion_message/offers.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! Message handling for BOLT 12 Offers.
1111
1212
use core::convert::TryFrom;
13+
use core::fmt;
1314
use crate::io::{self, Read};
1415
use crate::ln::msgs::DecodeError;
1516
use crate::offers::invoice_error::InvoiceError;
@@ -58,7 +59,7 @@ pub trait OffersMessageHandler {
5859
/// Possible BOLT 12 Offers messages sent and received via an [`OnionMessage`].
5960
///
6061
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
61-
#[derive(Clone, Debug)]
62+
#[derive(Clone)]
6263
pub enum OffersMessage {
6364
/// A request for a [`Bolt12Invoice`] for a particular [`Offer`].
6465
///
@@ -92,6 +93,22 @@ impl OffersMessage {
9293
}
9394
}
9495

96+
impl fmt::Debug for OffersMessage {
97+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98+
match self {
99+
OffersMessage::InvoiceRequest(message) => {
100+
write!(f, "{:?}", message.as_tlv_stream())
101+
}
102+
OffersMessage::Invoice(message) => {
103+
write!(f, "{:?}", message.as_tlv_stream())
104+
}
105+
OffersMessage::InvoiceError(message) => {
106+
write!(f, "{:?}", message)
107+
}
108+
}
109+
}
110+
}
111+
95112
impl OnionMessageContents for OffersMessage {
96113
fn tlv_type(&self) -> u64 {
97114
match self {

lightning/src/onion_message/packet.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
147147
}
148148

149149
/// The contents of an onion message.
150-
pub trait OnionMessageContents: Writeable {
150+
pub trait OnionMessageContents: Writeable + core::fmt::Debug {
151151
/// Returns the TLV type identifying the message contents. MUST be >= 64.
152152
fn tlv_type(&self) -> u64;
153153
}

lightning/src/util/ser_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ macro_rules! tlv_stream {
917917

918918
#[cfg_attr(test, derive(PartialEq))]
919919
#[derive(Debug)]
920-
pub(super) struct $nameref<'a> {
920+
pub(crate) struct $nameref<'a> {
921921
$(
922922
pub(super) $field: Option<tlv_record_ref_type!($fieldty)>,
923923
)*

0 commit comments

Comments
 (0)