Skip to content

Pad all sent TCP frames to the same size via ChunkedMessageQueue#4446

Open
tnull wants to merge 3 commits intolightningdevkit:mainfrom
tnull:2026-02-chunky
Open

Pad all sent TCP frames to the same size via ChunkedMessageQueue#4446
tnull wants to merge 3 commits intolightningdevkit:mainfrom
tnull:2026-02-chunky

Conversation

@tnull
Copy link
Contributor

@tnull tnull commented Feb 25, 2026

In this PR we implement padding all sent TCP frames to the same size by ensuring all writes happen in chunks of length CHUNK_SIZE and any remainders are filled by adequately sized Ping messages.

This approach operating on the network-layer was discussed in the spec call and seems to be preferred by everybody. Hence it supersedes the approach taken in #4248.

TODO

  • Measurement/evaluation of introduced overhead

@tnull tnull requested a review from TheBlueMatt February 25, 2026 14:33
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Feb 25, 2026

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tnull tnull self-assigned this Feb 25, 2026
@tnull tnull moved this to Goal: Merge in Weekly Goals Feb 25, 2026
@tnull tnull changed the title Add ChunkedMessageQueue for message padding Pad all sent TCP frames to the same size via ChunkedMessageQueue Feb 25, 2026
@tnull tnull force-pushed the 2026-02-chunky branch 2 times, most recently from 48bb745 to 64e28db Compare February 25, 2026 15:08
@tnull
Copy link
Contributor Author

tnull commented Feb 25, 2026

Validated via Wireshark and LDK Node tests:

2026-02-25-161017_hyprshot

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 96.11307% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.98%. Comparing base (eb3980d) to head (d8de722).
⚠️ Report is 39 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/peer_handler.rs 95.63% 9 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4446      +/-   ##
==========================================
+ Coverage   85.88%   85.98%   +0.10%     
==========================================
  Files         159      159              
  Lines      104302   104850     +548     
  Branches   104302   104850     +548     
==========================================
+ Hits        89578    90157     +579     
+ Misses      12222    12188      -34     
- Partials     2502     2505       +3     
Flag Coverage Δ
tests 85.98% <96.11%> (+0.10%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add `BorrowedVecWriter`, `encrypt_with_header_0s_at`, `encrypt_message_into`,
and `encrypt_buffer_into` to `PeerChannelEncryptor` to support encrypting
messages directly into a shared buffer at arbitrary offsets.

Define `ChunkedMessageQueue` struct in `peer_handler` with a contiguous byte
buffer that will replace the current `pending_outbound_buffer` /
`gossip_broadcast_buffer` dual-queue system. The queue pads all outgoing
traffic into fixed-size `CHUNK_SIZE` chunks using Ping messages as filler,
so an observer sees only constant-size writes on the wire. Ping padding
uses `ponglen = 65533` to suppress Pong responses per BOLT-1.

Co-Authored-By: HAL 9000
Replace `pending_outbound_buffer`,
`pending_outbound_buffer_first_msg_offset`, and
`gossip_broadcast_buffer` fields in `Peer` with a single `message_queue:
ChunkedMessageQueue`.

Co-Authored-By: HAL 9000
Add five new tests:
- `test_chunked_message_queue_ping_padding`: verifies chunk alignment for
  various message sizes
- `test_chunked_message_queue_small_remainder_overflow`: verifies the
  two-Ping edge case when remainder < `MIN_ENCRYPTED_PING_SIZE`
- `test_chunked_message_queue_chunk_alignment`: verifies alignment after
  encrypting multiple real messages
- `test_chunked_message_queue_buffer_compaction`: verifies `maybe_compact`
  correctly drains sent bytes
- `test_chunked_message_queue_pending_msg_bytes_tracking`: verifies that
  `pending_msg_bytes` tracks real message bytes and is unaffected by padding

Also extract a `get_test_encryptor` helper to reduce boilerplate across
the new tests.

Co-Authored-By: HAL 9000
Signed-off-by: Elias Rohrer <dev@tnull.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Goal: Merge

Development

Successfully merging this pull request may close these issues.

2 participants