Skip to content

Commit

Permalink
Use structured logging where appropriate in OnionMessenger
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Feb 13, 2024
1 parent 974aa69 commit b047c4c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lightning/src/onion_message/messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::packet::OnionMessageContents;
use super::packet::ParsedOnionMessageContents;
use super::offers::OffersMessageHandler;
use super::packet::{BIG_PACKET_HOP_DATA_LEN, ForwardControlTlvs, Packet, Payload, ReceiveControlTlvs, SMALL_PACKET_HOP_DATA_LEN};
use crate::util::logger::Logger;
use crate::util::logger::{Logger, WithContext};
use crate::util::ser::Writeable;

use core::fmt;
Expand Down Expand Up @@ -753,7 +753,8 @@ where
},
Ok(SendSuccess::BufferedAwaitingConnection(node_id)) => {
log_trace!(
self.logger, "Buffered onion message waiting on peer connection {}: {}",
WithContext::from(&self.logger, Some(*node_id), None),
"Buffered onion message waiting on peer connection {}: {}",
log_suffix, node_id
);
},
Expand Down Expand Up @@ -912,12 +913,13 @@ where
OMH::Target: OffersMessageHandler,
CMH::Target: CustomOnionMessageHandler,
{
fn handle_onion_message(&self, _peer_node_id: &PublicKey, msg: &OnionMessage) {
fn handle_onion_message(&self, peer_node_id: &PublicKey, msg: &OnionMessage) {
let logger = WithContext::from(&self.logger, Some(*peer_node_id), None);
match self.peel_onion_message(msg) {
Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
log_trace!(
self.logger,
"Received an onion message with path_id {:02x?} and {} reply_path: {:?}",
logger,
"Received an onion message with path_id {:02x?} and {} reply_path: {:?}",
path_id, if reply_path.is_some() { "a" } else { "no" }, message);

match message {
Expand All @@ -944,7 +946,10 @@ where
Ok(PeeledOnion::Forward(next_node_id, onion_message)) => {
let mut message_recipients = self.message_recipients.lock().unwrap();
if outbound_buffer_full(&next_node_id, &message_recipients) {
log_trace!(self.logger, "Dropping forwarded onion message to peer {}: outbound buffer full", next_node_id);
log_trace!(
logger,
"Dropping forwarded onion message to peer {}: outbound buffer full",
next_node_id);
return
}

Expand All @@ -958,16 +963,19 @@ where
e.get(), OnionMessageRecipient::ConnectedPeer(..)
) => {
e.get_mut().enqueue_message(onion_message);
log_trace!(self.logger, "Forwarding an onion message to peer {}", next_node_id);
log_trace!(logger, "Forwarding an onion message to peer {}", next_node_id);
},
_ => {
log_trace!(self.logger, "Dropping forwarded onion message to disconnected peer {}", next_node_id);
log_trace!(
logger,
"Dropping forwarded onion message to disconnected peer {}",
next_node_id);
return
},
}
},
Err(e) => {
log_error!(self.logger, "Failed to process onion message {:?}", e);
log_error!(logger, "Failed to process onion message {:?}", e);
}
}
}
Expand Down

0 comments on commit b047c4c

Please sign in to comment.