broadcast: parked-chunk buffering + poll-driven TTL cleanup - #72
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #63.
Ports the channel parked-chunk buffer and GC from ethp2p
broadcast/channel.go(handleChunk/handleSessionOpen/cleanup).ChannelRspreviously had no parked map or TTL handling — chunks arriving before theirSESSopen had nowhere to go, and stale sessions were never reaped.What it does
parkChunkbuffers a chunk that arrived before its session exists; per-message capmax_parked_chunks = 32(new chunk dropped →.dropped_fullwhen full, matching Go cancelling the stream).attachRelaySessionreplays and frees any parked chunks into the now-open session (GohandleSessionOpenflush).disposeSessionalso drops the message's parked chunks.cleanup(now_ms)disposes sessions older thanactive_session_ttl_msand drops parked buckets older thanpending_chunk_ttl_ms.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
ParkedChunkowns a copy of the peer id + data.cleanupis poll-driven with an explicitnow_ms(no ambient clock / ticker goroutine).SessionRs.created_at_mscarries the creation time —0means unset and is skipped, set by the driver that owns the clock. (Go'scleanupcurrently drops parked chunks unconditionally with a TODO to usependingChunkTTL; this implements that intent.)Tests (leak-checked)
chunk_rcvd),.dropped_full),cleanupdrops 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.