-
Notifications
You must be signed in to change notification settings - Fork 421
Remove the final_cltv_expiry_delta in RouteParameters entirely #2015
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
Remove the final_cltv_expiry_delta in RouteParameters entirely #2015
Conversation
|
Needs rebase |
f106a82 to
76a1530
Compare
|
Rebased. |
|
Looks like fuzz stuff needs updating diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs
index 9b3b76c2..3d9be984 100644
--- a/fuzz/src/full_stack.rs
+++ b/fuzz/src/full_stack.rs
@@ -513,7 +513,6 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
let params = RouteParameters {
payment_params,
final_value_msat,
- final_cltv_expiry_delta: 42,
};
let random_seed_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
let route = match find_route(&our_id, ¶ms, &network_graph, None, Arc::clone(&logger), &scorer, &random_seed_bytes) {
@@ -537,7 +536,6 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
let params = RouteParameters {
payment_params,
final_value_msat,
- final_cltv_expiry_delta: 42,
};
let random_seed_bytes: [u8; 32] = keys_manager.get_secure_random_bytes();
let mut route = match find_route(&our_id, ¶ms, &network_graph, None, Arc::clone(&logger), &scorer, &random_seed_bytes) {
diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs
index a7c50de4..66d68040 100644
--- a/fuzz/src/router.rs
+++ b/fuzz/src/router.rs
@@ -302,7 +302,6 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
payment_params: PaymentParameters::from_node_id(*target, final_cltv_expiry_delta)
.with_route_hints(last_hops.clone()),
final_value_msat,
- final_cltv_expiry_delta,
};
let _ = find_route(&our_pubkey, &route_params, &net_graph,
first_hops.map(|c| c.iter().collect::<Vec<_>>()).as_ref().map(|a| a.as_slice()), |
76a1530 to
1e1cb91
Compare
|
Oops, thanks. Also rebased. |
lightning/src/routing/router.rs
Outdated
| (9, final_cltv_expiry_delta, (default_value, default_final_cltv_expiry_delta)), | ||
| }); | ||
| Ok(Self { | ||
| payee_pubkey: payee_pubkey.0.unwrap(), |
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.
Wouldn't it provide better compile-time checks to use _init_tlv_based_struct_field ?
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.
Yea, I guess, I mean it currently does this but I agree if we ever change it we don't want this to blow up.
| pub final_cltv_expiry_delta: u32, | ||
| } | ||
|
|
||
| impl Writeable for PaymentParameters { |
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 keep using the macro but default to 0 (or MIN_CLTV_EXPIRY_DELTA), so the field can be set by higher-level reads? Do we expect users to be serializing this struct?
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.
If a user has a RouteParameters serialized in 113, eg because of a payment failure, and they retry it on restart in 114, we want to make sure the final_cltv_expiry_delta parameter moves over to the right place. Because its a given parameter I dont think we want to just assume its some specific value.
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.
Hmm, if we kept PayParams using the ser macro with a default value, RouteParams deser would always ensure it sets the correct value, though. I see why we need to break out of the macro for RouteParams, but just not sure I understand why we need to break out for PaymentParams.
If a user has a RouteParameters serialized in 113, eg because of a payment failure, and they retry it on restart in 114
+ retries on restart aren't supported in 114 (do you mean using send_payment?).
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.
The value read from the old field in RouteParameters needs to make it into the PaymentParameters somehow on read, I'm not sure how we do that without breaking up the macro as well?
- retries on restart aren't supported in 114 (do you mean using send_payment?).
Right, I guess I mean if you're using the PaymentPathFailed data to retry? I guess it borderline doesn't matter but it does feel weird to synthesize the wrong value in the serialized event.
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 wouldn't be synthesizing the wrong value, though, IIUC. Shouldn't this code in RouteParams deser cover this case, if they do want to use PaymentPathFailed::retry?
let mut payment_params: PaymentParameters = payment_params.0.unwrap();
if payment_params.final_cltv_expiry_delta == 0 {
payment_params.final_cltv_expiry_delta = final_cltv_expiry_delta.0.unwrap();
}
Another thought could be removing retry entirely, which we want to do at some point anyway, maybe even more ser complexity introduced there though.
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.
Anyway, we may be talking past each other, and it doesn't matter that much though the broken-up macro is somewhat ugly, so I won't die on this hill :)
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, okay, I indeed didn't understand your suggestion here - yes, I think all the places we read a RouteParameters in LDK we are happy with the special-case of 0 for min_final_cltv_delta being treated as "no value" and overwriting it. However, that's...weird in a public API? Like, there's an implicit Option, there, basically, and we can't have an actual Option there because the router can't deal with it. So I'd kinda rather force the caller to pass the value in via the ReadableArgs implementation rather than have an implicit Option?
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.
Yeah, just seems unlikely this struct would ever be serialized on its own, even if it's technically possible. Fine to leave as-is
valentinewallace
left a comment
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.
LGTM
Codecov ReportBase: 87.26% // Head: 87.42% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #2015 +/- ##
==========================================
+ Coverage 87.26% 87.42% +0.15%
==========================================
Files 101 101
Lines 44414 47347 +2933
Branches 44414 47347 +2933
==========================================
+ Hits 38759 41394 +2635
- Misses 5655 5953 +298
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
Looks good for squash |
alecchendev
left a comment
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.
Don't have much to add, just learned a lot about macros while trying to understand what this PR was doing.
One comprehension check: Is the main reason that RouteParameters even needs to be serializable in the first place because it's included in Event::PaymentFailed which may be persisted (because a user would want to respond to the event after a crash)?
We're actually planning to get rid of |
a4d85db to
de3fab7
Compare
|
Squashed fixups down. |
|
Needs rebase |
de3fab7 to
102e088
Compare
|
Rebased. |
102e088 to
d2307db
Compare
|
Rebased. |
d2307db to
28a94c1
Compare
|
Some rebase errors need fixing sadly |
|
Sorry was waiting on #2055 |
When we read a `Route` (or a list of `RouteHop`s), we should never have zero paths or zero `RouteHop`s in a path. As such, its fine to simply reject these at deserialization-time. Technically this could lead to something which we can generate not round-trip'ing serialization, but that seems okay here.
This adds `required` support for trait-wrapped reading (e.g. for objects read via `ReadableArgs`) as well as support for the trait-wrapped reading syntax across the TLV struct/enum serialization macros.
28a94c1 to
280f087
Compare
fbc0847 purported to "move" the `final_cltv_expiry_delta` field to `PaymentParamters` from `RouteParameters`. However, for naive backwards-compatibility reasons it left the existing on in place and only added a new, redundant field in `PaymentParameters`. It turns out there's really no reason for this - if we take a more critical eye towards backwards compatibility we can figure out the correct value in every `PaymentParameters` while deserializing. We do this here - making `PaymentParameters` a `ReadableArgs` taking a "default" `cltv_expiry_delta` when it goes to read. This allows existing `RouteParameters` objects to pass the read `final_cltv_expiry_delta` field in to be used if the new field wasn't present.
280f087 to
f03b7cd
Compare
|
Phew. What a rebase rally! :P |
|
Heh, it wasn't that important compared to the things it conflicted with 🤷♂️ |
fbc0847 purported to "move" the
final_cltv_expiry_deltafield toPaymentParamtersfromRouteParameters. However, for naive backwards-compatibilityreasons it left the existing on in place and only added a new,
redundant field in
PaymentParameters.It turns out there's really no reason for this - if we take a more
critical eye towards backwards compatibility we can figure out the
correct value in every
PaymentParameterswhile deserializing.We do this here - making
PaymentParametersaReadableArgstaking a "default"
cltv_expiry_deltawhen it goes to read. Thisallows existing
RouteParametersobjects to pass the readfinal_cltv_expiry_deltafield in to be used if the new fieldwasn't present.
Sadly, if we want to do this, we have to do it in the same release as the above commit, so it has to land for 114 :(