mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
Rework block processing (#4092)
* introduce availability pending block * add intoavailableblock trait * small fixes * add 'gossip blob cache' and start to clean up processing and transition types * shard memory blob cache * Initial commit * Fix after rebase * Add gossip verification conditions * cache cleanup * general chaos * extended chaos * cargo fmt * more progress * more progress * tons of changes, just tryna compile * everything, everywhere, all at once * Reprocess an ExecutedBlock on unavailable blobs * Add sus gossip verification for blobs * Merge stuff * Remove reprocessing cache stuff * lint * Add a wrapper to allow construction of only valid `AvailableBlock`s * rename blob arc list to blob list * merge cleanuo * Revert "merge cleanuo" This reverts commit5e98326878. * Revert "Revert "merge cleanuo"" This reverts commit3a4009443a. * fix rpc methods * move beacon block and blob to eth2/types * rename gossip blob cache to data availability checker * lots of changes * fix some compilation issues * fix compilation issues * fix compilation issues * fix compilation issues * fix compilation issues * fix compilation issues * cargo fmt * use a common data structure for block import types * fix availability check on proposal import * refactor the blob cache and split the block wrapper into two types * add type conversion for signed block and block wrapper * fix beacon chain tests and do some renaming, add some comments * Partial processing (#4) * move beacon block and blob to eth2/types * rename gossip blob cache to data availability checker * lots of changes * fix some compilation issues * fix compilation issues * fix compilation issues * fix compilation issues * fix compilation issues * fix compilation issues * cargo fmt * use a common data structure for block import types * fix availability check on proposal import * refactor the blob cache and split the block wrapper into two types * add type conversion for signed block and block wrapper * fix beacon chain tests and do some renaming, add some comments * cargo update (#6) --------- Co-authored-by: realbigsean <sean@sigmaprime.io> Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -218,10 +218,7 @@ impl BlockId {
|
||||
chain: &BeaconChain<T>,
|
||||
) -> Result<BlobSidecarList<T::EthSpec>, warp::Rejection> {
|
||||
let root = self.root(chain)?.0;
|
||||
let Some(data_availability_boundary) = chain.data_availability_boundary() else {
|
||||
return Err(warp_utils::reject::custom_not_found("Deneb fork disabled".into()));
|
||||
};
|
||||
match chain.get_blobs(&root, data_availability_boundary) {
|
||||
match chain.get_blobs(&root) {
|
||||
Ok(Some(blob_sidecar_list)) => Ok(blob_sidecar_list),
|
||||
Ok(None) => Err(warp_utils::reject::custom_not_found(format!(
|
||||
"No blobs with block root {} found in the store",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockProductionError};
|
||||
use eth2::types::BlockContents;
|
||||
use eth2::types::{BeaconBlockAndBlobSidecars, BlockContents};
|
||||
use std::sync::Arc;
|
||||
use types::{AbstractExecPayload, BeaconBlock, BeaconBlockAndBlobSidecars, ForkName};
|
||||
use types::{AbstractExecPayload, BeaconBlock, ForkName};
|
||||
|
||||
type Error = warp::reject::Rejection;
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn build_block_contents<T: BeaconChainTypes, Payload: AbstractExecPayload<T:
|
||||
}
|
||||
ForkName::Eip4844 => {
|
||||
let block_root = &block.canonical_root();
|
||||
if let Some(blob_sidecars) = chain.blob_cache.pop(block_root) {
|
||||
if let Some(blob_sidecars) = chain.proposal_blob_cache.pop(block_root) {
|
||||
let block_and_blobs = BeaconBlockAndBlobSidecars {
|
||||
block,
|
||||
blob_sidecars,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use crate::metrics;
|
||||
use beacon_chain::blob_verification::{AsBlock, BlockWrapper, IntoAvailableBlock};
|
||||
|
||||
use beacon_chain::blob_verification::{AsBlock, BlockWrapper};
|
||||
use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now};
|
||||
use beacon_chain::{
|
||||
BeaconChain, BeaconChainTypes, BlockError, CountUnrealized, NotifyExecutionLayer,
|
||||
};
|
||||
use eth2::types::SignedBlockContents;
|
||||
use beacon_chain::{AvailabilityProcessingStatus, NotifyExecutionLayer};
|
||||
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError, CountUnrealized};
|
||||
use eth2::types::{SignedBlockContents, VariableList};
|
||||
use execution_layer::ProvenancedPayload;
|
||||
use lighthouse_network::PubsubMessage;
|
||||
use network::NetworkMessage;
|
||||
@@ -70,54 +70,51 @@ pub async fn publish_block<T: BeaconChainTypes>(
|
||||
}
|
||||
SignedBeaconBlock::Eip4844(_) => {
|
||||
crate::publish_pubsub_message(network_tx, PubsubMessage::BeaconBlock(block.clone()))?;
|
||||
if let Some(blobs) = maybe_blobs {
|
||||
for (blob_index, blob) in blobs.into_iter().enumerate() {
|
||||
if let Some(signed_blobs) = maybe_blobs {
|
||||
for (blob_index, blob) in signed_blobs.clone().into_iter().enumerate() {
|
||||
crate::publish_pubsub_message(
|
||||
network_tx,
|
||||
PubsubMessage::BlobSidecar(Box::new((blob_index as u64, blob))),
|
||||
)?;
|
||||
}
|
||||
let blobs_vec = signed_blobs.into_iter().map(|blob| blob.message).collect();
|
||||
let blobs = VariableList::new(blobs_vec).map_err(|e| {
|
||||
warp_utils::reject::custom_server_error(format!("Invalid blobs length: {e:?}"))
|
||||
})?;
|
||||
BlockWrapper::BlockAndBlobs(block, blobs)
|
||||
} else {
|
||||
block.into()
|
||||
}
|
||||
block.into()
|
||||
}
|
||||
};
|
||||
|
||||
let available_block = match wrapped_block.into_available_block(block_root, &chain) {
|
||||
Ok(available_block) => available_block,
|
||||
Err(e) => {
|
||||
let msg = format!("{:?}", e);
|
||||
error!(
|
||||
log,
|
||||
"Invalid block provided to HTTP API";
|
||||
"reason" => &msg
|
||||
);
|
||||
return Err(warp_utils::reject::broadcast_without_import(msg));
|
||||
}
|
||||
};
|
||||
// Determine the delay after the start of the slot, register it with metrics.
|
||||
|
||||
let block_clone = wrapped_block.block_cloned();
|
||||
let slot = block_clone.message().slot();
|
||||
let proposer_index = block_clone.message().proposer_index();
|
||||
match chain
|
||||
.process_block(
|
||||
block_root,
|
||||
available_block.clone(),
|
||||
wrapped_block,
|
||||
CountUnrealized::True,
|
||||
NotifyExecutionLayer::Yes,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(root) => {
|
||||
Ok(AvailabilityProcessingStatus::Imported(root)) => {
|
||||
info!(
|
||||
log,
|
||||
"Valid block from HTTP API";
|
||||
"block_delay" => ?delay,
|
||||
"root" => format!("{}", root),
|
||||
"proposer_index" => available_block.message().proposer_index(),
|
||||
"slot" => available_block.slot(),
|
||||
"proposer_index" => proposer_index,
|
||||
"slot" =>slot,
|
||||
);
|
||||
|
||||
// Notify the validator monitor.
|
||||
chain.validator_monitor.read().register_api_block(
|
||||
seen_timestamp,
|
||||
available_block.message(),
|
||||
block_clone.message(),
|
||||
root,
|
||||
&chain.slot_clock,
|
||||
);
|
||||
@@ -133,7 +130,7 @@ pub async fn publish_block<T: BeaconChainTypes>(
|
||||
late_block_logging(
|
||||
&chain,
|
||||
seen_timestamp,
|
||||
available_block.message(),
|
||||
block_clone.message(),
|
||||
root,
|
||||
"local",
|
||||
&log,
|
||||
@@ -142,12 +139,30 @@ pub async fn publish_block<T: BeaconChainTypes>(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Ok(AvailabilityProcessingStatus::PendingBlock(block_root)) => {
|
||||
let msg = format!("Missing block with root {:?}", block_root);
|
||||
error!(
|
||||
log,
|
||||
"Invalid block provided to HTTP API";
|
||||
"reason" => &msg
|
||||
);
|
||||
Err(warp_utils::reject::broadcast_without_import(msg))
|
||||
}
|
||||
Ok(AvailabilityProcessingStatus::PendingBlobs(blob_ids)) => {
|
||||
let msg = format!("Missing blobs {:?}", blob_ids);
|
||||
error!(
|
||||
log,
|
||||
"Invalid block provided to HTTP API";
|
||||
"reason" => &msg
|
||||
);
|
||||
Err(warp_utils::reject::broadcast_without_import(msg))
|
||||
}
|
||||
Err(BlockError::BlockIsAlreadyKnown) => {
|
||||
info!(
|
||||
log,
|
||||
"Block from HTTP API already known";
|
||||
"block" => ?block_root,
|
||||
"slot" => available_block.slot(),
|
||||
"slot" => slot,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user