mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-19 05:48:31 +00:00
Merge commit '036b797b2c1831352f937356576b3c78c65220ad' into eip4844
This commit is contained in:
@@ -438,6 +438,46 @@ pub struct BeaconChain<T: BeaconChainTypes> {
|
||||
type BeaconBlockAndState<T, Payload> = (BeaconBlock<T, Payload>, BeaconState<T>);
|
||||
|
||||
impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
/// Checks if a block is finalized.
|
||||
/// The finalization check is done with the block slot. The block root is used to verify that
|
||||
/// the finalized slot is in the canonical chain.
|
||||
pub fn is_finalized_block(
|
||||
&self,
|
||||
block_root: &Hash256,
|
||||
block_slot: Slot,
|
||||
) -> Result<bool, Error> {
|
||||
let finalized_slot = self
|
||||
.canonical_head
|
||||
.cached_head()
|
||||
.finalized_checkpoint()
|
||||
.epoch
|
||||
.start_slot(T::EthSpec::slots_per_epoch());
|
||||
let is_canonical = self
|
||||
.block_root_at_slot(block_slot, WhenSlotSkipped::None)?
|
||||
.map_or(false, |canonical_root| block_root == &canonical_root);
|
||||
Ok(block_slot <= finalized_slot && is_canonical)
|
||||
}
|
||||
|
||||
/// Checks if a state is finalized.
|
||||
/// The finalization check is done with the slot. The state root is used to verify that
|
||||
/// the finalized state is in the canonical chain.
|
||||
pub fn is_finalized_state(
|
||||
&self,
|
||||
state_root: &Hash256,
|
||||
state_slot: Slot,
|
||||
) -> Result<bool, Error> {
|
||||
let finalized_slot = self
|
||||
.canonical_head
|
||||
.cached_head()
|
||||
.finalized_checkpoint()
|
||||
.epoch
|
||||
.start_slot(T::EthSpec::slots_per_epoch());
|
||||
let is_canonical = self
|
||||
.state_root_at_slot(state_slot)?
|
||||
.map_or(false, |canonical_root| state_root == &canonical_root);
|
||||
Ok(state_slot <= finalized_slot && is_canonical)
|
||||
}
|
||||
|
||||
/// Persists the head tracker and fork choice.
|
||||
///
|
||||
/// We do it atomically even though no guarantees need to be made about blocks from
|
||||
|
||||
Reference in New Issue
Block a user