Expand description
Common trait for sync protocol implementations.
This module defines the SyncProtocolExecutor trait that all sync protocols
implement. This enables:
- Protocol implementation details contained within each protocol module
- Common interface for
SyncManagerto invoke any protocol - Same code path for production and simulation (only
Storebackend differs)
§Architecture
┌─────────────────────────────────────────────────────────────────┐
│ SyncProtocolExecutor trait │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ HashComparison │ │ Snapshot │ │ LevelWise │ │
│ │ Protocol │ │ Protocol │ │ Protocol │ │
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │ │
│ └────────────────────┼────────────────────┘ │
│ │ │
│ ┌───────────┴───────────┐ │
│ │ SyncTransport │ │
│ │ (Stream or SimStream) │ │
│ └───────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘§Responder Dispatch Model
The SyncManager dispatches incoming sync requests using this flow:
- Manager receives stream and calls
recv()to get the first message - Manager matches on
InitPayloadto determine which protocol to use - Manager extracts protocol-specific data from the first message
- Manager calls
run_responder()passing the extracted data viaResponderInit
This design is necessary because the manager must peek at the first message
for routing, but once consumed it cannot be “un-read”. The ResponderInit
associated type allows each protocol to declare what data it needs from
the first request.
§Example
ⓘ
use calimero_node_primitives::sync::{SyncProtocolExecutor, HashComparisonProtocol};
// Production initiator
let mut transport = StreamTransport::new(&mut stream);
let stats = HashComparisonProtocol::run_initiator(
&mut transport,
&store,
context_id,
identity,
HashComparisonConfig { remote_root_hash },
).await?;
// Production responder (manager extracts first request data)
let first_request = HashComparisonFirstRequest { node_id, max_depth };
HashComparisonProtocol::run_responder(
&mut transport,
&store,
context_id,
identity,
first_request,
).await?;Traits§
- Sync
Protocol Executor - Trait for sync protocol implementations.