Open
Description
Store full state snapshots in DHT to reduce the workload for a new peer to get up-to-date.
struct Snapshot {
data: Vec<u8>,
hashes: Vec<ActionHash> // hashes of all update statevectors included
}
-
On regular interval
- Check if my agent pub key is closest to assigned key based on my timestamp (to reduce redundant snapshots)
- get all agents associated with document, order ascending
- get timestamp
- calculate timestamp % number of agents
- pick the agent at that index
- if the agent is me, continue
- get last snapshot + all updates since last snapshot, merge into single statevector
- publish statevector as snapshot, specify hash of all updates included within it
- Check if my agent pub key is closest to assigned key based on my timestamp (to reduce redundant snapshots)
-
When new agent joins
- fetch latest snapshot
- fetch all statevectors not included in latest snapshot
- merge latest snapsho with statevectors
- apply to ydoc