fn update_orphan_ancestors(
        &mut self,
        blockstore: &Blockstore,
        mut orphan_tree_root: Slot,
        epoch_stakes: &HashMap<Epoch, EpochStakes>,
        epoch_schedule: &EpochSchedule,
    ) -> Option<Slot> {
        // Must only be called on existing orphan trees
        assert!(self.trees.contains_key(&orphan_tree_root));

        // Check blockstore for any new parents of the heaviest orphan tree. Attempt
        // to chain the orphan back to the main fork rooted at `self.root`.
        while orphan_tree_root != self.root {
            let (new_ancestors, parent_tree_root) =
                self.find_ancestor_subtree_of_slot(blockstore, orphan_tree_root);
            {
                let heaviest_tree = self
                    .trees
                    .get_mut(&orphan_tree_root)
                    .expect("Orphan must exist");

                let num_skip = if parent_tree_root.is_some() {
                    // Skip the leaf of the parent tree that the
                    // orphan would merge with later in a call
                    // to `merge_trees`
                    1
                } else {
                    0
                };

                for ancestor in new_ancestors.iter().skip(num_skip).rev() {
                    self.slot_to_tree.insert(*ancestor, orphan_tree_root);
                    heaviest_tree.add_root_parent((*ancestor, Hash::default()));
                }
            }
            if let Some(parent_tree_root) = parent_tree_root {
                // If another subtree is discovered to be the parent
                // of this subtree, merge the two.
                self.merge_trees(
                    orphan_tree_root,
                    parent_tree_root,
                    *new_ancestors
                        .front()
                        .expect("Must exist leaf to merge to if `tree_to_merge`.is_some()"),
                    epoch_stakes,
                    epoch_schedule,
                );
                orphan_tree_root = parent_tree_root;
            } else {
                // If there's no other subtree to merge with, then return
                // the current known earliest ancestor of this branch
                if let Some(earliest_ancestor) = new_ancestors.front() {
                    let orphan_tree = self
                        .trees
                        .remove(&orphan_tree_root)
                        .expect("orphan tree must exist");
                    self.rename_tree_root(&orphan_tree, *earliest_ancestor);
                    assert!(self.trees.insert(*earliest_ancestor, orphan_tree).is_none());
                    orphan_tree_root = *earliest_ancestor;
                }
                break;
            }
        }

        if self.is_unrooted_slot(orphan_tree_root) {
            // If this orphan branch chained down to an unrooted
            // slot, then purge the entire subtree as we know the
            // entire subtree is unrooted
            let orphan_tree = self
                .trees
                .remove(&orphan_tree_root)
                .expect("Must exist, was found in `self.trees` above");
            self.remove_tree_slots(
                orphan_tree
                    .all_slots_stake_voted_subtree()
                    .map(|((slot, _), _)| slot),
                self.root,
            );
            None
        } else {
            // Return the (potentially new in the case of some merges)
            // root of this orphan subtree
            Some(orphan_tree_root)
        }
    }
// Attempts to chain the orphan subtree rooted at `orphan_tree_root`
// to any earlier subtree with new any ancestry information in `blockstore`.
// Returns the earliest known ancestor of `heaviest_tree_root`.
Attempts to chain the orphan subtree rooted at `orphan_tree_root`
to any earlier subtree with new any ancestry information in `blockstore`.
Returns the earliest known ancestor of `heaviest_tree_root`.
Attempts to chain the orphan subtree rooted at ` orphan_tree_root ` to any earlier subtree with new any ancestry information in ` blockstore ` . Returns the earliest known ancestor of ` heaviest_tree_root ` .
fn update_orphan_ancestors(
        &mut self,
        blockstore: &Blockstore,
        mut orphan_tree_root: Slot,
        epoch_stakes: &HashMap<Epoch, EpochStakes>,
        epoch_schedule: &EpochSchedule,
    ) -> Option<Slot> {
        // Must only be called on existing orphan trees
        assert!(self.trees.contains_key(&orphan_tree_root));
        // Check blockstore for any new parents of the heaviest orphan tree. Attempt
        // to chain the orphan back to the main fork rooted at `self.root`.
        while orphan_tree_root != self.root {
            let (new_ancestors, parent_tree_root) =
                self.find_ancestor_subtree_of_slot(blockstore, orphan_tree_root);
            {
                let heaviest_tree = self
                    .trees
                    .get_mut(&orphan_tree_root)
                    .expect("Orphan must exist");
                let num_skip = if parent_tree_root.is_some() {
                    // Skip the leaf of the parent tree that the
                    // orphan would merge with later in a call
                    // to `merge_trees`
                    1
                } else {
                    0
                };
                for ancestor in new_ancestors.iter().skip(num_skip).rev() {
                    self.slot_to_tree.insert(*ancestor, orphan_tree_root);
                    heaviest_tree.add_root_parent((*ancestor, Hash::default()));
                }
            }
            if let Some(parent_tree_root) = parent_tree_root {
                // If another subtree is discovered to be the parent
                // of this subtree, merge the two.
                self.merge_trees(
                    orphan_tree_root,
                    parent_tree_root,
                    *new_ancestors
                        .front()
                        .expect("Must exist leaf to merge to if `tree_to_merge`.is_some()"),
                    epoch_stakes,
                    epoch_schedule,
                );
                orphan_tree_root = parent_tree_root;
            } else {
                // If there's no other subtree to merge with, then return
                // the current known earliest ancestor of this branch
                if let Some(earliest_ancestor) = new_ancestors.front() {
                    let orphan_tree = self
                        .trees
                        .remove(&orphan_tree_root)
                        .expect("orphan tree must exist");
                    self.rename_tree_root(&orphan_tree, *earliest_ancestor);
                    assert!(self.trees.insert(*earliest_ancestor, orphan_tree).is_none());
                    orphan_tree_root = *earliest_ancestor;
                }
                break;
            }
        }
        if self.is_unrooted_slot(orphan_tree_root) {
            // If this orphan branch chained down to an unrooted
            // slot, then purge the entire subtree as we know the
            // entire subtree is unrooted
            let orphan_tree = self
                .trees
                .remove(&orphan_tree_root)
                .expect("Must exist, was found in `self.trees` above");
            self.remove_tree_slots(
                orphan_tree
                    .all_slots_stake_voted_subtree()
                    .map(|((slot, _), _)| slot),
                self.root,
            );
            None
        } else {
            // Return the (potentially new in the case of some merges)
            // root of this orphan subtree
            Some(orphan_tree_root)
        }
    }
