Skip to content
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

Onion messages: support reply paths #1652

Merged
merged 3 commits into from
Aug 24, 2022

Conversation

valentinewallace
Copy link
Contributor

Adds support for sending reply paths in our onion messages, and for decoding them on onion message read.

valentinewallace added a commit to valentinewallace/rust-lightning that referenced this pull request Aug 6, 2022
Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in lightningdevkit#1652.
valentinewallace added a commit to valentinewallace/rust-lightning that referenced this pull request Aug 6, 2022
Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in lightningdevkit#1652.
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Looks pretty straightforward, only one real comment.

lightning/src/onion_message/blinded_route.rs Outdated Show resolved Hide resolved
@@ -142,7 +142,7 @@ impl<Signer: Sign, K: Deref, L: Deref> OnionMessenger<Signer, K, L>

/// Send an empty onion message to `destination`, routing it through `intermediate_nodes`.
/// See [`OnionMessenger`] for example usage.
pub fn send_onion_message(&self, intermediate_nodes: &[PublicKey], destination: Destination) -> Result<(), SendError> {
pub fn send_onion_message(&self, intermediate_nodes: &[PublicKey], destination: Destination, reply_path: Option<BlindedRoute>) -> Result<(), SendError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume in the future once we have a router to figure out message routes we'll make the argument a simple boolean and do a path lookup for a reply path route (or in a new function or whatever)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I think that makes sense. This API may remain pretty low-level and keep a version of the parameter, but we'll need some way of getting a reply_path for outbound invoice_requests, likely via the router you mention.

@valentinewallace valentinewallace force-pushed the 2022-08-reply-paths branch 3 times, most recently from b698401 to 5afb049 Compare August 8, 2022 18:17
valentinewallace added a commit to valentinewallace/rust-lightning that referenced this pull request Aug 9, 2022
Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in lightningdevkit#1652.
valentinewallace added a commit to valentinewallace/rust-lightning that referenced this pull request Aug 15, 2022
Prior to this change, we could have failed to decode a valid payload of size
>253. This is because we were decoding the length (a BigSize, big-endian) as a
VarInt (little-endian).

Found in lightningdevkit#1652.
lightning/src/onion_message/blinded_route.rs Show resolved Hide resolved
lightning/src/onion_message/messenger.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/blinded_route.rs Outdated Show resolved Hide resolved
lightning/src/onion_message/blinded_route.rs Outdated Show resolved Hide resolved
jkczyz
jkczyz previously approved these changes Aug 23, 2022
@TheBlueMatt
Copy link
Collaborator

Fuzz test is failing now.

@TheBlueMatt
Copy link
Collaborator

Otherwise LGTM.

And fix one test to be uniform with the others
Previously, we were decoding payload lengths as a VarInt. Per the spec, this is
wrong -- it should be decoded as a BigSize.  This bug also exists in our
payment payload decoding, to be fixed separately.

Upcoming reply path tests caught this bug because we hadn't encoded a payload
greater than 253 before, so we hadn't hit the problem that VarInts are encoded
as little-endian whereas BigSizes are encoded as big-endian.
@valentinewallace
Copy link
Contributor Author

Had to rebase to repro the test failure locally. Also removed some warnings that I didn't realize appeared on the last push.

@codecov-commenter
Copy link

Codecov Report

Merging #1652 (132d7f5) into main (17ae116) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 132d7f5 differs from pull request most recent head 950b7d7. Consider uploading reports for the commit 950b7d7 to get more accurate results

@@            Coverage Diff             @@
##             main    #1652      +/-   ##
==========================================
+ Coverage   90.85%   90.87%   +0.01%     
==========================================
  Files          85       85              
  Lines       45714    45755      +41     
  Branches    45714    45755      +41     
==========================================
+ Hits        41534    41580      +46     
+ Misses       4180     4175       -5     
Impacted Files Coverage Δ
lightning/src/onion_message/blinded_route.rs 97.05% <100.00%> (+1.31%) ⬆️
lightning/src/onion_message/functional_tests.rs 95.87% <100.00%> (-2.89%) ⬇️
lightning/src/onion_message/messenger.rs 89.53% <100.00%> (+0.31%) ⬆️
lightning/src/onion_message/packet.rs 80.82% <100.00%> (+3.19%) ⬆️
lightning/src/ln/monitor_tests.rs 99.35% <0.00%> (-0.13%) ⬇️
lightning/src/ln/functional_tests.rs 96.78% <0.00%> (-0.03%) ⬇️
lightning/src/ln/channelmanager.rs 85.13% <0.00%> (-0.03%) ⬇️
lightning/src/chain/channelmonitor.rs 91.12% <0.00%> (+0.05%) ⬆️
... and 4 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

LGTM assuming CI passes.

@@ -344,6 +347,7 @@ fn packet_payloads_and_keys<T: secp256k1::Signing + secp256k1::Verification>(
} else if let Some(encrypted_payload) = enc_payload_opt {
payloads.push((Payload::Receive {
control_tlvs: ReceiveControlTlvs::Blinded(encrypted_payload),
reply_path: reply_path.take(),
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, reply_path is captured by reference (I think?) in the closure, so it will be None if this case is hit more than once when called by construct_keys_callback. Is this the desired behavior? I guess so because there would only be one Payload::Receive?

Related, the same may occur below where reply_path.take() is called again outside of the closure. Partly trying to check my understanding if that case will be hit below but not in the closure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that's intentional. There should only be one Payload::Receive pushed, so reply_path should only be taken once.

@jkczyz jkczyz merged commit f2ece97 into lightningdevkit:main Aug 24, 2022
@jkczyz jkczyz mentioned this pull request May 10, 2023
60 tasks
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