// Find the block height where the chain split occurs. The chain split height is the height of the first block that is
// not common between the local and network chains.
Find the block height where the chain split occurs. The chain split height is the height of the first block that is
not common between the local and network chains.
Find the block height where the chain split occurs . The chain split height is the height of the first block that is not common between the local and network chains .
async fn find_chain_split_height<B: BlockchainBackend + 'static>(
    shared: &mut BaseNodeStateMachine<B>,
    sync_peers: &mut SyncPeers,
    tip_height: u64,
) -> Result<u64, BlockSyncError>
{
    for block_nums in (1..=tip_height)
        .rev()
        .collect::<Vec<u64>>()
        .chunks(shared.config.block_sync_config.header_request_size)
    {
        let (headers, sync_peer) = request_headers(
            LOG_TARGET,
            shared,
            sync_peers,
            block_nums,
            shared.config.block_sync_config.max_header_request_retry_attempts,
        )
        .await?;
        for header in headers {
            // Check if header is linked to local chain
            if let Ok(prev_header) =
                async_db::fetch_header_by_block_hash(shared.db.clone(), header.prev_hash.clone()).await
            {
                return if prev_header.height + 1 == header.height {
                    Ok(header.height)
                } else {
                    warn!(
                        target: LOG_TARGET,
                        "Banning peer {} from local node, because they supplied invalid chain link", sync_peer
                    );
                    ban_sync_peer(
                        LOG_TARGET,
                        &mut shared.connectivity,
                        sync_peers,
                        &sync_peer,
                        shared.config.sync_peer_config.short_term_peer_ban_duration,
                        "Peer supplied invalid chain link".to_string(),
                    )
                    .await?;
                    Err(BlockSyncError::InvalidChainLink)
                };
            }
        }
    }
    warn!(
        target: LOG_TARGET,
        "Banning all peers from local node, because they could not provide a valid chain link",
    );
    ban_all_sync_peers(
        LOG_TARGET,
        shared,
        sync_peers,
        shared.config.sync_peer_config.peer_ban_duration,
        "Mass ban because peer could not provide a valid chain link".to_string(),
    )
    .await?;
    Err(BlockSyncError::ForkChainNotLinked)
}
async fn find_chain_split_height < B : BlockchainBackend + ' static > ( shared : & mut BaseNodeStateMachine < B > , sync_peers : & mut SyncPeers , tip_height : u64 , ) -> Result < u64 , BlockSyncError > { for block_nums in ( 1 ..= tip_height ) . rev ( ) . collect :: < Vec < u64 > > ( ) . chunks ( shared . config . block_sync_config . header_request_size ) { let ( headers , sync_peer ) = request_headers ( LOG_TARGET , shared , sync_peers , block_nums , shared . config . block_sync_config . max_header_request_retry_attempts , ) . await ? ; for header in headers { // Check if header is linked to local chain if let Ok ( prev_header ) = async_db :: fetch_header_by_block_hash ( shared . db . clone ( ) , header . prev_hash . clone ( ) ) . await { return if prev_header . height + 1 == header . height { Ok ( header . height ) } else { warn ! ( target LOG_TARGET " " sync_peer ) ; ban_sync_peer ( LOG_TARGET , & mut shared . connectivity , sync_peers , & sync_peer , shared . config . sync_peer_config . short_term_peer_ban_duration , " " . to_string ( ) , ) . await ? ; Err ( BlockSyncError :: InvalidChainLink ) } ; } } } warn ! ( target LOG_TARGET " " ) ; ban_all_sync_peers ( LOG_TARGET , shared , sync_peers , shared . config . sync_peer_config . peer_ban_duration , " " . to_string ( ) , ) . await ? ; Err ( BlockSyncError :: ForkChainNotLinked ) }
Find the block height where the chain split occurs.
Find the block height where the chain split occurs .
shared
&mut BaseNodeStateMachine<B>
sync_peers
&mut SyncPeers
tip_height
u64