Skip to content

Optimize block connection logging using LazyTxid#4659

Open
kamal-ogtl wants to merge 3 commits into
lightningdevkit:mainfrom
kamal-ogtl:block-connection-logging
Open

Optimize block connection logging using LazyTxid#4659
kamal-ogtl wants to merge 3 commits into
lightningdevkit:mainfrom
kamal-ogtl:block-connection-logging

Conversation

@kamal-ogtl
Copy link
Copy Markdown

This PR replaces PR #4586. I am resubmitting it from this account because my previous account (Alkamal01) is currently experiencing unexpected visibility restrictions from GitHub's automated filters, making the original PR inaccessible to reviewers. This contains the same code and logic as originally proposed.

Fixes #2348. Supersedes #4420.

best_block_updated was logging at TRACE, making it impossible to track chain tip progress without enabling full trace logging. This upgrades it to INFO.

Also adds per-txid DEBUG logs in transactions_confirmed so individual transactions triggering channel updates are visible at a useful log level.

The original PR #4420 also added an INFO log in filtered_block_connected, but that duplicates the one in best_block_updated (which filtered_block_connected calls directly). That log is left out here.

Upgrade best_block_updated log from TRACE to INFO so chain tip
updates are visible without enabling full trace logging.

Add per-txid DEBUG logs in transactions_confirmed to make it easier
to identify which transactions triggered channel updates.
…gging

Use a lazy Display wrapper to format confirmed txids, preventing unconditional hashing when DEBUG logging is disabled.
@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Jun 4, 2026

I've assigned @valentinewallace as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Comment on lines +16200 to +16202
for (_, tx) in txdata.iter() {
log_debug!(self.logger, "Confirmed transaction {} in block {} at height {}", LazyTxid(tx), block_hash, height);
}
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.

This loop logs every transaction in txdata, but txdata is not necessarily filtered to only channel-relevant transactions. In the Listen::block_connectedfiltered_block_connectedtransactions_confirmed path, txdata contains all transactions in the block (see block_connected default impl in chain/mod.rs:190-192). Even with BIP 157/158 compact block filters, the filtering is block-level, not transaction-level, so a matching block still delivers all its transactions here.

On mainnet blocks with ~2000-3000 transactions, this produces thousands of DEBUG log lines per block (~every 10 minutes), almost all for transactions completely unrelated to the node's channels. If DEBUG is enabled, each line also triggers a compute_txid() (double-SHA256 of the serialized transaction).

Consider either:

  1. Moving this logging after channel processing so you only log transactions that actually triggered a channel update, or
  2. Gating this on TRACE instead of DEBUG, consistent with the existing aggregate log on the line above.

@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

Review Summary

Inline comments posted:

  • lightning/src/ln/channelmanager.rs:16200-16202 — Per-transaction DEBUG logging iterates over all transactions in txdata, which in the block_connected path includes every transaction in the block (potentially thousands on mainnet), not just channel-relevant ones. This produces excessive log output at DEBUG level and triggers compute_txid() for each irrelevant transaction when DEBUG logging is enabled.

No other issues found. The LazyTxid pattern correctly defers compute_txid() until formatting time, the TRACE→INFO promotion for best_block_updated is reasonable, and the code is structurally sound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve block connection logging

3 participants