Skip to content
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

routing+channeldb: use a more minimal encoding for MC routes #8911

Merged

Conversation

ellemouton
Copy link
Collaborator

@ellemouton ellemouton commented Jul 15, 2024

Before this commit, Mission Control would serialise the entire route.Route for each mission control entry. However, MC only uses a fraction of the info in route.Route. Continuing to persist the entire encoding may become more constly once we start sending to more blinded routes because then this encoding will also include the encrypted cipher text sent to each hop on the blinded path.
So this commit migrates the MC store to only persist the data that the MC actually uses.

Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@ellemouton ellemouton marked this pull request as draft July 15, 2024 10:59
@bhandras
Copy link
Collaborator

bhandras commented Jul 15, 2024

Concept ACK, great idea to remove unused data and simplify the encoding! 🚀

I think in the end the choice of encoding (whether to use TLV or not) is not super important as eventually we should fully migrate to SQL.

@bitromortac bitromortac self-requested a review July 19, 2024 10:21
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch 5 times, most recently from 2268ccb to b37d014 Compare July 19, 2024 11:09
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch from b37d014 to f30310c Compare August 6, 2024 12:36
@ellemouton ellemouton marked this pull request as ready for review August 6, 2024 12:36
@ellemouton ellemouton marked this pull request as draft August 6, 2024 17:12
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch 2 times, most recently from 1c44d76 to 43f787e Compare August 8, 2024 06:14
@ellemouton ellemouton marked this pull request as ready for review August 8, 2024 06:14
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch 2 times, most recently from 4f0c2eb to 1c0bba2 Compare August 13, 2024 14:22
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Did a first pass. Looks good to me, nice work on the commit structure (as always 😉 ). Might need some updates after recently merged PRs, but other than that this is pretty close.

// first hop in the path. A route is only selected as valid if all the channels
// have sufficient capacity to carry the initial payment amount after fees are
// accounted for.
type Route struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I think I just made this a bit more complicated by merging #9049, which added a new field to this struct, including new encoding/decoding logic that probably needs to be copied (lnwire/custom_records.go). Although no existing records should ever have that data. But if this PR only goes in with 0.19, there could be such records from 0.18.4 to 0.19.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the relevant commit btw: 4804cbf

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for pointing this out 🙏

I think we should still be good here though if im not mistaken since the new records would never have been encoded in the mission control store right? since that uses SerialiseRoute directly which does not use the new fields.

but I'll add the new fields to the struct for completeness sake 👍

routing/result_interpretation.go Show resolved Hide resolved
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch from 3cf0d5f to 9d45dc9 Compare September 9, 2024 09:37
Copy link
Collaborator Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

Thanks @guggero 🙏

Updated with the hasCustomRecords suggestion & also added the new fields to Route

// first hop in the path. A route is only selected as valid if all the channels
// have sufficient capacity to carry the initial payment amount after fees are
// accounted for.
type Route struct {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for pointing this out 🙏

I think we should still be good here though if im not mistaken since the new records would never have been encoded in the mission control store right? since that uses SerialiseRoute directly which does not use the new fields.

but I'll add the new fields to the struct for completeness sake 👍

@guggero guggero self-requested a review September 9, 2024 09:54
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM and tACK (on a copy of my mainnet node's MC history) 🎉

channeldb/migration/lnwire21/onion_error.go Outdated Show resolved Hide resolved
channeldb/migration32/route.go Outdated Show resolved Hide resolved
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch from 9d45dc9 to 74b6af9 Compare September 16, 2024 11:03
Copy link
Collaborator Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

shweeeeet - updated! thanks @guggero

channeldb/migration32/route.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

Nice work 🎉! I'm curious how much this saves us, I'll also run a test migration next.

If we would like to add more data again in the future, how would that look like? Would adding a tlv stream make sense for extensibility?

channeldb/migration/lnwire21/onion_error.go Show resolved Hide resolved
routing/result_interpretation.go Outdated Show resolved Hide resolved
routing/missioncontrol_store.go Outdated Show resolved Hide resolved
routing/missioncontrol_store_test.go Show resolved Hide resolved
channeldb/migration32/migration.go Outdated Show resolved Hide resolved
@lightninglabs-deploy
Copy link

@ellemouton, remember to re-request review from reviewers when ready

@ellemouton
Copy link
Collaborator Author

I'm curious how much this saves us

It will save us a lot especially once route blinding is more frequently used since currently, that would mean storing the encrypted data for a blinded route for each mission control entry

If we would like to add more data again in the future, how would that look like? Would adding a tlv stream make sense for extensibility?

Yeah i had the same thought before & chatted to oli about this but we decided this is fine for now especially given the shift to SQL land. If we do need to add more fields here before we get to sql land, then we can just do a migration at the time to shift to TLV form.

To prevent the need to copy the entire onion_error.go file for a new
Mission Control migration, this commit just updates the existing
lnwire21/onion_error.go file with the new CodeInvalidBlinding code. The
lnwire21 should not really ever be updated but adding a new code should
be fine as it does not affect old migrations since this is a new code.
We add the new custom records encoding/decoding logic to the "frozen"
lnwire21 package. We can do this because nothing uses this logic yet. If
the custom records logic changes, the changes should _not_ be added to
the lnwire21 version.
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch from 74b6af9 to 5c8c5e0 Compare September 30, 2024 07:06
Copy link
Collaborator Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

Thanks for the review @bitromortac 🙏
Ready for final round

routing/missioncontrol_store_test.go Show resolved Hide resolved
@ellemouton
Copy link
Collaborator Author

The other thing I forgot to mention above re the question regarding "how much are we actually saving here":

The main reason we are doing this PR is so that we dont need all the currently needed Route info in order to construct an MC entry - this is so that we can create MC entries on Route blinding receives as is done in #8991
which would not be possible given the current structure :)

Copy link
Collaborator

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

LGTM 🎉, I tested the migration as well

channeldb/migration32/hop.go Outdated Show resolved Hide resolved
In preparation for the commit which will add the main logic for
migration 32 (which will migrate the MC store to use a more minimal
encoding), this commit just adds some of the code that the migration
will need to the package.
Add a new mcRoute type that houses the data about a route that MC
actually uses. Then add a migration (channeldb/migration32) that
migrates the existing store from its current serialisation to the new,
more minimal serialisation.
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch from 5c8c5e0 to eb6c552 Compare September 30, 2024 09:40
@ellemouton ellemouton force-pushed the reduceMCRouteEncoding branch from eb6c552 to 34303e7 Compare October 1, 2024 08:53
@ellemouton ellemouton merged commit 75eaaf7 into lightningnetwork:master Oct 1, 2024
27 of 33 checks passed
@ellemouton ellemouton deleted the reduceMCRouteEncoding branch October 1, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migration mission control size/kilo medium, proper context needed, less than 1000 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants