mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
cleanup
This commit is contained in:
@@ -188,8 +188,9 @@ fn build_data_column_sidecars<E: EthSpec>(
|
|||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<DataColumnSidecarList<E>, String> {
|
) -> Result<DataColumnSidecarList<E>, String> {
|
||||||
let number_of_columns = spec.number_of_columns;
|
let number_of_columns = spec.number_of_columns;
|
||||||
let max_blobs_per_block =
|
let max_blobs_per_block = spec
|
||||||
spec.max_blobs_per_block(signed_block_header.message.slot.epoch(E::slots_per_epoch())) as usize;
|
.max_blobs_per_block(signed_block_header.message.slot.epoch(E::slots_per_epoch()))
|
||||||
|
as usize;
|
||||||
let mut columns = vec![Vec::with_capacity(max_blobs_per_block); number_of_columns];
|
let mut columns = vec![Vec::with_capacity(max_blobs_per_block); number_of_columns];
|
||||||
let mut column_kzg_proofs = vec![Vec::with_capacity(max_blobs_per_block); number_of_columns];
|
let mut column_kzg_proofs = vec![Vec::with_capacity(max_blobs_per_block); number_of_columns];
|
||||||
|
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ impl BlobsByRangeRequest {
|
|||||||
/// Note: **must not** use for anything consensus critical, only for
|
/// Note: **must not** use for anything consensus critical, only for
|
||||||
/// bounds checking and rate limiting.
|
/// bounds checking and rate limiting.
|
||||||
pub fn max_blobs_requested<E: EthSpec>(&self) -> u64 {
|
pub fn max_blobs_requested<E: EthSpec>(&self) -> u64 {
|
||||||
self.count.saturating_mul(MAX_BLOBS_PER_BLOCK_CEILING as u64)
|
self.count.saturating_mul(MAX_BLOBS_PER_BLOCK_CEILING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ use std::time::Duration;
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use types::blob_sidecar::FixedBlobSidecarList;
|
use types::blob_sidecar::FixedBlobSidecarList;
|
||||||
use types::{
|
use types::{
|
||||||
BlobSidecar, ColumnIndex, DataColumnSidecar, DataColumnSidecarList, EthSpec,
|
BlobSidecar, ColumnIndex, DataColumnSidecar, DataColumnSidecarList, EthSpec, Hash256,
|
||||||
Hash256, SignedBeaconBlock, Slot,
|
SignedBeaconBlock, Slot,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod custody;
|
pub mod custody;
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ use std::slice::SliceIndex;
|
|||||||
/// An ordered, heap-allocated, variable-length, homogeneous collection of `T`, with no more than
|
/// An ordered, heap-allocated, variable-length, homogeneous collection of `T`, with no more than
|
||||||
/// `max_len` values.
|
/// `max_len` values.
|
||||||
///
|
///
|
||||||
|
/// In cases where the `max_length` of the container is unknown at time of initialization, we provide
|
||||||
|
/// a `Self::empty_uninitialized` constructor that initializes a runtime list without setting the max_len.
|
||||||
|
///
|
||||||
|
/// To ensure there are no inconsistent states, we do not allow any mutating operation if `max_len` is not set.
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
@@ -35,6 +40,16 @@ use std::slice::SliceIndex;
|
|||||||
///
|
///
|
||||||
/// // Push a value to if it _does_ exceed the maximum.
|
/// // Push a value to if it _does_ exceed the maximum.
|
||||||
/// assert!(long.push(6).is_err());
|
/// assert!(long.push(6).is_err());
|
||||||
|
///
|
||||||
|
/// let mut uninit = RuntimeVariableList::empty_unitialized();
|
||||||
|
/// assert!(uninit.push(5).is_err());
|
||||||
|
///
|
||||||
|
/// // Set max_len to allow mutation.
|
||||||
|
/// uninit.set_max_len(5usize);
|
||||||
|
///
|
||||||
|
/// uninit.push(5).unwrap();
|
||||||
|
/// assert_eq!(&uninit[..], &[5]);
|
||||||
|
///
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
|
||||||
#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))]
|
#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))]
|
||||||
@@ -73,7 +88,7 @@ impl<T> RuntimeVariableList<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create an empty list.
|
/// Create an empty list with the given `max_len`.
|
||||||
pub fn empty(max_len: usize) -> Self {
|
pub fn empty(max_len: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
vec: vec![],
|
vec: vec![],
|
||||||
@@ -95,7 +110,7 @@ impl<T> RuntimeVariableList<T> {
|
|||||||
/// Returns an instance of `Self` with max_len = None.
|
/// Returns an instance of `Self` with max_len = None.
|
||||||
///
|
///
|
||||||
/// No mutating operation can be performed on an uninitialized instance
|
/// No mutating operation can be performed on an uninitialized instance
|
||||||
/// without first setting max_len.
|
/// without first setting `max_len`.
|
||||||
pub fn empty_uninitialized() -> Self {
|
pub fn empty_uninitialized() -> Self {
|
||||||
Self {
|
Self {
|
||||||
vec: vec![],
|
vec: vec![],
|
||||||
@@ -129,7 +144,7 @@ impl<T> RuntimeVariableList<T> {
|
|||||||
/// Returns `Err(())` when appending `value` would exceed the maximum length.
|
/// Returns `Err(())` when appending `value` would exceed the maximum length.
|
||||||
pub fn push(&mut self, value: T) -> Result<(), Error> {
|
pub fn push(&mut self, value: T) -> Result<(), Error> {
|
||||||
let Some(max_len) = self.max_len else {
|
let Some(max_len) = self.max_len else {
|
||||||
// TODO(pawan): set a better error
|
// TODO(pawan): set a better error?
|
||||||
return Err(Error::MissingLengthInformation);
|
return Err(Error::MissingLengthInformation);
|
||||||
};
|
};
|
||||||
if self.vec.len() < max_len {
|
if self.vec.len() < max_len {
|
||||||
@@ -247,6 +262,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Emulates a SSZ `Vector`.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RuntimeFixedList<T> {
|
pub struct RuntimeFixedList<T> {
|
||||||
vec: Vec<T>,
|
vec: Vec<T>,
|
||||||
@@ -267,6 +283,7 @@ impl<T: Clone + Default> RuntimeFixedList<T> {
|
|||||||
self.vec.as_slice()
|
self.vec.as_slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::len_without_is_empty)]
|
||||||
pub fn len(&self) -> usize {
|
pub fn len(&self) -> usize {
|
||||||
self.len
|
self.len
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user