blob production

This commit is contained in:
realbigsean
2022-10-05 17:14:45 -04:00
parent 91efb9d4c7
commit b5b4ce9509
17 changed files with 623 additions and 168 deletions

View File

@@ -255,7 +255,7 @@ struct PartialBeaconBlock<E: EthSpec, Payload> {
deposits: Vec<Deposit>,
voluntary_exits: Vec<SignedVoluntaryExit>,
sync_aggregate: Option<SyncAggregate<E>>,
prepare_payload_handle: Option<PreparePayloadHandle<Payload>>,
prepare_payload_handle: Option<PreparePayloadHandle<Payload, E>>,
}
pub type BeaconForkChoice<T> = ForkChoice<
@@ -3291,15 +3291,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
//
// Wait for the execution layer to return an execution payload (if one is required).
let prepare_payload_handle = partial_beacon_block.prepare_payload_handle.take();
let execution_payload = if let Some(prepare_payload_handle) = prepare_payload_handle {
let execution_payload = prepare_payload_handle
.await
.map_err(BlockProductionError::TokioJoin)?
.ok_or(BlockProductionError::ShuttingDown)??;
Some(execution_payload)
} else {
None
};
let (execution_payload, kzg_commitments, blobs) =
if let Some(prepare_payload_handle) = prepare_payload_handle {
let (execution_payload, commitments, blobs) = prepare_payload_handle
.await
.map_err(BlockProductionError::TokioJoin)?
.ok_or(BlockProductionError::ShuttingDown)??;
(execution_payload, commitments, blobs)
} else {
return Err(BlockProductionError::MissingExecutionPayload);
};
// Part 3/3 (blocking)
//
@@ -3311,6 +3312,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
chain.complete_partial_beacon_block(
partial_beacon_block,
execution_payload,
kzg_commitments,
verification,
)
},
@@ -3557,7 +3559,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
fn complete_partial_beacon_block<Payload: ExecPayload<T::EthSpec>>(
&self,
partial_beacon_block: PartialBeaconBlock<T::EthSpec, Payload>,
execution_payload: Option<Payload>,
execution_payload: Payload,
kzg_commitments: Vec<KzgCommitment>,
verification: ProduceBlockVerification,
) -> Result<BeaconBlockAndState<T::EthSpec, Payload>, BlockProductionError> {
let PartialBeaconBlock {
@@ -3633,8 +3636,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
voluntary_exits: voluntary_exits.into(),
sync_aggregate: sync_aggregate
.ok_or(BlockProductionError::MissingSyncAggregate)?,
execution_payload: execution_payload
.ok_or(BlockProductionError::MissingExecutionPayload)?,
execution_payload,
},
}),
BeaconState::Eip4844(_) => BeaconBlock::Eip4844(BeaconBlockEip4844 {
@@ -3653,10 +3655,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
voluntary_exits: voluntary_exits.into(),
sync_aggregate: sync_aggregate
.ok_or(BlockProductionError::MissingSyncAggregate)?,
execution_payload: execution_payload
.ok_or(BlockProductionError::MissingExecutionPayload)?,
execution_payload,
//FIXME(sean) get blobs
blob_kzg_commitments: VariableList::empty(),
blob_kzg_commitments: VariableList::from(kzg_commitments),
},
}),
};

View File

