fn handle_possible_reorg<T: BlockchainBackend>(
    db: &mut T,
    block_validator: &StatefulValidator<Block, T>,
    chain_strength_comparer: &dyn ChainStrengthComparer,
    block: Arc<Block>,
) -> Result<BlockAddResult, ChainStorageError>
{
    let db_height = db
        .fetch_chain_metadata()?
        .height_of_longest_chain
        .ok_or_else(|| ChainStorageError::InvalidQuery("Cannot retrieve block. Blockchain DB is empty".into()))
        .map_err(|e| {
            error!(
                target: LOG_TARGET,
                "Could not retrieve block, block chain is empty {:?}", e
            );
            e
        })?;
    insert_orphan(db, block.clone())?;
    debug!(
        target: LOG_TARGET,
        "Added candidate block #{} ({}) to the orphan database. Best height is {}.",
        block.header.height,
        block.hash().to_hex(),
        db_height,
    );
    // Trigger a reorg check for all blocks in the orphan block pool
    handle_reorg(db, block_validator, chain_strength_comparer, block)
}
// Checks whether we should add the block as an orphan. If it is the case, the orphan block is added and the chain
// is reorganised if necessary.
Checks whether we should add the block as an orphan. If it is the case, the orphan block is added and the chain
is reorganised if necessary.
Checks whether we should add the block as an orphan . If it is the case the orphan block is added and the chain is reorganised if necessary .
fn handle_possible_reorg<T: BlockchainBackend>(
    db: &mut T,
    block_validator: &StatefulValidator<Block, T>,
    chain_strength_comparer: &dyn ChainStrengthComparer,
    block: Arc<Block>,
) -> Result<BlockAddResult, ChainStorageError>
{
    let db_height = db
        .fetch_chain_metadata()?
        .height_of_longest_chain
        .ok_or_else(|| ChainStorageError::InvalidQuery("Cannot retrieve block. Blockchain DB is empty".into()))
        .map_err(|e| {
            error!(
                target: LOG_TARGET,
                "Could not retrieve block, block chain is empty {:?}", e
            );
            e
        })?;
    insert_orphan(db, block.clone())?;
    debug!(
        target: LOG_TARGET,
        "Added candidate block #{} ({}) to the orphan database. Best height is {}.",
        block.header.height,
        block.hash().to_hex(),
        db_height,
    );
    // Trigger a reorg check for all blocks in the orphan block pool
    handle_reorg(db, block_validator, chain_strength_comparer, block)
}
fn handle_possible_reorg < T : BlockchainBackend > ( db : & mut T , block_validator : & StatefulValidator < Block , T > , chain_strength_comparer : & dyn ChainStrengthComparer , block : Arc < Block > , ) -> Result < BlockAddResult , ChainStorageError > { let db_height = db . fetch_chain_metadata ( ) ? . height_of_longest_chain . ok_or_else ( | | ChainStorageError :: InvalidQuery ( " " . into ( ) ) ) . map_err ( | e | { error ! ( target LOG_TARGET " " e ) ; e } ) ? ; insert_orphan ( db , block . clone ( ) ) ? ; debug ! ( target LOG_TARGET " " block header height block hash ( ) to_hex ( ) db_height ) ; // Trigger a reorg check for all blocks in the orphan block pool handle_reorg ( db , block_validator , chain_strength_comparer , block ) }
Checks whether we should add the block as an orphan.
Checks whether we should add the block as an orphan .
db
&mut T
block_validator
&StatefulValidator<Block, T>
chain_strength_comparer
&dyn ChainStrengthComparer
block
Arc<Block>
db
&mut T
block_validator
&StatefulValidator<Block, T>
chain_strength_comparer
&dyn ChainStrengthComparer
block
Arc<Block>