Skip to main content

SyncEngine

Struct SyncEngine 

Source
pub struct SyncEngine {
    pub transport: Arc<dyn MessagingTransport>,
    pub store: Arc<dyn StateStore>,
    pub config: SyncConfig,
    /* private fields */
}
Expand description

Orchestrates cross-chain state propagation.

Composes a MessagingTransport for sending messages and a StateStore for local persistence. All strategy decisions are left to the caller.

§Example

use std::sync::Arc;
use xenith_core::{InMemoryStore, ReadStrategy};
use xenith_sync::{SyncEngine, SyncConfig};

let engine = SyncEngine::new(
    transport,
    Arc::new(InMemoryStore::default()),
    SyncConfig::default(),
);

Fields§

§transport: Arc<dyn MessagingTransport>§store: Arc<dyn StateStore>§config: SyncConfig

Implementations§

Source§

impl SyncEngine

Source

pub fn new( transport: Arc<dyn MessagingTransport>, store: Arc<dyn StateStore>, config: SyncConfig, ) -> Self

Source

pub fn new_with_reader( transport: Arc<dyn MessagingTransport>, store: Arc<dyn StateStore>, config: SyncConfig, reader: MultiChainReader, ) -> Self

Create a SyncEngine that can execute ReadStrategy::Quorum reads.

The reader is used to issue parallel storage reads across all chains registered in its provider map when verifying on-chain agreement.

Source

pub async fn push( &self, key: StateKey, value: Bytes, targets: Vec<ChainId>, source: ChainId, metadata: Option<KeyMetadata>, ) -> Result<SyncReceipt>

Broadcast value to each chain in targets, then persist it locally.

Pass metadata if you intend to use ReadStrategy::Quorum for this key. Metadata must include the EVM contract address and storage slot that corresponds to the value being synced. Without it, Quorum reads will fail.

The store is written only when at least one send succeeded, or when targets is empty (local-only push). If every send fails the store is left untouched and SyncReceipt::store_written is false.

Per-chain send errors are collected into SyncReceipt::failures rather than aborting early, so the caller can inspect and retry individual chains.

Source

pub async fn read( &self, key: StateKey, strategy: ReadStrategy, ) -> Result<SyncedState>

Retrieve state for key and apply strategy to determine its sync status.

Source

pub async fn resolve( &self, key: StateKey, resolver: &dyn ConflictResolver, ) -> Result<StateValue>

Resolve any divergence for key using the supplied resolver, persist the winner, and return it.

Source

pub async fn subscribe<F, Fut>( &self, key: StateKey, source: ChainId, poll_interval_ms: u64, handler: F, ) -> Result<SubscriptionHandle>
where F: Fn(StateValue) -> Fut + Send + 'static, Fut: Future<Output = ()> + Send,

Subscribe to state updates for a key from a source chain.

Fires handler whenever a new StateValue with a higher StateVersion is observed — either via incoming transport messages or via direct writes to the local store.

§Poll interval guidance

poll_interval_ms controls how frequently the transport is polled for incoming messages and the local store is checked for updates.

Recommended values:

  • Testing / local development: 50–100ms
  • Production liquidation bots: 500–1000ms (1 RPC call per tick)
  • Production arbitrage bots: 200–500ms (latency-sensitive)

Each tick issues one MessagingTransport::poll_incoming call to the transport, which typically maps to one eth_getLogs RPC call. Set the interval according to your RPC rate limits and latency requirements.

§Cancellation

Returns a SubscriptionHandle. Call handle.cancel() or pass it to SyncEngine::unsubscribe to stop the polling loop.

Source

pub async fn unsubscribe(&self, handle: SubscriptionHandle)

Cancel a subscription returned by subscribe.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.