mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Implement get validator block endpoint for EIP-4844
This commit is contained in:
@@ -4759,30 +4759,41 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.kzg
|
||||
.as_ref()
|
||||
.ok_or(BlockProductionError::TrustedSetupNotInitialized)?;
|
||||
let kzg_aggregated_proof =
|
||||
kzg_utils::compute_aggregate_kzg_proof::<T::EthSpec>(kzg, &blobs)
|
||||
.map_err(BlockProductionError::KzgError)?;
|
||||
let beacon_block_root = block.canonical_root();
|
||||
let expected_kzg_commitments = block.body().blob_kzg_commitments().map_err(|_| {
|
||||
BlockProductionError::InvalidBlockVariant(
|
||||
"EIP4844 block does not contain kzg commitments".to_string(),
|
||||
)
|
||||
})?;
|
||||
let blobs_sidecar = BlobsSidecar {
|
||||
beacon_block_slot: slot,
|
||||
beacon_block_root,
|
||||
blobs,
|
||||
kzg_aggregated_proof,
|
||||
};
|
||||
kzg_utils::validate_blobs_sidecar(
|
||||
kzg,
|
||||
slot,
|
||||
beacon_block_root,
|
||||
expected_kzg_commitments,
|
||||
&blobs_sidecar,
|
||||
)
|
||||
.map_err(BlockProductionError::KzgError)?;
|
||||
self.blob_cache.put(beacon_block_root, blobs_sidecar);
|
||||
|
||||
let blob_sidecars = VariableList::from(
|
||||
blobs
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(blob_index, blob)| {
|
||||
BlobSidecar {
|
||||
block_root: beacon_block_root,
|
||||
index: blob_index as u64,
|
||||
slot,
|
||||
block_parent_root: block.parent_root(),
|
||||
proposer_index,
|
||||
blob,
|
||||
kzg_commitment: expected_kzg_commitments[blob_index].clone(),
|
||||
kzg_proof: Default::default(), // TODO: compute KZG proof
|
||||
}
|
||||
})
|
||||
.collect::<Vec<BlobSidecar<T::EthSpec>>>(),
|
||||
);
|
||||
|
||||
// TODO: validate blobs
|
||||
// kzg_utils::validate_blobs_sidecar(
|
||||
// kzg,
|
||||
// slot,
|
||||
// beacon_block_root,
|
||||
// expected_kzg_commitments,
|
||||
// &blobs_sidecar,
|
||||
// ).map_err(BlockProductionError::KzgError)?;
|
||||
self.blob_cache.put(beacon_block_root, blob_sidecars);
|
||||
}
|
||||
|
||||
metrics::inc_counter(&metrics::BLOCK_PRODUCTION_SUCCESSES);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use lru::LruCache;
|
||||
use parking_lot::Mutex;
|
||||
use types::{BlobsSidecar, EthSpec, Hash256};
|
||||
use types::{BlobSidecars, EthSpec, Hash256};
|
||||
|
||||
pub const DEFAULT_BLOB_CACHE_SIZE: usize = 10;
|
||||
|
||||
/// A cache blobs by beacon block root.
|
||||
pub struct BlobCache<T: EthSpec> {
|
||||
blobs: Mutex<LruCache<BlobCacheId, BlobsSidecar<T>>>,
|
||||
blobs: Mutex<LruCache<BlobCacheId, BlobSidecars<T>>>,
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq, Eq)]
|
||||
@@ -21,11 +21,11 @@ impl<T: EthSpec> Default for BlobCache<T> {
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BlobCache<T> {
|
||||
pub fn put(&self, beacon_block: Hash256, blobs: BlobsSidecar<T>) -> Option<BlobsSidecar<T>> {
|
||||
pub fn put(&self, beacon_block: Hash256, blobs: BlobSidecars<T>) -> Option<BlobSidecars<T>> {
|
||||
self.blobs.lock().put(BlobCacheId(beacon_block), blobs)
|
||||
}
|
||||
|
||||
pub fn pop(&self, root: &Hash256) -> Option<BlobsSidecar<T>> {
|
||||
pub fn pop(&self, root: &Hash256) -> Option<BlobSidecars<T>> {
|
||||
self.blobs.lock().pop(&BlobCacheId(*root))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,6 +266,7 @@ pub enum BlockProductionError {
|
||||
blob_block_hash: ExecutionBlockHash,
|
||||
payload_block_hash: ExecutionBlockHash,
|
||||
},
|
||||
NoBlobsCached,
|
||||
FailedToReadFinalizedBlock(store::Error),
|
||||
MissingFinalizedBlock(Hash256),
|
||||
BlockTooLarge(usize),
|
||||
|
||||
Reference in New Issue
Block a user