Skip to content

fix: cache relay addrs short, list them last#159

Merged
lidel merged 1 commit into
mainfrom
cache-relay-addr-ttl
Jun 17, 2026
Merged

fix: cache relay addrs short, list them last#159
lidel merged 1 commit into
mainfrom
cache-relay-addr-ttl

Conversation

@lidel

@lidel lidel commented Jun 16, 2026

Copy link
Copy Markdown
Member

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/providers response, 44% of all addresses were relay addresses, one peer alone listing 26.

Fix

  • Cache relay addresses under a shorter TTL (twice the relay reservation TTL). The probe loop renews them only while the peer stays reachable, so live relay-only peers survive and dead relays age out in hours, not days.
  • Return direct addresses before relay addresses, so a client dials a directly reachable one first.

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.

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
@lidel lidel requested a review from a team June 16, 2026 20:59
@lidel lidel marked this pull request as ready for review June 16, 2026 20:59
@lidel lidel merged commit 656183d into main Jun 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants