-
Notifications
You must be signed in to change notification settings - 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
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.
@ellemouton, remember to re-request review from reviewers when ready |
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 🧹
endNode := &models.Node{} | ||
endNode := target | ||
if i != len(routeHint)-1 { | ||
endNode.AddPubKey(routeHint[i+1].NodeID) |
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.
nice refactor 🎉
} | ||
|
||
// HaveAnnouncement returns true if we have received a node announcement for | ||
// this node. We determine this by checking if we a signature for the |
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.
nice change 👍
nit: have
error) { | ||
|
||
if !l.HaveNodeAnnouncement { | ||
if !n.HaveAnnouncement() { |
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.
if we add && signed
here, I think we don't need the workaround for the self announcement?
var err error | ||
for _, rpcNode := range graph.Nodes { | ||
node := &models.Node{ | ||
HaveNodeAnnouncement: true, |
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.
do we need to apply the workaround here, to not break this? otherwise I think we won't insert the other properties
// lnwire.NodeAnnouncement1 message. | ||
func NodeFromWireAnnouncement(msg *lnwire.NodeAnnouncement1) *Node { | ||
timestamp := time.Unix(int64(msg.Timestamp), 0) | ||
features := lnwire.NewFeatureVector(msg.Features, lnwire.Features) |
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: could pass msg.Features
to NewV1Node
directly
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?
} | ||
|
||
// 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?
var pubKey [33]byte | ||
copy(pubKey[:], pub.SerializeCompressed()) |
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 feel like a route.NewMustVertexFromBytes
without error check could be useful
// DB is an interface describing a persisted Lightning Network graph. | ||
// | ||
//nolint:interfacebloat | ||
type DB interface { |
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.
nice, was it already possible before this PR to remove this, or was this enabled here?
graph/interfaces.go
Outdated
// star-graph. | ||
ForAllOutgoingChannels(ctx context.Context, | ||
cb func(c *models.ChannelEdgeInfo, | ||
e *models.ChannelEdgePolicy) error, reset func()) error |
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: introduced in previous commit
A simple refactor & clean-up PR.
The main thing here is an added Version field to the
models.Node
struct & 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