Skip to main content

sync

Function sync 

Source
pub fn sync<T: SyncTransport>(
    local_events: &[Event],
    transport: &mut T,
) -> Result<(Vec<Event>, SyncReport), T::Error>
Expand description

Synchronise local events with a remote replica.

§Protocol

  1. Build a Prolly Tree from local_events.
  2. Exchange root hashes with the remote.
  3. If hashes match: replicas are identical — return early.
  4. Diff the trees to identify event hashes missing from each side.
  5. Send local events that the remote is missing.
  6. Receive remote events that we are missing.
  7. Return a SyncReport summarising the exchange.

After sync, the caller is responsible for persisting the received events to the local event log and rebuilding the projection.

§Errors

Returns T::Error if any transport operation fails.