Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder flow for Deneb & Blobs #4428

Merged
merged 32 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4e9b5bb
Add Deneb builder flow types with generics
jimmygchen Jun 21, 2023
d772ada
Update validator client `get_blinded_blocks` call to support Deneb
jimmygchen Jun 22, 2023
1d4c55a
`produceBlindedBlock` endpoint updates:
jimmygchen Jun 22, 2023
fdbba30
Appease Clippy lint
jimmygchen Jun 22, 2023
59fb1af
Partial implementation of submit blinded block & blobs. Refactor exis…
jimmygchen Jun 22, 2023
361664f
Add associated types for BlockProposal
jimmygchen Jun 30, 2023
c03802c
Merge branch 'deneb-free-blobs' into deneb-builder-take-2
jimmygchen Jul 4, 2023
b0d8d90
Rename `AbstractSidecar` to `Sidecar`
jimmygchen Jul 4, 2023
8e5a088
Merge branch 'deneb-free-blobs' into deneb-builder-take-2
jimmygchen Jul 26, 2023
33ac592
Remove blob cache as it's no longer necessary
jimmygchen Jul 26, 2023
df84f17
Remove unnecessary enum variant
jimmygchen Jul 26, 2023
1cfa6d2
Clean up
jimmygchen Jul 26, 2023
80d3b2d
Hanlde unblinded blobs and publish full block contents
jimmygchen Jul 27, 2023
b040d5b
Fix tests
jimmygchen Jul 27, 2023
b344415
Add local EL blobs caching in blinded flow
jimmygchen Jul 31, 2023
2f28d84
Remove BlockProposal and move associated Sidecar trait to AbstractExe…
jimmygchen Jul 31, 2023
d219302
Merge remote-tracking branch 'origin/deneb-free-blobs' into deneb-bui…
jimmygchen Jul 31, 2023
8667954
Merge branch 'deneb-free-blobs' into deneb-builder-take-2
jimmygchen Aug 4, 2023
9fec52a
add blob roots associated type
realbigsean Aug 3, 2023
74a91c4
move raw blobs associated type to sidecar trait
realbigsean Aug 6, 2023
97ee1f4
Fix todos and improve error handling
jimmygchen Aug 8, 2023
f36bf59
Merge remote-tracking branch 'origin/deneb-free-blobs' into deneb-bui…
jimmygchen Aug 8, 2023
1882540
Merge branch 'deneb-free-blobs' into deneb-builder-take-2
jimmygchen Aug 9, 2023
803045b
Consolidate BlobsBundle from `execution_layer` into `consensus/types`
jimmygchen Aug 9, 2023
d3befb0
Rename RawBlobs, Blobs, and BlobRoots
jimmygchen Aug 9, 2023
e0aba92
Use `BlobRoots` type alias
jimmygchen Aug 9, 2023
f2ed354
Update error message.
jimmygchen Aug 9, 2023
3b9de46
update builder bid type
realbigsean Aug 8, 2023
a3be906
Merge branch 'deneb-builder-take-2' of github.com:jimmygchen/lighthou…
jimmygchen Aug 9, 2023
1ac148c
Fix lint
jimmygchen Aug 9, 2023
ee2f1a1
remove generic from builder bid
realbigsean Aug 9, 2023
9e52ca4
Merge remote-tracking branch 'origin/deneb-free-blobs' into deneb-bui…
jimmygchen Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 54 additions & 65 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::attester_cache::{AttesterCache, AttesterCacheKey};
use crate::beacon_block_streamer::{BeaconBlockStreamer, CheckEarlyAttesterCache};
use crate::beacon_proposer_cache::compute_proposer_duties_from_head;
use crate::beacon_proposer_cache::BeaconProposerCache;
use crate::blob_cache::BlobCache;
use crate::blob_verification::{self, GossipBlobError, GossipVerifiedBlob};
use crate::block_times_cache::BlockTimesCache;
use crate::block_verification::POS_PANDA_BANNER;
Expand Down Expand Up @@ -67,8 +66,10 @@ use crate::validator_monitor::{
HISTORIC_EPOCHS as VALIDATOR_MONITOR_HISTORIC_EPOCHS,
};
use crate::validator_pubkey_cache::ValidatorPubkeyCache;
use crate::{kzg_utils, AvailabilityPendingExecutedBlock};
use crate::{metrics, BeaconChainError, BeaconForkChoiceStore, BeaconSnapshot, CachedHead};
use crate::{
kzg_utils, metrics, AvailabilityPendingExecutedBlock, BeaconChainError, BeaconForkChoiceStore,
BeaconSnapshot, CachedHead,
};
use eth2::types::{EventKind, SseBlock, SseExtendedPayloadAttributes, SyncDuty};
use execution_layer::{
BlockProposalContents, BuilderParams, ChainHealth, ExecutionLayer, FailedCondition,
Expand Down Expand Up @@ -118,7 +119,7 @@ use task_executor::{ShutdownReason, TaskExecutor};
use tokio_stream::Stream;
use tree_hash::TreeHash;
use types::beacon_state::CloneConfig;
use types::blob_sidecar::{BlobSidecarList, FixedBlobSidecarList};
use types::blob_sidecar::{BlobItems, BlobSidecarList, FixedBlobSidecarList};
use types::consts::deneb::MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS;
use types::*;

Expand Down Expand Up @@ -473,12 +474,15 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub validator_monitor: RwLock<ValidatorMonitor<T::EthSpec>>,
/// The slot at which blocks are downloaded back to.
pub genesis_backfill_slot: Slot,
pub proposal_blob_cache: BlobCache<T::EthSpec>,
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
pub kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
}

