-
Notifications
You must be signed in to change notification settings - Fork 2.2k
PoC Onion messaging using msgmux
#9868
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?
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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 start of the onion message saga 🎉, I think the msgmux
is the way to go here. I am not sure if we should use one server for all peers but if we use it we should buffer the update channel of the onionserver
.
Let's now decrypt the onion message in the next PR ?
lnwire/onion_message.go
Outdated
} | ||
|
||
onionLen := len(o.OnionBlob) | ||
if err := WriteElement(w, uint16(onionLen)); err != nil { |
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.
Why not use varint ?
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 WriteUint16
is maybe even a better choice. WriteElement
is about to be decommissioned so I changed the other references as well.
lnrpc/lightning.proto
Outdated
// onion message. | ||
string blinding_point = 2; | ||
|
||
// Onion is the raw serialized mix header used to relay messages in a |
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: what do you mean by mix header
I mean this is the body of the message why do you call it header ?
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.
"mix header" is the term used in the original Sphinx paper. The "mix header" is the part that contains the per-hop encrypted instructions for each node along the route. I find the usage here confusing as well. (It's copy-pasta from Carla's code, but I'll take responsibility for any confusion 😄).
I'll update it to this:
// Onion is the raw serialized Sphinx onion packet containing the
// per-hop encrypted routing information used to relay this message
// through the network in a privacy-preserving manner.
msgmux/onion_endpoint.go
Outdated
|
||
// SendMessage processes the incoming onion message. | ||
// It returns true if the message was successfully processed. | ||
func (o *OnionEndpoint) SendMessage(ctx context.Context, msg PeerMsg) bool { |
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 find the name confusing it is called SendMessage but handles Incoming onion messages
maybe call it forwardToListener or something ?
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.
Tell me about it! But this is what the msgmux
interface enforces:
https://github.com/gijswijs/lnd/blob/dea09c824f91bd7a08b901ad54caab610204a4b0/msgmux/msg_router.go#L37-L51
server.go
Outdated
@@ -5314,7 +5314,7 @@ func (s *server) applyChannelUpdate(update *lnwire.ChannelUpdate1, | |||
func (s *server) SendCustomMessage(peerPub [33]byte, msgType lnwire.MessageType, | |||
data []byte) error { | |||
|
|||
peer, err := s.FindPeerByPubStr(hex.EncodeToString(peerPub[:])) | |||
peer, err := s.FindPeerByPubStr(string(peerPub[:])) |
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 should fix this in the FindPeerByPubStr
method, we should use a proper hex-encoded string.
@@ -886,6 +890,21 @@ func (p *Brontide) Start() error { | |||
return fmt.Errorf("unable to load channels: %w", err) | |||
} | |||
|
|||
onionMessageEndpoint := msgmux.NewOnionEndpoint( | |||
p.cfg.OnionMessageServer, |
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 am not sure if this is the right approach, we use 1 server-level Server with an update channel which is not buffered to funnel in all onion message from all peers, seem not really efficient ?
this is the update channel of the server:
Lines 154 to 161 in c6d6d4c
func (s *Server) SendUpdate(update interface{}) error { | |
select { | |
case s.updates <- update: | |
return nil | |
case <-s.quit: | |
return ErrServerShuttingDown | |
} |
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.
Not sure if I completely follow you critique.
We have a single subscription endpoint for onion messages (similar to custom messages) which allows for "listening in" on onion messages received by this node. We pass along the subscription server here to the msgmux
endpoint so that when we handle the onion message, we can notify a subscriber of an incoming message.
Buffering or rate limiting the actual onion message itself should happen upstream of the notification server, right?
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 talked about this via other means and agreed upon the fact that we need to differentiate incoming messages so that onion-messages will not hinder channel msges to be received in time.
5762808
to
9f23971
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.
removing request for review in the mean time :) feel free to re-request when ready!
This message type is a message that carries an onion-encrypted payload used for BOLT12 messages.
This commit creates the necessary endpoints for onion messages. Specifically, it adds the following: - `SendOnionMessage` endpoint to send onion messages. - `SubscribeOnionMessages` endpoint to subscribe to incoming onion messages. It uses the `msgmux` package to handle the onion messages.
e5726a7
to
fefe590
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, @gijswijs, for putting this together! I've added some comments. Overall, I like the design and how it's seamlessly integrated with the LND system/subsystems. I can form a clear mental picture of the changes. Nice work!
return err | ||
} | ||
|
||
o.OnionBlob = make([]byte, onionLen) |
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: Perhaps adding a basic sanity check about onion message length (e.g. empty one) and the onion blob size (we can utilize lnwire/lnwire.MaxMsgBody
) makes the size boundary more clear
|
||
// A compile-time check to ensure OnionEndpoint implements the Endpoint | ||
// interface. | ||
var _ msgmux.Endpoint = (*OnionEndpoint)(nil) |
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: The interface check var _ msgmux.Endpoint = (*OnionEndpoint)(nil)
is separated from the OnionEndpoint
struct making it harder to see what interfaces are implemented, considering move it immediately after the OnionEndpoint
definition (and perhaps considering moving OnionMessageUpdate
before OnionEndpoint
for better organization). With this in place perhaps this comment wouldn't have posted #9868 (comment)
type OnionEndpoint struct { | ||
// subscribe.Server is used for subscriptions to onion messages. | ||
onionMessageServer *subscribe.Server | ||
} |
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: This is for my education. It seems there is no rate limiting exists on incoming onion messages per peer which allows peers to spam unlimited onion messages potentially overwhelming node resources and message questions ?
I've already saw your comment #9868 (comment):
Buffering or rate limiting the actual onion message itself should happen upstream of the notification server, right?
Does that mean we currently get out of the box rate limiting (assuming same priority) for each endpoint we register or it is a TODO?
|
||
// Send the message as low-priority. For now we assume that all | ||
// application-defined message are low priority. | ||
return peer.SendMessageLazy(true, msg) |
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.
+1 Nice!
|
||
var peerArr [33]byte | ||
copy(peerArr[:], peer) | ||
err := o.onionMessageServer.SendUpdate(&OnionMessageUpdate{ |
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.
It appears this sends updates to the subscribers without any priority control which could block subscriber notifications when processing high-volume onion messages but when we send the onion message we assign it low priority as in SendOnionMessage
using SendMessageLazy
. Should we enforce same/similar priority mechanism constraint here so it wouldn't interfere with probably higher priority updates?
This may overlap with this comment #9868 (comment).
@@ -5404,6 +5420,33 @@ func (s *server) SendCustomMessage(peerPub [33]byte, msgType lnwire.MessageType, | |||
return peer.SendMessageLazy(true, msg) | |||
} | |||
|
|||
// SendOnionMessage sends a custom message to the peer with the specified | |||
// pubkey. | |||
// TODO(gijs): change this message to include path finding. |
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.
Perhaps this is the reason why the PR in draft mode?
In the spirit of share early, share often and also in the spirit of relatively small and incremental PRs, I'm sharing my first stab at onion messaging using the new message multiplexer package
msgmux
. It's derived from the custom message handling, but adjusted as needed to conform to themsgmux
constraint.Scope of this PR:
msgmux
endpoint inbrontide
Out-of-scope (for now)
brontide
based on