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

A struct that keeps track of the current block 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> BlockSync<N>

source

pub fn new(mode: BlockSyncMode, ledger: Arc<dyn LedgerService<N>>) -> Self

Initializes a new block sync module.

source

pub const fn mode(&self) -> BlockSyncMode

Returns the block sync mode.

source

pub fn is_block_synced(&self) -> bool

Returns true if the node is synced up to the latest block (within the given tolerance).

source§

impl<N: Network> BlockSync<N>

source

pub fn get_block_locators(&self) -> Result<BlockLocators<N>>

Returns the block locators.

source

pub async fn try_block_sync<C: CommunicationService>(&self, communication: &C)

Performs one iteration of the block sync.

source

pub fn process_block_response( &self, peer_ip: SocketAddr, blocks: Vec<Block<N>> ) -> Result<()>

Processes the block response from the given peer IP.

source

pub fn process_next_block(&self, next_height: u32) -> Option<Block<N>>

Returns the next block to process, if one is ready.

source

pub fn advance_with_sync_blocks( &self, peer_ip: SocketAddr, blocks: Vec<Block<N>> ) -> Result<()>

Attempts to advance with blocks from the sync pool.

source§

impl<N: Network> BlockSync<N>

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 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)

TODO (howardwu): Remove the common_ancestor entry. But check that this is safe (that we don’t rely upon it for safety when we re-connect with the same peer). Removes the peer from the sync pool, if they exist.

Trait Implementations§

source§

impl<N: Clone + Network> Clone for BlockSync<N>

source§

fn clone(&self) -> BlockSync<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N: Debug + Network> Debug for BlockSync<N>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<N> !RefUnwindSafe for BlockSync<N>

§

impl<N> Send for BlockSync<N>

§

impl<N> Sync for BlockSync<N>

§

impl<N> Unpin for BlockSync<N>

§

impl<N> !UnwindSafe for BlockSync<N>

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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 T
where 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