-
Notifications
You must be signed in to change notification settings - Fork 375
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
Trampoline Payload Construction Method #3386
base: main
Are you sure you want to change the base?
Trampoline Payload Construction Method #3386
Conversation
lightning/src/routing/router.rs
Outdated
@@ -454,6 +454,9 @@ impl_writeable_tlv_based!(BlindedTail, { | |||
pub struct Path { | |||
/// The list of unblinded hops in this [`Path`]. Must be at least length one. | |||
pub hops: Vec<RouteHop>, | |||
/// The list of unblinded Trampoline hops. If present, must be at least one. | |||
/// The public key of the first Trampoline hop must match the public key of the last regular hop. |
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 don't see why this needs to be true. Can we just have each trampoline hop be next hops starting after the last unblinded node.
7cad33e
to
856ce97
Compare
856ce97
to
5ea3ada
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3386 +/- ##
==========================================
+ Coverage 89.74% 90.44% +0.69%
==========================================
Files 130 130
Lines 107793 113400 +5607
Branches 107793 113400 +5607
==========================================
+ Hits 96743 102569 +5826
+ Misses 8651 8495 -156
+ Partials 2399 2336 -63 ☔ View full report in Codecov by Sentry. |
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.
Ah I guess my previous comments still need to be addressed.
lightning/src/routing/router.rs
Outdated
@@ -404,13 +404,16 @@ pub struct BlindedTail { | |||
pub excess_final_cltv_expiry_delta: u32, | |||
/// The total amount paid on this [`Path`], excluding the fees. | |||
pub final_value_msat: u64, | |||
/// Used for determining the type of Trampoline path to construct | |||
pub final_hop_supports_trampoline: 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.
Should we instead consider storing a *Features
of some form?
5ea3ada
to
af1818b
Compare
ee68783
to
4dd0fea
Compare
lightning/src/ln/onion_utils.rs
Outdated
Ok((res, value_msat, cltv)) | ||
} | ||
|
||
fn build_trampoline_onion_payloads_callback<'a, H, B, F>( |
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.
Is there a way to DRY this with build_onion_payloads_callback
, via implementing a trait on OutboundTrampolinePayload
and OutboundOnionPayload
that the common method is parameterized by? Kinda like what we do for decode_next_hop
and how it works for both onion message and onion payment packets.
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'm not sure the payloads_callback is super DRYable, because all the response types that are being pushed vary strongly between RouteHop and TrampolineHop, but I think I was able to at least DRY up the onion_keys callback.
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 ended up looking into this a bit more to see if we could avoid all the C&P, got this patch to compile: valentinewallace@974f212
It needs to be filled out a bit but take a look!
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! I incorporated it for the most part. The impl is a bit duplicative the way I did it, but the borrow checker and I are looking into simplifying it a bit
dc679c0
to
7477b1a
Compare
lightning/src/ln/onion_utils.rs
Outdated
cur_value_msat += final_value_msat; | ||
callback( | ||
PayloadCallbackAction::PushBack, | ||
msgs::OutboundTrampolinePayload::BlindedReceive { |
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 looks like in https://github.com/lightning/bolts/blob/fa0594ac2af3531d734f1d707a146d6e13679451/bolt04/trampoline-payment-onion-test.json there can be final trampoline hops that are unblinded, but that doesn't look supported in the code atm. Are we explicitly only supporting trampoline to blinded paths?
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.
yup, we deliberately are. We originally supported non-blinded destinations but decided not to.
7477b1a
to
ba71d6e
Compare
b934379
to
6569246
Compare
09c7f70
to
adb0b88
Compare
Haven't looked closely yet but it looks like the non-test changes in the latest commit belong in earlier commit(s). Feel free to squash IMO! |
adb0b88
to
9535d78
Compare
I think the squashing should have taken care of that, though let me know if you'd like any other changes move around. |
@@ -1757,3 +1762,83 @@ fn route_blinding_spec_test_vector() { | |||
_ => panic!("Unexpected error") | |||
} | |||
} | |||
|
|||
#[test] | |||
fn combined_trampoline_onion_creation_test() { |
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.
Could you add a comment or adjust the test name to document that these are from the spec test vectors?
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.
done
lightning/src/routing/router.rs
Outdated
} | ||
|
||
impl_writeable_tlv_based!(BlindedTail, { | ||
(0, hops, required_vec), | ||
(2, blinding_point, required), | ||
(4, excess_final_cltv_expiry_delta, required), | ||
(6, final_value_msat, required), | ||
(8, final_hop_supports_trampoline, required), |
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.
Older versions won't be able to read these now since it's a required TLV, probably want to use an odd TLV and default_value
/// The node_announcement features of the node at this hop. For the last hop, these may be | ||
/// amended to match the features present in the invoice this node generated. | ||
pub node_features: NodeFeatures, | ||
/// The fee taken on this hop (for paying for the use of the *next* channel in the path). |
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.
Isn't it the fee taken for the next several hops until the next trampoline node, or the intro node? I think the docs for this field might need a glance to make sure they're accurate for trampoline, same for cltv_expiry_delta
lightning/src/ln/onion_utils.rs
Outdated
excess_final_cltv_expiry_delta: bt.excess_final_cltv_expiry_delta, | ||
}); | ||
|
||
// don't include blinded tail when Trampoline hops are present |
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.
Probably should include why we're doing this
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.
done
lightning/src/ln/onion_utils.rs
Outdated
Ok((res, value_msat, cltv)) | ||
} | ||
|
||
fn build_trampoline_onion_payloads_callback<'a, H, B, F>( |
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 ended up looking into this a bit more to see if we could avoid all the C&P, got this patch to compile: valentinewallace@974f212
It needs to be filled out a bit but take a look!
9535d78
to
ab320ba
Compare
ab320ba
to
e191a3d
Compare
@@ -1670,6 +1671,7 @@ impl Writeable for Event { | |||
(2, payment_hash, option), | |||
(4, path.hops, required_vec), | |||
(6, path.blinded_tail, option), | |||
(8, path.trampoline_hops, optional_vec), |
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 trying to understand how types get assigned in LDK - it's an optional field here so shouldn't it have an odd type value ? thanks for clarifying.
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.
those concepts are a bit orthogonal. Even means if it's present, you cannot ignore it, i.e. you have to understand how to parse it, whereas odd means it's fine to just skip that value if you don't know what to do with it.
Optional means that the value may not need to be set. So you can have optional even fields like here, where there may not be a value, but if there is one, it's important to understand it correctly.
The only scenario I cannot really think of a good use case for is required odd fields, which would suggest that the value must always be present, but is fine to skip when parsing.
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.
thank you I understand now.
@@ -668,7 +668,7 @@ impl HTLCSource { | |||
pub fn dummy() -> Self { | |||
assert!(cfg!(not(feature = "grind_signatures"))); | |||
HTLCSource::OutboundRoute { | |||
path: Path { hops: Vec::new(), blinded_tail: None }, | |||
path: Path { hops: Vec::new(), trampoline_hops: Vec::new(), blinded_tail: None }, |
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: every other vec in this patch is initialized with vec![]
, perhaps make this consistent ? your call feel free to dismiss.
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.
oh, good point!
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.
ah, actually, the other element had already been initialized with Vec::new(), so I think that's more consistent in this instance
e191a3d
to
249a1a0
Compare
249a1a0
to
549fdd5
Compare
Introduce a method for constructing Trampoline payloads.
This will allow the non-Trampoline method to be modified to generate a Trampoline onion and finish its own regular payload construction.
Builds on top of #3333.