Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions beacon_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ client = { path = "client" }
directory = { workspace = true }
dirs = { workspace = true }
environment = { workspace = true }
eth2 = { workspace = true }
eth2_config = { workspace = true }
execution_layer = { workspace = true }
genesis = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ fn verify_attestation_is_finalized_checkpoint_or_descendant<T: BeaconChainTypes>
let attestation_block_root = attestation_data.beacon_block_root;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read the PR body description before the diff :)

let finalized_slot = fork_choice
.finalized_checkpoint()
.local()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let split = chain.store.get_split_info();
Expand Down
78 changes: 32 additions & 46 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::light_client_optimistic_update_verification::{
Error as LightClientOptimisticUpdateError, VerifiedLightClientOptimisticUpdate,
};
use crate::light_client_server_cache::LightClientServerCache;
use crate::migrate::{BackgroundMigrator, ManualFinalizationNotification};
use crate::migrate::BackgroundMigrator;
use crate::naive_aggregation_pool::{
AggregatedAttestationMap, Error as NaiveAggregationError, NaiveAggregationPool,
SyncContributionAggregateMap,
Expand Down Expand Up @@ -122,8 +122,8 @@ use std::sync::Arc;
use std::time::Duration;
use store::iter::{BlockRootsIterator, ParentRootBlockIterator, StateRootsIterator};
use store::{
BlobSidecarListFromRoot, DBColumn, DatabaseBlock, Error as DBError, HotColdDB, HotStateSummary,
KeyValueStore, KeyValueStoreOp, StoreItem, StoreOp,
BlobSidecarListFromRoot, DBColumn, DatabaseBlock, Error as DBError, HotColdDB, KeyValueStore,
KeyValueStoreOp, StoreItem, StoreOp,
};
use task_executor::{RayonPoolType, ShutdownReason, TaskExecutor};
use tokio_stream::Stream;
Expand Down Expand Up @@ -549,10 +549,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
block_root: &Hash256,
block_slot: Slot,
) -> Result<bool, Error> {
// Used by the API: finalized if prior to the network finality not the local view
let finalized_slot = self
.canonical_head
.cached_head()
.finalized_checkpoint()
.on_chain()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let is_canonical = self
Expand All @@ -579,10 +581,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
state_root: &Hash256,
state_slot: Slot,
) -> Result<FinalizationAndCanonicity, Error> {
// Used by the API: finalized if prior to the network finality not the local view
let finalized_slot = self
.canonical_head
.cached_head()
.finalized_checkpoint()
.on_chain()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let slot_is_finalized = state_slot <= finalized_slot;
Expand All @@ -595,6 +599,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
})
}

pub fn irreversible_slot(&self) -> Slot {
let local_finalized_slot = self
.head()
.finalized_checkpoint()
.local()
.epoch
.start_slot(T::EthSpec::slots_per_epoch());
let split = self.store.get_split_info();
std::cmp::max(local_finalized_slot, split.slot)
}

/// Return a database operation for writing the `PersistedBeaconChain` to disk.
///
/// These days the `PersistedBeaconChain` is only used to store the genesis block root, so it
Expand Down Expand Up @@ -1415,7 +1430,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let fork_choice = self.canonical_head.fork_choice_read_lock();
fork_choice
.proto_array()
.heads_descended_from_finalization::<T::EthSpec>(fork_choice.finalized_checkpoint())
.heads_descended_from_finalization::<T::EthSpec>(
fork_choice.finalized_checkpoint().as_local(),
)
.iter()
.map(|node| (node.root, node.slot))
.collect()
Expand Down Expand Up @@ -1672,39 +1689,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.store_migrator.process_manual_compaction();
}

pub fn manually_finalize_state(
&self,
state_root: Hash256,
checkpoint: Checkpoint,
) -> Result<(), Error> {
let HotStateSummary {
slot,
latest_block_root,
..
} = self
.store
.load_hot_state_summary(&state_root)
.map_err(BeaconChainError::DBError)?
.ok_or(BeaconChainError::MissingHotStateSummary(state_root))?;

if slot != checkpoint.epoch.start_slot(T::EthSpec::slots_per_epoch())
|| latest_block_root != *checkpoint.root
{
return Err(BeaconChainError::InvalidCheckpoint {
state_root,
checkpoint,
});
}

let notif = ManualFinalizationNotification {
state_root: state_root.into(),
checkpoint,
};

self.store_migrator.process_manual_finalization(notif);
Ok(())
}

/// Returns an aggregated `Attestation`, if any, that has a matching `attestation.data`.
///
/// The attestation will be obtained from `self.naive_aggregation_pool`.
Expand Down Expand Up @@ -4106,8 +4090,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// We are doing this to ensure that we detect changes in finalization. It's possible
// that fork choice has already been updated to the finalized checkpoint in the block
// we're importing.
let current_head_finalized_checkpoint =
self.canonical_head.cached_head().finalized_checkpoint();
let current_head_finalized_checkpoint = self
.canonical_head
.cached_head()
.finalied_checkpoint_from_head_state();
// Compare the existing finalized checkpoint with the incoming block's finalized checkpoint.
let new_finalized_checkpoint = state.finalized_checkpoint();

Expand Down Expand Up @@ -5988,16 +5974,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let justified_block = self
.spawn_blocking_handle(
move || {
chain
.canonical_head
.fork_choice_read_lock()
.get_justified_block()
let fork_choice = chain.canonical_head.fork_choice_read_lock();
fork_choice.get_block(&fork_choice.justified_checkpoint().on_chain().root)
},
"invalid_payload_fork_choice_get_justified",
)
.await??;
.await?;

if justified_block.execution_status.is_invalid() {
if let Some(justified_block) = justified_block
&& justified_block.execution_status.is_invalid()
{
crit!(
msg = "ensure you are not connected to a malicious network. This error is not \
recoverable, please reach out to the lighthouse developers for assistance.",
Expand Down Expand Up @@ -7215,7 +7201,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// Check if finalization is advancing.
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());
let epochs_since_finalization =
current_epoch.saturating_sub(cached_head.finalized_checkpoint().epoch);
current_epoch.saturating_sub(cached_head.finalized_checkpoint().on_chain().epoch);
let finalization_check = epochs_since_finalization.as_usize()
<= self.config.builder_fallback_epochs_since_finalization;

Expand Down
Loading
Loading