pub fn add_block(&self, block: Arc<Block>) -> Result<BlockAddResult, ChainStorageError> {
        let new_height = block.header.height;
        // Perform orphan block validation.
        if let Err(e) = self.validators.orphan.validate(&block) {
            warn!(
                target: LOG_TARGET,
                "Block #{} ({}) failed validation - {}",
                &new_height,
                block.hash().to_hex(),
                e.to_string()
            );
            return Err(e.into());
        }

        trace!(
            target: LOG_TARGET,
            "[add_block] acquired write access db lock for block #{} ",
            &new_height
        );
        let mut db = self.db_write_access()?;
        let block_add_result = add_block(
            &mut *db,
            &*self.validators.block,
            &*self.consensus_manager.chain_strength_comparer(),
            block,
        )?;

        // Cleanup orphan block pool
        match block_add_result {
            BlockAddResult::OrphanBlock | BlockAddResult::ChainReorg(_, _) => {
                cleanup_orphans(&mut *db, self.config.orphan_storage_capacity)?
            },
            _ => {},
        }

        // Cleanup of backend when in pruned mode.
        match block_add_result {
            BlockAddResult::Ok | BlockAddResult::ChainReorg(_, _) => prune_database(
                &mut *db,
                self.config.pruning_interval,
                self.config.pruning_horizon,
                new_height,
            )?,
            _ => {},
        }

        trace!(
            target: LOG_TARGET,
            "[add_block] released write access db lock for block #{} ",
            &new_height
        );
        Ok(block_add_result)
    }
/// Tries to add a block to the longest chain.
///
/// The block is added to the longest chain if and only if
///   * Block block is not already in the database, AND
///   * The block is next in the chain, AND
///   * The Validator passes
///   * There are no problems with the database backend (e.g. disk full)
///
/// If the block is _not_ next in the chain, the block will be added to the orphan pool if the orphan validator
/// passes, and then the database is checked for whether there has been a chain reorganisation.
///
/// # Returns
///
/// An error is returned if
/// * there was a problem accessing the database,
/// * the validation fails
///
/// Otherwise the function returns successfully.
/// A successful return value can be one of
///   * `BlockExists`: the block has already been added; No action was taken.
///   * `Ok`: The block was added and all validation checks passed
///   * `OrphanBlock`: The block did not form part of the main chain and was added as an orphan.
///   * `ChainReorg`: The block was added, which resulted in a chain-reorg.
///
/// If an error does occur while writing the new block parts, all changes are reverted before returning.
Tries to add a block to the longest chain.
The block is added to the longest chain if and only if
Block block is not already in the database, AND
The block is next in the chain, AND
The Validator passes
There are no problems with the database backend

If the block is _not_ next in the chain, the block will be added to the orphan pool if the orphan validator
passes, and then the database is checked for whether there has been a chain reorganisation.
Tries to add a block to the longest chain . The block is added to the longest chain if and only if Block block is not already in the database AND The block is next in the chain AND The Validator passes There are no problems with the database backend If the block is _not_ next in the chain the block will be added to the orphan pool if the orphan validator passes and then the database is checked for whether there has been a chain reorganisation .
pub fn add_block(&self, block: Arc<Block>) -> Result<BlockAddResult, ChainStorageError> {
        let new_height = block.header.height;
        // Perform orphan block validation.
        if let Err(e) = self.validators.orphan.validate(&block) {
            warn!(
                target: LOG_TARGET,
                "Block #{} ({}) failed validation - {}",
                &new_height,
                block.hash().to_hex(),
                e.to_string()
            );
            return Err(e.into());
        }
        trace!(
            target: LOG_TARGET,
            "[add_block] acquired write access db lock for block #{} ",
            &new_height
        );
        let mut db = self.db_write_access()?;
        let block_add_result = add_block(
            &mut *db,
            &*self.validators.block,
            &*self.consensus_manager.chain_strength_comparer(),
            block,
        )?;
        // Cleanup orphan block pool
        match block_add_result {
            BlockAddResult::OrphanBlock | BlockAddResult::ChainReorg(_, _) => {
                cleanup_orphans(&mut *db, self.config.orphan_storage_capacity)?
            },
            _ => {},
        }
        // Cleanup of backend when in pruned mode.
        match block_add_result {
            BlockAddResult::Ok | BlockAddResult::ChainReorg(_, _) => prune_database(
                &mut *db,
                self.config.pruning_interval,
                self.config.pruning_horizon,
                new_height,
            )?,
            _ => {},
        }
        trace!(
            target: LOG_TARGET,
            "[add_block] released write access db lock for block #{} ",
            &new_height
        );
        Ok(block_add_result)
    }
pub fn add_block ( & self , block : Arc < Block > ) -> Result < BlockAddResult , ChainStorageError > { let new_height = block . header . height ; // Perform orphan block validation. if let Err ( e ) = self . validators . orphan . validate ( & block ) { warn ! ( target LOG_TARGET " " new_height block hash ( ) to_hex ( ) e to_string ( ) ) ; return Err ( e . into ( ) ) ; } trace ! ( target LOG_TARGET " " new_height ) ; let mut db = self . db_write_access ( ) ? ; let block_add_result = add_block ( & mut * db , & * self . validators . block , & * self . consensus_manager . chain_strength_comparer ( ) , block , ) ? ; // Cleanup orphan block pool match block_add_result { BlockAddResult :: OrphanBlock | BlockAddResult :: ChainReorg ( _ , _ ) => { cleanup_orphans ( & mut * db , self . config . orphan_storage_capacity ) ? } , _ => { } , } // Cleanup of backend when in pruned mode. match block_add_result { BlockAddResult :: Ok | BlockAddResult :: ChainReorg ( _ , _ ) => prune_database ( & mut * db , self . config . pruning_interval , self . config . pruning_horizon , new_height , ) ? , _ => { } , } trace ! ( target LOG_TARGET " " new_height ) ; Ok ( block_add_result ) }
Tries to add a block to the longest chain.
Tries to add a block to the longest chain .
&self
block
Arc<Block>
An error is returned if
there was a problem accessing the database,
the validation fails

Otherwise the function returns successfully.
A successful return value can be one of
`BlockExists`: the block has already been added; No action was taken.
`Ok`: The block was added and all validation checks passed
`OrphanBlock`: The block did not form part of the main chain and was added as an orphan.
`ChainReorg`: The block was added, which resulted in a chain-reorg.

If an error does occur while writing the new block parts, all changes are reverted before returning.
An error is returned if there was a problem accessing the database the validation fails Otherwise the function returns successfully . A successful return value can be one of ` BlockExists ` : the block has already been added ; No action was taken . ` Ok ` : The block was added and all validation checks passed ` OrphanBlock ` : The block did not form part of the main chain and was added as an orphan . ` ChainReorg ` : The block was added which resulted in a chain - reorg . If an error does occur while writing the new block parts all changes are reverted before returning .
&self
block
Arc<Block>