Skip to content

Move code out of add_entry! in get_route #2920

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

Closed

Conversation

Velnbur
Copy link

@Velnbur Velnbur commented Mar 4, 2024

Move all of the code out of add_entry! macro inside get_route to facilitate development experience inside it (as by this time macro backtrace is still only available in nightly versions of compiler) and reduce enourmous get_route function size.

Copy link

coderabbitai bot commented Mar 4, 2024

Walkthrough

The recent update involves a significant refactoring effort within the routing logic of the application. A complex macro previously embedded in the code has been elegantly extracted and encapsulated into a new function named add_entry_internal. This strategic move not only enhances the readability and maintainability of the codebase but also streamlines the overall code organization, ensuring that the logic initially encapsulated by the macro remains intact and functionally coherent.

Changes

File(s) Change Summary
lightning/src/routing/router.rs Refactored to extract a complex macro into a separate function add_entry_internal, improving readability and maintainability.

🐇✨
In the realm of code, where logic intertwines,
A rabbit hopped through, refining the lines.
From macro to function, it leaped with grace,
Enhancing the flow, in the digital space.
Readability blooms, maintainability sings,
In the heart of the code, where the magic springs.
🌟🐰


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7a35bf8 and de2a0b7.
Files selected for processing (1)
  • lightning/src/routing/router.rs (2 hunks)

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 83.13609% with 57 lines in your changes missing coverage. Please review.

Project coverage is 89.69%. Comparing base (78c0eaa) to head (b4c62dc).
Report is 1071 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/routing/router.rs 83.13% 48 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2920      +/-   ##
==========================================
- Coverage   89.80%   89.69%   -0.12%     
==========================================
  Files         121      121              
  Lines      100045   100039       -6     
  Branches   100045   100039       -6     
==========================================
- Hits        89845    89728     -117     
- Misses       7533     7623      +90     
- Partials     2667     2688      +21     

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

@Velnbur Velnbur force-pushed the move-add-entry-macro-in-get-route branch from de2a0b7 to e85a59a Compare March 4, 2024 21:18
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7a35bf8 and e85a59a.
Files selected for processing (1)
  • lightning/src/routing/router.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • lightning/src/routing/router.rs

@TheBlueMatt
Copy link
Collaborator

Hmmm, I'm definitely a fan of moving code out of get_route, but passing in 28 arguments doesn't really improve readability :/. For panics specifically, luckily the panic messages share the arguments passed to the panic, so its still not that hard to just search for the specific panic we hit (and we can add relevant messages to any panics that don't have such clarity). For generally cleaning up routing, if you want to continue down this path we'll need to try to build state structs that we can pass around as singular objects rather than individual fields.

@Velnbur
Copy link
Author

Velnbur commented Mar 5, 2024

but passing in 28 arguments doesn't really improve readability :/.

Yeah, that's a great point, and capturing them through macro makes it hard to read as well. Just wanted to make it "compatible" with other code that's written in parallel with this PR.

For generally cleaning up routing, if you want to continue down this path we'll need to try to build state structs that we can pass around as singular objects rather than individual fields.

I wanted to hear that, so if there is some interest in it, I may continue

P.S.: Also it seems that the codecov found untested lines with this PR :)

@TheBlueMatt
Copy link
Collaborator

The other issue we're gonna hit is the routefinding rewrites in #2803 are going to conflict heavily here :/

@TheBlueMatt
Copy link
Collaborator

Okay...the bulk of #2803 landed. Any desire to pick this back up?

@Velnbur Velnbur force-pushed the move-add-entry-macro-in-get-route branch from e85a59a to 4e3f404 Compare July 11, 2024 15:15
@Velnbur
Copy link
Author

Velnbur commented Jul 11, 2024

Rebased.

Okay...the bulk of #2803 landed. Any desire to pick this back up?

Yes, if there is still any interest in it.

to try to build state structs that we can pass around as singular objects rather than individual fields.

I'll start from this then. Beginning with obvious ones like num_ignored_* and config variables

@Velnbur
Copy link
Author

Velnbur commented Jul 11, 2024

Still need to add something for the "state" of the path-finding algorithm, but even at this point I'll be glad for any comments about the direction of the changes

Velnbur added 2 commits July 11, 2024 23:19
Move all of the code out of `add_entry!` macro inside `get_route` to
facilitate development experience inside it and reduce enourmous
`get_route` function size.
@Velnbur Velnbur force-pushed the move-add-entry-macro-in-get-route branch from 9a94b41 to dfb03aa Compare July 11, 2024 20:29
@Velnbur Velnbur marked this pull request as draft July 11, 2024 20:36
@Velnbur Velnbur force-pushed the move-add-entry-macro-in-get-route branch from dfb03aa to bc51298 Compare July 12, 2024 12:14
Velnbur added 2 commits July 12, 2024 15:50
Group const after initialization values used across the `get_route`
method into single `GetRouteParameters` struct.
To `NextHopsData` and use it instead everywhere possible
@Velnbur Velnbur force-pushed the move-add-entry-macro-in-get-route branch from bc51298 to b4c62dc Compare July 12, 2024 12:50
@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Jul 15, 2024

Nice, yea, in principle this looks great to me, assuming benchmarks don't turn up anything weird (might well be faster cause improved code density).

@TheBlueMatt
Copy link
Collaborator

Closing as abandoned.

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.

3 participants