Skip to content

broadcast: parked-chunk buffering + poll-driven TTL cleanup - #72

Merged
ch4r10t33r merged 1 commit into
mainfrom
feat/parked-chunks-63
Jul 3, 2026
Merged

broadcast: parked-chunk buffering + poll-driven TTL cleanup#72
ch4r10t33r merged 1 commit into
mainfrom
feat/parked-chunks-63

Conversation

@ch4r10t33r

Copy link
Copy Markdown
Collaborator

Closes #63.

Ports the channel parked-chunk buffer and GC from ethp2p broadcast/channel.go (handleChunk / handleSessionOpen / cleanup). ChannelRs previously had no parked map or TTL handling — chunks arriving before their SESS open had nowhere to go, and stale sessions were never reaped.

What it does

  • parkChunk buffers a chunk that arrived before its session exists; per-message cap max_parked_chunks = 32 (new chunk dropped → .dropped_full when full, matching Go cancelling the stream).
  • attachRelaySession replays and frees any parked chunks into the now-open session (Go handleSessionOpen flush).
  • disposeSession also drops the message's parked chunks.
  • cleanup(now_ms) disposes sessions older than active_session_ttl_ms and drops parked buckets older than pending_chunk_ttl_ms.
  • Adds the constants channel_inbox_cap (1024), max_parked_chunks (32), active_session_ttl_ms (5m), pending_chunk_ttl_ms (10s), cleanup_interval_ms (30s), routing_tick_interval_ms (25).

Adaptations

  • Go parks the QUIC stream and lets flow control back-pressure the sender; the Zig ingest path already holds the read bytes, so ParkedChunk owns a copy of the peer id + data.
  • cleanup is poll-driven with an explicit now_ms (no ambient clock / ticker goroutine). SessionRs.created_at_ms carries the creation time — 0 means unset and is skipped, set by the driver that owns the clock. (Go's cleanup currently drops parked chunks unconditionally with a TODO to use pendingChunkTTL; this implements that intent.)

Tests (leak-checked)

  • replay-on-attach (verified via a recording observer's chunk_rcvd),
  • cap enforcement (33rd park → .dropped_full),
  • cleanup drops stale parked chunks + disposes expired sessions (and leaves fresh ones).

Verified on stock Zig 0.16.0: zig fmt --check, zig build test, zig build test-broadcast (TSan). README updated.

Ports the channel parked-chunk buffer and GC from ethp2p
`broadcast/channel.go`:
  - `parkChunk` buffers a chunk that arrived before its session exists,
    per-message cap `max_parked_chunks = 32` (new chunk dropped when full,
    matching Go cancelling the stream),
  - `attachRelaySession` replays and frees any parked chunks into the
    now-open session (Go `handleSessionOpen` flush),
  - `disposeSession` also drops the message's parked chunks,
  - `cleanup(now_ms)` disposes sessions past `active_session_ttl_ms` and
    drops parked buckets past `pending_chunk_ttl_ms` — poll-driven (the Zig
    sim has no ambient clock or ticker goroutine); `SessionRs.created_at_ms`
    carries the creation time (0 = unset, skipped).
  - Adds the capacity/lifetime constants `channel_inbox_cap`,
    `max_parked_chunks`, `active_session_ttl_ms`, `pending_chunk_ttl_ms`,
    `cleanup_interval_ms`, `routing_tick_interval_ms`.

Go parks the QUIC stream and lets flow control back-pressure the sender;
the Zig ingest path already holds the read bytes, so `ParkedChunk` owns a
copy of the peer id and data.

Tests (leak-checked): replay-on-attach (via a recording observer), cap
enforcement (drop beyond 32), and cleanup of stale parked chunks +
expired sessions. README implementation-status table updated.

Closes #63.
@ch4r10t33r
ch4r10t33r merged commit bebaadf into main Jul 3, 2026
7 checks passed
@ch4r10t33r
ch4r10t33r deleted the feat/parked-chunks-63 branch July 3, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

broadcast: channel parked-chunk buffering + TTL cleanup

1 participant