Repository navigation
fix(relay): dedupe and cap a deletion request's e ids (#1090) - #1164
Conversation
A kind-5 request's `e` arm handed every parseable id to `delete_by_pubkey_and_ids` unbounded and undeduplicated: ~7 180 ids at the shipped `maxPayloadSize`, repeats included. Collect them through `event_ids()`, which keeps first-seen order, collapses repeats and stops at the (cap + 1)th distinct id, and refuse a request naming more than `MAX_EVENT_IDS_PER_REQUEST` (100) with `OK false` before anything is deleted or stored, the same shape as the address arm's refusal. The number is derived from a measured per-id cost (LMDB, release: 3.95 ms per 100 hits, ~0.008 ms per id at the margin, against ~0.010 ms per address), so 100 ids cost what 100 addresses cost: ~120 ms of writer time per minute per free key. nip-parity.md §9 item 12 records the cap as a deliberate divergence from the TypeScript target. Closes #1090 Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 3dfe4e6)
🦋 Changeset detectedLatest commit: 9c6b058 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Medium impact] The PR appears safe to merge.
|
Opened on @AgrimTawani's behalf so the change is not re-authored: the commit is his, cherry-picked with
-xfromAgrimTawani:fix/1090-cap-delete-e-ids.Closes #1090.
What it does
A kind-5 request's
earm handed every parseable id todelete_by_pubkey_and_ids, unbounded and undeduplicated — ~7 180 ids at the shippedmaxPayloadSize, repeats included. The ids now go throughevent_ids(), which keeps first-seen order, collapses repeats and stops at the (cap + 1)th distinct id, and a request naming more thanMAX_EVENT_IDS_PER_REQUEST(100) is refused withOK falsebefore anything is deleted or stored — the same shape as the address arm's refusal, because a partial delete answeredtruewould claim deletions that did not happen.The cap is derived from its own measurement rather than copied from
MAX_ADDRESSES_PER_REQUEST: 100 hits cost 3.95 ms in one LMDB write transaction (~0.008 ms per id at the margin, against ~0.010 ms per address), so kind-5's 30/min per free key stays at ~120 ms of single-writer time per minute, the same 0.2 % the address cap allows.docs/rewrite/nip-parity.md§9 item 12 records the divergence from the TypeScript target.Verified before opening
rewrite/main(f971d6f3) with no conflicts; 4 files — the strategy, its tests, the parity note, one changeset.package.json, lockfile or script is touched. No hidden or bidirectional characters in the added lines.tests/strategies.rscovering the cap, cap + 1 and repeats, per the commit.