|
| 1 | +NIP-67 |
| 2 | +====== |
| 3 | + |
| 4 | +EOSE Completeness Hint |
| 5 | +---------------------- |
| 6 | + |
| 7 | +`draft` `optional` |
| 8 | + |
| 9 | +This NIP extends the `EOSE` message defined in [NIP-01](01.md) with an optional third element that signals the client that the relay has sent every stored event matching the subscription's filters. |
| 10 | + |
| 11 | +## Motivation |
| 12 | + |
| 13 | +`EOSE` as defined in NIP-01 signals the boundary between stored and real-time events. It does not tell the client whether there are more stored events the relay chose not to send. Relays commonly enforce an internal cap (e.g. 500 events per filter) that is independent of the client's `limit`. Clients today guess completeness by comparing the number of events received to the `limit` they requested: |
| 14 | + |
| 15 | +- If fewer than `limit` events arrive, assume completion. |
| 16 | +- Otherwise, issue another `REQ` with `until` set to the oldest received event's `created_at`, and repeat. |
| 17 | + |
| 18 | +This heuristic has two well-known problems: |
| 19 | + |
| 20 | +1. When the relay's internal cap is lower than the client's `limit` (e.g. cap 300, client asks for 500), the client receives 300 events and incorrectly concludes the result is complete, silently missing data. |
| 21 | +2. When the total number of matching events happens to equal the relay's cap, the client cannot tell and must issue an additional `REQ` just to observe zero results. A relay that caps at 300 events will always be queried at least twice for any subscription that exhausts the cap. |
| 22 | + |
| 23 | +A single extra field on `EOSE` removes this ambiguity. |
| 24 | + |
| 25 | +## Specification |
| 26 | + |
| 27 | +A relay that implements this NIP MAY append a third element to the `EOSE` message: an array of hint strings. |
| 28 | + |
| 29 | +``` |
| 30 | +["EOSE", <subscription_id>, [<hint>, ...]] |
| 31 | +``` |
| 32 | + |
| 33 | +Currently two hint values are defined: |
| 34 | + |
| 35 | +- `"finish"`: the relay has sent every stored event matching the subscription's filters. The client SHOULD NOT paginate this subscription further. |
| 36 | +- `"more"`: the relay holds more matching stored events than it has sent. The client SHOULD paginate to retrieve them. A relay MAY send this hint, but is not required to, since detecting whether more events exist is not cheap on every storage backend. |
| 37 | + |
| 38 | +The array MAY carry multiple hints simultaneously, and MAY be empty. Clients MUST ignore unknown hint values without error. |
| 39 | + |
| 40 | +Their presence is definitive; their absence is not. When a relay omits the third element, or sends neither `"finish"` nor `"more"`, the client SHOULD paginate using `until = oldest received event's created_at` as usual. |
| 41 | + |
| 42 | +Clients that do not implement this NIP will ignore the extra element, as JSON arrays with trailing elements are accepted by conforming parsers and existing implementations index `EOSE` by position. Relays that do not implement this NIP continue to send `EOSE` with two elements and clients fall back to the legacy heuristic described above. |
| 43 | + |
| 44 | +The hint refers only to stored events. It has no effect on the real-time delivery of new events, which continues under the regular NIP-01 rules until the client sends `CLOSE` or the relay sends `CLOSED`. |
| 45 | + |
| 46 | +Future revisions of this NIP may define additional hint values. Implementations SHOULD accept unknown hint values without error and treat them as if absent. |
| 47 | + |
| 48 | +## Semantics around `created_at` ties |
| 49 | + |
| 50 | +When a relay does not send `"finish"`, multiple events may share the oldest `created_at` value in the response. Clients paginating with `until = oldest_created_at` risk missing events that share that timestamp. Relays SHOULD, when possible, advance the internal cursor so that all events with the boundary `created_at` are included in one response, emitting `"finish"` only when there are no older events remaining. |
| 51 | + |
| 52 | +## Relay advertisement |
| 53 | + |
| 54 | +Relays implementing this NIP SHOULD include `67` in the `supported_nips` field of their [NIP-11](11.md) document. |
| 55 | + |
| 56 | +## Examples |
| 57 | + |
| 58 | +Relay has more matching events than its internal cap (legacy-shaped response, client paginates): |
| 59 | + |
| 60 | +``` |
| 61 | +["REQ", "sub1", {"authors": ["abcd..."], "kinds": [1]}] |
| 62 | +["EVENT", "sub1", {...}] |
| 63 | +... (300 events total) |
| 64 | +["EOSE", "sub1"] |
| 65 | +``` |
| 66 | + |
| 67 | +Relay has sent every matching stored event: |
| 68 | + |
| 69 | +``` |
| 70 | +["REQ", "sub2", {"ids": ["abcd..."]}] |
| 71 | +["EVENT", "sub2", {...}] |
| 72 | +["EOSE", "sub2", ["finish"]] |
| 73 | +``` |
| 74 | + |
| 75 | +Relay has more matching events and says so explicitly: |
| 76 | + |
| 77 | +``` |
| 78 | +["REQ", "sub2b", {"authors": ["abcd..."], "kinds": [1]}] |
| 79 | +["EVENT", "sub2b", {...}] |
| 80 | +... (300 events total) |
| 81 | +["EOSE", "sub2b", ["more"]] |
| 82 | +``` |
| 83 | + |
| 84 | +Relay does not implement this NIP (legacy behavior — client falls back to heuristic): |
| 85 | + |
| 86 | +``` |
| 87 | +["REQ", "sub3", {"kinds": [1], "limit": 500}] |
| 88 | +["EVENT", "sub3", {...}] |
| 89 | +... (N events) |
| 90 | +["EOSE", "sub3"] |
| 91 | +``` |
0 commit comments