pub fn prune_by_height(&mut self, finalized_tip_height: block::Height) {
        // split_off returns the values _greater than or equal to_ the key. What
        // we need is the keys that are less than or equal to
        // `finalized_tip_height`. To get this we have split at
        // `finalized_tip_height + 1` and swap the removed portion of the list
        // with the remainder.
        let split_height = finalized_tip_height + 1;
        let split_height =
            split_height.expect("height after finalized tip won't exceed max height");
        let mut by_height = self.by_height.split_off(&split_height);
        mem::swap(&mut self.by_height, &mut by_height);

        for hash in by_height.into_iter().flat_map(|(_, hashes)| hashes) {
            let (expired_block, expired_sender) =
                self.blocks.remove(&hash).expect("block is present");
            let parent_hash = &expired_block.block.header.previous_block_hash;

            // we don't care if the receiver was dropped
            let _ = expired_sender.send(Err(
                "pruned block at or below the finalized tip height".into()
            ));

            // TODO: only remove UTXOs if there are no queued blocks with that UTXO
            //       (known_utxos is best-effort, so this is ok for now)
            for outpoint in expired_block.new_outputs.keys() {
                self.known_utxos.remove(outpoint);
            }

            let parent_list = self
                .by_parent
                .get_mut(parent_hash)
                .expect("parent is present");

            if parent_list.len() == 1 {
                let removed = self
                    .by_parent
                    .remove(parent_hash)
                    .expect("parent is present");
                assert!(
                    removed.contains(&hash),
                    "hash must be present in parent hash list"
                );
            } else {
                assert!(
                    parent_list.remove(&hash),
                    "hash must be present in parent hash list"
                );
            }
        }

        tracing::trace!(num_blocks = %self.blocks.len(), "Finished pruning blocks at or beneath the finalized tip height",);
        self.update_metrics();
    }
/// Remove all queued blocks whose height is less than or equal to the given
/// `finalized_tip_height`.
Remove all queued blocks whose height is less than or equal to the given
`finalized_tip_height`.
Remove all queued blocks whose height is less than or equal to the given ` finalized_tip_height ` .
pub fn prune_by_height(&mut self, finalized_tip_height: block::Height) {
        // split_off returns the values _greater than or equal to_ the key. What
        // we need is the keys that are less than or equal to
        // `finalized_tip_height`. To get this we have split at
        // `finalized_tip_height + 1` and swap the removed portion of the list
        // with the remainder.
        let split_height = finalized_tip_height + 1;
        let split_height =
            split_height.expect("height after finalized tip won't exceed max height");
        let mut by_height = self.by_height.split_off(&split_height);
        mem::swap(&mut self.by_height, &mut by_height);
        for hash in by_height.into_iter().flat_map(|(_, hashes)| hashes) {
            let (expired_block, expired_sender) =
                self.blocks.remove(&hash).expect("block is present");
            let parent_hash = &expired_block.block.header.previous_block_hash;
            // we don't care if the receiver was dropped
            let _ = expired_sender.send(Err(
                "pruned block at or below the finalized tip height".into()
            ));
            // TODO: only remove UTXOs if there are no queued blocks with that UTXO
            //       (known_utxos is best-effort, so this is ok for now)
            for outpoint in expired_block.new_outputs.keys() {
                self.known_utxos.remove(outpoint);
            }
            let parent_list = self
                .by_parent
                .get_mut(parent_hash)
                .expect("parent is present");
            if parent_list.len() == 1 {
                let removed = self
                    .by_parent
                    .remove(parent_hash)
                    .expect("parent is present");
                assert!(
                    removed.contains(&hash),
                    "hash must be present in parent hash list"
                );
            } else {
                assert!(
                    parent_list.remove(&hash),
                    "hash must be present in parent hash list"
                );
            }
        }
        tracing::trace!(num_blocks = %self.blocks.len(), "Finished pruning blocks at or beneath the finalized tip height",);
        self.update_metrics();
    }
pub fn prune_by_height ( & mut self , finalized_tip_height : block :: Height ) { // split_off returns the values _greater than or equal to_ the key. What // we need is the keys that are less than or equal to // `finalized_tip_height`. To get this we have split at // `finalized_tip_height + 1` and swap the removed portion of the list // with the remainder. let split_height = finalized_tip_height + 1 ; let split_height = split_height . expect ( " " ) ; let mut by_height = self . by_height . split_off ( & split_height ) ; mem :: swap ( & mut self . by_height , & mut by_height ) ; for hash in by_height . into_iter ( ) . flat_map ( | ( _ , hashes ) | hashes ) { let ( expired_block , expired_sender ) = self . blocks . remove ( & hash ) . expect ( " " ) ; let parent_hash = & expired_block . block . header . previous_block_hash ; // we don't care if the receiver was dropped let _ = expired_sender . send ( Err ( " " . into ( ) ) ) ; // TODO: only remove UTXOs if there are no queued blocks with that UTXO //       (known_utxos is best-effort, so this is ok for now) for outpoint in expired_block . new_outputs . keys ( ) { self . known_utxos . remove ( outpoint ) ; } let parent_list = self . by_parent . get_mut ( parent_hash ) . expect ( " " ) ; if parent_list . len ( ) == 1 { let removed = self . by_parent . remove ( parent_hash ) . expect ( " " ) ; assert ! ( removed contains ( hash ) " " ) ; } else { assert ! ( parent_list remove ( hash ) " " ) ; } } tracing :: trace ! ( num_blocks self blocks len ( ) " " ) ; self . update_metrics ( ) ; }
Remove all queued blocks whose height is less than or equal to the given
`finalized_tip_height`.
Remove all queued blocks whose height is less than or equal to the given ` finalized_tip_height ` .
&mut self
finalized_tip_height
block::Height