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

Serialize blinded Trampoline hops #3007

Conversation

arik-so
Copy link
Contributor

@arik-so arik-so commented Apr 19, 2024

Add BlindedForward and BlindedReceive variants to OutboundTrampolinePayload.

@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 97.50000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 90.89%. Comparing base (66fb520) to head (9d01751).
Report is 66 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/msgs.rs 97.50% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3007      +/-   ##
==========================================
+ Coverage   89.66%   90.89%   +1.23%     
==========================================
  Files         126      127       +1     
  Lines      102676   115370   +12694     
  Branches   102676   115370   +12694     
==========================================
+ Hits        92062   104864   +12802     
+ Misses       7894     7854      -40     
+ Partials     2720     2652      -68     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? 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.

Similarly, why is this draft? What's it waiting on?

@@ -1767,6 +1768,21 @@ mod fuzzy_internal_msgs {
outgoing_cltv_value: u32,
/// The node id to which the trampoline node must find a route
outgoing_node_id: PublicKey,
},
#[allow(unused)]
BlindedForward {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we get some docs, what does BlindedForward and BlindedReceive actually mean?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Any update here?

@arik-so arik-so mentioned this pull request Apr 22, 2024
30 tasks
@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from 67ecd63 to 4b631d6 Compare June 17, 2024 08:44
@TheBlueMatt
Copy link
Collaborator

CI is quite sad.

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch 2 times, most recently from e3c86f7 to 4c785b5 Compare June 20, 2024 15:41
@arik-so arik-so marked this pull request as ready for review June 24, 2024 17:27
@TheBlueMatt
Copy link
Collaborator

Feel free to squash before any reviewers take a big look.

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from 4c785b5 to 16d1ba1 Compare June 26, 2024 12:55
/// List of blinded path options the last trampoline hop may choose to route through.
payment_paths: Vec<BlindedPath>,
/// If applicable, features of the BOLT12 invoice being paid.
invoice_features: Option<Bolt12InvoiceFeatures>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure this is supposed to be a Bolt12InvoiceFeatures and not a BlindedPathFeatures? I mean it makes sense just want to double-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by BlindedPathFeatures do you mean BlindedHopFeatures?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Uhhh...I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, pretty sure invoice features are correct here

@@ -1767,6 +1768,21 @@ mod fuzzy_internal_msgs {
outgoing_cltv_value: u32,
/// The node id to which the trampoline node must find a route
outgoing_node_id: PublicKey,
},
#[allow(unused)]
BlindedForward {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any update here?

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from 53b7f63 to b9f002e Compare September 22, 2024 14:07
Comment on lines 2796 to 2797
p.inner_blinded_path().encode().into_iter().chain(p.payinfo.encode()).collect::<Vec<u8>>()
}).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're building multiple vecs here where I think we can get away with none. May need to support writing iterators over bytes, but that should be doable?

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from b9f002e to 9d01751 Compare October 10, 2024 16:50
(2, HighZeroBytesDroppedBigSize(*amt_to_forward), required),
(4, HighZeroBytesDroppedBigSize(*outgoing_cltv_value), required),
(21, invoice_features.as_ref().map(|m| WithoutLength(m)), option)
}, [&blinded_path_tlv]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we expand this to support writing Iterator<u8>s?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean such as in BlindedReceive, which allows passing custom TLVs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, like that.

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from 9d01751 to aa73fe2 Compare October 11, 2024 17:12
Comment on lines 2797 to 2799
}).collect();
let blinded_path_tlv = (22, blinded_path_value);
let custom_tlvs: Vec<&(u64, Vec<u8>)> = core::iter::once(blinded_path_tlv).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you collecting into a vec and then iterating it? Let's avoid the allocation.

});
},
Self::BlindedReceive { sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs, intro_node_blinding_point, keysend_preimage, custom_tlvs } => {
let keysend_tlv = keysend_preimage.map(|preimage| (5482373484, preimage.encode()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, is this defined in the BlindedReceive proposed? And, if it is, can we swap it for a type in a sensible range so we can drop the collect + sort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the identical type ID we currently use in the non-Trampoline payload, but no, Eclair does not have a defined value for this in their code at this time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's pick one that isn't in the experimental range and pressure them to use that instead :)

@TheBlueMatt
Copy link
Collaborator

Looks like this needs rebase and CI was failing.

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch 4 times, most recently from 017b9a7 to d0363d5 Compare October 23, 2024 15:58
Comment on lines 2795 to 2797
let blinded_path_value: Vec<u8> = payment_paths.iter().flat_map(|p| {
p.inner_blinded_path().encode().into_iter().chain(p.payinfo.encode())
}).collect();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The current logic here, for each blinded path, allocates two vecs, and then at the end we allocate another vec. Instead, we should allocate one vec (with_capacity) and then write all the fields we want into it, saving two allocations per path.

});
},
Self::BlindedReceive { sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, encrypted_tlvs, intro_node_blinding_point, keysend_preimage, custom_tlvs } => {
let keysend_tlv = keysend_preimage.map(|preimage| preimage.encode());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't build a vec for 32 bytes. I'm kinda confused why we can't just write the keysend_preimage directly?

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from d0363d5 to 589ef85 Compare October 23, 2024 17:00
Comment on lines 2797 to 2798
current_payment_path.inner_blinded_path().write(&mut blinded_path_serialization)?;
current_payment_path.payinfo.write(&mut blinded_path_serialization)?;
Copy link
Collaborator

@TheBlueMatt TheBlueMatt Oct 23, 2024

Choose a reason for hiding this comment

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

If we're gonna handle the error anyway lets just write into a fixed-length buffer on stack?

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from 589ef85 to 3df5131 Compare October 23, 2024 18:08
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, feel free to squash.

current_payment_path.inner_blinded_path().write(&mut blinded_path_slice)?;
current_payment_path.payinfo.write(&mut blinded_path_slice)?;
}
2048 - blinded_path_slice.len()
Copy link
Collaborator

Choose a reason for hiding this comment

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

super nit

Suggested change
2048 - blinded_path_slice.len()
blinded_path_serialization.len - blinded_path_slice.len()

@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch 2 times, most recently from bbf5d18 to e11a5ab Compare October 23, 2024 18:45
@arik-so arik-so force-pushed the arik/trampoline/2024-04-trampoline-blinded-hop-serialization branch from e11a5ab to d111981 Compare October 23, 2024 20:06
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.

Pretty trivial, if there's any issues we'll find it when we go to use this stuff. Landing.

@TheBlueMatt TheBlueMatt merged commit 206ab82 into lightningdevkit:main Oct 23, 2024
17 of 18 checks passed
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.

3 participants