feat(sync): bound egress with a global byte rate limiter (#1157) - #1162
Merged
Conversation
A public read-only node serves anonymous readers, so its outbound bandwidth must be bounded or a peer can drain it by repeatedly pulling. This adds a global egress cap, the last abuse-hardening gate for a public serving host. - `GlobalEgressLimiter`: a token bucket over bytes served, global (not per-peer — a per-id budget is evaded by rotating node ids, the same Sybil reasoning as the accept-rate limiter), shared across the host's concurrent session tasks. Burst 64 MiB, refill 16 MiB/s. - The session sender trims the set it offers to the prefix the budget affords, then pages it normally, so a throttled transfer is a valid session whose withheld tail is re-offered by the next session's inventory diff. The budget is charged per entry under one lock, released before any await and poison-tolerant. - Metered on the anonymous-servable account-log and content paths in both dispatchers; table sync is admitted only under Closed, so it carries no anonymous egress and is left unmetered. - The resident host and `sync serve` each own one limiter shared across their connections.
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.
A public read-only node (#1157) serves anonymous readers, so its outbound bandwidth must be bounded or a peer can drain it by repeatedly pulling the snapshot. This adds a global egress cap — the last abuse-hardening gate before such a node is exposed.
What changed
GlobalEgressLimiter— a token bucket over bytes served, GLOBAL rather than per-peer (a per-id budget is evaded by rotating node ids — the same Sybil reasoning as the merged accept-rate limiter), shared across the host's concurrent session tasks viaArc<Mutex>. Burst 64 MiB, refill 16 MiB/s (implementation-local, tunable later).moreflag stays correct and a throttled transfer is a valid session (not a protocol error). The withheld tail is re-offered by the next session's inventory diff, so a throttled reader converges across retries. The budget is charged per entry under one lock, released before any.awaitand poison-tolerant./3content paths; table sync is admitted only underClosed, so it carries no anonymous egress and is left unmetered.sync serveeach own one limiter shared across their connections.With this, a published node authors public (#1158), serves anonymous read (#1161), and is egress-bounded — the abuse posture (global accept-rate + per-peer session caps + per-account byte ceilings + this egress cap; anonymous readers cannot push) needed to expose it.
Tests
The bucket bounds bytes then refills; an exhausted budget serves nothing and converges after refill; a multi-page transfer (>
MAX_ENTRIES_PER_PAGE) under a generous budget is served intact with a correct sent count.Verification
cargo +nightly fmt --check; clippy--workspace --all-targetsunder--no-default-featuresand--all-features, plus the--features evalgates — all-D warningsclean;cargo nextest run --workspace(5010) andcargo test -p rag-rat-sync(both CI runners).