Skip to content

Conversation

@TheBlueMatt
Copy link
Collaborator

On my machine this decreases the build step of trivial-change lightning-crate test re-builds by around 10%

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Nov 15, 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.

@codecov
Copy link

codecov bot commented Nov 15, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.33%. Comparing base (bda19d6) to head (7cea2e9).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 91.66% 10 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4224      +/-   ##
==========================================
- Coverage   89.34%   89.33%   -0.01%     
==========================================
  Files         180      180              
  Lines      138341   138469     +128     
  Branches   138341   138469     +128     
==========================================
+ Hits       123596   123706     +110     
- Misses      12123    12137      +14     
- Partials     2622     2626       +4     
Flag Coverage Δ
fuzzing 35.98% <60.25%> (+0.06%) ⬆️
tests 88.70% <91.66%> (-0.01%) ⬇️

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.

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.

Not just a build time improvement, but also a reduction of the friction in code navigation and debugging!

}}
}

fn convert_channel_err_internal<Close: FnOnce(ClosureReason, &str) -> (ShutdownResult, Option<(msgs::ChannelUpdate, NodeId, NodeId)>)>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Comments explaining this function and the one below would be welcome.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you feel like is missing clarity?

Copy link
Contributor

Choose a reason for hiding this comment

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

More details about what the function is doing. Of course if you know what it does, you can see that reflected in the code. But if you are new to the code, a bit of explanation is helpful. Why it is needed, what it does, how to use it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm really not at all clear what I could possibly add with a comment here - the method takes a ChannelError and returns a MsgHandleErrInternal, doing a conversion, like the name says. The return value is maybe non-obvious, but its also an _internal method that exists to do the thing convert_channel_err!() says it is doing. I could document it with just a doc comment saying "does the work for convert_channel_err!(), but I'm not convinced that's actually improving readability :)

(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Abort(reason), chan_id))
},
ChannelError::Close((msg, reason)) => {
let (shutdown_res, chan_update) = close(reason, &msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this be a function without a side effect, just call the close logic one level up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not immediately obvious to me how to do this cleanly - we need the shutdown_res to build the MsgHandleErrInternal which we want to do here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Just asking, but I see the point.

@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.

joostjager
joostjager previously approved these changes Nov 17, 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.

Macro deletion, it's good :)

(false, MsgHandleErrInternal::from_chan_no_close(ChannelError::Abort(reason), chan_id))
},
ChannelError::Close((msg, reason)) => {
let (shutdown_res, chan_update) = close(reason, &msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Just asking, but I see the point.

The `handle_monitor_update_completion` macro is called from a
number of places in `channelmanager.rs` and dumps quite a bit of
code into each callsite. Here we take the unlocked half of
`handle_monitor_update_completion` and move it into a function in
`ChannelManager`.

As a result, building the `lightning` crate tests after a
single-line `println` change in `channelmanager.rs` was reduced by
around a full second (out of ~28.5 originally) on my machine using
rustc 1.85.0. Memory usage of the `expand_crate` step went from
+554MB to +548MB in the same test.
In the next commit we'll functionize some of the
`ChannelError`-handling logic, requiring it have access to
`handle_new_monitor_update_locked_actions_handled_by_caller!` which
thus needs to be defined above it.
`convert_channel_err` is used extensively in `channelmanager.rs`
(often indirectly via `try_channel_entry`) and generates nontrivial
code (especially once you include `locked_close_channel`). Here we
take the `FUNDED` cases of it and move them to an internal function
reducing the generated code size.

On the same machine as described two commits ago, this further
reduces build times by about another second.
`convert_channel_err` is used extensively in `channelmanager.rs`
(often indirectly via `try_channel_entry`) and generates nontrivial
code (especially once you include `locked_close_channel`). Here we
take the `UNFUNDED` case of it and move them to an internal
function reducing the generated code size.

On the same machine as described three commits ago, this further
reduces build times from the previous commit by about another
second.
Now that `convert_channel_err` is primarily in two functions,
`locked_close_channel` is just a dumb macro that has two forms,
each only called once. Instead, drop it and inline its contents
into `convert_*_channel_err`.
@TheBlueMatt
Copy link
Collaborator Author

Squashed and rebased, fixing the commit message.

Copy link
Contributor

@elnosh elnosh left a comment

Choose a reason for hiding this comment

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

was reviewing before the rebase but LGTM

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