Skip to content

Commit 67aee85

Browse files
committed
initial change
1 parent 22bbd3c commit 67aee85

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ impl<E: EthSpec> PendingComponents<E> {
272272
&self,
273273
spec: &Arc<ChainSpec>,
274274
num_expected_columns_opt: Option<usize>,
275+
min_proofs_required_opt: Option<usize>,
275276
recover: R,
276277
) -> Result<Option<AvailableExecutedBlock<E>>, AvailabilityCheckError>
277278
where
@@ -349,11 +350,8 @@ impl<E: EthSpec> PendingComponents<E> {
349350
return Ok(None);
350351
};
351352

352-
// Check if this node needs execution proofs to validate blocks.
353-
let needs_execution_proofs = spec.zkvm_min_proofs_required().is_some();
354-
355-
if needs_execution_proofs {
356-
let min_proofs = spec.zkvm_min_proofs_required().unwrap();
353+
// Check if this block needs execution proofs.
354+
if let Some(min_proofs) = min_proofs_required_opt {
357355
let num_proofs = self.execution_proof_subnet_count();
358356
if num_proofs < min_proofs {
359357
// Not enough execution proofs yet
@@ -605,7 +603,13 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
605603
);
606604
});
607605

608-
self.check_availability_and_cache_components(block_root, pending_components, None)
606+
let min_proofs_required_opt = self.get_min_proofs_required(epoch);
607+
self.check_availability_and_cache_components(
608+
block_root,
609+
pending_components,
610+
None,
611+
min_proofs_required_opt,
612+
)
609613
}
610614

611615
#[allow(clippy::type_complexity)]
@@ -645,10 +649,12 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
645649
);
646650
});
647651

652+
let min_proofs_required_opt = self.get_min_proofs_required(epoch);
648653
self.check_availability_and_cache_components(
649654
block_root,
650655
pending_components,
651656
Some(num_expected_columns),
657+
min_proofs_required_opt,
652658
)
653659
}
654660

@@ -682,6 +688,7 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
682688
})?;
683689

684690
let num_expected_columns_opt = self.get_num_expected_columns(epoch);
691+
let min_proofs_required_opt = self.get_min_proofs_required(epoch);
685692

686693
pending_components.span.in_scope(|| {
687694
debug!(
@@ -696,6 +703,7 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
696703
block_root,
697704
pending_components,
698705
num_expected_columns_opt,
706+
min_proofs_required_opt,
699707
)
700708
}
701709

@@ -704,10 +712,12 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
704712
block_root: Hash256,
705713
pending_components: MappedRwLockReadGuard<'_, PendingComponents<T::EthSpec>>,
706714
num_expected_columns_opt: Option<usize>,
715+
min_proofs_required_opt: Option<usize>,
707716
) -> Result<Availability<T::EthSpec>, AvailabilityCheckError> {
708717
if let Some(available_block) = pending_components.make_available(
709718
&self.spec,
710719
num_expected_columns_opt,
720+
min_proofs_required_opt,
711721
|block, span| self.state_cache.recover_pending_executed_block(block, span),
712722
)? {
713723
// Explicitly drop read lock before acquiring write lock
@@ -876,6 +886,7 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
876886
})?;
877887

878888
let num_expected_columns_opt = self.get_num_expected_columns(epoch);
889+
let min_proofs_required_opt = self.get_min_proofs_required(epoch);
879890

880891
pending_components.span.in_scope(|| {
881892
debug!(
@@ -889,6 +900,7 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
889900
block_root,
890901
pending_components,
891902
num_expected_columns_opt,
903+
min_proofs_required_opt,
892904
)
893905
}
894906

@@ -903,6 +915,16 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
903915
}
904916
}
905917

918+
/// Returns the minimum number of execution proofs required for a block at the given epoch.
919+
/// Returns `None` if proofs are not required (zkVM not enabled for this epoch).
920+
fn get_min_proofs_required(&self, epoch: Epoch) -> Option<usize> {
921+
if self.spec.is_zkvm_enabled_for_epoch(epoch) {
922+
self.spec.zkvm_min_proofs_required()
923+
} else {
924+
None
925+
}
926+
}
927+
906928
/// maintain the cache
907929
pub fn do_maintenance(&self, cutoff_epoch: Epoch) -> Result<(), AvailabilityCheckError> {
908930
// clean up any lingering states in the state cache

0 commit comments

Comments
 (0)