Skip to content

Commit

Permalink
Code cleanup: add type aliases and update comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jun 28, 2024
1 parent 6ac055d commit f93e2b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
13 changes: 4 additions & 9 deletions beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::blob_verification::{verify_kzg_for_blob_list, GossipVerifiedBlob, Kzg
use crate::block_verification_types::{
AvailabilityPendingExecutedBlock, AvailableExecutedBlock, RpcBlock,
};
use crate::data_availability_checker::overflow_lru_cache::OverflowLRUCache;
use crate::data_availability_checker::overflow_lru_cache::{
AvailabilityAndReconstructedColumns, OverflowLRUCache,
};
use crate::{BeaconChain, BeaconChainTypes, BeaconStore};
use kzg::Kzg;
use slog::{debug, error, o, Logger};
Expand Down Expand Up @@ -158,17 +160,10 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
self.availability_cache.peek_data_column(data_column_id)
}

#[allow(clippy::type_complexity)]
pub fn reconstruct_data_columns(
&self,
block_root: Hash256,
) -> Result<
Option<(
Availability<<T as BeaconChainTypes>::EthSpec>,
DataColumnSidecarVec<<T as BeaconChainTypes>::EthSpec>,
)>,
Error,
> {
) -> Result<Option<AvailabilityAndReconstructedColumns<T::EthSpec>>, Error> {
let Some(kzg) = self.kzg.as_ref() else {
return Err(AvailabilityCheckError::KzgNotInitialized);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub enum BlockImportRequirement {
CustodyColumns(usize),
}

pub type AvailabilityAndReconstructedColumns<E> = (Availability<E>, DataColumnSidecarVec<E>);

impl<E: EthSpec> PendingComponents<E> {
/// Returns an immutable reference to the cached block.
pub fn get_cached_block(&self) -> &Option<DietAvailabilityPendingExecutedBlock<E>> {
Expand Down Expand Up @@ -852,15 +854,12 @@ impl<T: BeaconChainTypes> OverflowLRUCache<T> {
}
}

#[allow(clippy::type_complexity)]
pub fn reconstruct_data_columns(
&self,
kzg: &Kzg,
block_root: Hash256,
) -> Result<
Option<(Availability<T::EthSpec>, DataColumnSidecarVec<T::EthSpec>)>,
AvailabilityCheckError,
> {
) -> Result<Option<AvailabilityAndReconstructedColumns<T::EthSpec>>, AvailabilityCheckError>
{
// Clone the pending components, so we don't hold the read lock during reconstruction
let Some(mut pending_components) = self
.peek_pending_components(&block_root, |pending_components_opt| {
Expand Down
4 changes: 3 additions & 1 deletion beacon_node/network/src/network_beacon_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
});
}

/// Attempt to reconstruct all data columns if the following conditions satisfies:
/// - Our custody requirement is all columns
/// - We >= 50% of columns, but not all columns
async fn attempt_data_column_reconstruction(&self, block_root: Hash256) {
let result = self.chain.reconstruct_data_columns(block_root).await;
match result {
Expand All @@ -793,7 +796,6 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
self.chain.recompute_head_at_current_slot().await;
}
AvailabilityProcessingStatus::MissingComponents(_, _) => {
// TODO: confirm we only perform reconstruction after block is received
debug!(
self.log,
"Block components still missing block after reconstruction";
Expand Down

0 comments on commit f93e2b5

Please sign in to comment.