fix: cache relay addrs short, list them last#159
Merged
Conversation
Relay (/p2p-circuit) reservations are short-lived: a relay drops one the moment the peer disconnects and otherwise expires it at the reservation TTL (~1h), so caching relay addresses for the full 48h served clients relay paths that were long dead. Cache them under a shorter TTL and list them after direct addresses so clients dial reachable addresses first. - cached_addr_book.go: add DefaultRelayAddrTTL (twice the relay reservation TTL) and a WithRelayAddrTTL option; CacheAddrs splits direct and relay addrs by TTL; replacePeerAddrs and the disconnect handler cap relay addrs while keeping a live relay session's connected TTL - server_routers.go: filterPrivateMultiaddr lists relay addresses last - docs/peer-address-caching.md: document relay-address handling
guillaumemichel
approved these changes
Jun 17, 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.
Problem
someguy caches
/p2p-circuit(relay) addresses for the same 48h as direct ones. But a relay reservation is short-lived: it lasts at most an hour, and the relay drops it the instant the peer disconnects. So clients get handed relay paths that died hours ago and waste time dialing them, with relay-only peers the worst case. In THIS real/routing/v1/providersresponse, 44% of all addresses were relay addresses, one peer alone listing 26.Fix
This is Someguy cache optimization only. It won't reduce how many relay addresses a node announces; that volume belongs upstream in go-libp2p. Rationale lives in
docs/peer-address-caching.md.