Skip to main content

SyncProtocolExecutor

Trait SyncProtocolExecutor 

Source
pub trait SyncProtocolExecutor {
    type Config: Send;
    type ResponderInit: Send;
    type Stats: Send + Default;

    // Required methods
    fn run_initiator<'life0, 'life1, 'async_trait, T>(
        transport: &'life0 mut T,
        store: &'life1 Store,
        context_id: ContextId,
        identity: PublicKey,
        config: Self::Config,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Stats>> + 'async_trait>>
       where T: 'async_trait + SyncTransport,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn run_responder<'life0, 'life1, 'async_trait, T>(
        transport: &'life0 mut T,
        store: &'life1 Store,
        context_id: ContextId,
        identity: PublicKey,
        first_request: Self::ResponderInit,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>
       where T: 'async_trait + SyncTransport,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for sync protocol implementations.

Each sync protocol (HashComparison, Snapshot, LevelWise, etc.) implements this trait. The protocol logic is generic over:

  • T: SyncTransport - the transport layer (production streams or simulation channels)
  • Store - the storage backend (RocksDB or InMemoryDB)

This enables the same protocol code to run in both production and simulation.

Note: Uses ?Send because RuntimeEnv (used for storage access) contains Rc which is not Send. Callers must not spawn these futures across threads.

Required Associated Types§

Source

type Config: Send

Protocol-specific configuration for the initiator.

For example, HashComparison needs the remote root hash.

Source

type ResponderInit: Send

Data extracted from the first request for responder dispatch.

The manager parses the first InitPayload and constructs this type to pass to run_responder. This is necessary because the manager consumes the first message for routing, so the protocol cannot recv() it again.

For example:

  • HashComparison needs { node_id, max_depth } from TreeNodeRequest
  • LevelWise needs { level, parent_ids } from LevelWiseRequest
Source

type Stats: Send + Default

Protocol-specific statistics/results.

Required Methods§

Source

fn run_initiator<'life0, 'life1, 'async_trait, T>( transport: &'life0 mut T, store: &'life1 Store, context_id: ContextId, identity: PublicKey, config: Self::Config, ) -> Pin<Box<dyn Future<Output = Result<Self::Stats>> + 'async_trait>>
where T: 'async_trait + SyncTransport, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Run the initiator (pulling) side of the protocol.

The initiator requests data from the responder and applies it locally.

§Arguments
  • transport - The transport for sending/receiving messages
  • store - The local storage (works with both RocksDB and InMemoryDB)
  • context_id - The context being synced
  • identity - Our identity for this context
  • config - Protocol-specific configuration
§Returns

Protocol-specific statistics on success.

Source

fn run_responder<'life0, 'life1, 'async_trait, T>( transport: &'life0 mut T, store: &'life1 Store, context_id: ContextId, identity: PublicKey, first_request: Self::ResponderInit, ) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>
where T: 'async_trait + SyncTransport, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Run the responder side of the protocol.

The responder answers requests from the initiator. The first request’s data is passed via first_request because the manager has already consumed the first message for routing.

§Arguments
  • transport - The transport for sending/receiving messages
  • store - The local storage
  • context_id - The context being synced
  • identity - Our identity for this context
  • first_request - Data from the first InitPayload, extracted by the manager

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§