fixes sorting ambiguity.

This commit is contained in:
Vitor Pamplona 2023-11-08 16:35:32 -05:00
parent 7b764aa917
commit 73b32742c4

12
29.md
View File

@ -25,9 +25,9 @@ Request:
Upon receiving a `HASH-REQ` the relay MUST: Upon receiving a `HASH-REQ` the relay MUST:
1. Apply all nostr filters in the subscription to the database 1. Apply all nostr filters in the subscription to the database
2. Sort all resulting events by `.created_at` 2. Sort all resulting events by `.created_at` descending (as usual)
3. Group by the first `WINDOW-SIZE` chars of the stringified `.created_at` 3. Group by the first `WINDOW-SIZE` chars of the stringified `.created_at`
4. For each group, create an array of event ids: `["idHex1", "idHex2", "idHex3"]`, JSON-serialize it, and hash it using SHA-256 4. For each group, create an array of event ids: `["idHex1", "idHex2", "idHex3"]` in the same order as before, JSON-serialize the array, and hash it using SHA-256
5. Return the group list, with their truncated `.created_at` identifier and hash to the peer. 5. Return the group list, with their truncated `.created_at` identifier and hash to the peer.
After calculating the hashes, the relay responds with an EOSE-ended sequence of After calculating the hashes, the relay responds with an EOSE-ended sequence of
@ -46,16 +46,16 @@ The peer then compares the receiving hashes with those stored locally and, if di
The choice of window size is use case dependent. Clients can start with a large window after the first round of results adjust the filters and reduce the window size to further reduce the group to be re-downloaded. The choice of window size is use case dependent. Clients can start with a large window after the first round of results adjust the filters and reduce the window size to further reduce the group to be re-downloaded.
### Appendix A: Explanation of Window Size calculations ### Appendix A: Window Size explanation
The `WINDOW-SIZE` is a number between 0 and 10 and represents each order of magnitude of `.created_at`. It defines the size of each group as well as their start and end times for the `.created_at` field. The `WINDOW-SIZE` is a number between 0 and 10 and represents each order of magnitude of `.created_at`. It defines the size of each group as well as their start and end times for the `.created_at` field.
By truncating the `.created_at` to the first `WINDOW-SIZE` chars, it effectively creates the groups below: By truncating the `.created_at` to the first `WINDOW-SIZE` chars, it effectively creates the groups below:
- `WINDOW-SIZE=0`: Returns only one hash for the entire subscription - `WINDOW-SIZE=0`: Returns only one hash for the entire subscription
- `WINDOW-SIZE=1`: Groups by periods of 1000000000 seconds (~31.7 years): Periods start with `*000000000 and end with `*999999999` - `WINDOW-SIZE=1`: Groups by periods of 1000000000 seconds (~31.7 years): Periods start with `*000000000` and end with `*999999999`
- `WINDOW-SIZE=2`: Groups by periods of 100000000 seconds (~3.17 years): Periods start with `**00000000 and end with `**99999999` - `WINDOW-SIZE=2`: Groups by periods of 100000000 seconds (~3.17 years): Periods start with `**00000000` and end with `**99999999`
- `WINDOW-SIZE=3`: Groups by periods of 10000000 seconds (~16.53 weeks): Periods start with `***0000000 and end with `***9999999` - `WINDOW-SIZE=3`: Groups by periods of 10000000 seconds (~16.53 weeks): Periods start with `***0000000` and end with `***9999999`
- `WINDOW-SIZE=4`: Groups by periods of 1000000 seconds (~11.57 days): Periods start with `****000000` and end with `****999999` - `WINDOW-SIZE=4`: Groups by periods of 1000000 seconds (~11.57 days): Periods start with `****000000` and end with `****999999`
- `WINDOW-SIZE=5`: Groups by periods of 100000 seconds (~1.16 days): Periods start with `*****00000` and end with `*****99999` - `WINDOW-SIZE=5`: Groups by periods of 100000 seconds (~1.16 days): Periods start with `*****00000` and end with `*****99999`
- `WINDOW-SIZE=6`: Groups by periods of 10000 seconds (~2.77 hours): Periods start with `******0000` and end with `******9999` - `WINDOW-SIZE=6`: Groups by periods of 10000 seconds (~2.77 hours): Periods start with `******0000` and end with `******9999`