Skip to content

Commit bca732e

Browse files
authored
Update is_available check to support PeerDAS. (#6076)
* 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.
1 parent 06dff60 commit bca732e

File tree

8 files changed

+195
-23
lines changed

8 files changed

+195
-23
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3288,9 +3288,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
32883288
}
32893289
}
32903290
}
3291+
let epoch = slot.epoch(T::EthSpec::slots_per_epoch());
32913292
let availability = self
32923293
.data_availability_checker
3293-
.put_rpc_blobs(block_root, blobs)?;
3294+
.put_rpc_blobs(block_root, epoch, blobs)?;
32943295

32953296
self.process_availability(slot, availability).await
32963297
}

beacon_node/beacon_chain/src/blob_verification.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ use ssz_types::VariableList;
1616
use std::time::Duration;
1717
use tree_hash::TreeHash;
1818
use types::blob_sidecar::BlobIdentifier;
19-
use types::{BeaconStateError, BlobSidecar, EthSpec, Hash256, SignedBeaconBlockHeader, Slot};
19+
use types::{
20+
BeaconStateError, BlobSidecar, Epoch, EthSpec, Hash256, SignedBeaconBlockHeader, Slot,
21+
};
2022

2123
/// An error occurred while validating a gossip blob.
2224
#[derive(Debug)]
@@ -223,6 +225,9 @@ impl<T: BeaconChainTypes> GossipVerifiedBlob<T> {
223225
pub fn slot(&self) -> Slot {
224226
self.blob.blob.slot()
225227
}
228+
pub fn epoch(&self) -> Epoch {
229+
self.blob.blob.epoch()
230+
}
226231
pub fn index(&self) -> u64 {
227232
self.blob.blob.index
228233
}

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,17 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
9494
log: &Logger,
9595
spec: ChainSpec,
9696
) -> Result<Self, AvailabilityCheckError> {
97-
let overflow_cache =
98-
DataAvailabilityCheckerInner::new(OVERFLOW_LRU_CAPACITY, store, spec.clone())?;
97+
// TODO(das): support supernode or custom custody requirement
98+
let custody_subnet_count = spec.custody_requirement as usize;
99+
let custody_column_count =
100+
custody_subnet_count.saturating_mul(spec.data_columns_per_subnet());
101+
102+
let overflow_cache = DataAvailabilityCheckerInner::new(
103+
OVERFLOW_LRU_CAPACITY,
104+
store,
105+
custody_column_count,
106+
spec.clone(),
107+
)?;
99108
Ok(Self {
100109
availability_cache: Arc::new(overflow_cache),
101110
slot_clock,
@@ -143,6 +152,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
143152
pub fn put_rpc_blobs(
144153
&self,
145154
block_root: Hash256,
155+
epoch: Epoch,
146156
blobs: FixedBlobSidecarList<T::EthSpec>,
147157
) -> Result<Availability<T::EthSpec>, AvailabilityCheckError> {
148158
let Some(kzg) = self.kzg.as_ref() else {
@@ -159,7 +169,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
159169
.map_err(AvailabilityCheckError::Kzg)?;
160170

161171
self.availability_cache
162-
.put_kzg_verified_blobs(block_root, verified_blobs)
172+
.put_kzg_verified_blobs(block_root, epoch, verified_blobs)
163173
}
164174

165175
/// Check if we've cached other blobs for this block. If it completes a set and we also
@@ -171,8 +181,11 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
171181
&self,
172182
gossip_blob: GossipVerifiedBlob<T>,
173183
) -> Result<Availability<T::EthSpec>, AvailabilityCheckError> {
174-
self.availability_cache
175-
.put_kzg_verified_blobs(gossip_blob.block_root(), vec![gossip_blob.into_inner()])
184+
self.availability_cache.put_kzg_verified_blobs(
185+
gossip_blob.block_root(),
186+
gossip_blob.epoch(),
187+
vec![gossip_blob.into_inner()],
188+
)
176189
}
177190

178191
/// Check if we have all the blobs for a block. Returns `Availability` which has information

beacon_node/beacon_chain/src/data_availability_checker/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum Error {
1010
blob_commitment: KzgCommitment,
1111
block_commitment: KzgCommitment,
1212
},
13+
UnableToDetermineImportRequirement,
1314
Unexpected,
1415
SszTypes(ssz_types::Error),
1516
MissingBlobs,
@@ -41,6 +42,7 @@ impl Error {
4142
| Error::Unexpected
4243
| Error::ParentStateMissing(_)
4344
| Error::BlockReplayError(_)
45+
| Error::UnableToDetermineImportRequirement
4446
| Error::RebuildingStateCaches(_)
4547
| Error::SlotClockError => ErrorCategory::Internal,
4648
Error::Kzg(_)

0 commit comments

Comments
 (0)