mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Remove TTD flags and safe-slots-to-import-* (#6489)
* Delete SAFE_SLOTS_TO_IMPORT_OPTIMISTICALLY * Update fork choice tests * Remove TTD related flags * Add deprecation warning * Remove more dead code * Delete EF on_merge_block tests * Remove even more dead code * Address Mac's review comments
This commit is contained in:
@@ -1300,43 +1300,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `Ok(false)` if a block is not viable to be imported optimistically.
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
/// Equivalent to the function with the same name in the optimistic sync specs:
|
||||
///
|
||||
/// https://github.com/ethereum/consensus-specs/blob/dev/sync/optimistic.md#helpers
|
||||
pub fn is_optimistic_candidate_block(
|
||||
&self,
|
||||
current_slot: Slot,
|
||||
block_slot: Slot,
|
||||
block_parent_root: &Hash256,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<bool, Error<T::Error>> {
|
||||
// If the block is sufficiently old, import it.
|
||||
if block_slot + spec.safe_slots_to_import_optimistically <= current_slot {
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// If the parent block has execution enabled, always import the block.
|
||||
//
|
||||
// See:
|
||||
//
|
||||
// https://github.com/ethereum/consensus-specs/pull/2844
|
||||
if self
|
||||
.proto_array
|
||||
.get_block(block_parent_root)
|
||||
.map_or(false, |parent| {
|
||||
parent.execution_status.is_execution_enabled()
|
||||
})
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// Return the current finalized checkpoint.
|
||||
pub fn finalized_checkpoint(&self) -> Checkpoint {
|
||||
*self.fc_store.finalized_checkpoint()
|
||||
|
||||
@@ -256,36 +256,6 @@ impl ForkChoiceTest {
|
||||
self
|
||||
}
|
||||
|
||||
/// Moves to the next slot that is *outside* the `SAFE_SLOTS_TO_UPDATE_JUSTIFIED` range.
|
||||
///
|
||||
/// If the chain is presently in an unsafe period, transition through it and the following safe
|
||||
/// period.
|
||||
///
|
||||
/// Note: the `SAFE_SLOTS_TO_UPDATE_JUSTIFIED` variable has been removed
|
||||
/// from the fork choice spec in Q1 2023. We're still leaving references to
|
||||
/// it in our tests because (a) it's easier and (b) it allows us to easily
|
||||
/// test for the absence of that parameter.
|
||||
pub fn move_to_next_unsafe_period(self) -> Self {
|
||||
self.move_inside_safe_to_update()
|
||||
.move_outside_safe_to_update()
|
||||
}
|
||||
|
||||
/// Moves to the next slot that is *outside* the `SAFE_SLOTS_TO_UPDATE_JUSTIFIED` range.
|
||||
pub fn move_outside_safe_to_update(self) -> Self {
|
||||
while is_safe_to_update(self.harness.chain.slot().unwrap(), &self.harness.chain.spec) {
|
||||
self.harness.advance_slot()
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Moves to the next slot that is *inside* the `SAFE_SLOTS_TO_UPDATE_JUSTIFIED` range.
|
||||
pub fn move_inside_safe_to_update(self) -> Self {
|
||||
while !is_safe_to_update(self.harness.chain.slot().unwrap(), &self.harness.chain.spec) {
|
||||
self.harness.advance_slot()
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Applies a block directly to fork choice, bypassing the beacon chain.
|
||||
///
|
||||
/// Asserts the block was applied successfully.
|
||||
@@ -516,10 +486,6 @@ impl ForkChoiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_safe_to_update(slot: Slot, spec: &ChainSpec) -> bool {
|
||||
slot % E::slots_per_epoch() < spec.safe_slots_to_update_justified
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn justified_and_finalized_blocks() {
|
||||
let tester = ForkChoiceTest::new();
|
||||
@@ -536,15 +502,13 @@ fn justified_and_finalized_blocks() {
|
||||
assert!(fork_choice.get_finalized_block().is_ok());
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - The new justified checkpoint descends from the current. Near genesis.
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_descendent_inside_safe_slots() {
|
||||
async fn justified_checkpoint_updates_with_descendent_first_justification() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.move_inside_safe_to_update()
|
||||
.assert_justified_epoch(0)
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
@@ -552,49 +516,29 @@ async fn justified_checkpoint_updates_with_descendent_inside_safe_slots() {
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - This is **not** the first justification since genesis
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_descendent_outside_safe_slots() {
|
||||
async fn justified_checkpoint_updates_with_descendent() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch <= 2)
|
||||
.await
|
||||
.unwrap()
|
||||
.move_outside_safe_to_update()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_justified_epoch(3);
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint descends from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - This is the first justification since genesis
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_first_justification_outside_safe_to_update() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.move_to_next_unsafe_period()
|
||||
.assert_justified_epoch(0)
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.assert_justified_epoch(2);
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint **does not** descend from the current.
|
||||
/// - Current slot is within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - Finalized epoch has **not** increased.
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_non_descendent_inside_safe_slots_without_finality() {
|
||||
async fn justified_checkpoint_updates_with_non_descendent() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.move_inside_safe_to_update()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_block_directly_to_fork_choice(|_, state| {
|
||||
// The finalized checkpoint should not change.
|
||||
@@ -611,64 +555,6 @@ async fn justified_checkpoint_updates_with_non_descendent_inside_safe_slots_with
|
||||
.assert_justified_epoch(3);
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint **does not** descend from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`.
|
||||
/// - Finalized epoch has **not** increased.
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_without_finality() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.move_to_next_unsafe_period()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_block_directly_to_fork_choice(|_, state| {
|
||||
// The finalized checkpoint should not change.
|
||||
state.finalized_checkpoint().epoch = Epoch::new(0);
|
||||
|
||||
// The justified checkpoint has changed.
|
||||
state.current_justified_checkpoint_mut().epoch = Epoch::new(3);
|
||||
// The new block should **not** include the current justified block as an ancestor.
|
||||
state.current_justified_checkpoint_mut().root = *state
|
||||
.get_block_root(Epoch::new(1).start_slot(E::slots_per_epoch()))
|
||||
.unwrap();
|
||||
})
|
||||
.await
|
||||
// Now that `SAFE_SLOTS_TO_UPDATE_JUSTIFIED` has been removed, the new
|
||||
// block should have updated the justified checkpoint.
|
||||
.assert_justified_epoch(3);
|
||||
}
|
||||
|
||||
/// - The new justified checkpoint **does not** descend from the current.
|
||||
/// - Current slot is **not** within `SAFE_SLOTS_TO_UPDATE_JUSTIFIED`
|
||||
/// - Finalized epoch has increased.
|
||||
#[tokio::test]
|
||||
async fn justified_checkpoint_updates_with_non_descendent_outside_safe_slots_with_finality() {
|
||||
ForkChoiceTest::new()
|
||||
.apply_blocks_while(|_, state| state.current_justified_checkpoint().epoch == 0)
|
||||
.await
|
||||
.unwrap()
|
||||
.apply_blocks(1)
|
||||
.await
|
||||
.move_to_next_unsafe_period()
|
||||
.assert_justified_epoch(2)
|
||||
.apply_block_directly_to_fork_choice(|_, state| {
|
||||
// The finalized checkpoint should change.
|
||||
state.finalized_checkpoint_mut().epoch = Epoch::new(1);
|
||||
|
||||
// The justified checkpoint has changed.
|
||||
state.current_justified_checkpoint_mut().epoch = Epoch::new(3);
|
||||
// The new block should **not** include the current justified block as an ancestor.
|
||||
state.current_justified_checkpoint_mut().root = *state
|
||||
.get_block_root(Epoch::new(1).start_slot(E::slots_per_epoch()))
|
||||
.unwrap();
|
||||
})
|
||||
.await
|
||||
.assert_justified_epoch(3);
|
||||
}
|
||||
|
||||
/// Check that the balances are obtained correctly.
|
||||
#[tokio::test]
|
||||
async fn justified_balances() {
|
||||
|
||||
Reference in New Issue
Block a user