// Perform a comprehensive search to remove all the minimum height orphans to maintain the configured orphan pool
// storage limit. If the node is configured to run in pruned mode then orphan blocks with heights lower than the horizon
// block height will also be discarded.
Perform a comprehensive search to remove all the minimum height orphans to maintain the configured orphan pool
storage limit. If the node is configured to run in pruned mode then orphan blocks with heights lower than the horizon
block height will also be discarded.
Perform a comprehensive search to remove all the minimum height orphans to maintain the configured orphan pool storage limit . If the node is configured to run in pruned mode then orphan blocks with heights lower than the horizon block height will also be discarded .
fn cleanup_orphans<T: BlockchainBackend>(db: &mut T, orphan_storage_capacity: usize) -> Result<(), ChainStorageError> {
    let orphan_count = db.get_orphan_count()?;
    let num_over_limit = orphan_count.saturating_sub(orphan_storage_capacity);
    if num_over_limit > 0 {
        info!(
            target: LOG_TARGET,
            "Orphan block storage limit reached, performing cleanup.",
        );
        let mut orphans = Vec::<(u64, BlockHash)>::with_capacity(orphan_count);
        db.for_each_orphan(|pair| {
            let (block_hash, block) = pair.unwrap();
            orphans.push((block.header.height, block_hash));
        })
        .expect("Unexpected result for database query");
        orphans.sort_by(|a, b| a.0.cmp(&b.0));
        let metadata = db.fetch_chain_metadata()?;
        let horizon_height = metadata.horizon_block(metadata.height_of_longest_chain.unwrap_or(0));
        let mut txn = DbTransaction::new();
        for (removed_count, (height, block_hash)) in orphans.into_iter().enumerate() {
            if height > horizon_height && removed_count >= num_over_limit {
                break;
            }
            debug!(
                target: LOG_TARGET,
                "Discarding orphan block #{} ({}).",
                height,
                block_hash.to_hex()
            );
            txn.delete(DbKey::OrphanBlock(block_hash.clone()));
        }
        commit(db, txn)?;
    }
    Ok(())
}
fn cleanup_orphans < T : BlockchainBackend > ( db : & mut T , orphan_storage_capacity : usize ) -> Result < ( ) , ChainStorageError > { let orphan_count = db . get_orphan_count ( ) ? ; let num_over_limit = orphan_count . saturating_sub ( orphan_storage_capacity ) ; if num_over_limit > 0 { info ! ( target LOG_TARGET " " ) ; let mut orphans = Vec :: < ( u64 , BlockHash ) > :: with_capacity ( orphan_count ) ; db . for_each_orphan ( | pair | { let ( block_hash , block ) = pair . unwrap ( ) ; orphans . push ( ( block . header . height , block_hash ) ) ; } ) . expect ( " " ) ; orphans . sort_by ( | a , b | a . 0 . cmp ( & b . 0 ) ) ; let metadata = db . fetch_chain_metadata ( ) ? ; let horizon_height = metadata . horizon_block ( metadata . height_of_longest_chain . unwrap_or ( 0 ) ) ; let mut txn = DbTransaction :: new ( ) ; for ( removed_count , ( height , block_hash ) ) in orphans . into_iter ( ) . enumerate ( ) { if height > horizon_height && removed_count >= num_over_limit { break ; } debug ! ( target LOG_TARGET " " height block_hash to_hex ( ) ) ; txn . delete ( DbKey :: OrphanBlock ( block_hash . clone ( ) ) ) ; } commit ( db , txn ) ? ; } Ok ( ( ) ) }
Perform a comprehensive search to remove all the minimum height orphans to maintain the configured orphan pool
storage limit.
Perform a comprehensive search to remove all the minimum height orphans to maintain the configured orphan pool storage limit .
db
&mut T
orphan_storage_capacity
usize