Skip to content

Channelmanager: improve block connection logging#4586

Open
Alkamal01 wants to merge 1 commit intolightningdevkit:mainfrom
Alkamal01:block-connection-logging
Open

Channelmanager: improve block connection logging#4586
Alkamal01 wants to merge 1 commit intolightningdevkit:mainfrom
Alkamal01:block-connection-logging

Conversation

@Alkamal01
Copy link
Copy Markdown

Channelmanager: improve block connection logging

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.
@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented May 2, 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 +15971 to +15973
for (_, tx) in txdata.iter() {
log_debug!(self.logger, "Confirmed transaction {} in block {} at height {}", tx.compute_txid(), 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.

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.

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

Review Summary

Inline comments posted:

  • lightning/src/ln/channelmanager.rs:15971-15973compute_txid() (double-SHA256) is called unconditionally for every transaction in the loop, even when DEBUG logging is disabled. The log macro evaluates arguments eagerly; the level filtering happens inside Logger::log, not before. This adds unnecessary hashing overhead on every block connection for users who don't have DEBUG enabled.

No cross-cutting concerns beyond the inline comment.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.16%. Comparing base (6573d42) to head (fdfef44).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4586      +/-   ##
==========================================
+ Coverage   86.99%   87.16%   +0.17%     
==========================================
  Files         163      161       -2     
  Lines      109008   109263     +255     
  Branches   109008   109263     +255     
==========================================
+ Hits        94828    95236     +408     
+ Misses      11696    11550     -146     
+ Partials     2484     2477       -7     
Flag Coverage Δ
fuzzing ?
fuzzing-fake-hashes 31.21% <100.00%> (?)
fuzzing-real-hashes 22.94% <100.00%> (?)
tests 86.22% <100.00%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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