mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 22:38:34 +00:00
Relax requirements that a checkpoint state must be epoch aligned post-gloas
This commit is contained in:
@@ -101,6 +101,7 @@ pub enum Error {
|
||||
from_state_slot: Slot,
|
||||
target_slot: Slot,
|
||||
},
|
||||
FinalizedStateAlreadySet,
|
||||
}
|
||||
|
||||
pub trait HandleUnavailable<T> {
|
||||
|
||||
@@ -474,6 +474,25 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
}
|
||||
}
|
||||
|
||||
/// See [`StateCache::set_initial_finalized_state`](crate::state_cache::StateCache::set_initial_finalized_state).
|
||||
pub fn set_initial_finalized_state(
|
||||
&self,
|
||||
state_root: Hash256,
|
||||
block_root: Hash256,
|
||||
state: BeaconState<E>,
|
||||
) -> Result<(), Error> {
|
||||
let start_slot = self.get_anchor_info().anchor_slot;
|
||||
let pre_finalized_slots_to_retain = self
|
||||
.hierarchy
|
||||
.closest_layer_points(state.slot(), start_slot);
|
||||
self.state_cache.lock().set_initial_finalized_state(
|
||||
state_root,
|
||||
block_root,
|
||||
state,
|
||||
&pre_finalized_slots_to_retain,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn update_finalized_state(
|
||||
&self,
|
||||
state_root: Hash256,
|
||||
|
||||
@@ -124,6 +124,36 @@ impl<E: EthSpec> StateCache<E> {
|
||||
roots
|
||||
}
|
||||
|
||||
/// Used by checkpoint sync to initialize the finalized state in the state cache.
|
||||
///
|
||||
/// Post-gloas the checkpoint state may not be epoch-aligned, e.g when the epoch boundary
|
||||
/// slot is skipped. We relax the epoch-alignment requirement for the initial state only.
|
||||
/// Runtime finalization updates should use [`update_finalized_state`](Self::update_finalized_state),
|
||||
/// which enforces alignment.
|
||||
pub fn set_initial_finalized_state(
|
||||
&mut self,
|
||||
state_root: Hash256,
|
||||
block_root: Hash256,
|
||||
state: BeaconState<E>,
|
||||
pre_finalized_slots_to_retain: &[Slot],
|
||||
) -> Result<(), Error> {
|
||||
if self.finalized_state.is_some() {
|
||||
return Err(Error::FinalizedStateAlreadySet);
|
||||
}
|
||||
|
||||
if !state.fork_name_unchecked().gloas_enabled() && state.slot() % E::slots_per_epoch() != 0
|
||||
{
|
||||
return Err(Error::FinalizedStateUnaligned);
|
||||
}
|
||||
|
||||
self.update_finalized_state_inner(
|
||||
state_root,
|
||||
block_root,
|
||||
state,
|
||||
pre_finalized_slots_to_retain,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn update_finalized_state(
|
||||
&mut self,
|
||||
state_root: Hash256,
|
||||
@@ -135,6 +165,21 @@ impl<E: EthSpec> StateCache<E> {
|
||||
return Err(Error::FinalizedStateUnaligned);
|
||||
}
|
||||
|
||||
self.update_finalized_state_inner(
|
||||
state_root,
|
||||
block_root,
|
||||
state,
|
||||
pre_finalized_slots_to_retain,
|
||||
)
|
||||
}
|
||||
|
||||
fn update_finalized_state_inner(
|
||||
&mut self,
|
||||
state_root: Hash256,
|
||||
block_root: Hash256,
|
||||
state: BeaconState<E>,
|
||||
pre_finalized_slots_to_retain: &[Slot],
|
||||
) -> Result<(), Error> {
|
||||
if self
|
||||
.finalized_state
|
||||
.as_ref()
|
||||
|
||||
Reference in New Issue
Block a user