specs/standards/core/sync.md

125 lines
4.2 KiB
Markdown
Raw Normal View History

2024-06-12 11:06:17 -04:00
---
title: WAKU-SYNC
name: Waku Sync
editor: Simon-Pierre Vivier <simvivier@status.im>
contributors:
- Prem Chaitanya Prathi <prem@status.im>
- Hanno Cornelius <hanno@status.im>
---
2024-09-06 11:18:14 -04:00
## Abstract
2024-06-12 11:06:17 -04:00
This specification explains the `WAKU-SYNC` protocol
which enables the reconciliation of two sets of message hashes
2024-09-06 11:18:14 -04:00
in the context of keeping multiple Store nodes synchronized.
2024-06-12 11:06:17 -04:00
Waku Sync is a wrapper around
[Negentropy](https://github.com/hoytech/negentropy) a [range-based set reconciliation protocol](https://logperiodic.com/rbsr.html).
2024-09-06 11:18:14 -04:00
## Specification
2024-06-12 11:06:17 -04:00
**Protocol identifier**: `/vac/waku/sync/1.0.0`
2024-09-06 11:18:14 -04:00
### Terminology
2024-06-12 11:06:17 -04:00
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”,
“RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in [RFC2119](https://www.ietf.org/rfc/rfc2119.txt).
The term Negentropy refers to the protocol of the same name.
Negentropy payload refers to
the messages created by the Negentropy protocol.
Client always refers to the initiator
and the server the receiver of the first payload.
2024-09-06 11:18:14 -04:00
### Design Requirements
2024-07-02 16:04:38 -04:00
Nodes enabling Waku Sync SHOULD
2024-09-05 08:33:30 -04:00
manage and keep message hashes in a local cache
2024-07-02 16:04:38 -04:00
for the range of time
2024-09-06 11:18:14 -04:00
during which synchronization is required.
2024-07-02 16:04:38 -04:00
Nodes SHOULD use the same time range,
for Waku we chose one hour as the global default.
2024-09-05 08:33:30 -04:00
Waku Relay or Light Push protocol MAY be enabled
2024-09-06 11:18:14 -04:00
and used in conjunction with Sync
2024-07-02 16:04:38 -04:00
as a source of new message hashes
2024-09-05 08:33:30 -04:00
for the cache.
2024-07-02 16:04:38 -04:00
Nodes MAY use the Store protocol
2024-09-05 08:33:30 -04:00
to request missing messages once reconciliation is complete
2024-07-02 16:04:38 -04:00
or to provide messages to requesting clients.
2024-06-12 11:06:17 -04:00
2024-09-06 11:18:14 -04:00
### Payload
2024-06-12 11:06:17 -04:00
```protobuf
syntax = "proto3";
package waku.sync.v1;
message SyncPayload {
optional bytes negentropy = 1;
repeated bytes hashes = 20;
}
```
2024-09-06 11:18:14 -04:00
### Session Flow
2024-06-12 11:06:17 -04:00
A client initiate a session with a server
2024-07-02 16:04:38 -04:00
by sending a `SyncPayload` with
only the `negentropy` field set to it.
This field MUST contain
the first negentropy payload
created by the client
for this session.
2024-06-12 11:06:17 -04:00
The server receives a `SyncPayload`.
A new negentropy payload is computed from the received one.
The server sends back a `SyncPayload` to the client.
The client receives a `SyncPayload`.
A new negentropy payload OR an empty one is computed.
If a new payload is computed then
the exchanges between client and server continues until
the client computes an empty payload.
This client computation also outputs any hash differences found,
those MUST be stored.
In the case of an empty payload,
the client MUST send back a `SyncPayload`
2024-09-06 11:18:14 -04:00
with all the hashes previously found in the `hashes` field and
2024-07-02 16:04:38 -04:00
an empty `nengentropy` field.
2024-06-12 11:06:17 -04:00
2024-09-06 11:18:14 -04:00
## Attack Vectors
2024-06-12 11:06:17 -04:00
Nodes using `WAKU-SYNC` are fully trusted.
2024-09-05 08:33:30 -04:00
Message hashes are assumed to be of valid messages received via Waku Relay or Light push.
2024-06-12 11:06:17 -04:00
Further refinements to the protocol are planned
to reduce the trust level required to operate.
2024-09-06 11:18:14 -04:00
Notably by verifying messages RLN proof at reception.
2024-06-12 11:06:17 -04:00
2024-09-06 11:18:14 -04:00
## Implementation
2024-09-03 11:52:48 -04:00
The following is not part of the specifications but good to know implementation details.
### Interval
2024-09-06 11:18:14 -04:00
Ad-hoc syncing can be useful in some cases but continuous periodic sync
minimize the differences in messages stored across the network.
2024-09-03 11:52:48 -04:00
Syncing early and often is the best strategy.
The default used in nwaku is 5 minutes interval between sync with a range of 1 hour.
### Range
We also offset the sync range by 20 seconds in the past.
The actual start of the sync range is T-01:00:20 and the end T-00:00:20
2024-09-06 11:18:14 -04:00
This is to handle the inherent jitters of GossipSub.
2024-09-03 11:52:48 -04:00
In other words, it is the amount of time needed to confirm if a message is missing or not.
### Storage
The storage implementation should reflect the Waku context.
Most messages that will be added will be recent and
all removed messages will be older ones.
When differences are found some messages will have to be inserted randomly.
It is expected to be a less likely case than time based insertion and removal.
Last but not least it must be optimized for sequential read
as it is the most often used operation.
2024-09-06 11:18:14 -04:00
## Copyright
2024-06-12 11:06:17 -04:00
Copyright and related rights waived via
[CC0](https://creativecommons.org/publicdomain/zero/1.0/).
2024-09-06 11:18:14 -04:00
## References
2024-06-12 11:06:17 -04:00
- https://logperiodic.com/rbsr.html
- https://github.com/hoytech/negentropy