fn initialize_block_metadata_db(
    env: &Environment,
    block_metadata_db: &Database,
    deleted_block_hashes: &HashSet<&[u8]>,
    should_check_integrity: bool,
) -> Result<(), Error> {
    info!("initializing block metadata database");
    let mut txn = env.begin_rw_txn()?;
    let mut cursor = txn.open_rw_cursor(*block_metadata_db)?;

    for (raw_key, raw_val) in cursor.iter() {
        if deleted_block_hashes.contains(raw_key) {
            cursor.del(WriteFlags::empty())?;
            continue;
        }

        if should_check_integrity {
            let signatures: BlockSignatures = lmdb_ext::deserialize(raw_val)?;

            // Signature verification could be very slow process
            // It iterates over every signature and verifies them.
            signatures.verify().map_err(Error::SignatureVerification)?;
            if raw_key != signatures.block_hash.as_ref() {
                return Err(Error::CorruptedBlockSignatureIndex {
                    raw_key: raw_key.to_vec(),
                    block_hash_bytes: signatures.block_hash.as_ref().to_vec(),
                });
            };
        }
    }

    drop(cursor);
    txn.commit()?;

    info!("block metadata database initialized");
    Ok(())
}
/// Purges stale entries from the block metadata database, and checks the integrity of the remainder
/// if `should_check_integrity` is true.
Purges stale entries from the block metadata database, and checks the integrity of the remainder
if `should_check_integrity` is true.
Purges stale entries from the block metadata database and checks the integrity of the remainder if ` should_check_integrity ` is true .
fn initialize_block_metadata_db(
    env: &Environment,
    block_metadata_db: &Database,
    deleted_block_hashes: &HashSet<&[u8]>,
    should_check_integrity: bool,
) -> Result<(), Error> {
    info!("initializing block metadata database");
    let mut txn = env.begin_rw_txn()?;
    let mut cursor = txn.open_rw_cursor(*block_metadata_db)?;
    for (raw_key, raw_val) in cursor.iter() {
        if deleted_block_hashes.contains(raw_key) {
            cursor.del(WriteFlags::empty())?;
            continue;
        }
        if should_check_integrity {
            let signatures: BlockSignatures = lmdb_ext::deserialize(raw_val)?;
            // Signature verification could be very slow process
            // It iterates over every signature and verifies them.
            signatures.verify().map_err(Error::SignatureVerification)?;
            if raw_key != signatures.block_hash.as_ref() {
                return Err(Error::CorruptedBlockSignatureIndex {
                    raw_key: raw_key.to_vec(),
                    block_hash_bytes: signatures.block_hash.as_ref().to_vec(),
                });
            };
        }
    }
    drop(cursor);
    txn.commit()?;
    info!("block metadata database initialized");
    Ok(())
}
fn initialize_block_metadata_db ( env : & Environment , block_metadata_db : & Database , deleted_block_hashes : & HashSet < & [ u8 ] > , should_check_integrity : bool , ) -> Result < ( ) , Error > { info ! ( " " ) ; let mut txn = env . begin_rw_txn ( ) ? ; let mut cursor = txn . open_rw_cursor ( * block_metadata_db ) ? ; for ( raw_key , raw_val ) in cursor . iter ( ) { if deleted_block_hashes . contains ( raw_key ) { cursor . del ( WriteFlags :: empty ( ) ) ? ; continue ; } if should_check_integrity { let signatures : BlockSignatures = lmdb_ext :: deserialize ( raw_val ) ? ; // Signature verification could be very slow process // It iterates over every signature and verifies them. signatures . verify ( ) . map_err ( Error :: SignatureVerification ) ? ; if raw_key != signatures . block_hash . as_ref ( ) { return Err ( Error :: CorruptedBlockSignatureIndex { raw_key : raw_key . to_vec ( ) , block_hash_bytes : signatures . block_hash . as_ref ( ) . to_vec ( ) , } ) ; } ; } } drop ( cursor ) ; txn . commit ( ) ? ; info ! ( " " ) ; Ok ( ( ) ) }
Purges stale entries from the block metadata database, and checks the integrity of the remainder
if `should_check_integrity` is true.
Purges stale entries from the block metadata database and checks the integrity of the remainder if ` should_check_integrity ` is true .
env
&Environment
block_metadata_db
&Database
deleted_block_hashes
&HashSet<&[u8]>
should_check_integrity
bool
env
&Environment
block_metadata_db
&Database
deleted_block_hashes
&HashSet<&[u8]>
should_check_integrity
bool