mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 23:04:53 +00:00
More deneb cleanup (#4640)
* remove protoc and token from network tests github action
* delete unused beacon chain methods
* downgrade writing blobs to store log
* reduce diff in block import logic
* remove some todo's and deneb built in network
* remove unnecessary error, actually use some added metrics
* remove some metrics, fix missing components on publish funcitonality
* fix status tests
* rename sidecar by root to blobs by root
* clean up some metrics
* remove unnecessary feature gate from attestation subnet tests, clean up blobs by range response code
* pawan's suggestion in `protocol_info`, peer score in matching up batch sync block and blobs
* fix range tests for deneb
* pub block and blob db cache behind the same mutex
* remove unused errs and an empty file
* move sidecar trait to new file
* move types from payload to eth2 crate
* update comment and add flag value name
* make function private again, remove allow unused
* use reth rlp for tx decoding
* fix compile after merge
* rename kzg commitments
* cargo fmt
* remove unused dep
* Update beacon_node/execution_layer/src/lib.rs
Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com>
* Update beacon_node/beacon_processor/src/lib.rs
Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com>
* pawan's suggestiong for vec capacity
* cargo fmt
* Revert "use reth rlp for tx decoding"
This reverts commit 5181837d81.
* remove reth rlp
---------
Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com>
This commit is contained in:
@@ -9,19 +9,21 @@ use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
pub type KzgCommitments<T> = VariableList<KzgCommitment, <T as EthSpec>::MaxBlobsPerBlock>;
|
||||
//TODO: Remove this type and use `BlockBodyKzgCommitments` everywhere when this PR is merged:
|
||||
// https://github.com/ethereum/builder-specs/pull/87
|
||||
pub type BuilderKzgCommitments<T> = VariableList<KzgCommitment, <T as EthSpec>::MaxBlobsPerBlock>;
|
||||
pub type BlockBodyKzgCommitments<T> =
|
||||
VariableList<KzgCommitment, <T as EthSpec>::MaxBlobCommitmentsPerBlock>;
|
||||
|
||||
pub fn to_block_kzg_commitments<E: EthSpec>(
|
||||
commitments: KzgCommitments<E>,
|
||||
commitments: BuilderKzgCommitments<E>,
|
||||
) -> BlockBodyKzgCommitments<E> {
|
||||
commitments.to_vec().into()
|
||||
}
|
||||
|
||||
pub fn from_block_kzg_commitments<E: EthSpec>(
|
||||
commitments: &BlockBodyKzgCommitments<E>,
|
||||
) -> KzgCommitments<E> {
|
||||
) -> BuilderKzgCommitments<E> {
|
||||
commitments.to_vec().into()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,112 +1,21 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::{Blob, ChainSpec, Domain, EthSpec, Fork, Hash256, SignedBlobSidecar, SignedRoot, Slot};
|
||||
use bls::SecretKey;
|
||||
use derivative::Derivative;
|
||||
use kzg::{Kzg, KzgCommitment, KzgPreset, KzgProof};
|
||||
use rand::Rng;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::Encode;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::{FixedVector, VariableList};
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
use derivative::Derivative;
|
||||
use kzg::{Kzg, KzgCommitment, KzgPreset, KzgProof};
|
||||
use rand::Rng;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::{FixedVector, VariableList};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
use bls::SecretKey;
|
||||
use test_random_derive::TestRandom;
|
||||
|
||||
use crate::beacon_block_body::KzgCommitments;
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::{
|
||||
AbstractExecPayload, BeaconBlock, Blob, ChainSpec, Domain, EthSpec, Fork, Hash256,
|
||||
SignedBlobSidecar, SignedRoot, Slot,
|
||||
};
|
||||
|
||||
pub trait Sidecar<E: EthSpec>:
|
||||
serde::Serialize
|
||||
+ Clone
|
||||
+ DeserializeOwned
|
||||
+ Encode
|
||||
+ Decode
|
||||
+ Hash
|
||||
+ TreeHash
|
||||
+ TestRandom
|
||||
+ Debug
|
||||
+ SignedRoot
|
||||
+ Sync
|
||||
+ Send
|
||||
+ for<'a> arbitrary::Arbitrary<'a>
|
||||
{
|
||||
type BlobItems: BlobItems<E>;
|
||||
fn slot(&self) -> Slot;
|
||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||
blob_items: Self::BlobItems,
|
||||
block: &BeaconBlock<E, Payload>,
|
||||
expected_kzg_commitments: &KzgCommitments<E>,
|
||||
kzg_proofs: Vec<KzgProof>,
|
||||
) -> Result<SidecarList<E, Self>, String>;
|
||||
}
|
||||
|
||||
pub trait BlobItems<T: EthSpec>: Sync + Send + Sized {
|
||||
fn try_from_blob_roots(roots: BlobRootsList<T>) -> Result<Self, String>;
|
||||
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String>;
|
||||
fn len(&self) -> usize;
|
||||
fn is_empty(&self) -> bool;
|
||||
fn blobs(&self) -> Option<&BlobsList<T>>;
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BlobItems<T> for BlobsList<T> {
|
||||
fn try_from_blob_roots(_roots: BlobRootsList<T>) -> Result<Self, String> {
|
||||
Err("Unexpected conversion from blob roots to blobs".to_string())
|
||||
}
|
||||
|
||||
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String> {
|
||||
Ok(blobs)
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
VariableList::len(self)
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
VariableList::is_empty(self)
|
||||
}
|
||||
|
||||
fn blobs(&self) -> Option<&BlobsList<T>> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BlobItems<T> for BlobRootsList<T> {
|
||||
fn try_from_blob_roots(roots: BlobRootsList<T>) -> Result<Self, String> {
|
||||
Ok(roots)
|
||||
}
|
||||
|
||||
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String> {
|
||||
VariableList::new(
|
||||
blobs
|
||||
.into_iter()
|
||||
.map(|blob| blob.tree_hash_root())
|
||||
.collect(),
|
||||
)
|
||||
.map_err(|e| format!("{e:?}"))
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
VariableList::len(self)
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
VariableList::is_empty(self)
|
||||
}
|
||||
|
||||
fn blobs(&self) -> Option<&BlobsList<T>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Container of the data that identifies an individual blob.
|
||||
#[derive(
|
||||
Serialize, Deserialize, Encode, Decode, TreeHash, Copy, Clone, Debug, PartialEq, Eq, Hash,
|
||||
@@ -158,52 +67,6 @@ pub struct BlobSidecar<T: EthSpec> {
|
||||
pub kzg_proof: KzgProof,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Sidecar<E> for BlobSidecar<E> {
|
||||
type BlobItems = BlobsList<E>;
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.slot
|
||||
}
|
||||
|
||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||
blobs: BlobsList<E>,
|
||||
block: &BeaconBlock<E, Payload>,
|
||||
expected_kzg_commitments: &KzgCommitments<E>,
|
||||
kzg_proofs: Vec<KzgProof>,
|
||||
) -> Result<SidecarList<E, Self>, String> {
|
||||
let beacon_block_root = block.canonical_root();
|
||||
let slot = block.slot();
|
||||
let blob_sidecars = BlobSidecarList::from(
|
||||
blobs
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(blob_index, blob)| {
|
||||
let kzg_commitment = expected_kzg_commitments
|
||||
.get(blob_index)
|
||||
.ok_or("KZG commitment should exist for blob")?;
|
||||
|
||||
let kzg_proof = kzg_proofs
|
||||
.get(blob_index)
|
||||
.ok_or("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: block.proposer_index(),
|
||||
blob,
|
||||
kzg_commitment: *kzg_commitment,
|
||||
kzg_proof: *kzg_proof,
|
||||
}))
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?,
|
||||
);
|
||||
|
||||
Ok(blob_sidecars)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<Arc<BlobSidecar<E>>> for BlindedBlobSidecar {
|
||||
fn from(blob_sidecar: Arc<BlobSidecar<E>>) -> Self {
|
||||
BlindedBlobSidecar {
|
||||
@@ -353,54 +216,6 @@ pub struct BlindedBlobSidecar {
|
||||
|
||||
impl SignedRoot for BlindedBlobSidecar {}
|
||||
|
||||
impl<E: EthSpec> Sidecar<E> for BlindedBlobSidecar {
|
||||
type BlobItems = BlobRootsList<E>;
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.slot
|
||||
}
|
||||
|
||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||
blob_roots: BlobRootsList<E>,
|
||||
block: &BeaconBlock<E, Payload>,
|
||||
expected_kzg_commitments: &KzgCommitments<E>,
|
||||
kzg_proofs: Vec<KzgProof>,
|
||||
) -> Result<SidecarList<E, BlindedBlobSidecar>, String> {
|
||||
let beacon_block_root = block.canonical_root();
|
||||
let slot = block.slot();
|
||||
|
||||
let blob_sidecars = BlindedBlobSidecarList::<E>::from(
|
||||
blob_roots
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(blob_index, blob_root)| {
|
||||
let kzg_commitment = expected_kzg_commitments
|
||||
.get(blob_index)
|
||||
.ok_or("KZG commitment should exist for blob")?;
|
||||
|
||||
let kzg_proof = kzg_proofs.get(blob_index).ok_or(format!(
|
||||
"Missing KZG proof for slot {} blob index: {}",
|
||||
slot, blob_index
|
||||
))?;
|
||||
|
||||
Ok(Arc::new(BlindedBlobSidecar {
|
||||
block_root: beacon_block_root,
|
||||
index: blob_index as u64,
|
||||
slot,
|
||||
block_parent_root: block.parent_root(),
|
||||
proposer_index: block.proposer_index(),
|
||||
blob_root,
|
||||
kzg_commitment: *kzg_commitment,
|
||||
kzg_proof: *kzg_proof,
|
||||
}))
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?,
|
||||
);
|
||||
|
||||
Ok(blob_sidecars)
|
||||
}
|
||||
}
|
||||
|
||||
pub type SidecarList<T, Sidecar> = VariableList<Arc<Sidecar>, <T as EthSpec>::MaxBlobsPerBlock>;
|
||||
pub type BlobSidecarList<T> = SidecarList<T, BlobSidecar<T>>;
|
||||
pub type BlindedBlobSidecarList<T> = SidecarList<T, BlindedBlobSidecar>;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::beacon_block_body::KzgCommitments;
|
||||
use crate::beacon_block_body::BuilderKzgCommitments;
|
||||
use crate::{
|
||||
BlobRootsList, BlobsBundle, ChainSpec, EthSpec, ExecutionPayloadHeaderCapella,
|
||||
ExecutionPayloadHeaderDeneb, ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRef, ForkName,
|
||||
ForkVersionDeserialize, KzgProofs, SignedRoot, Uint256,
|
||||
BlobRootsList, ChainSpec, EthSpec, ExecutionPayloadHeaderCapella, ExecutionPayloadHeaderDeneb,
|
||||
ExecutionPayloadHeaderMerge, ExecutionPayloadHeaderRef, ForkName, ForkVersionDeserialize,
|
||||
KzgProofs, SignedRoot, Uint256,
|
||||
};
|
||||
use bls::PublicKeyBytes;
|
||||
use bls::Signature;
|
||||
@@ -10,32 +10,16 @@ use serde::Deserializer;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::Encode;
|
||||
use superstruct::superstruct;
|
||||
use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
#[derive(PartialEq, Debug, Default, Serialize, Deserialize, TreeHash, Clone, Encode)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct BlindedBlobsBundle<E: EthSpec> {
|
||||
pub commitments: KzgCommitments<E>,
|
||||
pub commitments: BuilderKzgCommitments<E>,
|
||||
pub proofs: KzgProofs<E>,
|
||||
pub blob_roots: BlobRootsList<E>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> From<BlobsBundle<E>> for BlindedBlobsBundle<E> {
|
||||
fn from(blobs_bundle: BlobsBundle<E>) -> Self {
|
||||
BlindedBlobsBundle {
|
||||
commitments: blobs_bundle.commitments,
|
||||
proofs: blobs_bundle.proofs,
|
||||
blob_roots: blobs_bundle
|
||||
.blobs
|
||||
.into_iter()
|
||||
.map(|blob| blob.tree_hash_root())
|
||||
.collect::<Vec<_>>()
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[superstruct(
|
||||
variants(Merge, Capella, Deneb),
|
||||
variant_attributes(
|
||||
|
||||
@@ -36,4 +36,5 @@ pub mod deneb {
|
||||
}
|
||||
pub const VERSIONED_HASH_VERSION_KZG: u8 = 1;
|
||||
pub const BLOB_SIDECAR_SUBNET_COUNT: u64 = 6;
|
||||
pub const MAX_BLOBS_PER_BLOCK: u64 = BLOB_SIDECAR_SUBNET_COUNT;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ use metastruct::metastruct;
|
||||
///
|
||||
/// Credit to Reth for the type definition.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[metastruct(mappings(map_execution_block_header_fields_except_withdrawals(exclude(
|
||||
#[metastruct(mappings(map_execution_block_header_fields_base(exclude(
|
||||
withdrawals_root,
|
||||
blob_gas_used,
|
||||
excess_blob_gas,
|
||||
|
||||
@@ -99,6 +99,7 @@ pub mod slot_data;
|
||||
pub mod sqlite;
|
||||
|
||||
pub mod blob_sidecar;
|
||||
pub mod sidecar;
|
||||
pub mod signed_blob;
|
||||
|
||||
use ethereum_types::{H160, H256};
|
||||
@@ -121,7 +122,7 @@ pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
|
||||
pub use crate::beacon_state::{BeaconTreeHashCache, Error as BeaconStateError, *};
|
||||
pub use crate::blob_sidecar::{
|
||||
BlindedBlobSidecar, BlindedBlobSidecarList, BlobRootsList, BlobSidecar, BlobSidecarList,
|
||||
BlobsList, Sidecar, SidecarList,
|
||||
BlobsList, SidecarList,
|
||||
};
|
||||
pub use crate::bls_to_execution_change::BlsToExecutionChange;
|
||||
pub use crate::chain_spec::{ChainSpec, Config, Domain};
|
||||
@@ -161,9 +162,8 @@ pub use crate::participation_flags::ParticipationFlags;
|
||||
pub use crate::participation_list::ParticipationList;
|
||||
pub use crate::payload::{
|
||||
AbstractExecPayload, BlindedPayload, BlindedPayloadCapella, BlindedPayloadDeneb,
|
||||
BlindedPayloadMerge, BlindedPayloadRef, BlobsBundle, BlockType, ExecPayload,
|
||||
ExecutionPayloadAndBlobs, FullPayload, FullPayloadCapella, FullPayloadContents,
|
||||
FullPayloadDeneb, FullPayloadMerge, FullPayloadRef, OwnedExecPayload,
|
||||
BlindedPayloadMerge, BlindedPayloadRef, BlockType, ExecPayload, FullPayload,
|
||||
FullPayloadCapella, FullPayloadDeneb, FullPayloadMerge, FullPayloadRef, OwnedExecPayload,
|
||||
};
|
||||
pub use crate::pending_attestation::PendingAttestation;
|
||||
pub use crate::preset::{AltairPreset, BasePreset, BellatrixPreset, CapellaPreset};
|
||||
@@ -221,5 +221,6 @@ pub use bls::{
|
||||
|
||||
pub use kzg::{KzgCommitment, KzgProof};
|
||||
|
||||
pub use sidecar::Sidecar;
|
||||
pub use ssz_types::{typenum, typenum::Unsigned, BitList, BitVector, FixedVector, VariableList};
|
||||
pub use superstruct::superstruct;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use crate::beacon_block_body::KzgCommitments;
|
||||
use crate::{test_utils::TestRandom, *};
|
||||
use derivative::Derivative;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
use serde_json::Value;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::borrow::Cow;
|
||||
@@ -971,85 +969,3 @@ impl<T: EthSpec> From<BlindedPayload<T>> for ExecutionPayloadHeader<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Encode)]
|
||||
#[serde(untagged)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[ssz(enum_behaviour = "transparent")]
|
||||
pub enum FullPayloadContents<E: EthSpec> {
|
||||
Payload(ExecutionPayload<E>),
|
||||
PayloadAndBlobs(ExecutionPayloadAndBlobs<E>),
|
||||
}
|
||||
|
||||
impl<E: EthSpec> FullPayloadContents<E> {
|
||||
pub fn new(
|
||||
execution_payload: ExecutionPayload<E>,
|
||||
maybe_blobs: Option<BlobsBundle<E>>,
|
||||
) -> Self {
|
||||
match maybe_blobs {
|
||||
None => Self::Payload(execution_payload),
|
||||
Some(blobs_bundle) => Self::PayloadAndBlobs(ExecutionPayloadAndBlobs {
|
||||
execution_payload,
|
||||
blobs_bundle,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn payload_ref(&self) -> &ExecutionPayload<E> {
|
||||
match self {
|
||||
FullPayloadContents::Payload(payload) => payload,
|
||||
FullPayloadContents::PayloadAndBlobs(payload_and_blobs) => {
|
||||
&payload_and_blobs.execution_payload
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn block_hash(&self) -> ExecutionBlockHash {
|
||||
self.payload_ref().block_hash()
|
||||
}
|
||||
|
||||
pub fn deconstruct(self) -> (ExecutionPayload<E>, Option<BlobsBundle<E>>) {
|
||||
match self {
|
||||
FullPayloadContents::Payload(payload) => (payload, None),
|
||||
FullPayloadContents::PayloadAndBlobs(payload_and_blobs) => (
|
||||
payload_and_blobs.execution_payload,
|
||||
Some(payload_and_blobs.blobs_bundle),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ForkVersionDeserialize for FullPayloadContents<E> {
|
||||
fn deserialize_by_fork<'de, D: Deserializer<'de>>(
|
||||
value: Value,
|
||||
fork_name: ForkName,
|
||||
) -> Result<Self, D::Error> {
|
||||
match fork_name {
|
||||
ForkName::Merge | ForkName::Capella => serde_json::from_value(value)
|
||||
.map(Self::Payload)
|
||||
.map_err(serde::de::Error::custom),
|
||||
ForkName::Deneb => serde_json::from_value(value)
|
||||
.map(Self::PayloadAndBlobs)
|
||||
.map_err(serde::de::Error::custom),
|
||||
ForkName::Base | ForkName::Altair => Err(serde::de::Error::custom(format!(
|
||||
"FullPayloadContents deserialization for {fork_name} not implemented"
|
||||
))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Encode)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct ExecutionPayloadAndBlobs<E: EthSpec> {
|
||||
pub execution_payload: ExecutionPayload<E>,
|
||||
pub blobs_bundle: BlobsBundle<E>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, Encode)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct BlobsBundle<E: EthSpec> {
|
||||
pub commitments: KzgCommitments<E>,
|
||||
pub proofs: KzgProofs<E>,
|
||||
#[serde(with = "ssz_types::serde_utils::list_of_hex_fixed_vec")]
|
||||
pub blobs: BlobsList<E>,
|
||||
}
|
||||
|
||||
191
consensus/types/src/sidecar.rs
Normal file
191
consensus/types/src/sidecar.rs
Normal file
@@ -0,0 +1,191 @@
|
||||
use crate::beacon_block_body::BuilderKzgCommitments;
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::{
|
||||
AbstractExecPayload, BeaconBlock, BlindedBlobSidecar, BlindedBlobSidecarList, BlobRootsList,
|
||||
BlobSidecar, BlobSidecarList, BlobsList, EthSpec, SidecarList, SignedRoot, Slot,
|
||||
};
|
||||
use kzg::KzgProof;
|
||||
use serde::de::DeserializeOwned;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_types::VariableList;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::sync::Arc;
|
||||
use tree_hash::TreeHash;
|
||||
|
||||
pub trait Sidecar<E: EthSpec>:
|
||||
serde::Serialize
|
||||
+ Clone
|
||||
+ DeserializeOwned
|
||||
+ Encode
|
||||
+ Decode
|
||||
+ Hash
|
||||
+ TreeHash
|
||||
+ TestRandom
|
||||
+ Debug
|
||||
+ SignedRoot
|
||||
+ Sync
|
||||
+ Send
|
||||
+ for<'a> arbitrary::Arbitrary<'a>
|
||||
{
|
||||
type BlobItems: BlobItems<E>;
|
||||
fn slot(&self) -> Slot;
|
||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||
blob_items: Self::BlobItems,
|
||||
block: &BeaconBlock<E, Payload>,
|
||||
expected_kzg_commitments: &BuilderKzgCommitments<E>,
|
||||
kzg_proofs: Vec<KzgProof>,
|
||||
) -> Result<SidecarList<E, Self>, String>;
|
||||
}
|
||||
|
||||
pub trait BlobItems<T: EthSpec>: Sync + Send + Sized {
|
||||
fn try_from_blob_roots(roots: BlobRootsList<T>) -> Result<Self, String>;
|
||||
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String>;
|
||||
fn len(&self) -> usize;
|
||||
fn is_empty(&self) -> bool;
|
||||
fn blobs(&self) -> Option<&BlobsList<T>>;
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BlobItems<T> for BlobsList<T> {
|
||||
fn try_from_blob_roots(_roots: BlobRootsList<T>) -> Result<Self, String> {
|
||||
Err("Unexpected conversion from blob roots to blobs".to_string())
|
||||
}
|
||||
|
||||
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String> {
|
||||
Ok(blobs)
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
VariableList::len(self)
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
VariableList::is_empty(self)
|
||||
}
|
||||
|
||||
fn blobs(&self) -> Option<&BlobsList<T>> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BlobItems<T> for BlobRootsList<T> {
|
||||
fn try_from_blob_roots(roots: BlobRootsList<T>) -> Result<Self, String> {
|
||||
Ok(roots)
|
||||
}
|
||||
|
||||
fn try_from_blobs(blobs: BlobsList<T>) -> Result<Self, String> {
|
||||
VariableList::new(
|
||||
blobs
|
||||
.into_iter()
|
||||
.map(|blob| blob.tree_hash_root())
|
||||
.collect(),
|
||||
)
|
||||
.map_err(|e| format!("{e:?}"))
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
VariableList::len(self)
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
VariableList::is_empty(self)
|
||||
}
|
||||
|
||||
fn blobs(&self) -> Option<&BlobsList<T>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Sidecar<E> for BlobSidecar<E> {
|
||||
type BlobItems = BlobsList<E>;
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.slot
|
||||
}
|
||||
|
||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||
blobs: BlobsList<E>,
|
||||
block: &BeaconBlock<E, Payload>,
|
||||
expected_kzg_commitments: &BuilderKzgCommitments<E>,
|
||||
kzg_proofs: Vec<KzgProof>,
|
||||
) -> Result<SidecarList<E, Self>, String> {
|
||||
let beacon_block_root = block.canonical_root();
|
||||
let slot = block.slot();
|
||||
let blob_sidecars = BlobSidecarList::from(
|
||||
blobs
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(blob_index, blob)| {
|
||||
let kzg_commitment = expected_kzg_commitments
|
||||
.get(blob_index)
|
||||
.ok_or("KZG commitment should exist for blob")?;
|
||||
|
||||
let kzg_proof = kzg_proofs
|
||||
.get(blob_index)
|
||||
.ok_or("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: block.proposer_index(),
|
||||
blob,
|
||||
kzg_commitment: *kzg_commitment,
|
||||
kzg_proof: *kzg_proof,
|
||||
}))
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?,
|
||||
);
|
||||
|
||||
Ok(blob_sidecars)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> Sidecar<E> for BlindedBlobSidecar {
|
||||
type BlobItems = BlobRootsList<E>;
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
self.slot
|
||||
}
|
||||
|
||||
fn build_sidecar<Payload: AbstractExecPayload<E>>(
|
||||
blob_roots: BlobRootsList<E>,
|
||||
block: &BeaconBlock<E, Payload>,
|
||||
expected_kzg_commitments: &BuilderKzgCommitments<E>,
|
||||
kzg_proofs: Vec<KzgProof>,
|
||||
) -> Result<SidecarList<E, BlindedBlobSidecar>, String> {
|
||||
let beacon_block_root = block.canonical_root();
|
||||
let slot = block.slot();
|
||||
|
||||
let blob_sidecars = BlindedBlobSidecarList::<E>::from(
|
||||
blob_roots
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(blob_index, blob_root)| {
|
||||
let kzg_commitment = expected_kzg_commitments
|
||||
.get(blob_index)
|
||||
.ok_or("KZG commitment should exist for blob")?;
|
||||
|
||||
let kzg_proof = kzg_proofs.get(blob_index).ok_or(format!(
|
||||
"Missing KZG proof for slot {} blob index: {}",
|
||||
slot, blob_index
|
||||
))?;
|
||||
|
||||
Ok(Arc::new(BlindedBlobSidecar {
|
||||
block_root: beacon_block_root,
|
||||
index: blob_index as u64,
|
||||
slot,
|
||||
block_parent_root: block.parent_root(),
|
||||
proposer_index: block.proposer_index(),
|
||||
blob_root,
|
||||
kzg_commitment: *kzg_commitment,
|
||||
kzg_proof: *kzg_proof,
|
||||
}))
|
||||
})
|
||||
.collect::<Result<Vec<_>, String>>()?,
|
||||
);
|
||||
|
||||
Ok(blob_sidecars)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::sidecar::Sidecar;
|
||||
use crate::{
|
||||
test_utils::TestRandom, BlindedBlobSidecar, Blob, BlobSidecar, ChainSpec, Domain, EthSpec,
|
||||
Fork, Hash256, Sidecar, Signature, SignedRoot, SigningData,
|
||||
Fork, Hash256, Signature, SignedRoot, SigningData,
|
||||
};
|
||||
use bls::PublicKey;
|
||||
use derivative::Derivative;
|
||||
|
||||
Reference in New Issue
Block a user