@@ -249,6 +249,11 @@ pub enum BlockProductionError {
BlockingFailed(execution_layer::Error),
TerminalPoWBlockLookupFailed(execution_layer::Error),
GetPayloadFailed(execution_layer::Error),
GetBlobsFailed(execution_layer::Error),
BlobPayloadMismatch {
blob_block_hash: ExecutionBlockHash,
payload_block_hash: ExecutionBlockHash,
},
FailedToReadFinalizedBlock(store::Error),
MissingFinalizedBlock(Hash256),
BlockTooLarge(usize),

View File

@@ -12,6 +12,7 @@ use crate::{
BeaconChain, BeaconChainError, BeaconChainTypes, BlockError, BlockProductionError,
ExecutionPayloadError,
};
use execution_layer::json_structures::JsonBlobBundlesV1;
use execution_layer::{BuilderParams, PayloadStatus};
use fork_choice::{InvalidationOperation, PayloadVerificationStatus};
use proto_array::{Block as ProtoBlock, ExecutionStatus};
@@ -25,12 +26,13 @@ use std::sync::Arc;
use tokio::task::JoinHandle;
use tree_hash::TreeHash;
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, EthSpec, ExecPayload, ExecutionBlockHash,
Hash256, SignedBeaconBlock, Slot,
BeaconBlockRef, BeaconState, BeaconStateError, Blob, BlobsSidecar, EthSpec, ExecPayload,
ExecutionBlockHash, Hash256, KzgCommitment, SignedBeaconBlock, Slot,
};
pub type PreparePayloadResult<Payload> = Result<Payload, BlockProductionError>;
pub type PreparePayloadHandle<Payload> = JoinHandle<Option<PreparePayloadResult<Payload>>>;
pub type PreparePayloadResult<Payload, E> =
Result<(Payload, Vec<KzgCommitment>, Vec<Blob<E>>), BlockProductionError>;
pub type PreparePayloadHandle<Payload, E> = JoinHandle<Option<PreparePayloadResult<Payload, E>>>;
#[derive(PartialEq)]
pub enum AllowOptimisticImport {
@@ -354,7 +356,7 @@ pub fn get_execution_payload<
state: &BeaconState<T::EthSpec>,
proposer_index: u64,
builder_params: BuilderParams,
) -> Result<PreparePayloadHandle<Payload>, BlockProductionError> {
) -> Result<PreparePayloadHandle<Payload, T::EthSpec>, BlockProductionError> {
// Compute all required values from the `state` now to avoid needing to pass it into a spawned
// task.
let spec = &chain.spec;
@@ -413,7 +415,7 @@ pub async fn prepare_execution_payload<T, Payload>(
proposer_index: u64,
latest_execution_payload_header_block_hash: ExecutionBlockHash,
builder_params: BuilderParams,
) -> Result<Payload, BlockProductionError>
) -> PreparePayloadResult<Payload, T::EthSpec>
where
T: BeaconChainTypes,
Payload: ExecPayload<T::EthSpec> + Default,
@@ -473,8 +475,8 @@ where
// Note: the suggested_fee_recipient is stored in the `execution_layer`, it will add this parameter.
//
// This future is not executed here, it's up to the caller to await it.
let execution_payload = execution_layer
.get_payload::<Payload>(
let (execution_payload_result, blobs_result) = tokio::join!(
execution_layer.get_payload::<Payload>(
parent_hash,
timestamp,
random,
@@ -482,17 +484,20 @@ where
forkchoice_update_params,
builder_params,
&chain.spec,
)
.await
.map_err(BlockProductionError::GetPayloadFailed)?;
),
execution_layer.get_blob_bundles(parent_hash, timestamp, random, proposer_index)
);
/*
TODO: fetch blob bundles from el engine for block building
let suggested_fee_recipient = execution_layer.get_suggested_fee_recipient(proposer_index).await;
let blobs = execution_layer.get_blob_bundles(parent_hash, timestamp, random, suggested_fee_recipient)
.await
.map_err(BlockProductionError::GetPayloadFailed)?;
*/
let execution_payload =
execution_payload_result.map_err(BlockProductionError::GetPayloadFailed)?;
let blobs = blobs_result.map_err(BlockProductionError::GetPayloadFailed)?;
Ok(execution_payload)
if execution_payload.block_hash() != blobs.block_hash {
return Err(BlockProductionError::BlobPayloadMismatch {
blob_block_hash: blobs.block_hash,
payload_block_hash: execution_payload.block_hash(),
});
}
Ok((execution_payload, blobs.kzgs, blobs.blobs))
}