Skip to content

Conversation

valentinewallace
Copy link
Contributor

Prefactor to some of @joostjager's experimental work including serialized channels in ChannelMonitorUpdates as part of getting rid of ChannelManager persistence.

We'll be breaking up this macro in upcoming commits.
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Oct 1, 2025

👋 Thanks for assigning @joostjager 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.

Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 62.06897% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.73%. Comparing base (54ed941) to head (b588431).
⚠️ Report is 41 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 62.06% 9 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4138      +/-   ##
==========================================
+ Coverage   88.62%   88.73%   +0.11%     
==========================================
  Files         180      180              
  Lines      134895   135826     +931     
  Branches   134895   135826     +931     
==========================================
+ Hits       119546   120528     +982     
+ Misses      12587    12526      -61     
- Partials     2762     2772      +10     
Flag Coverage Δ
fuzzing 21.70% <41.37%> (-0.07%) ⬇️
tests 88.57% <62.06%> (+0.11%) ⬆️

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.

@valentinewallace valentinewallace force-pushed the 2025-10-monitor-upd-macro branch 2 times, most recently from 0e37cb0 to 57d0422 Compare October 8, 2025 19:27
@valentinewallace valentinewallace marked this pull request as ready for review October 8, 2025 19:29
@ldk-reviews-bot ldk-reviews-bot requested a review from jkczyz October 8, 2025 19:29
@valentinewallace valentinewallace removed the request for review from jkczyz October 8, 2025 19:29
joostjager
joostjager previously approved these changes Oct 9, 2025
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

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

Love to see the macro overloads disappear. Macros are already hard enough to deal with / navigate through without overloads.

I don't know how much you've been looking into (or already knew) what these macros do exactly, but any knowledge that you can solidify into additional comments seems very helpful to me.

/// them (otherwise they can end up getting applied out-of-order) but it's not always possible to
/// drop the aforementioned peer state locks at a given callsite. In this situation, use this macro
/// to apply the monitor update immediately and handle the monitor update completion actions at a
/// later time.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice explanation. I strongly believe that adding comments like this will make the code base a lot easier to work with, especially for new people.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

/// Returns whether the monitor update is completed, `false` if the update is in-progress.
fn handle_monitor_update_res<LG: Logger>(
&self, update_res: ChannelMonitorUpdateStatus, channel_id: ChannelId, logger: LG,
) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really convinced it makes sense to move some logs into a freestanding method? How does this improve readability? Or did you benchmark compilation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am getting a bit faster compile times with this change, not sure what the bar is for "worthwhile improvement."

From a clean build:

valentine@Valentines-MacBook-Pro rust-lightning % hyperfine --prepare 'cargo clean' \
  'cargo build -p lightning' \
  'git stash && cargo build -p lightning'
Benchmark 1: cargo build -p lightning
  Time (mean ± σ):     48.756 s ±  0.225 s    [User: 135.911 s, System: 6.500 s]
  Range (min … max):   48.448 s … 49.058 s    10 runs

Benchmark 2: git stash && cargo build -p lightning
  Time (mean ± σ):     48.625 s ±  0.145 s    [User: 135.571 s, System: 6.543 s]
  Range (min … max):   48.436 s … 48.852 s    10 runs

Summary
  git stash && cargo build -p lightning ran
    1.00 ± 0.01 times faster than cargo build -p lightning

^Benchmark 1 reverts the new function back to a macro on this branch.

Incremental build time reverting to a macro:

valentine@Valentines-MacBook-Pro rust-lightning % hyperfine 'touch lightning/src/ln/chan_utils.rs && cargo build -p lightning'
Benchmark 1: touch lightning/src/ln/chan_utils.rs && cargo build -p lightning
  Time (mean ± σ):      5.733 s ±  0.046 s    [User: 5.007 s, System: 1.043 s]
  Range (min … max):    5.671 s …  5.840 s    10 runs

Incremental build time with this current branch:

valentine@Valentines-MacBook-Pro rust-lightning % hyperfine 'touch lightning/src/ln/chan_utils.rs && cargo build -p lightning'
Benchmark 1: touch lightning/src/ln/chan_utils.rs && cargo build -p lightning
  Time (mean ± σ):      5.625 s ±  0.020 s    [User: 4.925 s, System: 1.038 s]
  Range (min … max):    5.591 s …  5.649 s    10 runs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, not a lot, but also not zero. Does it need to be a function in ChannelManager or can it be a loose function in channelmanager.rs to at least keep the code together in the same place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to a loose function!

Generally we'd like to use functions instead of macros where we can both for
readability and for compile times.
Makes handle_new_monitor_update more readable.
Makes handle_new_monitor_update more readable.
Makes handle_new_monitor_update more readable. Also documents the variant and
why someone may want to use it.
Finishes work over the past few commits of breaking up the
handle_new_monitor_update macro.
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.

4 participants