Skip to content

Commit 84067e0

Browse files
committed
Rebasing commits
logging every sent receive onion message adding fmt display in logging adding fmt display in logging resolving conflict resolving conflict_2 adding logging after resolved conflict implemented debug in offer struct solving CI checks errors fixing CI/CD errors fixing problems from reviews fixing doc test improved minor changes
1 parent d2242f6 commit 84067e0

File tree

6 files changed

+53
-21
lines changed

6 files changed

+53
-21
lines changed

lightning/src/offers/invoice.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ impl Bolt12Invoice {
718718
self.contents.verify(TlvStream::new(&self.bytes), key, secp_ctx)
719719
}
720720

721-
#[cfg(test)]
722-
pub(super) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
721+
pub(crate) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
723722
let (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, invoice_tlv_stream) =
724723
self.contents.as_tlv_stream();
725724
let signature_tlv_stream = SignatureTlvStreamRef {
@@ -1153,7 +1152,6 @@ impl_writeable!(FallbackAddress, { version, program });
11531152
type FullInvoiceTlvStream =
11541153
(PayerTlvStream, OfferTlvStream, InvoiceRequestTlvStream, InvoiceTlvStream, SignatureTlvStream);
11551154

1156-
#[cfg(test)]
11571155
type FullInvoiceTlvStreamRef<'a> = (
11581156
PayerTlvStreamRef<'a>,
11591157
OfferTlvStreamRef<'a>,

lightning/src/offers/invoice_request.rs

Lines changed: 1 addition & 3 deletions
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/messenger.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use crate::prelude::*;
7070
/// # use std::sync::Arc;
7171
/// # struct FakeLogger;
7272
/// # impl Logger for FakeLogger {
73-
/// # fn log(&self, record: &Record) { unimplemented!() }
73+
/// # fn log(&self, record: &Record) { println!("{:?}" , record); }
7474
/// # }
7575
/// # struct FakeMessageRouter {}
7676
/// # impl MessageRouter for FakeMessageRouter {
@@ -516,8 +516,12 @@ where
516516
pub fn send_onion_message<T: OnionMessageContents>(
517517
&self, path: OnionMessagePath, contents: T, reply_path: Option<BlindedPath>
518518
) -> Result<(), SendError> {
519-
let (first_node_id, onion_msg) = create_onion_message(
520-
&self.entropy_source, &self.node_signer, &self.secp_ctx, path, contents, reply_path
519+
520+
log_trace!(self.logger, "Sending onion message: {:?}", message);
521+
522+
let (introduction_node_id, onion_msg) = create_onion_message(
523+
&self.entropy_source, &self.node_signer, &self.secp_ctx,
524+
path, message, reply_path
521525
)?;
522526

523527
let mut pending_per_peer_msgs = self.pending_messages.lock().unwrap();
@@ -569,7 +573,7 @@ where
569573
},
570574
};
571575

572-
log_trace!(self.logger, "Sending onion message {}", log_suffix);
576+
log_trace!(self.logger, "Responding to onion message {:?} with path_id {:02x?}", response, path_id);
573577

574578
if let Err(e) = self.send_onion_message(path, contents, reply_path) {
575579
log_trace!(self.logger, "Failed sending onion message {}: {:?}", log_suffix, e);
@@ -627,9 +631,11 @@ where
627631
match peel_onion_message(
628632
msg, &self.secp_ctx, &*self.node_signer, &*self.logger, &*self.custom_handler
629633
) {
630-
Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
634+
Ok((Payload::Receive::<<<CMH as Deref>::Target as CustomOnionMessageHandler>::CustomMessage> {
635+
message, control_tlvs: ReceiveControlTlvs::Unblinded(ReceiveTlvs { path_id }), reply_path,
636+
}, None)) => {
631637
log_trace!(self.logger,
632-
"Received an onion message with path_id {:02x?} and {} reply_path",
638+
"Received an onion message {:?} with path_id {:02x?} and {} reply_path", message,
633639
path_id, if reply_path.is_some() { "a" } else { "no" });
634640

635641
match message {

lightning/src/onion_message/offers.rs

Lines changed: 18 additions & 1 deletion
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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::util::chacha20poly1305rfc::{ChaChaPolyReadAdapter, ChaChaPolyWriteAda
2323
use crate::util::logger::Logger;
2424
use crate::util::ser::{BigSize, FixedLengthReader, LengthRead, LengthReadable, LengthReadableArgs, Readable, ReadableArgs, Writeable, Writer};
2525

26-
use core::cmp;
26+
use core::{cmp, fmt};
2727
use crate::io::{self, Read};
2828
use crate::prelude::*;
2929

@@ -114,11 +114,10 @@ pub(super) enum Payload<T: OnionMessageContents> {
114114
}
115115
}
116116

117-
/// The contents of an [`OnionMessage`] as read from the wire.
118-
///
119-
/// [`OnionMessage`]: crate::ln::msgs::OnionMessage
120-
#[derive(Debug)]
121-
pub enum ParsedOnionMessageContents<T: OnionMessageContents> {
117+
// #[derive(Debug)]
118+
/// The contents of an onion message. In the context of offers, this would be the invoice, invoice
119+
/// request, or invoice error.
120+
pub enum OnionMessageContents<T: CustomOnionMessageContents> {
122121
/// A message related to BOLT 12 Offers.
123122
Offers(OffersMessage),
124123
/// A custom onion message specified by the user.
@@ -137,7 +136,21 @@ impl<T: OnionMessageContents> OnionMessageContents for ParsedOnionMessageContent
137136
}
138137
}
139138

140-
impl<T: OnionMessageContents> Writeable for ParsedOnionMessageContents<T> {
139+
impl<T: CustomOnionMessageContents> fmt::Debug for OnionMessageContents<T> {
140+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
141+
match self {
142+
OnionMessageContents::Offers(ref msg) => {
143+
write!(f, " (Offers): {:?}", msg)
144+
}
145+
OnionMessageContents::Custom(ref msg) => {
146+
write!(f, " (Custom) : {}", msg.tlv_type())
147+
}
148+
}
149+
}
150+
}
151+
152+
/// This is not exported to bindings users as methods on non-cloneable enums are not currently exportable
153+
impl<T: CustomOnionMessageContents> Writeable for OnionMessageContents<T> {
141154
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
142155
match self {
143156
ParsedOnionMessageContents::Offers(msg) => Ok(msg.write(w)?),

lightning/src/util/ser_macros.rs

Lines changed: 1 addition & 1 deletion
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)