pub fn new(
        db: B,
        consensus_manager: &ConsensusManager,
        validators: Validators<B>,
        config: BlockchainDatabaseConfig,
        cleanup_orphans_at_startup: bool,
    ) -> Result<Self, ChainStorageError>
    {
        debug!(
            target: LOG_TARGET,
            "Initializing database pj={}", config.pruning_horizon
        );
        let blockchain_db = BlockchainDatabase {
            db: Arc::new(RwLock::new(db)),
            validators,
            config,
            consensus_manager: consensus_manager.clone(),
        };
        let metadata = blockchain_db.get_chain_metadata()?;
        if metadata.height_of_longest_chain.is_none() {
            let genesis_block = consensus_manager.get_genesis_block();
            blockchain_db.store_new_block(genesis_block)?;
            blockchain_db.store_pruning_horizon(config.pruning_horizon)?;
        }
        if cleanup_orphans_at_startup {
            match blockchain_db.cleanup_all_orphans() {
                Ok(_) => info!(target: LOG_TARGET, "Orphan database cleaned out at startup.",),
                Err(e) => warn!(
                    target: LOG_TARGET,
                    "Orphan database could not be cleaned out at startup: ({}).", e
                ),
            }
        }
        if config.pruning_horizon != metadata.pruning_horizon {
            debug!(
                target: LOG_TARGET,
                "Updating pruning horizon from {} to {}.", metadata.pruning_horizon, config.pruning_horizon,
            );
            blockchain_db.store_pruning_horizon(config.pruning_horizon)?;
        }
        Ok(blockchain_db)
    }
/// Creates a new `BlockchainDatabase` using the provided backend.
Creates a new `BlockchainDatabase` using the provided backend.
Creates a new ` BlockchainDatabase ` using the provided backend .
pub fn new(
        db: B,
        consensus_manager: &ConsensusManager,
        validators: Validators<B>,
        config: BlockchainDatabaseConfig,
        cleanup_orphans_at_startup: bool,
    ) -> Result<Self, ChainStorageError>
    {
        debug!(
            target: LOG_TARGET,
            "Initializing database pj={}", config.pruning_horizon
        );
        let blockchain_db = BlockchainDatabase {
            db: Arc::new(RwLock::new(db)),
            validators,
            config,
            consensus_manager: consensus_manager.clone(),
        };
        let metadata = blockchain_db.get_chain_metadata()?;
        if metadata.height_of_longest_chain.is_none() {
            let genesis_block = consensus_manager.get_genesis_block();
            blockchain_db.store_new_block(genesis_block)?;
            blockchain_db.store_pruning_horizon(config.pruning_horizon)?;
        }
        if cleanup_orphans_at_startup {
            match blockchain_db.cleanup_all_orphans() {
                Ok(_) => info!(target: LOG_TARGET, "Orphan database cleaned out at startup.",),
                Err(e) => warn!(
                    target: LOG_TARGET,
                    "Orphan database could not be cleaned out at startup: ({}).", e
                ),
            }
        }
        if config.pruning_horizon != metadata.pruning_horizon {
            debug!(
                target: LOG_TARGET,
                "Updating pruning horizon from {} to {}.", metadata.pruning_horizon, config.pruning_horizon,
            );
            blockchain_db.store_pruning_horizon(config.pruning_horizon)?;
        }
        Ok(blockchain_db)
    }
pub fn new ( db : B , consensus_manager : & ConsensusManager , validators : Validators < B > , config : BlockchainDatabaseConfig , cleanup_orphans_at_startup : bool , ) -> Result < Self , ChainStorageError > { debug ! ( target LOG_TARGET " " config pruning_horizon ) ; let blockchain_db = BlockchainDatabase { db : Arc :: new ( RwLock :: new ( db ) ) , validators , config , consensus_manager : consensus_manager . clone ( ) , } ; let metadata = blockchain_db . get_chain_metadata ( ) ? ; if metadata . height_of_longest_chain . is_none ( ) { let genesis_block = consensus_manager . get_genesis_block ( ) ; blockchain_db . store_new_block ( genesis_block ) ? ; blockchain_db . store_pruning_horizon ( config . pruning_horizon ) ? ; } if cleanup_orphans_at_startup { match blockchain_db . cleanup_all_orphans ( ) { Ok ( _ ) => info ! ( target LOG_TARGET " " ) , Err ( e ) => warn ! ( target LOG_TARGET " " e ) , } } if config . pruning_horizon != metadata . pruning_horizon { debug ! ( target LOG_TARGET " " metadata pruning_horizon config pruning_horizon ) ; blockchain_db . store_pruning_horizon ( config . pruning_horizon ) ? ; } Ok ( blockchain_db ) }
Creates a new `BlockchainDatabase` using the provided backend.
Creates a new ` BlockchainDatabase ` using the provided backend .
db
B
consensus_manager
&ConsensusManager
validators
Validators<B>
config
BlockchainDatabaseConfig
cleanup_orphans_at_startup
bool
db
B
consensus_manager
&ConsensusManager
validators
Validators<B>
config
BlockchainDatabaseConfig
cleanup_orphans_at_startup
bool