Skip to content

Commit 66313f7

Browse files
committed
Changes to logger and macro logger
1 parent 6775b95 commit 66313f7

File tree

20 files changed

+513
-508
lines changed

20 files changed

+513
-508
lines changed

lightning-background-processor/src/lib.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ macro_rules! define_run_body {
272272
$loop_exit_check: expr, $await: expr, $get_timer: expr, $timer_elapsed: expr,
273273
$check_slow_await: expr)
274274
=> { {
275-
log_trace!($logger, "Calling ChannelManager's timer_tick_occurred on startup");
275+
log_trace!($logger, None, None, "Calling ChannelManager's timer_tick_occurred on startup");
276276
$channel_manager.timer_tick_occurred();
277-
log_trace!($logger, "Rebroadcasting monitor's pending claims on startup");
277+
log_trace!($logger, None, None, "Rebroadcasting monitor's pending claims on startup");
278278
$chain_monitor.rebroadcast_pending_claims();
279279

280280
let mut last_freshness_call = $get_timer(FRESHNESS_TIMER);
@@ -303,7 +303,7 @@ macro_rules! define_run_body {
303303

304304
// Exit the loop if the background processor was requested to stop.
305305
if $loop_exit_check {
306-
log_trace!($logger, "Terminating background processor.");
306+
log_trace!($logger, None, None, "Terminating background processor.");
307307
break;
308308
}
309309

@@ -316,17 +316,17 @@ macro_rules! define_run_body {
316316

317317
// Exit the loop if the background processor was requested to stop.
318318
if $loop_exit_check {
319-
log_trace!($logger, "Terminating background processor.");
319+
log_trace!($logger, None, None, "Terminating background processor.");
320320
break;
321321
}
322322

323323
if updates_available {
324-
log_trace!($logger, "Persisting ChannelManager...");
324+
log_trace!($logger, None, None, "Persisting ChannelManager...");
325325
$persister.persist_manager(&*$channel_manager)?;
326-
log_trace!($logger, "Done persisting ChannelManager.");
326+
log_trace!($logger, None, None, "Done persisting ChannelManager.");
327327
}
328328
if $timer_elapsed(&mut last_freshness_call, FRESHNESS_TIMER) {
329-
log_trace!($logger, "Calling ChannelManager's timer_tick_occurred");
329+
log_trace!($logger, None, None, "Calling ChannelManager's timer_tick_occurred");
330330
$channel_manager.timer_tick_occurred();
331331
last_freshness_call = $get_timer(FRESHNESS_TIMER);
332332
}
@@ -343,11 +343,11 @@ macro_rules! define_run_body {
343343
// may call Bitcoin Core RPCs during event handling, which very often takes
344344
// more than a handful of seconds to complete, and shouldn't disconnect all our
345345
// peers.
346-
log_trace!($logger, "100ms sleep took more than a second, disconnecting peers.");
346+
log_trace!($logger, None, None, "100ms sleep took more than a second, disconnecting peers.");
347347
$peer_manager.as_ref().disconnect_all_peers();
348348
last_ping_call = $get_timer(PING_TIMER);
349349
} else if $timer_elapsed(&mut last_ping_call, PING_TIMER) {
350-
log_trace!($logger, "Calling PeerManager's timer_tick_occurred");
350+
log_trace!($logger, None, None, "Calling PeerManager's timer_tick_occurred");
351351
$peer_manager.as_ref().timer_tick_occurred();
352352
last_ping_call = $get_timer(PING_TIMER);
353353
}
@@ -367,16 +367,16 @@ macro_rules! define_run_body {
367367
// The network graph must not be pruned while rapid sync completion is pending
368368
if let Some(network_graph) = $gossip_sync.prunable_network_graph() {
369369
#[cfg(feature = "std")] {
370-
log_trace!($logger, "Pruning and persisting network graph.");
370+
log_trace!($logger, None, None, "Pruning and persisting network graph.");
371371
network_graph.remove_stale_channels_and_tracking();
372372
}
373373
#[cfg(not(feature = "std"))] {
374-
log_warn!($logger, "Not pruning network graph, consider enabling `std` or doing so manually with remove_stale_channels_and_tracking_with_time.");
375-
log_trace!($logger, "Persisting network graph.");
374+
log_warn!($logger, None, None, "Not pruning network graph, consider enabling `std` or doing so manually with remove_stale_channels_and_tracking_with_time.");
375+
log_trace!($logger, None, None, "Persisting network graph.");
376376
}
377377

378378
if let Err(e) = $persister.persist_graph(network_graph) {
379-
log_error!($logger, "Error: Failed to persist network graph, check your disk and permissions {}", e)
379+
log_error!($logger, None, None, "Error: Failed to persist network graph, check your disk and permissions {}", e)
380380
}
381381

382382
have_pruned = true;
@@ -387,16 +387,16 @@ macro_rules! define_run_body {
387387

388388
if $timer_elapsed(&mut last_scorer_persist_call, SCORER_PERSIST_TIMER) {
389389
if let Some(ref scorer) = $scorer {
390-
log_trace!($logger, "Persisting scorer");
390+
log_trace!($logger, None, None, "Persisting scorer");
391391
if let Err(e) = $persister.persist_scorer(&scorer) {
392-
log_error!($logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
392+
log_error!($logger, None, None, "Error: Failed to persist scorer, check your disk and permissions {}", e)
393393
}
394394
}
395395
last_scorer_persist_call = $get_timer(SCORER_PERSIST_TIMER);
396396
}
397397

398398
if $timer_elapsed(&mut last_rebroadcast_call, REBROADCAST_TIMER) {
399-
log_trace!($logger, "Rebroadcasting monitor's pending claims");
399+
log_trace!($logger, None, None, "Rebroadcasting monitor's pending claims");
400400
$chain_monitor.rebroadcast_pending_claims();
401401
last_rebroadcast_call = $get_timer(REBROADCAST_TIMER);
402402
}
@@ -633,9 +633,9 @@ where
633633
}
634634
if let Some(ref scorer) = scorer {
635635
if update_scorer(scorer, &event) {
636-
log_trace!(logger, "Persisting scorer after update");
636+
log_trace!(logger, None, None, "Persisting scorer after update");
637637
if let Err(e) = persister.persist_scorer(&scorer) {
638-
log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
638+
log_error!(logger, None, None, "Error: Failed to persist scorer, check your disk and permissions {}", e)
639639
}
640640
}
641641
}
@@ -768,9 +768,9 @@ impl BackgroundProcessor {
768768
}
769769
if let Some(ref scorer) = scorer {
770770
if update_scorer(scorer, &event) {
771-
log_trace!(logger, "Persisting scorer after update");
771+
log_trace!(logger, None, None, "Persisting scorer after update");
772772
if let Err(e) = persister.persist_scorer(&scorer) {
773-
log_error!(logger, "Error: Failed to persist scorer, check your disk and permissions {}", e)
773+
log_error!(logger, None, None, "Error: Failed to persist scorer, check your disk and permissions {}", e)
774774
}
775775
}
776776
}

lightning-invoice/src/utils.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +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 secp256k1::PublicKey;
18+
use bitcoin::secp256k1::{PublicKey};
1919
use core::ops::Deref;
2020
use core::time::Duration;
2121

@@ -187,7 +187,7 @@ where
187187
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
188188
};
189189

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

193193
let mut invoice = invoice
@@ -236,7 +236,7 @@ where
236236
let mut phantom_hints: Vec<Vec<RouteHint>> = Vec::new();
237237

238238
for PhantomRouteHints { channels, phantom_scid, real_node_pubkey } in phantom_route_hints {
239-
log_trace!(logger, "Generating phantom route hints for node {}",
239+
log_trace!(logger, None, None, "Generating phantom route hints for node {}",
240240
log_pubkey!(real_node_pubkey));
241241
let mut route_hints = sort_and_filter_channels(channels, amt_msat, &logger);
242242

@@ -513,7 +513,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
513513
return Err(SignOrCreationError::CreationError(CreationError::MinFinalCltvExpiryDeltaTooShort));
514514
}
515515

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

518518
let invoice = match description {
519519
InvoiceDescription::Direct(description) => {
@@ -584,10 +584,10 @@ fn sort_and_filter_channels<L: Deref>(
584584
let mut online_min_capacity_channel_exists = false;
585585
let mut has_pub_unconf_chan = false;
586586

587-
log_trace!(logger, "Considering {} channels for invoice route hints", channels.len());
587+
log_trace!(logger, None, None, "Considering {} channels for invoice route hints", channels.len());
588588
for channel in channels.into_iter().filter(|chan| chan.is_channel_ready) {
589589
if channel.get_inbound_payment_scid().is_none() || channel.counterparty.forwarding_info.is_none() {
590-
log_trace!(logger, "Ignoring channel {} for invoice route hints", log_bytes!(channel.channel_id));
590+
log_trace!(logger, None, None, "Ignoring channel {} for invoice route hints", log_bytes!(channel.channel_id));
591591
continue;
592592
}
593593

@@ -600,15 +600,15 @@ fn sort_and_filter_channels<L: Deref>(
600600
} else {
601601
// If any public channel exists, return no hints and let the sender
602602
// look at the public channels instead.
603-
log_trace!(logger, "Not including channels in invoice route hints on account of public channel {}",
603+
log_trace!(logger, None, None, "Not including channels in invoice route hints on account of public channel {}",
604604
log_bytes!(channel.channel_id));
605605
return vec![]
606606
}
607607
}
608608

609609
if channel.inbound_capacity_msat >= min_inbound_capacity {
610610
if !min_capacity_channel_exists {
611-
log_trace!(logger, "Channel with enough inbound capacity exists for invoice route hints");
611+
log_trace!(logger, None, None, "Channel with enough inbound capacity exists for invoice route hints");
612612
min_capacity_channel_exists = true;
613613
}
614614

@@ -618,7 +618,7 @@ fn sort_and_filter_channels<L: Deref>(
618618
}
619619

620620
if channel.is_usable && !online_channel_exists {
621-
log_trace!(logger, "Channel with connected peer exists for invoice route hints");
621+
log_trace!(logger, None, None, "Channel with connected peer exists for invoice route hints");
622622
online_channel_exists = true;
623623
}
624624

@@ -638,7 +638,7 @@ fn sort_and_filter_channels<L: Deref>(
638638
let new_channel_preferable = channel.is_public == entry.get().is_public && !prefer_current;
639639

640640
if new_now_public || new_channel_preferable {
641-
log_trace!(logger,
641+
log_trace!(logger, None, None,
642642
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
643643
log_pubkey!(channel.counterparty.node_id),
644644
log_bytes!(channel.channel_id), channel.short_channel_id,
@@ -647,7 +647,7 @@ fn sort_and_filter_channels<L: Deref>(
647647
current_max_capacity);
648648
entry.insert(channel);
649649
} else {
650-
log_trace!(logger,
650+
log_trace!(logger, None, None,
651651
"Preferring counterparty {} channel {} (SCID {:?}, {} msats) over {} (SCID {:?}, {} msats) for invoice route hints",
652652
log_pubkey!(channel.counterparty.node_id),
653653
log_bytes!(entry.get().channel_id), entry.get().short_channel_id,
@@ -703,14 +703,14 @@ fn sort_and_filter_channels<L: Deref>(
703703
} else { true };
704704

705705
if include_channel {
706-
log_trace!(logger, "Including channel {} in invoice route hints",
706+
log_trace!(logger, None, None, "Including channel {} in invoice route hints",
707707
log_bytes!(channel.channel_id));
708708
} else if !has_enough_capacity {
709-
log_trace!(logger, "Ignoring channel {} without enough capacity for invoice route hints",
709+
log_trace!(logger, None, None, "Ignoring channel {} without enough capacity for invoice route hints",
710710
log_bytes!(channel.channel_id));
711711
} else {
712712
debug_assert!(!channel.is_usable || (has_pub_unconf_chan && !channel.is_public));
713-
log_trace!(logger, "Ignoring channel {} with disconnected peer",
713+
log_trace!(logger, None, None, "Ignoring channel {} with disconnected peer",
714714
log_bytes!(channel.channel_id));
715715
}
716716

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ops::Deref;
33
use core::sync::atomic::Ordering;
44

55
use bitcoin::BlockHash;
6-
use bitcoin::secp256k1::PublicKey;
6+
use bitcoin::secp256k1::{PublicKey};
77

88
use lightning::ln::msgs::{
99
DecodeError, ErrorAction, LightningError, UnsignedChannelUpdate,
@@ -59,7 +59,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
5959
mut read_cursor: &mut R,
6060
current_time_unix: Option<u64>
6161
) -> Result<u32, GraphSyncError> {
62-
log_trace!(self.logger, "Processing RGS data...");
62+
log_trace!(self.logger, None, None, "Processing RGS data...");
6363
let mut prefix = [0u8; 4];
6464
read_cursor.read_exact(&mut prefix)?;
6565

@@ -112,7 +112,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
112112
let node_id_1 = node_ids[node_id_1_index.0 as usize];
113113
let node_id_2 = node_ids[node_id_2_index.0 as usize];
114114

115-
log_gossip!(self.logger, "Adding channel {} from RGS announcement at {}",
115+
log_gossip!(self.logger, None, None, "Adding channel {} from RGS announcement at {}",
116116
short_channel_id, latest_seen_timestamp);
117117

118118
let announcement_result = network_graph.add_channel_from_partial_announcement(
@@ -126,7 +126,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
126126
if let ErrorAction::IgnoreDuplicateGossip = lightning_error.action {
127127
// everything is fine, just a duplicate channel announcement
128128
} else {
129-
log_warn!(self.logger, "Failed to process channel announcement: {:?}", lightning_error);
129+
log_warn!(self.logger, None, None, "Failed to process channel announcement: {:?}", lightning_error);
130130
return Err(lightning_error.into());
131131
}
132132
}
@@ -135,7 +135,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
135135
previous_scid = 0; // updates start at a new scid
136136

137137
let update_count: u32 = Readable::read(read_cursor)?;
138-
log_debug!(self.logger, "Processing RGS update from {} with {} nodes, {} channel announcements and {} channel updates.",
138+
log_debug!(self.logger, None, None, "Processing RGS update from {} with {} nodes, {} channel announcements and {} channel updates.",
139139
latest_seen_timestamp, node_id_count, announcement_count, update_count);
140140
if update_count == 0 {
141141
return Ok(latest_seen_timestamp);
@@ -188,7 +188,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
188188
synthetic_update.fee_base_msat = directional_info.fees.base_msat;
189189
synthetic_update.fee_proportional_millionths = directional_info.fees.proportional_millionths;
190190
} else {
191-
log_trace!(self.logger,
191+
log_trace!(self.logger, None, None,
192192
"Skipping application of channel update for chan {} with flags {} as original data is missing.",
193193
short_channel_id, channel_flags);
194194
skip_update_for_unknown_channel = true;
@@ -224,13 +224,13 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
224224
continue;
225225
}
226226

227-
log_gossip!(self.logger, "Updating channel {} with flags {} from RGS announcement at {}",
227+
log_gossip!(self.logger, None, None, "Updating channel {} with flags {} from RGS announcement at {}",
228228
short_channel_id, channel_flags, latest_seen_timestamp);
229229
match network_graph.update_channel_unsigned(&synthetic_update) {
230230
Ok(_) => {},
231231
Err(LightningError { action: ErrorAction::IgnoreDuplicateGossip, .. }) => {},
232232
Err(LightningError { action: ErrorAction::IgnoreAndLog(level), err }) => {
233-
log_given_level!(self.logger, level, "Failed to apply channel update: {:?}", err);
233+
log_given_level!(self.logger, level, None, None, "Failed to apply channel update: {:?}", err);
234234
},
235235
Err(LightningError { action: ErrorAction::IgnoreError, .. }) => {},
236236
Err(e) => return Err(e.into()),
@@ -244,7 +244,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
244244
}
245245

246246
self.is_initial_sync_complete.store(true, Ordering::Release);
247-
log_trace!(self.logger, "Done processing RGS data from {}", latest_seen_timestamp);
247+
log_trace!(self.logger, None, None, "Done processing RGS data from {}", latest_seen_timestamp);
248248
Ok(latest_seen_timestamp)
249249
}
250250
}

0 commit comments

Comments
 (0)