mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-17 12:58:31 +00:00
First pass
This commit is contained in:
@@ -13,8 +13,6 @@ use tree_hash_derive::TreeHash;
|
||||
|
||||
pub type KzgCommitments<E> =
|
||||
VariableList<KzgCommitment, <E as EthSpec>::MaxBlobCommitmentsPerBlock>;
|
||||
pub type KzgCommitmentOpts<E> =
|
||||
FixedVector<Option<KzgCommitment>, <E as EthSpec>::MaxBlobsPerBlock>;
|
||||
|
||||
/// The number of leaves (including padding) on the `BeaconBlockBody` Merkle tree.
|
||||
///
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::ForkName;
|
||||
use crate::{
|
||||
beacon_block_body::BLOB_KZG_COMMITMENTS_INDEX, BeaconBlockHeader, BeaconStateError, Blob,
|
||||
Epoch, EthSpec, FixedVector, Hash256, SignedBeaconBlockHeader, Slot, VariableList,
|
||||
};
|
||||
use crate::{ForkVersionDeserialize, KzgProofs, SignedBeaconBlock};
|
||||
use crate::{
|
||||
runtime_var_list::RuntimeFixedList, ForkVersionDeserialize, KzgProofs, RuntimeVariableList,
|
||||
SignedBeaconBlock,
|
||||
};
|
||||
use crate::{ChainSpec, ForkName};
|
||||
use bls::Signature;
|
||||
use derivative::Derivative;
|
||||
use kzg::{Blob as KzgBlob, Kzg, KzgCommitment, KzgProof, BYTES_PER_BLOB, BYTES_PER_FIELD_ELEMENT};
|
||||
@@ -30,19 +33,6 @@ pub struct BlobIdentifier {
|
||||
pub index: u64,
|
||||
}
|
||||
|
||||
impl BlobIdentifier {
|
||||
pub fn get_all_blob_ids<E: EthSpec>(block_root: Hash256) -> Vec<BlobIdentifier> {
|
||||
let mut blob_ids = Vec::with_capacity(E::max_blobs_per_block());
|
||||
for i in 0..E::max_blobs_per_block() {
|
||||
blob_ids.push(BlobIdentifier {
|
||||
block_root,
|
||||
index: i as u64,
|
||||
});
|
||||
}
|
||||
blob_ids
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for BlobIdentifier {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
@@ -260,19 +250,24 @@ impl<E: EthSpec> BlobSidecar<E> {
|
||||
blobs: BlobsList<E>,
|
||||
block: &SignedBeaconBlock<E>,
|
||||
kzg_proofs: KzgProofs<E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<BlobSidecarList<E>, BlobSidecarError> {
|
||||
let mut blob_sidecars = vec![];
|
||||
for (i, (kzg_proof, blob)) in kzg_proofs.iter().zip(blobs).enumerate() {
|
||||
let blob_sidecar = BlobSidecar::new(i, blob, block, *kzg_proof)?;
|
||||
blob_sidecars.push(Arc::new(blob_sidecar));
|
||||
}
|
||||
Ok(VariableList::from(blob_sidecars))
|
||||
Ok(RuntimeVariableList::from_vec(
|
||||
blob_sidecars,
|
||||
spec.max_blobs_per_block(block.epoch()) as usize,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub type BlobSidecarList<E> = VariableList<Arc<BlobSidecar<E>>, <E as EthSpec>::MaxBlobsPerBlock>;
|
||||
pub type FixedBlobSidecarList<E> =
|
||||
FixedVector<Option<Arc<BlobSidecar<E>>>, <E as EthSpec>::MaxBlobsPerBlock>;
|
||||
pub type BlobSidecarList<E> = RuntimeVariableList<Arc<BlobSidecar<E>>>;
|
||||
/// Alias for a non length-constrained list of `BlobSidecar`s.
|
||||
pub type BlobSidecarVec<E> = Vec<Arc<BlobSidecar<E>>>;
|
||||
pub type FixedBlobSidecarList<E> = RuntimeFixedList<Option<Arc<BlobSidecar<E>>>>;
|
||||
pub type BlobsList<E> = VariableList<Blob<E>, <E as EthSpec>::MaxBlobCommitmentsPerBlock>;
|
||||
|
||||
impl<E: EthSpec> ForkVersionDeserialize for BlobSidecarList<E> {
|
||||
|
||||
@@ -230,6 +230,7 @@ pub struct ChainSpec {
|
||||
pub max_request_data_column_sidecars: u64,
|
||||
pub min_epochs_for_blob_sidecars_requests: u64,
|
||||
pub blob_sidecar_subnet_count: u64,
|
||||
max_blobs_per_block: u64,
|
||||
|
||||
/*
|
||||
* Networking Derived
|
||||
@@ -607,6 +608,16 @@ impl ChainSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the deneb preset value if peerdas epoch hasn't hit.
|
||||
/// Otherwise, returns the value obtained from the config.yaml.
|
||||
pub fn max_blobs_per_block(&self, epoch: Epoch) -> u64 {
|
||||
if self.is_peer_das_enabled_for_epoch(epoch) {
|
||||
self.max_blobs_per_block
|
||||
} else {
|
||||
default_max_blobs_per_block()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn data_columns_per_subnet(&self) -> usize {
|
||||
self.number_of_columns
|
||||
.safe_div(self.data_column_sidecar_subnet_count as usize)
|
||||
@@ -843,6 +854,7 @@ impl ChainSpec {
|
||||
max_request_data_column_sidecars: default_max_request_data_column_sidecars(),
|
||||
min_epochs_for_blob_sidecars_requests: default_min_epochs_for_blob_sidecars_requests(),
|
||||
blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(),
|
||||
max_blobs_per_block: default_max_blobs_per_block(),
|
||||
|
||||
/*
|
||||
* Derived Deneb Specific
|
||||
@@ -1164,6 +1176,8 @@ impl ChainSpec {
|
||||
max_request_data_column_sidecars: default_max_request_data_column_sidecars(),
|
||||
min_epochs_for_blob_sidecars_requests: 16384,
|
||||
blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(),
|
||||
// TODO(pawan): check if gnosis preset values match
|
||||
max_blobs_per_block: default_max_blobs_per_block(),
|
||||
|
||||
/*
|
||||
* Derived Deneb Specific
|
||||
@@ -1364,6 +1378,9 @@ pub struct Config {
|
||||
#[serde(default = "default_blob_sidecar_subnet_count")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
blob_sidecar_subnet_count: u64,
|
||||
#[serde(default = "default_max_blobs_per_block")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
max_blobs_per_block: u64,
|
||||
|
||||
#[serde(default = "default_min_per_epoch_churn_limit_electra")]
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
@@ -1499,6 +1516,12 @@ const fn default_blob_sidecar_subnet_count() -> u64 {
|
||||
6
|
||||
}
|
||||
|
||||
/// Its important to keep this consistent with the deneb preset value for
|
||||
/// `MAX_BLOBS_PER_BLOCK` else we might run into consensus issues.
|
||||
const fn default_max_blobs_per_block() -> u64 {
|
||||
6
|
||||
}
|
||||
|
||||
const fn default_min_per_epoch_churn_limit_electra() -> u64 {
|
||||
128_000_000_000
|
||||
}
|
||||
@@ -1718,6 +1741,7 @@ impl Config {
|
||||
max_request_data_column_sidecars: spec.max_request_data_column_sidecars,
|
||||
min_epochs_for_blob_sidecars_requests: spec.min_epochs_for_blob_sidecars_requests,
|
||||
blob_sidecar_subnet_count: spec.blob_sidecar_subnet_count,
|
||||
max_blobs_per_block: spec.max_blobs_per_block,
|
||||
|
||||
min_per_epoch_churn_limit_electra: spec.min_per_epoch_churn_limit_electra,
|
||||
max_per_epoch_activation_exit_churn_limit: spec
|
||||
@@ -1795,6 +1819,7 @@ impl Config {
|
||||
max_request_data_column_sidecars,
|
||||
min_epochs_for_blob_sidecars_requests,
|
||||
blob_sidecar_subnet_count,
|
||||
max_blobs_per_block,
|
||||
|
||||
min_per_epoch_churn_limit_electra,
|
||||
max_per_epoch_activation_exit_churn_limit,
|
||||
@@ -1863,6 +1888,7 @@ impl Config {
|
||||
max_request_data_column_sidecars,
|
||||
min_epochs_for_blob_sidecars_requests,
|
||||
blob_sidecar_subnet_count,
|
||||
max_blobs_per_block,
|
||||
|
||||
min_per_epoch_churn_limit_electra,
|
||||
max_per_epoch_activation_exit_churn_limit,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::beacon_block_body::{KzgCommitments, BLOB_KZG_COMMITMENTS_INDEX};
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::BeaconStateError;
|
||||
use crate::{BeaconBlockHeader, EthSpec, Hash256, KzgProofs, SignedBeaconBlockHeader, Slot};
|
||||
use crate::{BeaconBlockHeader, Epoch, EthSpec, Hash256, KzgProofs, SignedBeaconBlockHeader, Slot};
|
||||
use crate::{BeaconStateError, ChainSpec};
|
||||
use bls::Signature;
|
||||
use derivative::Derivative;
|
||||
use kzg::Error as KzgError;
|
||||
@@ -110,18 +110,16 @@ impl<E: EthSpec> DataColumnSidecar<E> {
|
||||
.len()
|
||||
}
|
||||
|
||||
pub fn max_size() -> usize {
|
||||
pub fn max_size(max_blobs_per_block: usize) -> usize {
|
||||
Self {
|
||||
index: 0,
|
||||
column: VariableList::new(vec![Cell::<E>::default(); E::MaxBlobsPerBlock::to_usize()])
|
||||
.unwrap(),
|
||||
column: VariableList::new(vec![Cell::<E>::default(); max_blobs_per_block]).unwrap(),
|
||||
kzg_commitments: VariableList::new(vec![
|
||||
KzgCommitment::empty_for_testing();
|
||||
E::MaxBlobsPerBlock::to_usize()
|
||||
max_blobs_per_block
|
||||
])
|
||||
.unwrap(),
|
||||
kzg_proofs: VariableList::new(vec![KzgProof::empty(); E::MaxBlobsPerBlock::to_usize()])
|
||||
.unwrap(),
|
||||
kzg_proofs: VariableList::new(vec![KzgProof::empty(); max_blobs_per_block]).unwrap(),
|
||||
signed_block_header: SignedBeaconBlockHeader {
|
||||
message: BeaconBlockHeader::empty(),
|
||||
signature: Signature::empty(),
|
||||
|
||||
@@ -4,8 +4,7 @@ use safe_arith::SafeArith;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_types::typenum::{
|
||||
bit::B0, UInt, U0, U1, U1024, U1048576, U1073741824, U1099511627776, U128, U131072, U134217728,
|
||||
U16, U16777216, U2, U2048, U256, U262144, U32, U4, U4096, U512, U6, U625, U64, U65536, U8,
|
||||
U8192,
|
||||
U16, U16777216, U2, U2048, U256, U262144, U32, U4, U4096, U512, U625, U64, U65536, U8, U8192,
|
||||
};
|
||||
use ssz_types::typenum::{U17, U9};
|
||||
use std::fmt::{self, Debug};
|
||||
@@ -109,7 +108,6 @@ pub trait EthSpec:
|
||||
/*
|
||||
* New in Deneb
|
||||
*/
|
||||
type MaxBlobsPerBlock: Unsigned + Clone + Sync + Send + Debug + PartialEq + Unpin;
|
||||
type MaxBlobCommitmentsPerBlock: Unsigned + Clone + Sync + Send + Debug + PartialEq + Unpin;
|
||||
type FieldElementsPerBlob: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type BytesPerFieldElement: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
@@ -280,11 +278,6 @@ pub trait EthSpec:
|
||||
Self::MaxWithdrawalsPerPayload::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `MAX_BLOBS_PER_BLOCK` constant for this specification.
|
||||
fn max_blobs_per_block() -> usize {
|
||||
Self::MaxBlobsPerBlock::to_usize()
|
||||
}
|
||||
|
||||
/// Returns the `MAX_BLOB_COMMITMENTS_PER_BLOCK` constant for this specification.
|
||||
fn max_blob_commitments_per_block() -> usize {
|
||||
Self::MaxBlobCommitmentsPerBlock::to_usize()
|
||||
@@ -415,7 +408,6 @@ impl EthSpec for MainnetEthSpec {
|
||||
type GasLimitDenominator = U1024;
|
||||
type MinGasLimit = U5000;
|
||||
type MaxExtraDataBytes = U32;
|
||||
type MaxBlobsPerBlock = U6;
|
||||
type MaxBlobCommitmentsPerBlock = U4096;
|
||||
type BytesPerFieldElement = U32;
|
||||
type FieldElementsPerBlob = U4096;
|
||||
@@ -498,7 +490,6 @@ impl EthSpec for MinimalEthSpec {
|
||||
MinGasLimit,
|
||||
MaxExtraDataBytes,
|
||||
MaxBlsToExecutionChanges,
|
||||
MaxBlobsPerBlock,
|
||||
BytesPerFieldElement,
|
||||
PendingBalanceDepositsLimit,
|
||||
MaxConsolidationRequestsPerPayload,
|
||||
@@ -551,7 +542,6 @@ impl EthSpec for GnosisEthSpec {
|
||||
type SlotsPerEth1VotingPeriod = U1024; // 64 epochs * 16 slots per epoch
|
||||
type MaxBlsToExecutionChanges = U16;
|
||||
type MaxWithdrawalsPerPayload = U8;
|
||||
type MaxBlobsPerBlock = U6;
|
||||
type MaxBlobCommitmentsPerBlock = U4096;
|
||||
type FieldElementsPerBlob = U4096;
|
||||
type BytesPerFieldElement = U32;
|
||||
|
||||
@@ -138,7 +138,9 @@ pub use crate::beacon_block_body::{
|
||||
pub use crate::beacon_block_header::BeaconBlockHeader;
|
||||
pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
|
||||
pub use crate::beacon_state::{Error as BeaconStateError, *};
|
||||
pub use crate::blob_sidecar::{BlobIdentifier, BlobSidecar, BlobSidecarList, BlobsList};
|
||||
pub use crate::blob_sidecar::{
|
||||
BlobIdentifier, BlobSidecar, BlobSidecarList, BlobSidecarVec, BlobsList,
|
||||
};
|
||||
pub use crate::bls_to_execution_change::BlsToExecutionChange;
|
||||
pub use crate::chain_spec::{ChainSpec, Config, Domain};
|
||||
pub use crate::checkpoint::Checkpoint;
|
||||
|
||||
@@ -208,8 +208,6 @@ impl CapellaPreset {
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "UPPERCASE")]
|
||||
pub struct DenebPreset {
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_blobs_per_block: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
pub max_blob_commitments_per_block: u64,
|
||||
#[serde(with = "serde_utils::quoted_u64")]
|
||||
@@ -219,7 +217,6 @@ pub struct DenebPreset {
|
||||
impl DenebPreset {
|
||||
pub fn from_chain_spec<E: EthSpec>(_spec: &ChainSpec) -> Self {
|
||||
Self {
|
||||
max_blobs_per_block: E::max_blobs_per_block() as u64,
|
||||
max_blob_commitments_per_block: E::max_blob_commitments_per_block() as u64,
|
||||
field_elements_per_blob: E::field_elements_per_blob() as u64,
|
||||
}
|
||||
|
||||
@@ -214,6 +214,67 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RuntimeFixedList<T> {
|
||||
vec: Vec<T>,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl<T: Clone> RuntimeFixedList<T> {
|
||||
// TODO(pawan): no need to take len
|
||||
pub fn new(vec: Vec<T>) -> Self {
|
||||
let len = vec.len();
|
||||
Self { vec, len }
|
||||
}
|
||||
|
||||
pub fn to_vec(&self) -> Vec<T> {
|
||||
self.vec.clone()
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> &[T] {
|
||||
self.vec.as_slice()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.len
|
||||
}
|
||||
|
||||
pub fn into_vec(self) -> Vec<T> {
|
||||
self.vec
|
||||
}
|
||||
|
||||
pub fn take(&mut self) -> Self {
|
||||
let new = std::mem::take(&mut self.vec);
|
||||
Self {
|
||||
vec: new,
|
||||
len: self.len,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::ops::Deref for RuntimeFixedList<T> {
|
||||
type Target = [T];
|
||||
|
||||
fn deref(&self) -> &[T] {
|
||||
&self.vec[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::ops::DerefMut for RuntimeFixedList<T> {
|
||||
fn deref_mut(&mut self) -> &mut [T] {
|
||||
&mut self.vec[..]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> IntoIterator for &'a RuntimeFixedList<T> {
|
||||
type Item = &'a T;
|
||||
type IntoIter = std::slice::Iter<'a, T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.vec.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user