Struct snarkos_node_sync::BlockSync
source · 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; - the
request_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>>) -> Self
pub fn new(mode: BlockSyncMode, ledger: Arc<dyn LedgerService<N>>) -> 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).
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.