mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Enforce Optimistic Sync Conditions & CLI Tests (v2) (#3050)
## Description
This PR adds a single, trivial commit (f5d2b27d78) atop #2986 to resolve a tests compile error. The original author (@ethDreamer) is AFK so I'm getting this one merged ☺️
Please see #2986 for more information about the other, significant changes in this PR.
Co-authored-by: Mark Mackey <mark@sigmaprime.io>
Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>
This commit is contained in:
@@ -928,6 +928,54 @@ where
|
||||
.is_descendant(self.fc_store.finalized_checkpoint().root, block_root)
|
||||
}
|
||||
|
||||
/// 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 justified block has execution enabled, then optimistically import any block.
|
||||
if self
|
||||
.get_justified_block()?
|
||||
.execution_status
|
||||
.is_execution_enabled()
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
// If the block has an ancestor with a verified parent, import this block.
|
||||
//
|
||||
// TODO: This condition is not yet merged into the spec. See:
|
||||
//
|
||||
// https://github.com/ethereum/consensus-specs/pull/2841
|
||||
//
|
||||
// ## Note
|
||||
//
|
||||
// If `block_parent_root` is unknown this iter will always return `None`.
|
||||
if self
|
||||
.proto_array
|
||||
.iter_nodes(block_parent_root)
|
||||
.any(|node| node.execution_status.is_valid())
|
||||
{
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// Return the current finalized checkpoint.
|
||||
pub fn finalized_checkpoint(&self) -> Checkpoint {
|
||||
*self.fc_store.finalized_checkpoint()
|
||||
|
||||
Reference in New Issue
Block a user