-
Notifications
You must be signed in to change notification settings - Fork 412
Refactor BlindedPath
construction utils
#3248
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
Refactor BlindedPath
construction utils
#3248
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3248 +/- ##
==========================================
- Coverage 89.82% 89.79% -0.03%
==========================================
Files 125 125
Lines 102867 102882 +15
Branches 102867 102882 +15
==========================================
- Hits 92398 92388 -10
- Misses 7753 7777 +24
- Partials 2716 2717 +1 ☔ View full report in Codecov by Sentry. |
Needs a rebase. |
When constructing a BlindedPath, utils::construct_blinded_hops uses two iterators. However, this makes it difficult to pad blinded hops to equal sizes without allocating a vector or cloning data. Refactor the construct_keys_callback utility function so that is can be used with an Iterator with different Item types. This allows using a single Iterator of tuples while still supporting its use only with pubkeys.
Instead of accepting iterators yielding PublicKey by reference in utils::construct_keys_callback, take iterators yielding values since these implement Copy and need to be copied anyway. This will help avoid a situation when padding where both a reference and mutable reference are needed.
When constructing a BlindedPath, an Option<Destination> parameter to construct_keys_callback is never passed. Make a separate utility function that doesn't take this parameter. This allows for using the build_keys_helper macro with a Iterator yielding items other than PublicKey.
When constructing a blinded path, two iterators are used: one for the pubkeys and another for Writeable TLVs. The first iterator is used in the build_keys_helper utility function while the second is used inside of a callback. Update this utility to work on any type that can be borrowed as a PublicKey. This allows for using a single iterator of tuples, which is necessary for padding the hops without additional allocations and clones.
Instead of using separate iterators for pubkeys and TLVs, use an iterator that yields a tuple of them. This allows for holding a mutable reference to the TLVs such that they can be padded. With two iterators, the pubkey iterator would have a reference to the ForwardNode slice when constructing a payment path. However, this would prevent holding mutable references in the TLVs iterator.
667ffa6
to
76c9fda
Compare
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! 🚀
When constructing a
BlindedPath
, theconstruct_blinded_hops
utility function requires two iterators: one for public keys and another for TLVs. The first is used by theconstruct_keys_callback
function while the second is used in a callback passed to that function.There are few disadvantages to this:
Option<Destination>
parameter is not relevant as it is only used for constructing the full onion.This PR refactors the utility functions such that only a single iterator is used. This is useful as an iterator over mutable TLVs can be used to add padding, in particular for payment paths when adding dummy hops. See #3177 (comment).