Skip to content

Commit 656f958

Browse files
committed
Remove should_update_justified_checkpoint
1 parent db112c5 commit 656f958

1 file changed

Lines changed: 3 additions & 64 deletions

File tree

consensus/fork_choice/src/fork_choice.rs

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -653,58 +653,6 @@ where
653653
}
654654
}
655655

656-
/// Returns `true` if the given `store` should be updated to set
657-
/// `state.current_justified_checkpoint` its `justified_checkpoint`.
658-
///
659-
/// ## Specification
660-
///
661-
/// Is equivalent to:
662-
///
663-
/// https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/fork-choice.md#should_update_justified_checkpoint
664-
fn should_update_justified_checkpoint(
665-
&mut self,
666-
new_justified_checkpoint: Checkpoint,
667-
slots: UpdateJustifiedCheckpointSlots,
668-
spec: &ChainSpec,
669-
) -> Result<bool, Error<T::Error>> {
670-
self.update_time(slots.current_slot(), spec)?;
671-
672-
if compute_slots_since_epoch_start::<E>(self.fc_store.get_current_slot())
673-
< spec.safe_slots_to_update_justified
674-
{
675-
return Ok(true);
676-
}
677-
678-
let justified_slot =
679-
compute_start_slot_at_epoch::<E>(self.fc_store.justified_checkpoint().epoch);
680-
681-
// This sanity check is not in the spec, but the invariant is implied.
682-
if let Some(state_slot) = slots.state_slot() {
683-
if justified_slot >= state_slot {
684-
return Err(Error::AttemptToRevertJustification {
685-
store: justified_slot,
686-
state: state_slot,
687-
});
688-
}
689-
}
690-
691-
// We know that the slot for `new_justified_checkpoint.root` is not greater than
692-
// `state.slot`, since a state cannot justify its own slot.
693-
//
694-
// We know that `new_justified_checkpoint.root` is an ancestor of `state`, since a `state`
695-
// only ever justifies ancestors.
696-
//
697-
// A prior `if` statement protects against a justified_slot that is greater than
698-
// `state.slot`
699-
let justified_ancestor =
700-
self.get_ancestor(new_justified_checkpoint.root, justified_slot)?;
701-
if justified_ancestor != Some(self.fc_store.justified_checkpoint().root) {
702-
return Ok(false);
703-
}
704-
705-
Ok(true)
706-
}
707-
708656
/// See `ProtoArrayForkChoice::process_execution_payload_validation` for documentation.
709657
pub fn on_valid_execution_payload(
710658
&mut self,
@@ -1006,23 +954,14 @@ where
1006954
) -> Result<(), Error<T::Error>> {
1007955
// Update justified checkpoint.
1008956
if justified_checkpoint.epoch > self.fc_store.justified_checkpoint().epoch {
1009-
if justified_checkpoint.epoch > self.fc_store.best_justified_checkpoint().epoch {
1010-
self.fc_store
1011-
.set_best_justified_checkpoint(justified_checkpoint);
1012-
}
1013-
if self.should_update_justified_checkpoint(justified_checkpoint, slots, spec)? {
1014-
self.fc_store
1015-
.set_justified_checkpoint(justified_checkpoint)
1016-
.map_err(Error::UnableToSetJustifiedCheckpoint)?;
1017-
}
957+
self.fc_store
958+
.set_justified_checkpoint(justified_checkpoint)
959+
.map_err(Error::UnableToSetJustifiedCheckpoint)?;
1018960
}
1019961

1020962
// Update finalized checkpoint.
1021963
if finalized_checkpoint.epoch > self.fc_store.finalized_checkpoint().epoch {
1022964
self.fc_store.set_finalized_checkpoint(finalized_checkpoint);
1023-
self.fc_store
1024-
.set_justified_checkpoint(justified_checkpoint)
1025-
.map_err(Error::UnableToSetJustifiedCheckpoint)?;
1026965
}
1027966
Ok(())
1028967
}

0 commit comments

Comments
 (0)