-
Couldn't load subscription status.
- Fork 2.2k
[g175] refactor: prep for multiple Node versions #10279
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
base: 0-21-0-staging
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ellemouton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request is a refactor and cleanup aimed at preparing the codebase for supporting multiple versions of Lightning Network node announcements. It introduces a Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a refactor to prepare the codebase for handling multiple Node versions, specifically by adding a Version field to the models.Node struct and using a constructor to create Node instances. The changes primarily involve modifying the autopilot/prefattach_test.go, channeldb/db_test.go, discovery/chan_series.go, graph/builder.go, graph/builder_test.go, graph/db/graph.go, graph/db/graph_test.go, graph/db/interfaces.go, graph/db/kv_store.go, graph/db/models/channel_auth_proof.go, graph/db/models/channel_edge_info.go, graph/db/models/node.go, graph/db/notifications.go, graph/db/sql_migration.go, graph/db/sql_migration_test.go, lnrpc/devrpc/dev_server.go, routing/pathfind_test.go, routing/payment_session_source.go, routing/payment_session_test.go, routing/router_test.go, and server.go files. The review focuses on correctness, maintainability, and adherence to the repository's style guide, particularly concerning code documentation, commenting, spacing, and formatting.
496c5e3 to
8eb29f1
Compare
6b66a3b to
258ca41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, a lot of nice clean-ups 🧹
| if dbNode.LastUpdate.Valid { | ||
| node.LastUpdate = time.Unix(dbNode.LastUpdate.Int64, 0) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason why node.LastUpdate is non-optional when the db field is also nullable, whereas alias is optional for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can/should defs change it later on. I think this was mainly due to Alias/Color not being used often so the diff was small. LastUpdate is used more often - so I'll do that change in a commit by itself a bit later on 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes, it was also cause things like alias & color do become actual optional fields but update time must always be set & isnt really optional in that sense.
but yeah, we can make this more explicit later with helpers like "ExtractV1Node" or something
| } | ||
|
|
||
| // NewV1Node creates a new version 1 node from the passed fields. | ||
| func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using NodeV1Fields as a combined parameter somewhat defeats the purpose of making sure that a creator sets all field values, not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "combined parameter"?
I think having the struct shows clearly what values need to be set? ie, with this constructor we dont expose V2-only-fields that would just be lost on persistence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo having a struct argument makes the code slightly more readable. A long list of arguments can end up being very messy.
I think some editors/IDEs don't immediately fill struct fields (e.g. in vim it's doable but not a default) so perhaps @bitromortac was referring to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's cleaner to have it the way it is, just wasn't sure because of the PR description so that all the V1 fields are set for a V1 node, because you can leave out setting some fields of the struct in principle (in contrast to having all fields as parameters to NewV1Node like @bhandras mentioned). Just wanted to generate some awareness
|
@bhandras: review reminder |
Simplify the struct by removing un-used methods and outdated comments.
Remove the 2 sources of truth here. If we have a signature for the node, then we have the announcement.
Add a version field to models.Node and a V1 constructor for it.
Remove various unused fields and methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, very nice! 🎉
lnrpc/devrpc/dev_server.go
Outdated
| Alias: rpcNode.Alias, | ||
| // NOTE: this is a workaround to ensure that | ||
| // HaveAnnouncement() returns true so that the other | ||
| // fields are properly persisted. However, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comment ending seems missing.
|
|
||
| // Color is the selected color for the node. | ||
| Color color.RGBA | ||
| Color fn.Option[color.RGBA] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Should NodeV1Fields.Color/Alias be optional too?
| } | ||
|
|
||
| // NewV1Node creates a new version 1 node from the passed fields. | ||
| func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo having a struct argument makes the code slightly more readable. A long list of arguments can end up being very messy.
I think some editors/IDEs don't immediately fill struct fields (e.g. in vim it's doable but not a default) so perhaps @bitromortac was referring to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ⚡
| } | ||
|
|
||
| // NewV1Node creates a new version 1 node from the passed fields. | ||
| func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's cleaner to have it the way it is, just wasn't sure because of the PR description so that all the V1 fields are set for a V1 node, because you can leave out setting some fields of the struct in principle (in contrast to having all fields as parameters to NewV1Node like @bhandras mentioned). Just wanted to generate some awareness
A simple refactor & clean-up PR.
The main thing here is an added Version field to the
models.Nodestruct & using a constructor to create the Node instance so that all the V1 fields are set for a V1 node. This is in preparation for dealing with V2 Nodes.Part of #10293