mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
Ensure lookup sync checks caches correctly (#5840)
* Ensure lookup sync checks caches correctly * fix tests and remove unused method * Simplify BlockProcessStatus
This commit is contained in:
@@ -337,6 +337,20 @@ struct PartialBeaconBlock<E: EthSpec> {
|
||||
bls_to_execution_changes: Vec<SignedBlsToExecutionChange>,
|
||||
}
|
||||
|
||||
pub enum BlockProcessStatus<E: EthSpec> {
|
||||
/// Block is not in any pre-import cache. Block may be in the data-base or in the fork-choice.
|
||||
Unknown,
|
||||
/// Block is currently processing but not yet validated.
|
||||
NotValidated(Arc<SignedBeaconBlock<E>>),
|
||||
/// Block is fully valid, but not yet imported. It's cached in the da_checker while awaiting
|
||||
/// missing block components.
|
||||
ExecutionValidated(Arc<SignedBeaconBlock<E>>),
|
||||
}
|
||||
|
||||
pub struct BeaconChainMetrics {
|
||||
pub reqresp_pre_import_cache_len: usize,
|
||||
}
|
||||
|
||||
pub type LightClientProducerEvent<T> = (Hash256, Slot, SyncAggregate<T>);
|
||||
|
||||
pub type BeaconForkChoice<T> = ForkChoice<
|
||||
@@ -1237,6 +1251,27 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
Ok(self.store.get_blinded_block(block_root)?)
|
||||
}
|
||||
|
||||
/// Return the status of a block as it progresses through the various caches of the beacon
|
||||
/// chain. Used by sync to learn the status of a block and prevent repeated downloads /
|
||||
/// processing attempts.
|
||||
pub fn get_block_process_status(&self, block_root: &Hash256) -> BlockProcessStatus<T::EthSpec> {
|
||||
if let Some(block) = self
|
||||
.data_availability_checker
|
||||
.get_execution_valid_block(block_root)
|
||||
{
|
||||
return BlockProcessStatus::ExecutionValidated(block);
|
||||
}
|
||||
|
||||
if let Some(block) = self.reqresp_pre_import_cache.read().get(block_root) {
|
||||
// A block is on the `reqresp_pre_import_cache` but NOT in the
|
||||
// `data_availability_checker` only if it is actively processing. We can expect a future
|
||||
// event with the result of processing
|
||||
return BlockProcessStatus::NotValidated(block.clone());
|
||||
}
|
||||
|
||||
BlockProcessStatus::Unknown
|
||||
}
|
||||
|
||||
/// Returns the state at the given root, if any.
|
||||
///
|
||||
/// ## Errors
|
||||
@@ -6630,6 +6665,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
ForkName::Base => Err(Error::UnsupportedFork),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metrics(&self) -> BeaconChainMetrics {
|
||||
BeaconChainMetrics {
|
||||
reqresp_pre_import_cache_len: self.reqresp_pre_import_cache.read().len(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BeaconChainTypes> Drop for BeaconChain<T> {
|
||||
|
||||
Reference in New Issue
Block a user