2023-02-15 05:44:13 +00:00
|
|
|
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockProductionError};
|
2023-03-24 21:30:41 +00:00
|
|
|
use eth2::types::{BeaconBlockAndBlobSidecars, BlockContents};
|
2023-02-15 05:44:13 +00:00
|
|
|
use std::sync::Arc;
|
2023-03-24 21:30:41 +00:00
|
|
|
use types::{AbstractExecPayload, BeaconBlock, ForkName};
|
2023-02-15 05:44:13 +00:00
|
|
|
|
|
|
|
type Error = warp::reject::Rejection;
|
|
|
|
|
|
|
|
pub fn build_block_contents<T: BeaconChainTypes, Payload: AbstractExecPayload<T::EthSpec>>(
|
|
|
|
fork_name: ForkName,
|
|
|
|
chain: Arc<BeaconChain<T>>,
|
|
|
|
block: BeaconBlock<T::EthSpec, Payload>,
|
|
|
|
) -> Result<BlockContents<T::EthSpec, Payload>, Error> {
|
|
|
|
match fork_name {
|
|
|
|
ForkName::Base | ForkName::Altair | ForkName::Merge | ForkName::Capella => {
|
|
|
|
Ok(BlockContents::Block(block))
|
|
|
|
}
|
2023-03-26 15:49:16 +00:00
|
|
|
ForkName::Deneb => {
|
2023-02-15 05:44:13 +00:00
|
|
|
let block_root = &block.canonical_root();
|
2023-03-24 21:30:41 +00:00
|
|
|
if let Some(blob_sidecars) = chain.proposal_blob_cache.pop(block_root) {
|
2023-02-15 05:44:13 +00:00
|
|
|
let block_and_blobs = BeaconBlockAndBlobSidecars {
|
|
|
|
block,
|
|
|
|
blob_sidecars,
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(BlockContents::BlockAndBlobSidecars(block_and_blobs))
|
|
|
|
} else {
|
2023-03-15 19:32:22 +00:00
|
|
|
Err(warp_utils::reject::block_production_error(
|
2023-02-15 05:44:13 +00:00
|
|
|
BlockProductionError::NoBlobsCached,
|
2023-03-15 19:32:22 +00:00
|
|
|
))
|
2023-02-15 05:44:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|