Skip to content

feat(addressbook): prune stale entries by last-seen time#5513

Draft
martinconic wants to merge 1 commit into
masterfrom
feat/addressbook-pruning
Draft

feat(addressbook): prune stale entries by last-seen time#5513
martinconic wants to merge 1 commit into
masterfrom
feat/addressbook-pruning

Conversation

@martinconic

Copy link
Copy Markdown
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Implements address book pruning (#5491).

The address book recently gained a wrapping verifiedAddress{Address, Verified}
struct (v2.8.0, #5477). This PR extends it with a last-seen timestamp and uses
it to drop peers we have not seen for over a month, preventing the address book
from accumulating stale, unreachable peers indefinitely.

Changes

  • pkg/addressbook
    • Add LastSeen (unix seconds) to verifiedAddress.
    • Put stamps LastSeen on every write — covers the hive gossip path, which Puts on each sighting.
    • New UpdateLastSeen(overlay): read-modify-write that bumps only the timestamp; no-op if the overlay is absent.
    • New Prune(before time.Time): removes entries last seen before the cutoff. Entries with LastSeen == 0 are kept.
    • Inject a clock for testability.
  • pkg/topology/kademlia: call UpdateLastSeen on successful connection, both outbound (connectionAttemptsHandler) and inbound (onConnected). Failures are debug-logged and non-fatal.
  • pkg/node: prune entries not seen for 30 days at startup, right after the address book is constructed. Warning-logged and non-fatal so it never blocks boot.
  • pkg/statestore/storeadapter: migration step 10 stamps last_seen = now() onto existing entries that lack it (merging into the JSON object so all fields are preserved). Without this, the first prune after upgrade would wipe the whole address book.

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

@martinconic martinconic self-assigned this Jun 22, 2026
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.

1 participant