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: SyncConfigImplementations§
Source§impl SyncEngine
impl SyncEngine
pub fn new( transport: Arc<dyn MessagingTransport>, store: Arc<dyn StateStore>, config: SyncConfig, ) -> Self
Sourcepub fn new_with_reader(
transport: Arc<dyn MessagingTransport>,
store: Arc<dyn StateStore>,
config: SyncConfig,
reader: MultiChainReader,
) -> Self
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.
Sourcepub async fn push(
&self,
key: StateKey,
value: Bytes,
targets: Vec<ChainId>,
source: ChainId,
metadata: Option<KeyMetadata>,
) -> Result<SyncReceipt>
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.
Sourcepub async fn read(
&self,
key: StateKey,
strategy: ReadStrategy,
) -> Result<SyncedState>
pub async fn read( &self, key: StateKey, strategy: ReadStrategy, ) -> Result<SyncedState>
Retrieve state for key and apply strategy to determine its sync status.
Sourcepub async fn resolve(
&self,
key: StateKey,
resolver: &dyn ConflictResolver,
) -> Result<StateValue>
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.
Sourcepub async fn subscribe<F, Fut>(
&self,
key: StateKey,
source: ChainId,
poll_interval_ms: u64,
handler: F,
) -> Result<SubscriptionHandle>
pub async fn subscribe<F, Fut>( &self, key: StateKey, source: ChainId, poll_interval_ms: u64, handler: F, ) -> Result<SubscriptionHandle>
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.
Sourcepub async fn unsubscribe(&self, handle: SubscriptionHandle)
pub async fn unsubscribe(&self, handle: SubscriptionHandle)
Cancel a subscription returned by subscribe.