Skip to content

Commit 52bb581

Browse files
committed
cleanup
1 parent e71020e commit 52bb581

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

beacon_node/beacon_chain/src/kzg_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ fn build_data_column_sidecars<E: EthSpec>(
188188
spec: &ChainSpec,
189189
) -> Result<DataColumnSidecarList<E>, String> {
190190
let number_of_columns = spec.number_of_columns;
191-
let max_blobs_per_block =
192-
spec.max_blobs_per_block(signed_block_header.message.slot.epoch(E::slots_per_epoch())) as usize;
191+
let max_blobs_per_block = spec
192+
.max_blobs_per_block(signed_block_header.message.slot.epoch(E::slots_per_epoch()))
193+
as usize;
193194
let mut columns = vec![Vec::with_capacity(max_blobs_per_block); number_of_columns];
194195
let mut column_kzg_proofs = vec![Vec::with_capacity(max_blobs_per_block); number_of_columns];
195196

beacon_node/lighthouse_network/src/rpc/methods.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub const MAX_ERROR_LEN: u64 = 256;
2727
/// The max number of blobs we expect in the configs to set for compile time params.
2828
/// Note: This value is an estimate that we should use only for rate limiting,
2929
/// bounds checking and other non-consensus critical operations.
30-
///
30+
///
3131
/// For exact value, we should always check the chainspec.
3232
pub const MAX_BLOBS_PER_BLOCK_CEILING: u64 = 16;
3333

@@ -335,11 +335,11 @@ pub struct BlobsByRangeRequest {
335335
impl BlobsByRangeRequest {
336336
/// This function provides an upper bound on number of blobs expected in
337337
/// a certain slot range.
338-
///
338+
///
339339
/// Note: **must not** use for anything consensus critical, only for
340-
/// bounds checking and rate limiting.
340+
/// bounds checking and rate limiting.
341341
pub fn max_blobs_requested<E: EthSpec>(&self) -> u64 {
342-
self.count.saturating_mul(MAX_BLOBS_PER_BLOCK_CEILING as u64)
342+
self.count.saturating_mul(MAX_BLOBS_PER_BLOCK_CEILING)
343343
}
344344
}
345345

beacon_node/network/src/sync/network_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use std::time::Duration;
3535
use tokio::sync::mpsc;
3636
use types::blob_sidecar::FixedBlobSidecarList;
3737
use types::{
38-
BlobSidecar, ColumnIndex, DataColumnSidecar, DataColumnSidecarList, EthSpec,
39-
Hash256, SignedBeaconBlock, Slot,
38+
BlobSidecar, ColumnIndex, DataColumnSidecar, DataColumnSidecarList, EthSpec, Hash256,
39+
SignedBeaconBlock, Slot,
4040
};
4141

4242
pub mod custody;

consensus/types/src/blob_sidecar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<E: EthSpec> BlobSidecar<E> {
265265
}
266266

267267
pub type BlobSidecarList<E> = RuntimeVariableList<Arc<BlobSidecar<E>>>;
268-
/// Alias for a non length-constrained list of `BlobSidecar`s.
268+
/// Alias for a non length-constrained list of `BlobSidecar`s.
269269
pub type FixedBlobSidecarList<E> = RuntimeFixedList<Option<Arc<BlobSidecar<E>>>>;
270270
pub type BlobsList<E> = VariableList<Blob<E>, <E as EthSpec>::MaxBlobCommitmentsPerBlock>;
271271

consensus/types/src/runtime_var_list.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ use std::slice::SliceIndex;
1010
/// An ordered, heap-allocated, variable-length, homogeneous collection of `T`, with no more than
1111
/// `max_len` values.
1212
///
13+
/// In cases where the `max_length` of the container is unknown at time of initialization, we provide
14+
/// a `Self::empty_uninitialized` constructor that initializes a runtime list without setting the max_len.
15+
///
16+
/// To ensure there are no inconsistent states, we do not allow any mutating operation if `max_len` is not set.
17+
///
1318
/// ## Example
1419
///
1520
/// ```
@@ -35,6 +40,16 @@ use std::slice::SliceIndex;
3540
///
3641
/// // Push a value to if it _does_ exceed the maximum.
3742
/// assert!(long.push(6).is_err());
43+
///
44+
/// let mut uninit = RuntimeVariableList::empty_unitialized();
45+
/// assert!(uninit.push(5).is_err());
46+
///
47+
/// // Set max_len to allow mutation.
48+
/// uninit.set_max_len(5usize);
49+
///
50+
/// uninit.push(5).unwrap();
51+
/// assert_eq!(&uninit[..], &[5]);
52+
///
3853
/// ```
3954
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
4055
#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))]
@@ -73,7 +88,7 @@ impl<T> RuntimeVariableList<T> {
7388
}
7489
}
7590

76-
/// Create an empty list.
91+
/// Create an empty list with the given `max_len`.
7792
pub fn empty(max_len: usize) -> Self {
7893
Self {
7994
vec: vec![],
@@ -95,7 +110,7 @@ impl<T> RuntimeVariableList<T> {
95110
/// Returns an instance of `Self` with max_len = None.
96111
///
97112
/// No mutating operation can be performed on an uninitialized instance
98-
/// without first setting max_len.
113+
/// without first setting `max_len`.
99114
pub fn empty_uninitialized() -> Self {
100115
Self {
101116
vec: vec![],
@@ -129,7 +144,7 @@ impl<T> RuntimeVariableList<T> {
129144
/// Returns `Err(())` when appending `value` would exceed the maximum length.
130145
pub fn push(&mut self, value: T) -> Result<(), Error> {
131146
let Some(max_len) = self.max_len else {
132-
// TODO(pawan): set a better error
147+
// TODO(pawan): set a better error?
133148
return Err(Error::MissingLengthInformation);
134149
};
135150
if self.vec.len() < max_len {
@@ -247,6 +262,7 @@ where
247262
}
248263
}
249264

265+
/// Emulates a SSZ `Vector`.
250266
#[derive(Clone, Debug)]
251267
pub struct RuntimeFixedList<T> {
252268
vec: Vec<T>,
@@ -267,6 +283,7 @@ impl<T: Clone + Default> RuntimeFixedList<T> {
267283
self.vec.as_slice()
268284
}
269285

286+
#[allow(clippy::len_without_is_empty)]
270287
pub fn len(&self) -> usize {
271288
self.len
272289
}

0 commit comments

Comments
 (0)