Skip to content

Commit d04f91c

Browse files
committed
Improve comments
1 parent 3a60f4d commit d04f91c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

consensus/types/src/core/chain_spec.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,21 +2105,40 @@ fn max_blocks_by_root_request_common(max_request_blocks: u64) -> usize {
21052105
.len()
21062106
}
21072107

2108+
// Simplified function which precomputes the size of a `List` of `BlobIdentifiers`.
21082109
pub(crate) fn max_blobs_by_root_request_common(max_request_blob_sidecars: u64) -> usize {
2110+
// BlobIdentifier is a fixed-size struct with two fields:
2111+
// - block_root: Hash256 (32 bytes)
2112+
// - index: u64 (8 bytes)
2113+
// Total per element: 32 + 8 = 40 bytes
2114+
// Since BlobIdentifier is fixed-size, the outer List does not add any byte overhead.
2115+
let blob_identifier_ssz_size = 40_usize;
2116+
21092117
(max_request_blob_sidecars as usize)
2110-
.safe_mul(40)
2118+
.safe_mul(blob_identifier_ssz_size)
21112119
.expect("should not overflow")
21122120
}
21132121

2122+
// Simplified function which precomputes the size of a `List` of `DataColumnIdentifiers`.
21142123
pub(crate) fn max_data_columns_by_root_request_common<E: EthSpec>(
21152124
max_request_blocks: u64,
21162125
) -> usize {
2117-
let bytes_per_element = 8_usize
2126+
// DataColumnsByRootIdentifier is a variable-size struct with two fields:
2127+
// - block_root: Hash256 (32 bytes)
2128+
// - columns: List<ColumnIndex, NumberOfColumns> (4 byte offset + n × 8 bytes)
2129+
// Since DataColumnsByRootIdentifier is variable-size, the outer List adds a
2130+
// 4-byte offset per element.
2131+
// Total per element: 4 (outer offset) + 32 (block_root) + 4 (columns offset) + n × 8
2132+
let column_index_ssz_size = 8_usize;
2133+
let ssz_fixed_size = 40_usize;
2134+
2135+
let data_columns_by_root_identifier_ssz_size = column_index_ssz_size
21182136
.safe_mul(E::number_of_columns())
2119-
.and_then(|b| b.safe_add(40))
2137+
.and_then(|b| b.safe_add(ssz_fixed_size))
21202138
.expect("should not overflow");
2139+
21212140
(max_request_blocks as usize)
2122-
.safe_mul(bytes_per_element)
2141+
.safe_mul(data_columns_by_root_identifier_ssz_size)
21232142
.expect("should not overflow")
21242143
}
21252144

0 commit comments

Comments
 (0)