Skip to content

Commit

Permalink
Update is_available check to support PeerDAS. (#6076)
Browse files Browse the repository at this point in the history
* Update `is_available` check to support PeerDAS.

* Merge branch 'unstable' into da-checker-das

# Conflicts:
#	beacon_node/beacon_chain/src/data_availability_checker.rs
#	beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

* Simplify code using `map_or`

* Merge branch 'unstable' into da-checker-das

# Conflicts:
#	consensus/types/src/chain_spec.rs

* Remove `epoch` method from `PendingComponents`

* Add `put_kzg_verified_data_columns` method.
  • Loading branch information
jimmygchen authored Jul 22, 2024
1 parent 06dff60 commit bca732e
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 23 deletions.
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3288,9 +3288,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
}
}
let epoch = slot.epoch(T::EthSpec::slots_per_epoch());
let availability = self
.data_availability_checker
.put_rpc_blobs(block_root, blobs)?;
.put_rpc_blobs(block_root, epoch, blobs)?;

self.process_availability(slot, availability).await
}
Expand Down
7 changes: 6 additions & 1 deletion beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use ssz_types::VariableList;
use std::time::Duration;
use tree_hash::TreeHash;
use types::blob_sidecar::BlobIdentifier;
use types::{BeaconStateError, BlobSidecar, EthSpec, Hash256, SignedBeaconBlockHeader, Slot};
use types::{
BeaconStateError, BlobSidecar, Epoch, EthSpec, Hash256, SignedBeaconBlockHeader, Slot,
};

/// An error occurred while validating a gossip blob.
#[derive(Debug)]
Expand Down Expand Up @@ -223,6 +225,9 @@ impl<T: BeaconChainTypes> GossipVerifiedBlob<T> {
pub fn slot(&self) -> Slot {
self.blob.blob.slot()
}
pub fn epoch(&self) -> Epoch {
self.blob.blob.epoch()
}
pub fn index(&self) -> u64 {
self.blob.blob.index
}
Expand Down
23 changes: 18 additions & 5 deletions beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,17 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
log: &Logger,
spec: ChainSpec,
) -> Result<Self, AvailabilityCheckError> {
let overflow_cache =
DataAvailabilityCheckerInner::new(OVERFLOW_LRU_CAPACITY, store, spec.clone())?;
// TODO(das): support supernode or custom custody requirement
let custody_subnet_count = spec.custody_requirement as usize;
let custody_column_count =
custody_subnet_count.saturating_mul(spec.data_columns_per_subnet());

let overflow_cache = DataAvailabilityCheckerInner::new(
OVERFLOW_LRU_CAPACITY,
store,
custody_column_count,
spec.clone(),
)?;
Ok(Self {
availability_cache: Arc::new(overflow_cache),
slot_clock,
Expand Down Expand Up @@ -143,6 +152,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
pub fn put_rpc_blobs(
&self,
block_root: Hash256,
epoch: Epoch,
blobs: FixedBlobSidecarList<T::EthSpec>,
) -> Result<Availability<T::EthSpec>, AvailabilityCheckError> {
let Some(kzg) = self.kzg.as_ref() else {
Expand All @@ -159,7 +169,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
.map_err(AvailabilityCheckError::Kzg)?;

self.availability_cache
.put_kzg_verified_blobs(block_root, verified_blobs)
.put_kzg_verified_blobs(block_root, epoch, verified_blobs)
}

/// Check if we've cached other blobs for this block. If it completes a set and we also
Expand All @@ -171,8 +181,11 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
&self,
gossip_blob: GossipVerifiedBlob<T>,
) -> Result<Availability<T::EthSpec>, AvailabilityCheckError> {
self.availability_cache
.put_kzg_verified_blobs(gossip_blob.block_root(), vec![gossip_blob.into_inner()])
self.availability_cache.put_kzg_verified_blobs(
gossip_blob.block_root(),
gossip_blob.epoch(),
vec![gossip_blob.into_inner()],
)
}

/// Check if we have all the blobs for a block. Returns `Availability` which has information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum Error {
blob_commitment: KzgCommitment,
block_commitment: KzgCommitment,
},
UnableToDetermineImportRequirement,
Unexpected,
SszTypes(ssz_types::Error),
MissingBlobs,
Expand Down Expand Up @@ -41,6 +42,7 @@ impl Error {
| Error::Unexpected
| Error::ParentStateMissing(_)
| Error::BlockReplayError(_)
| Error::UnableToDetermineImportRequirement
| Error::RebuildingStateCaches(_)
| Error::SlotClockError => ErrorCategory::Internal,
Error::Kzg(_)
Expand Down
Loading

0 comments on commit bca732e

Please sign in to comment.