refactor(network): make the resident gate the single Zakura block-sync memory authority#415
Draft
p0mvn wants to merge 3 commits into
Draft
refactor(network): make the resident gate the single Zakura block-sync memory authority#415p0mvn wants to merge 3 commits into
p0mvn wants to merge 3 commits into
Conversation
|
Note Complete: Audit complete. No review-worthy issues remain after automatic triage. Three findings were auto-invalidated. Open the full results here. Analyzed 16 files, diff |
p0mvn
marked this pull request as draft
July 2, 2026 20:47
p0mvn
force-pushed
the
roman/zakura-single-admission-authority
branch
from
July 2, 2026 21:30
6f1ab60 to
da9c4fb
Compare
p0mvn
force-pushed
the
roman/zakura-single-admission-authority
branch
from
July 2, 2026 23:01
da9c4fb to
571f201
Compare
…c memory authority
p0mvn
force-pushed
the
roman/zakura-single-admission-authority
branch
from
July 3, 2026 01:12
571f201 to
bc5c72b
Compare
… request budget Post-rebase integration of #361 (probe-first no-progress policy, reliability-weighted cwnd, first-completion-wins for unmatched active bodies) with the single-admission-authority accounting: - The unmatched-body path gates on the new admit_received_body() check (a received body consumes no request budget, so the resident gate is the sole admission decision), claims pending heights via claim_received, and ends a competing peer's active reservation via release_active_reserved_height — the ended estimate is released after the forward, mirroring the matched receipt path. - release_reserved_heights loses its Held-skip special case (a received height is Released, which release_reserved() already skips); release_and_return_items becomes test-only (production paths must use the reserved-only variant so received bodies stay claimed for the commit pipeline). - The Drop-safety and GC-skip tests are re-premised on ended-reservation semantics instead of Held.
7 tasks
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.
Tier 2 of the block-sync memory-management simplification (tier 1 was #413).
Motivation
Block-sync had two independent memory ceilings in different units: the wire-byte
ByteBudget(in-flight reservations + held reorder/applying/channel bytes, no commit-window exemption) and the resident look-ahead gate (all pools at wire×4, window-exempt). The held-byte tracking in the wire budget was double accounting — the resident gate already bounds retention to budget + one commit window independent of it — and the entire shed-and-fund apparatus (FundFloorReservationoneshot round-trip through the sequencer task,shed_top_until_available, the per-body inline shed,reorder_max_height) existed solely to reconcile the floor against that second ceiling. The round-trip was also a latent liveness hazard: a wedged sequencer task deadlocked floor funding.Solution
The resident gate (
admit()) is now the single retention authority; theByteBudgetis a pure outstanding-request wire limiter.reserve_request_budgetis synchronous —try_reserve, else (floor priority only) a bounded overdraft via the existingcharge. The WorkQueue single-owner invariant caps cumulative overshoot at one response; the floor can never block, even transiently, and has no cross-task dependency. The whole shed-and-fund mechanism is deleted.sequencer_input_bytes, so it is never invisible to both counters). Held bodies charge nothing;BlockBudgetLedgershrinks toReserved → Released;settle/mark_held_direct/apply_budget_deltaare gone; the sequencer audit becomesbudget.audit(work.reserved_bytes())— the same paired-call-site drift detector over the one thing the budget now tracks.effective_max_reorder_lookahead_bytes()drops themax_inflight_block_bytes × 4coupling (the request cap no longer implies retention),clamp_inflight_block_bytes_to_flooris deleted (a sub-range request budget can no longer deadlock checkpoint sync), andmax_inflight_block_bytesis re-documented as the outstanding-request/DoS cap. Net: one memory knob (max_reorder_lookahead_bytes, resident-denominated), one concurrency knob.Trace field and metric names are unchanged;
budget_reservednow means outstanding request bytes and still drains at quiescence (the regtest trace-oracle check holds).Testing
cargo clippy --all-targets --features "zakura-testkit,internal-bench" -D warningsclean; zebra-network lib suite 837 green (193 block-sync, 27 config, 14 fuzz scenarios).floor_overdraft_is_bounded_and_immediate(budget exactly full → floor GetBlocks sent synchronously, overdraft = one request estimate),receipt_releases_wire_reservation_while_body_retained, late-body no-resurrection, floor-watchdog received-height skip. The fuzz memory invariant gained floor-overdraft slack + a quiescence-drain assertion;fuzz_commit_stallwas re-premised on the resident plateau (its wire-ceiling premise is void under the demotion); the two resident-plateau anchors are byte-for-byte untouched and green.Throughput: no regression, no measurable change — the per-binary means differ by −2%, far inside the ±15% run-to-run producer variance (both distributions span ~7.0K–10.1K). Memory: identical — the retained-wire plateau is pinned at the budget on every run of both binaries, and RSS ranges overlap. The structural change is directly visible in the traces: peak
budget_reserveddrops from ~802 MB (held bodies) to ~11 MB (outstanding requests only), and it still drains at quiescence.AI disclosure
AI (Claude Code) was used for the design exploration, implementation, tests, live validation, and this PR description. The author is responsible for the change.
Refs ZCA-742.