Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15968,6 +15968,15 @@ impl<

let block_hash = header.block_hash();
log_trace!(self.logger, "{} transactions included in block {} at height {} provided", txdata.len(), block_hash, height);
struct LazyTxid<'a>(&'a Transaction);
impl<'a> core::fmt::Display for LazyTxid<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{}", self.0.compute_txid())
}
}
for (_, tx) in txdata.iter() {
log_debug!(self.logger, "Confirmed transaction {} in block {} at height {}", LazyTxid(tx), block_hash, height);
}
Comment on lines +15977 to +15979
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute_txid() performs a double-SHA256 over the serialized transaction, and the log_given_level! macro evaluates its arguments unconditionally (the level check is inside the Logger::log implementation, not before argument evaluation). This means the loop runs and hashes every transaction even when the logger's level is above DEBUG.

Consider either:

  1. Guarding the loop behind a level check, or
  2. Folding these per-txid details into the existing TRACE log, or
  3. Using a lazy wrapper (e.g., a Display impl that computes on fmt) — though this still wouldn't avoid the loop itself.

While txdata only contains matching transactions (not the full block), computing txids unconditionally on every block connection is unnecessary overhead for users who don't have DEBUG enabled.


let _persistence_guard =
PersistenceNotifierGuard::optionally_notify_skipping_background_events(
Expand Down Expand Up @@ -15999,7 +16008,7 @@ impl<
// See the docs for `ChannelManagerReadArgs` for more.

let block_hash = header.block_hash();
log_trace!(self.logger, "New best block: {} at height {}", block_hash, height);
log_info!(self.logger, "New best block: {} at height {}", block_hash, height);

let _persistence_guard =
PersistenceNotifierGuard::optionally_notify_skipping_background_events(
Expand Down
Loading