DAGSyncer

Struct DAGSyncer 

Source
pub struct DAGSyncer<S: DAGStore> {
    store: S,
    config: SyncConfig,
}
Expand description

DAG synchronizer for gap-repair and reconciliation.

The syncer uses a pull-based approach:

  1. Compare heads with a peer
  2. Identify missing nodes
  3. Fetch missing nodes recursively until reaching common ancestors

Fields§

§store: S

The local DAG store.

§config: SyncConfig

Configuration.

Implementations§

Source§

impl<S: DAGStore> DAGSyncer<S>

Source

pub fn new(store: S) -> Self

Create a new syncer with a store.

Source

pub fn with_config(store: S, config: SyncConfig) -> Self

Create a syncer with custom configuration.

Source

pub fn store(&self) -> &S

Get a reference to the store.

Source

pub fn store_mut(&mut self) -> &mut S

Get a mutable reference to the store.

Source

pub fn heads(&self) -> Vec<Hash>

Get our current heads.

Source

pub fn need(&self, cids: &[Hash]) -> Vec<Hash>

Determine which of the given CIDs we need (don’t have locally).

Source

pub fn create_request(&self, peer_heads: &[Hash]) -> SyncRequest

Create a sync request for reconciliation with a peer.

Source

pub fn handle_request(&self, request: &SyncRequest) -> SyncResponse

Handle an incoming sync request from a peer.

Source

pub fn apply_response( &mut self, response: SyncResponse, ) -> Result<Vec<Hash>, SyncError>

Apply a sync response, storing received nodes.

Returns the CIDs of successfully stored nodes.

Source

pub fn apply_nodes_unchecked( &mut self, nodes: Vec<MerkleNode>, ) -> Result<Vec<Hash>, SyncError>

Apply nodes without strict parent checking.

Used when nodes may arrive out of order.

Source

fn collect_known(&self, heads: &[Hash]) -> HashSet<Hash>

Collect all CIDs reachable from the given heads (including the heads).

Source

pub fn find_missing_ancestors(&self, cids: &[Hash]) -> Vec<Hash>

Find the missing ancestors of the given CIDs.

This performs gap detection by traversing backwards from the given CIDs and identifying nodes that aren’t in our store.

Source

pub fn is_synced_with(&self, peer_heads: &[Hash]) -> bool

Check if we’re synchronized with a peer (have all their nodes).

Source

pub fn sync_status(&self) -> SyncStatus

Get statistics about sync status.

Auto Trait Implementations§

§

impl<S> Freeze for DAGSyncer<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for DAGSyncer<S>
where S: RefUnwindSafe,

§

impl<S> Send for DAGSyncer<S>
where S: Send,

§

impl<S> Sync for DAGSyncer<S>
where S: Sync,

§

impl<S> Unpin for DAGSyncer<S>
where S: Unpin,

§

impl<S> UnwindSafe for DAGSyncer<S>
where S: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.