Skip to content

Run rustfmt on channelmanager #3767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joostjager
Copy link
Contributor

@joostjager joostjager commented May 5, 2025

After reviewing a few rustfmt PRs and observing that personal preferences regarding formatting vary, I tried to do this one in a minimal way.

I went through the diff looking for blow up that really stood out, but there wasn't much that looked outside acceptable bounds to me. If anything, most of what rustfmt does is a positive change the way I see it. Reducing line density helps with readability, for me.

There were two match arms for UpdateAddHTLC that maybe received a bit too much love, even though I think even those can go through as is. Added #[rustfmt::skip] nonetheless to at least avoid what I think would be the worst pain for some.

Outstanding PRs can be rebased painlessly using a variant of the script described in #3749 (comment).

Update 5/27/2025: Added skips to every method.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented May 5, 2025

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

@joostjager joostjager requested a review from TheBlueMatt May 5, 2025 07:53
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 4th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 5th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 6th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 7th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 8th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 9th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@joostjager
Copy link
Contributor Author

Pushed a new take on channelmanager formatting. Used an automated script to insert the skip directives before every function.

@joostjager joostjager force-pushed the fmt-chanmgr branch 2 times, most recently from f033d19 to d7b433e Compare May 27, 2025 09:46
Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.89%. Comparing base (c6caad8) to head (83f41dd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3767      +/-   ##
==========================================
+ Coverage   89.87%   89.89%   +0.02%     
==========================================
  Files         160      160              
  Lines      129136   129172      +36     
  Branches   129136   129172      +36     
==========================================
+ Hits       116056   116123      +67     
+ Misses      10381    10358      -23     
+ Partials     2699     2691       -8     

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

@ldk-reviews-bot
Copy link

🔔 10th Reminder

Hey @TheBlueMatt @valentinewallace! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Concept ACK, I like this as an incremental approach, and any new methods that get added will be rustfmt'd from the start. Browsing through channelmanager.rs, it doesn't really seem too invasive to me.

Curious your thoughts moving forward after this --

Do you plan to create a follow-up removing (many of?) the skips? Or should we have a policy where going forward if a method is touched in a PR then it should be formatted?

@joostjager joostjager force-pushed the fmt-chanmgr branch 6 times, most recently from fd5301e to ae7d478 Compare May 28, 2025 10:29
@joostjager
Copy link
Contributor Author

Rebased after merge of #3802. Smooth workflow now in channelmanager.rs. Just remove a skip attribute and save (format on save) to go to standard formatting.

@joostjager
Copy link
Contributor Author

joostjager commented May 28, 2025

Concept ACK, I like this as an incremental approach, and any new methods that get added will be rustfmt'd from the start. Browsing through channelmanager.rs, it doesn't really seem too invasive to me.

It's indeed just the structs and enums that are changing. But those weren't easy to format-fix anyway.

Curious your thoughts moving forward after this --
Do you plan to create a follow-up removing (many of?) the skips? Or should we have a policy where going forward if a method is touched in a PR then it should be formatted?

Good question. If it were up to me, I'd just format the whole repository without any skips, and use the rebase script for outstanding PRs. But as there is no unanimous support for that, I am trying to at least make it better than what it was.

I think going forward from this PR, it's up to contributors to remove skip directives as they see fit. Probably based on functions touched. If that's done in a separate initial commit, and the same is done for conflicting prs that touch the same functions, I think a rebase shouldn't be problematic.

Alternatively a manual pass through this file can be made to remove some of the skips and wrap that in a separate PR. That's probably best done by someone who knows the parts of channelmgr that are in flight.

@jkczyz
Copy link
Contributor

jkczyz commented May 28, 2025

Concept ACK. I like this approach. A follow-up PR can probably remove a lot of skips where rustfmt makes trivial changes or those where there's no obvious refactoring. Then -- when touching a function in a PR -- anyone inclined could refactor it and drop the skip on a separate commit.

@valentinewallace
Copy link
Contributor

valentinewallace commented May 28, 2025

I had to add edition = "2021" to our rustfmt.toml for format-on-save to work in channelmanager.rs. Did you experience this @joostjager?

Without this, cargo fmt also does nothing and rustfmt channelmanager.rs errors with:

error[E0670]: `async fn` is not permitted in Rust 2015
     --> /Users/valentine/rust-lightning/lightning/src/ln/channelmanager.rs:11468:6
      |
11468 |     pub async fn process_pending_events_async<
      |         ^^^^^ to use `async fn`, switch to Rust 2018 or later
      |
      = help: pass `--edition 2021` to `rustc`
      = note: for more on editions, read https://doc.rust-lang.org/edition-guide

Edit: fixed this as well, see below comment.

@valentinewallace
Copy link
Contributor

valentinewallace commented May 28, 2025

FYI, there does seem to be some lag when formatting-on-save. At one point it was extremely slow and the lag was >10 seconds, but I'm unable to reproduce that now. For me the lag doesn't seem like a dealbreaker, but others may want to test it out.

Edit: I got some quite slow lag again after the file had been open for a while, restarting my text editor fixed it. Hmm.

Edit 2: Never mind, it was due to using a vim global for format-on-save instead of nvim_create_autocmd. Thanks @wpaulino for pointing this out!

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Ship it! 👏

@valentinewallace valentinewallace dismissed their stale review May 28, 2025 23:23

Dismissing my review because there's a fixup commit. But the ACK stands

@joostjager
Copy link
Contributor Author

Squashed

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Concept ACK: I like this approach - whoever touches some code would just remove the corresponding rustfmt::skip, and some time down the line we'd bit the bullet to do the remaining parts in one go (i.e., the parts that nobody ever touches).

@joostjager
Copy link
Contributor Author

Prepared a follow up PR for the full repo: #3809

@joostjager
Copy link
Contributor Author

As discussed in sync meet, I've updated the script to drop the skip directives for functions that only need their signature to change. Added fixup commit.

@ldk-reviews-bot
Copy link

🔔 11th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 12th Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@valentinewallace
Copy link
Contributor

Fixup LGTM

This allows devs to enable rustfmt on a per-function level.
@joostjager
Copy link
Contributor Author

Rebased. Would be nice to move towards a conclusion on this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants