@@ -923,6 +923,16 @@ impl ProtoArray {
923923 return false ;
924924 } ;
925925 let unrealized_justification = if self . justified_checkpoint . epoch + 1 == current_epoch {
926+ // This `unrealized_justified_checkpoint` is an `Option` that can be
927+ // `None` in the scenario that we're not computing unrealized
928+ // justification (UJ). During sync we avoid this computation as an
929+ // optimisation.
930+ //
931+ // I claim that it is safe to always have `unrealized_justification
932+ // == None` under the following conditions:
933+ //
934+ // 1. All competing heads do not have UJ computed.
935+ // 2. The store is not updated as per UJ values.
926936 node. unrealized_justified_checkpoint
927937 } else {
928938 None
@@ -943,56 +953,6 @@ impl ProtoArray {
943953 || self . is_finalized_checkpoint_descendant :: < E > ( node. root ) ;
944954
945955 correct_justified && correct_finalized
946- /*
947- let checkpoint_match_predicate =
948- |node_justified_checkpoint: Checkpoint, node_finalized_checkpoint: Checkpoint| {
949- let correct_justified = node_justified_checkpoint == self.justified_checkpoint
950- || self.justified_checkpoint.epoch == genesis_epoch;
951- let correct_finalized = node_finalized_checkpoint == self.finalized_checkpoint
952- || self.finalized_checkpoint.epoch == genesis_epoch;
953- correct_justified && correct_finalized
954- };
955-
956- if let (
957- Some(unrealized_justified_checkpoint),
958- Some(unrealized_finalized_checkpoint),
959- Some(justified_checkpoint),
960- Some(finalized_checkpoint),
961- ) = (
962- node.unrealized_justified_checkpoint,
963- node.unrealized_finalized_checkpoint,
964- node.justified_checkpoint,
965- node.finalized_checkpoint,
966- ) {
967- let current_epoch = current_slot.epoch(E::slots_per_epoch());
968-
969- // If previous epoch is justified, pull up all tips to at least the previous epoch
970- if CountUnrealizedFull::True == self.count_unrealized_full
971- && (current_epoch > genesis_epoch
972- && self.justified_checkpoint.epoch + 1 == current_epoch)
973- {
974- unrealized_justified_checkpoint.epoch + 1 >= current_epoch
975- // If previous epoch is not justified, pull up only tips from past epochs up to the current epoch
976- } else {
977- // If block is from a previous epoch, filter using unrealized justification & finalization information
978- if node.slot.epoch(E::slots_per_epoch()) < current_epoch {
979- checkpoint_match_predicate(
980- unrealized_justified_checkpoint,
981- unrealized_finalized_checkpoint,
982- )
983- // If block is from the current epoch, filter using the head state's justification & finalization information
984- } else {
985- checkpoint_match_predicate(justified_checkpoint, finalized_checkpoint)
986- }
987- }
988- } else if let (Some(justified_checkpoint), Some(finalized_checkpoint)) =
989- (node.justified_checkpoint, node.finalized_checkpoint)
990- {
991- checkpoint_match_predicate(justified_checkpoint, finalized_checkpoint)
992- } else {
993- false
994- }
995- */
996956 }
997957
998958 /// Return a reverse iterator over the nodes which comprise the chain ending at `block_root`.
0 commit comments