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 andrequest_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 itssync_ips
is empty; therequest_timestamps
map remains unchanged. - When a response is removed/completed, the
requests
map andrequest_timestamps
map also remove the entry for the request height. - When a request is timed out, the
requests
,request_timestamps
, andresponses
map remove the entry for the request height;
Implementations§
Source§impl<N: Network> BlockSync<N>
impl<N: Network> BlockSync<N>
Sourcepub fn new(
mode: BlockSyncMode,
ledger: Arc<dyn LedgerService<N>>,
tcp: Tcp,
) -> Self
pub fn new( mode: BlockSyncMode, ledger: Arc<dyn LedgerService<N>>, tcp: Tcp, ) -> Self
Initializes a new block sync module.
Sourcepub const fn mode(&self) -> BlockSyncMode
pub const fn mode(&self) -> BlockSyncMode
Returns the block sync mode.
Sourcepub fn is_block_synced(&self) -> bool
pub fn is_block_synced(&self) -> bool
Returns true
if the node is synced up to the latest block (within the given tolerance).
Sourcepub fn num_blocks_behind(&self) -> u32
pub fn num_blocks_behind(&self) -> u32
Returns the number of blocks the node is behind the greatest peer height.
Source§impl<N: Network> BlockSync<N>
impl<N: Network> BlockSync<N>
Sourcepub fn get_block_locators(&self) -> Result<BlockLocators<N>>
pub fn get_block_locators(&self) -> Result<BlockLocators<N>>
Returns the block locators.
Sourcepub async fn try_block_sync<C: CommunicationService>(&self, communication: &C)
pub async fn try_block_sync<C: CommunicationService>(&self, communication: &C)
Performs one iteration of the block sync.
Sourcepub fn process_block_response(
&self,
peer_ip: SocketAddr,
blocks: Vec<Block<N>>,
) -> Result<()>
pub fn process_block_response( &self, peer_ip: SocketAddr, blocks: Vec<Block<N>>, ) -> Result<()>
Processes the block response from the given peer IP.
Sourcepub fn process_next_block(&self, next_height: u32) -> Option<Block<N>>
pub fn process_next_block(&self, next_height: u32) -> Option<Block<N>>
Returns the next block to process, if one is ready.
Sourcepub fn advance_with_sync_blocks(
&self,
peer_ip: SocketAddr,
blocks: Vec<Block<N>>,
) -> Result<()>
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>
impl<N: Network> BlockSync<N>
Sourcepub fn find_sync_peers(&self) -> Option<(IndexMap<SocketAddr, u32>, u32)>
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.
Sourcepub fn update_peer_locators(
&self,
peer_ip: SocketAddr,
locators: BlockLocators<N>,
) -> Result<()>
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.
Sourcepub fn remove_peer(&self, peer_ip: &SocketAddr)
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§
Auto Trait Implementations§
impl<N> Freeze for BlockSync<N>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more