type BeaconBlockAndState<T, Payload> = (BeaconBlock<T, Payload>, BeaconState<T>);
type BeaconBlockAndState<T, Payload> = (
BeaconBlock<T, Payload>,
BeaconState<T>,
Option<SidecarList<T, <Payload as AbstractExecPayload<T>>::Sidecar>>,
);

impl FinalizationAndCanonicity {
pub fn is_finalized(self) -> bool {
Expand Down Expand Up @@ -4978,67 +4982,52 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

let blobs_verification_timer =
metrics::start_timer(&metrics::BLOCK_PRODUCTION_BLOBS_VERIFICATION_TIMES);
if let (Some(blobs), Some(proofs)) = (blobs_opt, proofs_opt) {
let kzg = self
.kzg
.as_ref()
.ok_or(BlockProductionError::TrustedSetupNotInitialized)?;
let beacon_block_root = block.canonical_root();
let expected_kzg_commitments = block.body().blob_kzg_commitments().map_err(|_| {
BlockProductionError::InvalidBlockVariant(
"DENEB block does not contain kzg commitments".to_string(),
)
})?;

if expected_kzg_commitments.len() != blobs.len() {
return Err(BlockProductionError::MissingKzgCommitment(format!(
"Missing KZG commitment for slot {}. Expected {}, got: {}",
slot,
blobs.len(),
expected_kzg_commitments.len()
)));
}
let maybe_sidecar_list = match (blobs_opt, proofs_opt) {
(Some(blobs_or_blobs_roots), Some(proofs)) => {
let expected_kzg_commitments =
block.body().blob_kzg_commitments().map_err(|_| {
BlockProductionError::InvalidBlockVariant(
"deneb block does not contain kzg commitments".to_string(),
)
})?;

let kzg_proofs = Vec::from(proofs);
if expected_kzg_commitments.len() != blobs_or_blobs_roots.len() {
return Err(BlockProductionError::MissingKzgCommitment(format!(
"Missing KZG commitment for slot {}. Expected {}, got: {}",
block.slot(),
blobs_or_blobs_roots.len(),
expected_kzg_commitments.len()
)));
}

kzg_utils::validate_blobs::<T::EthSpec>(
kzg.as_ref(),
expected_kzg_commitments,
&blobs,
&kzg_proofs,
)
.map_err(BlockProductionError::KzgError)?;

let blob_sidecars = BlobSidecarList::from(
blobs
.into_iter()
.enumerate()
.map(|(blob_index, blob)| {
let kzg_commitment = expected_kzg_commitments
.get(blob_index)
.expect("KZG commitment should exist for blob");

let kzg_proof = kzg_proofs
.get(blob_index)
.expect("KZG proof should exist for blob");

Ok(Arc::new(BlobSidecar {
block_root: beacon_block_root,
index: blob_index as u64,
slot,
block_parent_root: block.parent_root(),
proposer_index,
blob,
kzg_commitment: *kzg_commitment,
kzg_proof: *kzg_proof,
}))
})
.collect::<Result<Vec<_>, BlockProductionError>>()?,
);
let kzg_proofs = Vec::from(proofs);

if let Some(blobs) = blobs_or_blobs_roots.blobs() {
let kzg = self
.kzg
.as_ref()
.ok_or(BlockProductionError::TrustedSetupNotInitialized)?;
kzg_utils::validate_blobs::<T::EthSpec>(
kzg,
expected_kzg_commitments,
blobs,
&kzg_proofs,
)
.map_err(BlockProductionError::KzgError)?;
}

self.proposal_blob_cache
.put(beacon_block_root, blob_sidecars);
}
Some(
Sidecar::build_sidecar(
blobs_or_blobs_roots,
&block,
expected_kzg_commitments,
kzg_proofs,
)
.map_err(BlockProductionError::FailedToBuildBlobSidecars)?,
)
}
_ => None,
};

drop(blobs_verification_timer);

Expand All @@ -5052,7 +5041,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
"slot" => block.slot()
);

Ok((block, state))
Ok((block, state, maybe_sidecar_list))
}

