-
Notifications
You must be signed in to change notification settings - Fork 2.2k
lnwire: add missing Gossip 1.75 fields and message #10232
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: master
Are you sure you want to change the base?
lnwire: add missing Gossip 1.75 fields and message #10232
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 lays foundational work for the Gossip 1.75 protocol by updating existing message definitions and introducing new ones. It primarily focuses on enhancing the 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 PR updates the gossip protocol to version 1.75. The changes include renaming NodeAnnouncement
to NodeAnnouncement1
, adding an outpoint
field to ChannelAnnouncement2
, and defining the new NodeAnnouncement2
message. The implementation looks solid and includes relevant test updates.
I've found a few minor issues:
- An incorrect static size for the
OutPoint
TLV record. - A typo in an error message in the Tor address encoder for
NodeAnnouncement2
. - Several new unexported functions are missing comments, which is required by the style guide. I've pointed out a few examples.
Overall, great work on moving the gossip implementation forward.
3d6fdbd
to
fc770dd
Compare
fc770dd
to
019dc79
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.
Pretty close - left a few comments about some improvements we can make.
} | ||
|
||
// allNonSignatureRecordProducers returns all the TLV record producers for the | ||
// nonSignatureRecordProducers returns all the TLV record producers 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.
🌷
lnwire/outpoint.go
Outdated
} | ||
|
||
// outpointEncoder is a TLV encoder for OutPoint. | ||
func outpointEncoder(w io.Writer, val interface{}, _ *[8]byte) 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: can use val any
, same below
// InboundFee is an optional TLV record that contains the fee | ||
// information for incoming HTLCs. | ||
// TODO(elle): assign normal tlv type? | ||
InboundFee tlv.OptionalRecordT[tlv.TlvType55555, Fee] |
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 think we can just use FeeRecordType
.
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.
that just defines an int. we still need the tlv type here
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.
(same was done in ChannelUpdate1)
lnwire/dns_addr.go
Outdated
|
||
// Write the port as 2 bytes. | ||
var portBytes [2]byte | ||
err := WriteUint16(bytes.NewBuffer(portBytes[:0]), v.Port) |
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.
hmm why portBytes[:0]
but not portBytes[:]
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.
Totally agree that it's hard to read - so have updated with simplified version 👍
But out of interest:
portBytes[:0] creates a slice with zero length but the same underlying capacity as portBytes. This is used to reset the buffer position for bytes.NewBuffer() to start writing at the beginning of
the array.
If you used portBytes[:], it would create a slice with the full length (2 bytes) containing whatever data was previously in the array, which would interfere with the WriteUint16 function.
The [:0] slice gives bytes.NewBuffer an empty slice to start with, ensuring clean writes to the array.
lnwire/dns_addr.go
Outdated
} | ||
|
||
// dnsAddressEncoder is a TLV encoder for DNSAddress. | ||
func dnsAddressEncoder(w io.Writer, val interface{}, _ *[8]byte) 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: can use any
torV3 = tlv.ZeroRecordT[tlv.TlvType9, TorV3Addrs]() | ||
dns = tlv.ZeroRecordT[tlv.TlvType11, DNSAddress]() | ||
) | ||
stream, err := tlv.NewStream(ProduceRecordsSorted( |
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: newline above
func rgbEncoder(w io.Writer, val interface{}, _ *[8]byte) error { | ||
if v, ok := val.(*Color); ok { | ||
buf := bytes.NewBuffer(nil) | ||
err := WriteColorRGBA(buf, color.RGBA(*v)) |
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 think we can just pass w
here? why creating the buf
?
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.
WriteColorRGBA takes a buffer pointer
return err | ||
} | ||
onionService := tor.Base32Encoding.EncodeToString(ip[:]) | ||
onionService += tor.OnionSuffix |
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.
similar to how if len(host) != tor.V3DecodedLen
above we should also validate len(onionService)
019dc79
to
3676d59
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.
thanks @yyforyongyu 🙏
// InboundFee is an optional TLV record that contains the fee | ||
// information for incoming HTLCs. | ||
// TODO(elle): assign normal tlv type? | ||
InboundFee tlv.OptionalRecordT[tlv.TlvType55555, Fee] |
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.
that just defines an int. we still need the tlv type here
// InboundFee is an optional TLV record that contains the fee | ||
// information for incoming HTLCs. | ||
// TODO(elle): assign normal tlv type? | ||
InboundFee tlv.OptionalRecordT[tlv.TlvType55555, Fee] |
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.
(same was done in ChannelUpdate1)
lnwire/dns_addr.go
Outdated
|
||
// Write the port as 2 bytes. | ||
var portBytes [2]byte | ||
err := WriteUint16(bytes.NewBuffer(portBytes[:0]), v.Port) |
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.
Totally agree that it's hard to read - so have updated with simplified version 👍
But out of interest:
portBytes[:0] creates a slice with zero length but the same underlying capacity as portBytes. This is used to reset the buffer position for bytes.NewBuffer() to start writing at the beginning of
the array.
If you used portBytes[:], it would create a slice with the full length (2 bytes) containing whatever data was previously in the array, which would interfere with the WriteUint16 function.
The [:0] slice gives bytes.NewBuffer an empty slice to start with, ensuring clean writes to the array.
func rgbEncoder(w io.Writer, val interface{}, _ *[8]byte) error { | ||
if v, ok := val.(*Color); ok { | ||
buf := bytes.NewBuffer(nil) | ||
err := WriteColorRGBA(buf, color.RGBA(*v)) |
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.
WriteColorRGBA takes a buffer pointer
3676d59
to
72d41e1
Compare
Add a new OutPoint type that wraps wire.OutPoint and provides TLV encoding/decoding capabilities through the tlv.RecordProducer interface. This enables OutPoint to be used in TLV streams of messages.
The latest version of the spec has the outpoint included in the `channel_announcement2` message.
In preparation for adding a NodeAnnouncement2 struct along with a NodeAnnouncement interface, this commit renames the existing NodeAnnouncment struct to NodeAnnouncement1.
We leave a TODO that should be addressed after a discussion at the spec meeting. For now, having the incorrect TLV type is not a problem since this ChannelUpdate2 type is not used in production.
In preparation for using this type as a TLV record, we let it implement the RecordProducer interface.
In this commit, the lnwire.NodeAnnouncement2 type is defined. This will be used to represent the `node_announcement_2` message used in the Gossip 2 (1.75) protocol.
72d41e1
to
1ccb590
Compare
This PR does the following main things:
outpoint
field to theChannelAnnouncement2
message.NodeAnnouncement2
message which will be used to represent the newnode_announcement_1
message.This is part of the gossip 1.75 project. None of these types are used in the projection code yet.