Skip to content

Commit da9f77c

Browse files
committed
Add peer_id and channel_id explicitly to log records
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
1 parent 486c16a commit da9f77c

File tree

20 files changed

+450
-288
lines changed

20 files changed

+450
-288
lines changed

lightning-background-processor/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extern crate core;
1919
#[cfg(not(feature = "std"))]
2020
extern crate alloc;
2121

22-
#[macro_use] extern crate lightning;
2322
extern crate lightning_rapid_gossip_sync;
2423

2524
use lightning::chain;
@@ -37,6 +36,7 @@ use lightning::routing::router::Router;
3736
use lightning::routing::scoring::{Score, WriteableScore};
3837
use lightning::util::logger::Logger;
3938
use lightning::util::persist::Persister;
39+
use lightning::{_log_error as log_error, _log_trace as log_trace};
4040
#[cfg(feature = "std")]
4141
use lightning::util::wakers::Sleeper;
4242
use lightning_rapid_gossip_sync::RapidGossipSync;

lightning-invoice/src/utils.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use lightning::ln::inbound_payment::{create, create_from_hash, ExpandedKey};
1515
use lightning::routing::gossip::RoutingFees;
1616
use lightning::routing::router::{RouteHint, RouteHintHop, Router};
1717
use lightning::util::logger::Logger;
18+
use lightning::_log_trace_with_context as log_trace;
1819
use secp256k1::PublicKey;
1920
use core::ops::Deref;
2021
use core::time::Duration;
@@ -189,8 +190,7 @@ where
189190
)
190191
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
191192
};
192-
193-
log_trace!(logger, "Creating phantom invoice from {} participating nodes with payment hash {}",
193+
log_trace!(logger, None, None, "Creating phantom invoice from {} participating nodes with payment hash {}",
194194
phantom_route_hints.len(), log_bytes!(payment_hash.0));
195195

196196
let mut invoice = invoice
@@ -240,7 +240,7 @@ where
240240
let mut phantom_hints: Vec<_> = Vec::new();
241241

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

@@ -534,7 +534,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
534534
return Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort));
535535
}
536536

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

539539
let invoice = match description {
540540
InvoiceDescription::Direct(description) => {
@@ -624,10 +624,10 @@ where
624624
htlc_maximum_msat: channel.inbound_htlc_maximum_msat,}])
625625
};
626626

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

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

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

@@ -658,7 +658,7 @@ where
658658
}
659659

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

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

680680
if new_now_public || new_channel_preferable {
681-
log_trace!(logger,
681+
log_trace!(logger, None, None,
682682
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
683683
log_pubkey!(channel.counterparty.node_id),
684684
log_bytes!(channel.channel_id), channel.short_channel_id,
@@ -687,7 +687,7 @@ where
687687
current_max_capacity);
688688
entry.insert(channel);
689689
} else {
690-
log_trace!(logger,
690+
log_trace!(logger, None, None,
691691
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
692692
log_pubkey!(channel.counterparty.node_id),
693693
log_bytes!(entry.get().channel_id), entry.get().short_channel_id,
@@ -730,14 +730,14 @@ where
730730
} else { true };
731731

732732
if include_channel {
733-
log_trace!(logger, "Including channel {} in invoice route hints",
733+
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Including channel {} in invoice route hints",
734734
log_bytes!(channel.channel_id));
735735
} else if !has_enough_capacity {
736-
log_trace!(logger, "Ignoring channel {} without enough capacity for invoice route hints",
736+
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Ignoring channel {} without enough capacity for invoice route hints",
737737
log_bytes!(channel.channel_id));
738738
} else {
739739
debug_assert!(!channel.is_usable || (has_pub_unconf_chan && !channel.is_public));
740-
log_trace!(logger, "Ignoring channel {} with disconnected peer",
740+
log_trace!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "Ignoring channel {} with disconnected peer",
741741
log_bytes!(channel.channel_id));
742742
}
743743

lightning-rapid-gossip-sync/src/processing.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use lightning::ln::msgs::{
1010
};
1111
use lightning::routing::gossip::NetworkGraph;
1212
use lightning::util::logger::Logger;
13-
use lightning::{log_debug, log_warn, log_trace, log_given_level, log_gossip};
13+
14+
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};
1415
use lightning::util::ser::{BigSize, Readable};
1516
use lightning::io;
1617

lightning-transaction-sync/src/esplora.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::error::{TxSyncError, InternalError};
22
use crate::common::{SyncState, FilterQueue, ConfirmedTx};
33

44
use lightning::util::logger::Logger;
5-
use lightning::{log_error, log_info, log_debug, log_trace};
5+
use lightning::{_log_info as log_info, _log_debug as log_debug, _log_error as log_error ,_log_trace as log_trace};
66
use lightning::chain::WatchedOutput;
77
use lightning::chain::{Confirm, Filter};
88

lightning/src/chain/chainmonitor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ use core::ops::Deref;
4646
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
4747
use bitcoin::secp256k1::PublicKey;
4848

49+
use crate::util::macro_logger::default_logging::*;
50+
4951
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
5052
/// A specific update's ID stored in a `MonitorUpdateId`, separated out to make the contents
5153
/// entirely opaque.

0 commit comments

Comments
 (0)