Skip to content

relay: a kind-5 delete's e-id arm is uncapped and unbounded at the storage seam #1090

Closed

Description

@chappie-daemon

Found while closing #870's a-tag cap (job 025). Pre-existing: at 68be6f3a the arm already called delete_by_pubkey_and_ids with an unbounded list, so this is a behaviour change against the TypeScript parity target, not a repair of that job.

crates/nostream-relay/src/strategies/delete.rs collects every parseable e tag into ids with no bound. At the shipped maxPayloadSize (524 288) that is roughly 6 000 ids, handed as one call to delete_by_pubkey_and_ids:

  • LMDB: one transaction of ~6 000 point gets plus ~6 000 soft deletes.
  • Postgres: a single = ANY($2) with ~6 000 bytea elements.

The a-tag arm now has a 100-address cap for exactly this reason, and its doc comment carries the arithmetic: one address ≈ 0.04 ms, kind-5 is 30/min per free key, so ~6 000 tags is ≈ 7 s of the single LMDB writer per minute from one unauthenticated publisher. The same number applies here, and the surface is asymmetric: a reader who sees the 100-address cap and no mention of this path will assume deletions are bounded.

What it needs

  • A cap on distinct e ids per deletion request, with the same refusal shape the a arm uses (OK false, nothing deleted — a partial answer would lie).
  • The cap's number derived next to the same arithmetic rather than copied from the a arm, since one id is a point get and one address is a point lookup.
  • A note in docs/rewrite/nip-parity.md §9 item 12, which currently describes the a cap and not this.

Found by static review in 025-nip-currency (static round 5) and named by the operator as a known open arm rather than fixed there.

Activity

  1. added
    bug
    rewrite
    rust
    factory
    on Nov 9, 2026
  2. AgrimTawani commented on Nov 15, 2026

    @AgrimTawani
    Contributor

    @cameri @chappie-daemon I'd love to take this one, could I be assigned? Saw the e-id arm in delete.rs still collects every tag with no bound, while the a arm right above caps at 100, so a single free key can push ~6k ids per request. Plan:

    • Cap distinct e ids, with the same refusal as the a arm (OK false, nothing deleted)
    • Derive the number from its own point-get cost next to the existing arithmetic, not copied from the a cap
    • Tests at cap and cap+1, plus the note in nip-parity.md §9 item 12

    Can have a PR up soon!

  3. cameri commented on Nov 15, 2026

    @cameri
    Owner

    Assigned to you @AgrimTawani

  4. AgrimTawani commented on Nov 17, 2026

    @AgrimTawani
    Contributor

    Hey @cameri, the fix for this is ready, but PRs here are limited to collaborators, so GitHub won't let me open it. Could you give me access, or open it from my branch? rewrite/main...AgrimTawani:nostream:fix/1090-cap-delete-e-ids

    • Dedupes e ids and caps them at 100 distinct, with the same OK false refusal as the a arm
    • Cap derived from a measured per-id LMDB cost; tests at cap/cap+1/repeats, plus the nip-parity.md §9 note
    • All five CLAUDE.md checks pass on the latest rewrite/main
  5. chappie-daemon commented on Nov 17, 2026

    @chappie-daemon
    CollaboratorAuthor

    Merged as #1164 in 239bee00.

    Both e-id defects are fixed at the storage seam: repeated ids are collapsed before the delete call, and a request naming more than 100 distinct valid ids is refused before either arm runs, so an over-cap request deletes nothing and stores nothing.

    Verified rather than asserted: reverting the strategy to its pre-fix shape fails four tests — delete_refuses_a_request_naming_too_many_event_ids, delete_refusal_on_the_id_cap_skips_the_address_arm_too, delete_admits_a_cap_sized_batch_of_event_ids_with_repeats and delete_names_each_distinct_event_id_once. So the cap, the dedupe and the exactly-at-cap boundary are all pinned by tests that bite.

    Work by @AgrimTawani, carried with git cherry-pick -x; Rust Checks and the full unit and integration suites are green on the merged SHA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfactoryrewriterust

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions