This commit is contained in:
Mac L
2024-05-02 16:06:28 +10:00
parent 689cdaef61
commit d9a0c3d6c2
10 changed files with 139 additions and 157 deletions

View File

@@ -1,6 +1,6 @@
use beacon_chain::{BeaconBlockResponse, BeaconBlockResponseWrapper, BlockProductionError};
use eth2::types::{BlockContents, FullBlockContents, ProduceBlockV3Response};
use types::{EthSpec, ForkName};
use types::{EthSpec, FeatureName, ForkName};
type Error = warp::reject::Rejection;
pub fn build_block_contents<E: EthSpec>(
@@ -11,11 +11,8 @@ pub fn build_block_contents<E: EthSpec>(
BeaconBlockResponseWrapper::Blinded(block) => {
Ok(ProduceBlockV3Response::Blinded(block.block))
}
BeaconBlockResponseWrapper::Full(block) => match fork_name {
ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => Ok(
ProduceBlockV3Response::Full(FullBlockContents::Block(block.block)),
),
ForkName::Deneb | ForkName::Electra => {
BeaconBlockResponseWrapper::Full(block) => {
if fork_name.has_feature(FeatureName::Deneb) {
let BeaconBlockResponse {
block,
state: _,
@@ -37,7 +34,11 @@ pub fn build_block_contents<E: EthSpec>(
blobs,
}),
))
} else {
Ok(ProduceBlockV3Response::Full(FullBlockContents::Block(
block.block,
)))
}
},
}
}
}

View File

@@ -20,7 +20,7 @@ use tokio::sync::mpsc::UnboundedSender;
use tree_hash::TreeHash;
use types::{
AbstractExecPayload, BeaconBlockRef, BlobSidecarList, EthSpec, ExecPayload, ExecutionBlockHash,
ForkName, FullPayload, FullPayloadBellatrix, Hash256, SignedBeaconBlock,
FeatureName, ForkName, FullPayload, FullPayloadBellatrix, Hash256, SignedBeaconBlock,
SignedBlindedBeaconBlock, VariableList,
};
use warp::http::StatusCode;
@@ -77,28 +77,22 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
info!(log, "Signed block published to network via HTTP API"; "slot" => block.slot(), "publish_delay" => ?publish_delay);
match block.as_ref() {
SignedBeaconBlock::Base(_)
| SignedBeaconBlock::Altair(_)
| SignedBeaconBlock::Bellatrix(_)
| SignedBeaconBlock::Capella(_) => {
crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block))
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
}
SignedBeaconBlock::Deneb(_) | SignedBeaconBlock::Electra(_) => {
let mut pubsub_messages = vec![PubsubMessage::BeaconBlock(block)];
if let Some(blob_sidecars) = blobs_opt {
for (blob_index, blob) in blob_sidecars.into_iter().enumerate() {
pubsub_messages.push(PubsubMessage::BlobSidecar(Box::new((
blob_index as u64,
blob,
))));
}
if block.has_feature(FeatureName::Deneb) {
let mut pubsub_messages = vec![PubsubMessage::BeaconBlock(block)];
if let Some(blob_sidecars) = blobs_opt {
for (blob_index, blob) in blob_sidecars.into_iter().enumerate() {
pubsub_messages.push(PubsubMessage::BlobSidecar(Box::new((
blob_index as u64,
blob,
))));
}
crate::publish_pubsub_messages(&sender, pubsub_messages)
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
}
};
crate::publish_pubsub_messages(&sender, pubsub_messages)
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
} else {
crate::publish_pubsub_message(&sender, PubsubMessage::BeaconBlock(block))
.map_err(|_| BlockError::BeaconChainError(BeaconChainError::UnableToPublish))?;
}
Ok(())
};