nips/references-to-previous-events.md

139 lines
3.4 KiB
Markdown
Raw Normal View History

2023-05-29 07:26:31 -04:00
NIP-xx
======
References to previous events
-----------------------------
`draft` `optional` `author:milahu`
2023-05-29 09:45:24 -04:00
Events can contain references to previous events.
2023-05-29 07:26:31 -04:00
Implementation
--------------
Each reference to a previous events consists of
- the distance between this event and the previous event, as an integer number, greater-or-equal than 1
- the ID of the previous event
The choice of distances is arbitrary.
Some choices:
- exponentially increasing distances, for example: 1, 10, 100, 1000, 10000, ...
- linearly increasing distances, for example: 1, 10, 20, 30, 40, 50, ...
- random distances, for example: 1, 15, 32, 58, 93, 139, 185, ...
```json
{
"id": ...,
"kind": ...,
...,
...,
2023-05-29 09:43:56 -04:00
"e_prev": [
2023-05-29 09:41:57 -04:00
[<previous event distance>, <previous event ID>],
[<previous event distance>, <previous event ID>],
2023-05-29 07:26:31 -04:00
...
]
}
```
Soft chain of events
--------------------
This is useful to build a "soft chain" of events, so the recipient can detect missing events.
Events can go missing because of
- political reasons (censorship)
- technical reasons (data loss)
Redundancy
----------
Each event can contain multiple references to previous events.
The next-previous event (distance 1) SHOULD always be referenced.
The number of referenced previous events is arbitrary.
It can be as low as one previous event, or as high as all previous events.
This gives a tolerance for missing events:
When a previous event is missing, the recipient can seek back to another previous event.
Forward search for missing events
---------------------------------
When an event is missing, and cannot be found on any other relay, the recipient will want to "seek forward" from another previous event.
Example:
The last received event `E0` contains references to previous events `[E1, E3, E7]` with the distances `[1, 3, 7]`.
`E1` is missing (cannot be found on any relay).
`E3` is found and received.
Problem:
How can we find `E2`?
Usually we would use the previous-event-reference with distance 1 of `E1`, but we dont have `E1`.
Solution:
We ask relays for events with references to `E3` or `E7` (or any other previous event in this chain).
So relays SHOULD implement a "lookup of events by reference-to-previous-events".
Limitations
-----------
Missing events can be detected only for past events, relative to a received event.
Adoption
--------
Events created before the adoption of this NIP can be referenced in future events.
To improve space-efficiency, it can make sense to distribute these back-references across multiple events ("sparse chains", "fragmented chains").
2023-05-29 09:40:57 -04:00
Inconsistencies
---------------
There is no guarantee that the merging of multiple previous-events-lists produces a consistent chain of events.
Eventual inconsistencies can be resolved by sorting events by time or event ID.
(Multiple diverging chains can be merged by sorting events by time or event ID.)
Such inconsistencies allow modification of the chain (insertion or deletion of previous events), so the chain is mutable.
Visualization
-------------
Clients should visualize:
- the reference to the first previous event
- missing previous events
If there are many missing previous events, these can be collapsed to a "N missing events" block.
2023-05-29 09:43:56 -04:00
TODO: rename key
----------------
2023-05-29 07:26:31 -04:00
```json
{
...,
2023-05-29 09:43:56 -04:00
"e_prev": [
2023-05-29 07:26:31 -04:00
...
]
}
```
2023-05-29 09:43:56 -04:00
Rename the key to ...
2023-05-29 07:26:31 -04:00
- previous_events
2023-05-29 09:43:56 -04:00
- e_prev
2023-05-29 07:26:31 -04:00
- prevs
- history
- soft_chain
2023-05-29 09:43:56 -04:00
- chain
2023-05-29 07:26:31 -04:00
Keywords
--------
- blockchain
- censorship-resistance
- tamper-proof
- append-only