fix(nip17): drop since filter on kind 1059 subscription #4

Merged
padreug merged 1 commit from fix/gift-wrap-since-filter into main 2026-05-03 15:42:57 +00:00
Owner

Why

NIP-59 randomizes gift wrap created_at up to 2 days into the past to defeat metadata correlation. The lenient since = last_dm_time - 5min window from commit e0fdada (designed for NIP-04 messages with real timestamps) locks out any gift wrap whose randomized timestamp falls before the latest stored DM.

aio-demo symptom: established merchant with last_dm_time = today 14:40 subscribed with since = today 14:35. Customer published a new gift wrap whose randomized created_at was May 1 23:11. The relay's NostrFilter.matches sees event.created_at < self.since and returns False — relay logs ❌ Filter didn't match and the order never reaches the merchant. Locally this didn't reproduce because regtest had no DM history, so last_dm_time = 0 skipped the since clause.

Fix

Drop since entirely on the kind 1059 filter. Replay risk is bounded by:

  • Server-side dedup at the relay
  • NostrClient.is_duplicate_event() (bounded LRU set in our subscription health monitor)

Other filters (stalls, products, profiles) keep their since — those events use real timestamps so the optimization still works.

Test plan

  • make test — 44/44 pass
  • Deploy v1.1.0-aio.3 on aio-demo, retry the order flow that was failing, confirm _handle_gift_wrap runs and an invoice is generated
## Why NIP-59 randomizes gift wrap `created_at` up to 2 days into the past to defeat metadata correlation. The lenient `since = last_dm_time - 5min` window from commit `e0fdada` (designed for NIP-04 messages with real timestamps) locks out any gift wrap whose randomized timestamp falls before the latest stored DM. aio-demo symptom: established merchant with `last_dm_time = today 14:40` subscribed with `since = today 14:35`. Customer published a new gift wrap whose randomized `created_at` was `May 1 23:11`. The relay's `NostrFilter.matches` sees `event.created_at < self.since` and returns False — relay logs `❌ Filter didn't match` and the order never reaches the merchant. Locally this didn't reproduce because regtest had no DM history, so `last_dm_time = 0` skipped the `since` clause. ## Fix Drop `since` entirely on the kind 1059 filter. Replay risk is bounded by: - Server-side dedup at the relay - `NostrClient.is_duplicate_event()` (bounded LRU set in our subscription health monitor) Other filters (stalls, products, profiles) keep their `since` — those events use real timestamps so the optimization still works. ## Test plan - [x] `make test` — 44/44 pass - [ ] Deploy `v1.1.0-aio.3` on aio-demo, retry the order flow that was failing, confirm `_handle_gift_wrap` runs and an invoice is generated
fix(nip17): drop since filter on kind 1059 subscription
Some checks failed
ci.yml / fix(nip17): drop `since` filter on kind 1059 subscription (pull_request) Failing after 0s
ci.yml / fix(nip17): drop `since` filter on kind 1059 subscription (push) Failing after 0s
50f87c9970
NIP-59 randomizes gift wrap created_at up to 2 days into the past so
metadata observers can't correlate publish moments. The lenient
`since = last_dm_time - 5min` window from commit e0fdada was designed
for NIP-04 messages where created_at is the real send time; with
gift wraps it locks out any wrap whose randomized timestamp falls
before the latest stored DM.

aio-demo symptom: established merchant (last_dm_time = today 14:40)
subscribes with `since = today 14:35`. Customer publishes a new gift
wrap whose randomized created_at is May 1 23:11. NostrFilter.matches
sees `event.created_at < self.since` and returns False — relay logs
" Filter didn't match" and the order never reaches the merchant.

Fix: don't apply `since` at all on the kind 1059 filter. Replay risk
is bounded by server-side dedup and our existing
NostrClient.is_duplicate_event() guard. Other filters (stalls,
products, profiles) keep their `since` because those events use
real timestamps.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
padreug deleted branch fix/gift-wrap-since-filter 2026-05-03 15:42:58 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/nostrmarket!4
No description provided.