mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Merge pull request #4083 from jimmygchen/post-block-and-blobs
Implement POST beacon block for EIP-4844
This commit is contained in:
@@ -59,7 +59,7 @@ use types::{
|
||||
ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof,
|
||||
SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlsToExecutionChange,
|
||||
SignedContributionAndProof, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot,
|
||||
SyncCommitteeMessage, SyncContributionData,
|
||||
SyncCommitteeMessage, SyncContributionData, SignedBlockContents,
|
||||
};
|
||||
use version::{
|
||||
add_consensus_version_header, execution_optimistic_fork_versioned_response,
|
||||
@@ -1120,11 +1120,11 @@ pub fn serve<T: BeaconChainTypes>(
|
||||
.and(network_tx_filter.clone())
|
||||
.and(log_filter.clone())
|
||||
.and_then(
|
||||
|block: Arc<SignedBeaconBlock<T::EthSpec>>,
|
||||
|block_contents: SignedBlockContents<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
log: Logger| async move {
|
||||
publish_blocks::publish_block(None, block, chain, &network_tx, log)
|
||||
publish_blocks::publish_block(None, block_contents, chain, &network_tx, log)
|
||||
.await
|
||||
.map(|()| warp::reply().into_response())
|
||||
},
|
||||
|
||||
@@ -12,19 +12,21 @@ use tokio::sync::mpsc::UnboundedSender;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
AbstractExecPayload, BlindedPayload, EthSpec, ExecPayload, ExecutionBlockHash, FullPayload,
|
||||
Hash256, SignedBeaconBlock,
|
||||
Hash256, SignedBeaconBlock, SignedBlockContents,
|
||||
};
|
||||
use warp::Rejection;
|
||||
|
||||
/// Handles a request from the HTTP API for full blocks.
|
||||
pub async fn publish_block<T: BeaconChainTypes>(
|
||||
block_root: Option<Hash256>,
|
||||
block: Arc<SignedBeaconBlock<T::EthSpec>>,
|
||||
block_contents: SignedBlockContents<T::EthSpec>,
|
||||
chain: Arc<BeaconChain<T>>,
|
||||
network_tx: &UnboundedSender<NetworkMessage<T::EthSpec>>,
|
||||
log: Logger,
|
||||
) -> Result<(), Rejection> {
|
||||
let seen_timestamp = timestamp_now();
|
||||
let (block, maybe_blobs) = block_contents.deconstruct();
|
||||
let block = Arc::new(block);
|
||||
|
||||
//FIXME(sean) have to move this to prior to publishing because it's included in the blobs sidecar message.
|
||||
//this may skew metrics
|
||||
@@ -37,25 +39,27 @@ pub async fn publish_block<T: BeaconChainTypes>(
|
||||
|
||||
// Send the block, regardless of whether or not it is valid. The API
|
||||
// specification is very clear that this is the desired behaviour.
|
||||
let wrapped_block: BlockWrapper<T::EthSpec> =
|
||||
if matches!(block.as_ref(), &SignedBeaconBlock::Eip4844(_)) {
|
||||
if let Some(sidecar) = chain.blob_cache.pop(&block_root) {
|
||||
// TODO: Needs to be adjusted
|
||||
// let block_and_blobs = SignedBeaconBlockAndBlobsSidecar {
|
||||
// beacon_block: block,
|
||||
// blobs_sidecar: Arc::new(sidecar),
|
||||
// };
|
||||
unimplemented!("Needs to be adjusted")
|
||||
} else {
|
||||
//FIXME(sean): This should probably return a specific no-blob-cached error code, beacon API coordination required
|
||||
return Err(warp_utils::reject::broadcast_without_import(
|
||||
"no blob cached for block".into(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
let wrapped_block: BlockWrapper<T::EthSpec> = match block.as_ref() {
|
||||
SignedBeaconBlock::Base(_)
|
||||
| SignedBeaconBlock::Altair(_)
|
||||
| SignedBeaconBlock::Merge(_)
|
||||
| SignedBeaconBlock::Capella(_) => {
|
||||
crate::publish_pubsub_message(network_tx, PubsubMessage::BeaconBlock(block.clone()))?;
|
||||
block.into()
|
||||
};
|
||||
}
|
||||
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() {
|
||||
crate::publish_pubsub_message(
|
||||
network_tx,
|
||||
PubsubMessage::BlobSidecar(Box::new((blob_index as u64, blob))),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
block.into()
|
||||
}
|
||||
};
|
||||
|
||||
// Determine the delay after the start of the slot, register it with metrics.
|
||||
let block = wrapped_block.as_block();
|
||||
@@ -180,7 +184,7 @@ pub async fn publish_blinded_block<T: BeaconChainTypes>(
|
||||
let full_block = reconstruct_block(chain.clone(), block_root, block, log.clone()).await?;
|
||||
publish_block::<T>(
|
||||
Some(block_root),
|
||||
Arc::new(full_block),
|
||||
SignedBlockContents::Block(full_block),
|
||||
chain,
|
||||
network_tx,
|
||||
log,
|
||||
|
||||
Reference in New Issue
Block a user