Skip to content

Commit 8515d27

Browse files
committed
Example using pub use macro
1 parent 32eb894 commit 8515d27

File tree

20 files changed

+459
-316
lines changed

20 files changed

+459
-316
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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($logger, None, None, "Terminating background processor.");
320320
break;
321321
}
322322

323323
if updates_available {
324-
log_trace!($logger, "Persisting ChannelManager...");
324+
_log_trace_with_peer_id_channel_id!($logger, None, None, "Persisting ChannelManager...");
325325
$persister.persist_manager(&*$channel_manager)?;
326-
log_trace!($logger, "Done persisting ChannelManager.");
326+
_log_trace_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!($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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(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
@@ -186,8 +186,8 @@ where
186186
)
187187
.map_err(|_| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
188188
};
189-
190-
log_trace!(logger, "Creating phantom invoice from {} participating nodes with payment hash {}",
189+
// todo: example of external crate using log_trace! initially now unable to re-export with pub use _log_trace_with_peer_id_channel_id as log_trace
190+
_log_trace_with_peer_id_channel_id!(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_with_peer_id_channel_id!(logger, Some(real_node_pubkey), 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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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_with_peer_id_channel_id!(logger, Some(channel.counterparty.node_id), Some(channel.channel_id), "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
@@ -10,7 +10,7 @@ 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+
use lightning::{_log_debug_with_peer_id_channel_id, _log_warn_with_peer_id_channel_id, _log_trace_with_peer_id_channel_id, log_given_level, _log_gossip_with_peer_id_channel_id};
1414
use lightning::util::ser::{BigSize, Readable};
1515
use lightning::io;
1616

@@ -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_with_peer_id_channel_id!(self.logger, None, None, "Processing RGS data...");
6363
let mut prefix = [0u8; 4];
6464
read_cursor.read_exact(&mut prefix)?;
6565

@@ -122,7 +122,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
122122
let node_id_1 = node_ids[node_id_1_index.0 as usize];
123123
let node_id_2 = node_ids[node_id_2_index.0 as usize];
124124

125-
log_gossip!(self.logger, "Adding channel {} from RGS announcement at {}",
125+
_log_gossip_with_peer_id_channel_id!(self.logger, None, None,"Adding channel {} from RGS announcement at {}",
126126
short_channel_id, latest_seen_timestamp);
127127

128128
let announcement_result = network_graph.add_channel_from_partial_announcement(
@@ -136,7 +136,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
136136
if let ErrorAction::IgnoreDuplicateGossip = lightning_error.action {
137137
// everything is fine, just a duplicate channel announcement
138138
} else {
139-
log_warn!(self.logger, "Failed to process channel announcement: {:?}", lightning_error);
139+
_log_warn_with_peer_id_channel_id!(self.logger, None, None,"Failed to process channel announcement: {:?}", lightning_error);
140140
return Err(lightning_error.into());
141141
}
142142
}
@@ -145,7 +145,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
145145
previous_scid = 0; // updates start at a new scid
146146

147147
let update_count: u32 = Readable::read(read_cursor)?;
148-
log_debug!(self.logger, "Processing RGS update from {} with {} nodes, {} channel announcements and {} channel updates.",
148+
_log_debug_with_peer_id_channel_id!(self.logger, None, None, "Processing RGS update from {} with {} nodes, {} channel announcements and {} channel updates.",
149149
latest_seen_timestamp, node_id_count, announcement_count, update_count);
150150
if update_count == 0 {
151151
return Ok(latest_seen_timestamp);
@@ -198,7 +198,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
198198
synthetic_update.fee_base_msat = directional_info.fees.base_msat;
199199
synthetic_update.fee_proportional_millionths = directional_info.fees.proportional_millionths;
200200
} else {
201-
log_trace!(self.logger,
201+
_log_trace_with_peer_id_channel_id!(self.logger, None, None,
202202
"Skipping application of channel update for chan {} with flags {} as original data is missing.",
203203
short_channel_id, channel_flags);
204204
skip_update_for_unknown_channel = true;
@@ -234,13 +234,13 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
234234
continue;
235235
}
236236

237-
log_gossip!(self.logger, "Updating channel {} with flags {} from RGS announcement at {}",
237+
_log_gossip_with_peer_id_channel_id!(self.logger, None, None, "Updating channel {} with flags {} from RGS announcement at {}",
238238
short_channel_id, channel_flags, latest_seen_timestamp);
239239
match network_graph.update_channel_unsigned(&synthetic_update) {
240240
Ok(_) => {},
241241
Err(LightningError { action: ErrorAction::IgnoreDuplicateGossip, .. }) => {},
242242
Err(LightningError { action: ErrorAction::IgnoreAndLog(level), err }) => {
243-
log_given_level!(self.logger, level, "Failed to apply channel update: {:?}", err);
243+
log_given_level!(self.logger, level, None, None, "Failed to apply channel update: {:?}", err);
244244
},
245245
Err(LightningError { action: ErrorAction::IgnoreError, .. }) => {},
246246
Err(e) => return Err(e.into()),
@@ -254,7 +254,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
254254
}
255255

256256
self.is_initial_sync_complete.store(true, Ordering::Release);
257-
log_trace!(self.logger, "Done processing RGS data from {}", latest_seen_timestamp);
257+
_log_trace_with_peer_id_channel_id!(self.logger, None, None, "Done processing RGS data from {}", latest_seen_timestamp);
258258
Ok(latest_seen_timestamp)
259259
}
260260
}

0 commit comments

Comments
 (0)