fix(relay): decouple global circuit ceiling from the per-peer limit - #701
Merged
Merged
Conversation
`relay::Config.max_circuits` is a relay-wide ceiling in rust-libp2p, but it was set to `max_res_per_peer` (default 512), capping the entire relay at 512 concurrent circuits regardless of `--p2p-max-connections` (default 16384). Past that, every further circuit request is denied with RESOURCE_LIMIT_EXCEEDED (libp2p-relay-0.21.1 behaviour.rs:539-541 denies on `circuits.len() >= max_circuits`). go-libp2p has no global circuit cap at all: `Resources.MaxCircuits` is documented as the per-peer limit and is enforced only against the source and destination peer counts (go-libp2p@v0.41.1 p2p/protocol/circuitv2/relay/relay.go:293,301). Charon's `relayResources.MaxCircuits = config.MaxResPerPeer` (charon@v1.7.1 cmd/relay/p2p.go:67) is therefore a *per-peer* 512, with no relay-wide ceiling behind it. Keep `max_circuits_per_peer = max_res_per_peer` (mirrors Charon) and size the global ceiling from `max_conns`, the same connection budget that already feeds `max_reservations`. That preserves a safety valve rust-libp2p offers and go-libp2p lacks, without the artificial throttle. Fixes #484 Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
emlautarom1
approved these changes
Sep 18, 2026
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.
Fixes #484
Problem
crates/relay-server/src/config.rsset both circuit limits tomax_res_per_peer:In rust-libp2p
max_circuitsis a global ceiling. A circuit request is denied withRESOURCE_LIMIT_EXCEEDEDwhen either bound trips (libp2p-relay-0.21.1/src/behaviour.rs:539-541):So the whole relay was capped at 512 concurrent circuits regardless of
--p2p-max-connections(default 16384).Why this diverges from Charon
go-libp2p has no global circuit cap.
Resources.MaxCircuitsis documented as "the maximum number of open relay connections for each peer" (default 16) and is enforced only against the source and destination peer counts —go-libp2p@v0.41.1 p2p/protocol/circuitv2/relay/relay.go:293,301.Charon's
relayResources.MaxCircuits = config.MaxResPerPeer(charon@v1.7.1 cmd/relay/p2p.go:67) is therefore a per-peer 512 with nothing behind it.max_conns(16384)MaxReservations = MaxConns(16384)max_res_per_peer(512)MaxReservationsPerIP = MaxResPerPeer(512)max_res_per_peer(512)MaxCircuits = MaxResPerPeer(512, per-peer)max_res_per_peer(512)Fix
The per-peer value keeps mirroring Charon. The global ceiling is sized from
max_conns, the same connection budget that already feedsmax_reservations(and which Charon likewise routes only intoMaxReservations— its relay runs aNullResourceManager, so there is no connection-manager cap either). That keeps a safety valve rust-libp2p offers and go-libp2p lacks, without throttling a healthy mesh.usize::MAXwas considered to mirror "no global cap" exactly, but that drops the safety valve for no benefit. No new CLI flag: it would diverge from Charon's flag set with no current need.Tests
count_limits_from_configupdated — global and per-peer values now differ.global_circuit_ceiling_is_decoupled_from_per_peer_limitasserts 16384 / 512 at the production CLI defaults, guarding against a re-coupling regression.Notes
This is a latent scaling limit, not an active incident — dev-cluster circuit counts are well below 512. Being a resource-policy change, the chosen default is worth a look before merge.
Two stale details in the issue, neither affecting the fix: the
todo(varex83)it cites was removed in #514, and PR #629's branch was namedfeat/fix-484but actually closed #624 — this issue was never touched.Gates
cargo +nightly fmt --all -- --check✅cargo clippy -p pluto-relay-server --all-targets --all-features -- -D warnings✅cargo test -p pluto-relay-server --all-features✅ (44 passed)🤖 Generated with Claude Code