Introduce Padding for Payment and Message Blinded Tlvs
Description
This PR introduces padding for Payment and Message Blinded TLVs to ensure that the size of each packet in the path is uniform.
Notes:
-
Padding Implementation:
- The padding field is now expanded to contain
Option<Vec>. This change allows the inclusion of padding within the packet while retaining the flexibility to leave the padding asNone.
- The padding field is now expanded to contain
-
Impact on Path Length:
- With the added padding, the length of each individual packet increases, which results in a reduction of the maximum path length. Consequently, the
max_path_lengthinforward_check_failureshas been adjusted from18to17.
- With the added padding, the length of each individual packet increases, which results in a reduction of the maximum path length. Consequently, the
Codecov Report
Attention: Patch coverage is 98.48485% with 2 lines in your changes missing coverage. Please review.
Project coverage is 88.53%. Comparing base (
1434e9c) to head (758d06d).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| lightning/src/blinded_path/utils.rs | 94.44% | 1 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #3177 +/- ##
==========================================
- Coverage 88.54% 88.53% -0.01%
==========================================
Files 149 149
Lines 114579 114704 +125
Branches 114579 114704 +125
==========================================
+ Hits 101457 101558 +101
- Misses 10633 10650 +17
- Partials 2489 2496 +7
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Updated from pr3177.01 to pr3177.02 (diff): Addressed @jkczyz's comments.
Changes:
- Reordered commits and separated the update to the
Paddingstruct into a separate commit. - Updated the Padding struct to contain a
usizeinstead of aVecto save on heap allocation, and made theWritableimplementation more efficient. - Introduced two
f:commits to useiterclone instead ofVecallocation, keeping the code efficient. - Introduced a test and a test utility to verify that blinded message and payment paths are properly padded, ensuring a consistent payload size.
Updated from pr3177.02 to pr3177.03 (diff):
Changes:
- Rebase on main to fix ci.
Diff post rebase:
--- a/lightning/src/ln/offers_tests.rs
+++ b/lightning/src/ln/offers_tests.rs
@@ -1789,7 +1789,7 @@ fn test_blinded_path_padding() {
let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
- let invoice = extract_invoice(david, &onion_message);
+ let (invoice, _) = extract_invoice(david, &onion_message);
assert_eq!(invoice, expected_invoice);
Updated from pr3177.03 to pr3177.04 (diff): Addressed @jkczyz comments
- Refactor max_length calculation to be cleaner.
- Introduce wrapper struct instead of tuple to make the code clearer to understand.
- Move the padding testing to onion_message/functional_tests.rs to simplify the setup, and test the code at a more appropriate place.
Updated from pr3177.05 to pr3177.06 (diff): Addressed @jkczyz comments
Changes:
- Squash commits.
- Introduce a generic struct
WithPaddingto keep the code DRY. - Introduce a test for Blinded Payment Paths.
- Use saturating sub in padding length calculation to avoid overflows.
Updated from pr3177.06 to pr3177.07 (diff): Addressed @jkczyz comments
- Update comments.
- Introduce
debug_assert!()inWriteable for WithPadding. - Properly
assert!()the condition in test.
Updated from pr3177.07 to pr3177.08 (diff): Addressed @jkczyz comments
Changes:
- Introduce an
f:commit with an alternative approach toWithPadding. - The new approach introduces padding as an optional field within the
ForwardTlvsand theReceiveTlvsstruct.
Update: From pr3177.08 to pr3177.09 (diff):
Changes based on @jkczyz's feedback:
- Fixed the imports.
- Removed
BlindedPaymentTlvsRefand replaced it withBlindedPaymentTlvs. The former contained an immutable reference to the underlying TLVs, but the new implementation required mutability. Therefore, I transitioned to usingBlindedPaymentTlvsdirectly, makingBlindedPaymentTlvsRefredundant.
Update: From pr3177.09 to pr3177.10 (diff):
Changes based on @jkczyz's feedback:
- Rename
pad_tlvs->pad_to_length.
Update: From pr3177.10 to pr3177.11 (diff):
Changes:
- Cleaned up commit history (no changes to the code)
Update: From pr3177.11 to pr3177.12 (diff):
Changes:
- Rebase on @jkczyz's branch (with no changes to the approach) to test the PR with new
construct_blinded_hops, and experiment withBlindedPaymentTlvsMutapproach.
Update: From pr3177.12 to pr3177.13 (diff):
Changes:
- Rebase on #3248.
- Introduce a new utility function
inner_blinded_pathin BlindedMessagePath for testing.
Update: From pr3177.13 to pr3177.14 (diff):
Changes:
- Rebase on main.
- Changes from the last version: Rename
ForwardNode->MessageForwardNode.
Update: From pr3177.14 to pr3177.15 (diff):
Addressed @jkczyz comments:
- Update docs, to be grammatically and syntactically.
- Introduce the
BlindedPaymentTlvsMutapproach. - Clean commit history to keep changes properly separate.
- Update the test function to remove redundant utils.
Generally looks good. Just waiting on review for #3248.
#3248 Merged. Needs rebase :)
Update: From pr3177.16 to pr3177.17 (diff):
Addressed @jkczyz comment
Changes:
- Update pad_to_length functions to use match instead of unwrap()
- Update the test to have non-zero context, to ensure the size of receive tlvs and forward tlvs vary before padding.
Update: From pr3177.17 to pr3177.18 (diff): Addressed @jkczyz comment
Changes:
- Reverted visibility changes for
BlindedPathinBlindedMessagePath.
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.
Update:
From pr3177.19 to pr3177.20 (diff):
Addressed feedback from @TheBlueMatt and @jkczyz.
Changes:
- Simplified the padding approach by removing padding as a field from
{Forward, Receive}TLVs. - Introduced a
WithPaddinggeneric that handles padding for the given TLVs.
Considerations & Shortcomings:
- Instead of padding to a maximum value,
WithPaddingpads the TLVs to a rounded value. This avoids wasting space for very small packets while providing flexibility for future TLV expansions. - The current padding round-off value is 50 bytes. I believe this should offer enough buffer to obscure the internal TLV types, but would love to get feedback on a more optimal value.
- This approach doesn't safeguard against the improper use of a
1TLV record within the TLVs themselves. We may need to add a comment to prevent this misuse.
Todo:
- Currently, this approach also pads the compact blinded path. I'll address this in the next update.
Update: From pr3177.20 to pr3177.21 (diff): Addressed @TheBlueMatt comment
Changes:
- Update code so that we would not be padding the compact blinded paths.
- Introduce a test to check this condition.
Update: From pr3177.22 to pr3177.23 (diff):
Changes:
Fixed the Padding approach.
- Previous version: Packets were padded individually based on compact forward TLVs. This incorrectly led to padding ReceiveTlvs, even when they belonged to a compact blinded path.
- Fix: Now, the entire blinded path remains unpadded if any short_channel_id is present. This ensures correct handling of compact paths and eliminates unnecessary padding.
Update: From pr3177.23 to pr3177.24 (diff):
Addressed @jkczyz comments
Changes:
- Fix typo, and visibility.
Update: From pr3177.24 to pr3177.25 (diff): Addressed comments from @jkczyz and @TheBlueMatt.
Changes:
- Introduced different padding round-off for message and payment TLVs.
- Padding sizes were chosen based on the discussion in this thread.