/// This method must be called whenever an execution engine indicates that a payload is
Expand Down
35 changes: 0 additions & 35 deletions beacon_node/beacon_chain/src/blob_cache.rs

This file was deleted.

2 changes: 0 additions & 2 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::beacon_chain::{CanonicalHead, BEACON_CHAIN_DB_KEY, ETH1_CACHE_DB_KEY, OP_POOL_DB_KEY};
use crate::blob_cache::BlobCache;
use crate::data_availability_checker::DataAvailabilityChecker;
use crate::eth1_chain::{CachingEth1Backend, SszEth1};
use crate::eth1_finalization_cache::Eth1FinalizationCache;
Expand Down Expand Up @@ -889,7 +888,6 @@ where
DataAvailabilityChecker::new(slot_clock, kzg.clone(), store, self.spec)
.map_err(|e| format!("Error initializing DataAvailabiltyChecker: {:?}", e))?,
),
proposal_blob_cache: BlobCache::default(),
kzg,
};

Expand Down
4 changes: 3 additions & 1 deletion beacon_node/beacon_chain/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,22 @@ pub enum BlockProductionError {
blob_block_hash: ExecutionBlockHash,
payload_block_hash: ExecutionBlockHash,
},
NoBlobsCached,
FailedToReadFinalizedBlock(store::Error),
MissingFinalizedBlock(Hash256),
BlockTooLarge(usize),
ShuttingDown,
MissingBlobs,
MissingSyncAggregate,
MissingExecutionPayload,
MissingKzgCommitment(String),
MissingKzgProof(String),
TokioJoin(tokio::task::JoinError),
BeaconChain(BeaconChainError),
InvalidPayloadFork,
TrustedSetupNotInitialized,
InvalidBlockVariant(String),
KzgError(kzg::Error),
FailedToBuildBlobSidecars(String),
}

easy_from_to!(BlockProcessingError, BlockProductionError);
Expand Down
1 change: 0 additions & 1 deletion beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod beacon_chain;
mod beacon_fork_choice_store;
pub mod beacon_proposer_cache;
mod beacon_snapshot;
pub mod blob_cache;
pub mod blob_verification;
pub mod block_reward;
mod block_times_cache;
Expand Down
Loading
Loading