pub struct Sync<N: Network> { /* private fields */ }
Expand description

A struct that keeps track of the current sync state.

State

  • When a request is inserted, the requests map and request_timestamps map insert an entry for the request height.
  • When a response is inserted, the requests map inserts the entry for the request height.
  • When a request is completed, the requests map still has the entry, but its sync_ips is empty;
  • the request_timestamps map remains unchanged.
  • When a response is removed/completed, the requests map and request_timestamps map also remove the entry for the request height.
  • When a request is timed out, the requests, request_timestamps, and responses map remove the entry for the request height;

Implementations§

source§

impl<N: Network> Sync<N>

source

pub fn set_local_ip(&self, local_ip: SocketAddr)

Returns a dummy listening address of the associated node.

source

pub fn latest_canon_height(&self) -> u32

Returns the latest block height in the sync pool.

source

pub fn get_canon_height(&self, hash: &N::BlockHash) -> Option<u32>

Returns the canonical block height, if it exists.

source

pub fn get_canon_hash(&self, height: u32) -> Option<N::BlockHash>

Returns the canonical block hash for the given block height, if it exists.

source

pub fn get_peer_height(&self, peer_ip: &SocketAddr) -> Option<u32>

Returns the latest block height of the given peer IP.

source

pub fn get_peer_heights(&self) -> BTreeMap<u32, Vec<SocketAddr>>

Returns a map of peer height to peer IPs. e.g. {{ 127 => \[peer1, peer2\], 128 => \[peer3\], 135 => \[peer4, peer5\] }}

source

pub fn get_peers_by_height(&self) -> Vec<(SocketAddr, u32)>

Returns the list of peers with their heights, sorted by height (descending).

source

pub fn get_common_ancestor( &self, peer_a: SocketAddr, peer_b: SocketAddr ) -> Option<u32>

Returns the common ancestor for the given peer pair, if it exists.

source

pub fn get_block_request(&self, height: u32) -> Option<SyncRequest<N>>

Returns the block request for the given height, if it exists.

source

pub fn get_block_request_timestamp(&self, height: u32) -> Option<Instant>

Returns the timestamp of the last time the block was requested, if it exists.

source

pub fn insert_canon_locator(&self, height: u32, hash: N::BlockHash)

Inserts a canonical block hash for the given block height, overriding an existing entry if it exists.

source

pub fn insert_canon_locators(&self, locators: BlockLocators<N>) -> Result<()>

Inserts the block locators as canonical, overriding any existing entries.

source

pub fn find_sync_peers(&self) -> Option<(IndexMap<SocketAddr, u32>, u32)>

Returns the sync peers with their latest heights, and their minimum common ancestor, if the node can sync. This function returns peers that are consistent with each other, and have a block height that is greater than the canon height of this node.

source

pub fn prepare_block_requests(&self) -> Vec<(u32, SyncRequest<N>)>

Returns a list of block requests, if the node needs to sync.

source

pub fn insert_block_request( &self, height: u32, (hash, previous_hash, sync_ips): SyncRequest<N> ) -> Result<()>

Inserts a block request for the given height.

source

pub fn insert_block_response( &self, peer_ip: SocketAddr, block: Block<N> ) -> Result<()>

Inserts the given block response, after checking that the request exists and the response is well-formed. On success, this function removes the peer IP from the requests map. On failure, this function removes all block requests from the given peer IP.

source

pub fn update_peer_locators( &self, peer_ip: SocketAddr, locators: BlockLocators<N> ) -> Result<()>

Updates the block locators and common ancestors for the given peer IP. This function checks that the given block locators are well-formed, however it does not check that the block locators are consistent the peer’s previous block locators or other peers’ block locators.

source

pub fn remove_peer(&self, peer_ip: &SocketAddr)

Removes the peer from the sync pool, if they exist.

source

pub fn remove_block_request_to_peer(&self, peer_ip: &SocketAddr, height: u32)

Removes the block request for the given peer IP, if it exists.

source

pub fn remove_block_requests_to_peer(&self, peer_ip: &SocketAddr)

Removes all block requests for the given peer IP.

source

pub fn remove_block_request(&self, height: u32)

Removes the entire block request for the given height, if it exists.

source

pub fn remove_block_response(&self, height: u32) -> Option<Block<N>>

Removes and returns the block response for the given height, if the request is complete.

Trait Implementations§

source§

impl<N: Debug + Network> Debug for Sync<N>where N::BlockHash: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<N: Network> Default for Sync<N>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<N> !RefUnwindSafe for Sync<N>

§

impl<N> Send for Sync<N>

§

impl<N> Sync for Sync<N>

§

impl<N> Unpin for Sync<N>where <N as Network>::BlockHash: Unpin,

§

impl<N> UnwindSafe for Sync<N>where N: RefUnwindSafe, <N as Network>::BlockHash: UnwindSafe + RefUnwindSafe, <N as Environment>::Field: RefUnwindSafe, <<N as Environment>::PairingCurve as PairingEngine>::G1Affine: RefUnwindSafe, <N as Environment>::Projective: RefUnwindSafe, <N as Environment>::Scalar: RefUnwindSafe, <N as Network>::StateRoot: RefUnwindSafe, <N as Network>::TransactionID: RefUnwindSafe, <N as Network>::TransitionID: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more