Skip to content

Commit

Permalink
Add peer_id and channel_id explicitly to log records
Browse files Browse the repository at this point in the history
Adds Context logging alongside Default logging as
an alternative to enable compiler recommendations for
adding extra context (peer_id and channel_id) to
log records
  • Loading branch information
henghonglee committed Jun 6, 2023
1 parent 486c16a commit da9f77c
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 288 deletions.
2 changes: 1 addition & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extern crate core;
#[cfg(not(feature = "std"))]
extern crate alloc;

#[macro_use] extern crate lightning;
extern crate lightning_rapid_gossip_sync;

use lightning::chain;
Expand All @@ -37,6 +36,7 @@ use lightning::routing::router::Router;
use lightning::routing::scoring::{Score, WriteableScore};
use lightning::util::logger::Logger;
use lightning::util::persist::Persister;
use lightning::{_log_error as log_error, _log_trace as log_trace};
#[cfg(feature = "std")]
use lightning::util::wakers::Sleeper;
use lightning_rapid_gossip_sync::RapidGossipSync;
Expand Down
28 changes: 14 additions & 14 deletions lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use lightning::ln::inbound_payment::{create, create_from_hash, ExpandedKey};
use lightning::routing::gossip::RoutingFees;
use lightning::routing::router::{RouteHint, RouteHintHop, Router};
use lightning::util::logger::Logger;
use lightning::_log_trace_with_context as log_trace;
use secp256k1::PublicKey;
use core::ops::Deref;
use core::time::Duration;
Expand Down Expand Up @@ -189,8 +190,7 @@ where
)
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
};

log_trace!(logger, "Creating phantom invoice from {} participating nodes with payment hash {}",
log_trace!(logger, None, None, "Creating phantom invoice from {} participating nodes with payment hash {}",
phantom_route_hints.len(), log_bytes!(payment_hash.0));

let mut invoice = invoice
Expand Down Expand Up @@ -240,7 +240,7 @@ where
let mut phantom_hints: Vec<_> = Vec::new();

for PhantomRouteHints { channels, phantom_scid, real_node_pubkey } in phantom_route_hints {
log_trace!(logger, "Generating phantom route hints for node {}",
log_trace!(logger, None, None, "Generating phantom route hints for node {}",
log_pubkey!(real_node_pubkey));
let route_hints = sort_and_filter_channels(channels, amt_msat, &logger);

Expand Down Expand Up @@ -534,7 +534,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
return Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort));
}

log_trace!(logger, "Creating invoice with payment hash {}", log_bytes!(payment_hash.0));
log_trace!(logger, None, None, "Creating invoice with payment hash {}", log_bytes!(payment_hash.0));

let invoice = match description {
InvoiceDescription::Direct(description) => {
Expand Down Expand Up @@ -624,10 +624,10 @@ where
htlc_maximum_msat: channel.inbound_htlc_maximum_msat,}])
};

log_trace!(logger, "Considering {} channels for invoice route hints", channels.len());
log_trace!(logger, None, None, "Considering {} channels for invoice route hints", channels.len());
for channel in channels.into_iter().filter(|chan| chan.is_channel_ready) {
if channel.get_inbound_payment_scid().is_none() || channel.counterparty.forwarding_info.is_none() {
log_trace!(logger, "Ignoring channel {} for invoice route hints", log_bytes!(channel.channel_id));
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Ignoring channel {} for invoice route hints", log_bytes!(channel.channel_id));
continue;
}

Expand All @@ -640,15 +640,15 @@ where
} else {
// If any public channel exists, return no hints and let the sender
// look at the public channels instead.
log_trace!(logger, "Not including channels in invoice route hints on account of public channel {}",
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Not including channels in invoice route hints on account of public channel {}",
log_bytes!(channel.channel_id));
return vec![].into_iter().take(MAX_CHANNEL_HINTS).map(route_hint_from_channel);
}
}

if channel.inbound_capacity_msat >= min_inbound_capacity {
if !min_capacity_channel_exists {
log_trace!(logger, "Channel with enough inbound capacity exists for invoice route hints");
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Channel with enough inbound capacity exists for invoice route hints");
min_capacity_channel_exists = true;
}

Expand All @@ -658,7 +658,7 @@ where
}

if channel.is_usable && !online_channel_exists {
log_trace!(logger, "Channel with connected peer exists for invoice route hints");
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Channel with connected peer exists for invoice route hints");
online_channel_exists = true;
}

Expand All @@ -678,7 +678,7 @@ where
let new_channel_preferable = channel.is_public == entry.get().is_public && !prefer_current;

if new_now_public || new_channel_preferable {
log_trace!(logger,
log_trace!(logger, None, None,
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
log_pubkey!(channel.counterparty.node_id),
log_bytes!(channel.channel_id), channel.short_channel_id,
Expand All @@ -687,7 +687,7 @@ where
current_max_capacity);
entry.insert(channel);
} else {
log_trace!(logger,
log_trace!(logger, None, None,
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
log_pubkey!(channel.counterparty.node_id),
log_bytes!(entry.get().channel_id), entry.get().short_channel_id,
Expand Down Expand Up @@ -730,14 +730,14 @@ where
} else { true };

if include_channel {
log_trace!(logger, "Including channel {} in invoice route hints",
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Including channel {} in invoice route hints",
log_bytes!(channel.channel_id));
} else if !has_enough_capacity {
log_trace!(logger, "Ignoring channel {} without enough capacity for invoice route hints",
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Ignoring channel {} without enough capacity for invoice route hints",
log_bytes!(channel.channel_id));
} else {
debug_assert!(!channel.is_usable || (has_pub_unconf_chan && !channel.is_public));
log_trace!(logger, "Ignoring channel {} with disconnected peer",
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Ignoring channel {} with disconnected peer",
log_bytes!(channel.channel_id));
}

Expand Down
3 changes: 2 additions & 1 deletion lightning-rapid-gossip-sync/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use lightning::ln::msgs::{
};
use lightning::routing::gossip::NetworkGraph;
use lightning::util::logger::Logger;
use lightning::{log_debug, log_warn, log_trace, log_given_level, log_gossip};

use lightning::{_log_debug as log_debug, _log_trace as log_trace, _log_warn as log_warn, _log_gossip as log_gossip, _log_given_level as log_given_level};
use lightning::util::ser::{BigSize, Readable};
use lightning::io;

Expand Down
2 changes: 1 addition & 1 deletion lightning-transaction-sync/src/esplora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::error::{TxSyncError, InternalError};
use crate::common::{SyncState, FilterQueue, ConfirmedTx};

use lightning::util::logger::Logger;
use lightning::{log_error, log_info, log_debug, log_trace};
use lightning::{_log_info as log_info, _log_debug as log_debug, _log_error as log_error ,_log_trace as log_trace};
use lightning::chain::WatchedOutput;
use lightning::chain::{Confirm, Filter};

Expand Down
2 changes: 2 additions & 0 deletions lightning/src/chain/chainmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ use core::ops::Deref;
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use bitcoin::secp256k1::PublicKey;

use crate::util::macro_logger::default_logging::*;

#[derive(Clone, Copy, Hash, PartialEq, Eq)]
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
/// entirely opaque.
Expand Down
Loading

0 comments on commit da9f77c

Please sign in to comment.