fn update_orphan_ancestors ( & mut self , blockstore : & Blockstore , mut orphan_tree_root : Slot , epoch_stakes : & HashMap < Epoch , EpochStakes > , epoch_schedule : & EpochSchedule , ) -> Option < Slot > { // Must only be called on existing orphan trees assert ! ( self trees contains_key ( orphan_tree_root ) ) ; // Check blockstore for any new parents of the heaviest orphan tree. Attempt // to chain the orphan back to the main fork rooted at `self.root`. while orphan_tree_root != self . root { let ( new_ancestors , parent_tree_root ) = self . find_ancestor_subtree_of_slot ( blockstore , orphan_tree_root ) ; { let heaviest_tree = self . trees . get_mut ( & orphan_tree_root ) . expect ( " " ) ; let num_skip = if parent_tree_root . is_some ( ) { // Skip the leaf of the parent tree that the // orphan would merge with later in a call // to `merge_trees` 1 } else { 0 } ; for ancestor in new_ancestors . iter ( ) . skip ( num_skip ) . rev ( ) { self . slot_to_tree . insert ( * ancestor , orphan_tree_root ) ; heaviest_tree . add_root_parent ( ( * ancestor , Hash :: default ( ) ) ) ; } } if let Some ( parent_tree_root ) = parent_tree_root { // If another subtree is discovered to be the parent // of this subtree, merge the two. self . merge_trees ( orphan_tree_root , parent_tree_root , * new_ancestors . front ( ) . expect ( " " ) , epoch_stakes , epoch_schedule , ) ; orphan_tree_root = parent_tree_root ; } else { // If there's no other subtree to merge with, then return // the current known earliest ancestor of this branch if let Some ( earliest_ancestor ) = new_ancestors . front ( ) { let orphan_tree = self . trees . remove ( & orphan_tree_root ) . expect ( " " ) ; self . rename_tree_root ( & orphan_tree , * earliest_ancestor ) ; assert ! ( self trees insert ( earliest_ancestor orphan_tree ) is_none ( ) ) ; orphan_tree_root = * earliest_ancestor ; } break ; } } if self . is_unrooted_slot ( orphan_tree_root ) { // If this orphan branch chained down to an unrooted // slot, then purge the entire subtree as we know the // entire subtree is unrooted let orphan_tree = self . trees . remove ( & orphan_tree_root ) . expect ( " " ) ; self . remove_tree_slots ( orphan_tree . all_slots_stake_voted_subtree ( ) . map ( | ( ( slot , _ ) , _ ) | slot ) , self . root , ) ; None } else { // Return the (potentially new in the case of some merges) // root of this orphan subtree Some ( orphan_tree_root ) } }
Attempts to chain the orphan subtree rooted at `orphan_tree_root`
to any earlier subtree with new any ancestry information in `blockstore`.
Attempts to chain the orphan subtree rooted at ` orphan_tree_root ` to any earlier subtree with new any ancestry information in ` blockstore ` .
&mut self
blockstore
&Blockstore
orphan_tree_root
Slot
epoch_stakes
&HashMap<Epoch, EpochStakes>
epoch_schedule
&EpochSchedule