Describe the bug
findByFilters in event-repository.ts orders query results by event_created_at DESC only. When multiple events share the same created_at timestamp, the secondary sort by event_id ASC required by NIP-01 is missing, resulting in non-deterministic ordering of tied events across different clients and relays.
Three concrete scenarios where this manifests:
- High frequency publishing - a client publishes multiple events within the same second, two subscribers receive them in different orders from the same relay.
limit: 1 with timestamp collision - two events from the same pubkey have identical created_at, different clients get different "latest" events unpredictably.
- Cross-relay inconsistency - same
REQ sent to nostream and a NIP-01 compliant relay returns events in different orders, causing inconsistent feeds for the same subscription.
To Reproduce
Steps to reproduce the behavior:
- Publish two or more events with identical
created_at timestamps to the relay
- Send a
REQ message with a limit filter: ["REQ", "sub1", { "limit": n }]
- Observe that the order of events with the same
created_at is non-deterministic and inconsistent across different clients or relays
Expected behavior
Per NIP-01, when two or more events share the same created_at timestamp, they must be returned ordered by event_id ASC (lexicographical order) as a tiebreaker. The same REQ with the same filters should return events in the same deterministic order across all clients and relays.
System:
- OS: N/A — code-level bug, not system specific
- Platform: docker, standalone
- Version: v2.1.0
Logs
N/A — bug produces no error logs, only incorrect event ordering in query results.
Describe the bug
findByFiltersinevent-repository.tsorders query results byevent_created_at DESConly. When multiple events share the samecreated_attimestamp, the secondary sort byevent_id ASCrequired by NIP-01 is missing, resulting in non-deterministic ordering of tied events across different clients and relays.Three concrete scenarios where this manifests:
limit: 1with timestamp collision - two events from the same pubkey have identicalcreated_at, different clients get different "latest" events unpredictably.REQsent to nostream and a NIP-01 compliant relay returns events in different orders, causing inconsistent feeds for the same subscription.To Reproduce
Steps to reproduce the behavior:
created_attimestamps to the relayREQmessage with alimitfilter:["REQ", "sub1", { "limit": n }]created_atis non-deterministic and inconsistent across different clients or relaysExpected behavior
Per NIP-01, when two or more events share the same
created_attimestamp, they must be returned ordered byevent_id ASC(lexicographical order) as a tiebreaker. The sameREQwith the same filters should return events in the same deterministic order across all clients and relays.System:
Logs
N/A — bug produces no error logs, only incorrect event ordering in query results.