Skip to content

Pub make onion #2583

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

Merged
merged 1 commit into from
Sep 25, 2023
Merged

Conversation

Evanfeenstra
Copy link
Contributor

Adds a public construct_onion_message method on OnionMessenger. At sphinx chat we are experimenting with client-side onion route creation, and would like to use a method like this

reply_path: Option<BlindedPath>
) -> Result<Vec<u8>, SendError> {
let (_, onion_routing_packet) = self.make_onion_message(path, message, reply_path)?;
Ok(onion_routing_packet.onion_routing_packet.hop_data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we return the full OnionMessage? Presumably whatever is handling it needs the blinding_point as well to send.

}

/// Construct an onion message with contents `message` to the destination of `path`.
pub fn construct_onion_message<T: CustomOnionMessageContents>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like this method really wants to be static - IIUC your use-case is that you want to do the onion message construction on an edge node but then pass it to the first hop via some out-of-band protocol. Using an OnionMessenger could work for that, but seems a bit awkward to expose a method to return the message on a struct that's all about passing messages to peers. If we want a method that generates messages in a free-standing way, it probably should be a utility method, rather than a struct method taking &self. OTOH, if you want to use the struct, you could probably just intercept on the other send, calling send_onion_message then immediately calling next_onion_message_for_peer on the messenger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i see what you mean, its much cleaner as a static method. And u can use it just like SimpleRefOnionMessenger::make_onion_message. Thanks for taking a look!

@@ -631,7 +631,8 @@ pub struct UpdateAddHTLC {
pub struct OnionMessage {
/// Used in decrypting the onion packet's payload.
pub blinding_point: PublicKey,
pub(crate) onion_routing_packet: onion_message::Packet,
/// The full onion packet including hop data, pubkey, and hmac
pub onion_routing_packet: onion_message::Packet,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't (actually) public because Packet isn't pub (its only pub from a private module). You'll need to make the packet module pub.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Packet was already exported from the mod.rs as pub(crate), so I just made it pub and added doc comments

pub version: u8,
/// The PublicKey used during shared secret generation
pub public_key: PublicKey,
/// 1300 bytes payload for the next hop
Copy link
Collaborator

Choose a reason for hiding this comment

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

1300 bytes is for payment onions, not onion messages. This is arbitrary length.

pub struct Packet {
/// Bolt 04 version number
pub version: u8,
/// The PublicKey used during shared secret generation
Copy link
Collaborator

Choose a reason for hiding this comment

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

A bit more info would be nice, something like just "a random secp256k1 point which is ECDH'd to build a shared secret used to decrypt the hop_data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, thanks for the feedback

@TheBlueMatt
Copy link
Collaborator

This LGTM, can you squash the fixup commits down so that each commit stands on its own and no commit cleans up or fixes code introduced in a previous commit?

@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2023

Codecov Report

Patch coverage: 97.14% and project coverage change: -1.86% ⚠️

Comparison is base (53c8f89) 90.63% compared to head (30b74a6) 88.77%.
Report is 30 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2583      +/-   ##
==========================================
- Coverage   90.63%   88.77%   -1.86%     
==========================================
  Files         113      113              
  Lines       59057    84510   +25453     
  Branches    59057    84510   +25453     
==========================================
+ Hits        53524    75027   +21503     
- Misses       5533     7247    +1714     
- Partials        0     2236    +2236     
Files Changed Coverage Δ
lightning/src/ln/msgs.rs 76.79% <ø> (-9.41%) ⬇️
lightning/src/onion_message/packet.rs 62.41% <ø> (-32.79%) ⬇️
lightning/src/onion_message/messenger.rs 81.60% <97.14%> (-4.91%) ⬇️

... and 110 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Evanfeenstra
Copy link
Contributor Author

This LGTM, can you squash the fixup commits down so that each commit stands on its own and no commit cleans up or fixes code introduced in a previous commit?

ok done!

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -631,7 +631,8 @@ pub struct UpdateAddHTLC {
pub struct OnionMessage {
/// Used in decrypting the onion packet's payload.
pub blinding_point: PublicKey,
pub(crate) onion_routing_packet: onion_message::Packet,
/// The full onion packet including hop data, pubkey, and hmac
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future, docs should end in periods (particularly public docs)

@@ -283,6 +283,36 @@ where
&self, path: OnionMessagePath, message: OnionMessageContents<T>,
reply_path: Option<BlindedPath>
) -> Result<(), SendError> {
let (introduction_node_id, onion_msg) = Self::create_onion_message(
&self.entropy_source,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: You have whitespace hanging off the end of line here and a few other places. This should be highlighted by a local git show depending on your terminal settings.

@TheBlueMatt TheBlueMatt merged commit ce74634 into lightningdevkit:main Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants