Skip to content

Fix for #7377 Update DataColumnSidecarsByRoot request to use DataColumnsByRootIdentifier #7399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from

Conversation

SunnysidedJ
Copy link

Issue Addressed

Update DataColumnSidecarsByRoot request to use DataColumnsByRootIdentifier #7377

Proposed Changes

As described in ethereum/consensus-specs#4284

Additional Info

@SunnysidedJ SunnysidedJ changed the title initial commit, under test Fix for #7377 Update DataColumnSidecarsByRoot request to use DataColumnsByRootIdentifier May 5, 2025
@SunnysidedJ
Copy link
Author

Status: testing

@jimmygchen jimmygchen added das Data Availability Sampling ready-for-review The code is ready for review labels May 5, 2025
@jimmygchen jimmygchen added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels May 6, 2025
@SunnysidedJ
Copy link
Author

Status: review ready

@SunnysidedJ SunnysidedJ marked this pull request as ready for review May 6, 2025 09:27
@SunnysidedJ SunnysidedJ requested a review from jxs as a code owner May 6, 2025 09:27
@jimmygchen jimmygchen added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels May 7, 2025
@jimmygchen jimmygchen assigned jimmygchen and unassigned pawanjay176 May 7, 2025
Copy link
Member

@jimmygchen jimmygchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SunnysidedJ thanks a lot for this PR!
I'm still reviewing but thought I'd post my comments I have so far. I'll continue review this afternoon.

@@ -32,6 +34,51 @@ pub struct DataColumnIdentifier {
pub index: ColumnIndex,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DataColumnIdentifier can be removed

let number_of_columns = spec.number_of_columns as usize;
// TODO we aren't handling the case where self.indices > NUMBER_OF_COLUMNS defined by the
// spec. Do we do this else where? I think we shall use RuntimeVariableList::new() and
// handle errors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes agree that we should use RuntimeVariableList::new() instead, perhaps modify this function to try_into_request and return Result here

)?
.into_iter()
.map(|bytes| {
// Split manually: first 32 bytes = block_root and next 4 bytes = vector tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a bit cleaner to use SszDecoderBuilder here to decode, and call into a separate DataColumnByRootIdentifier decode function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this:

let mut builder = ssz::SszDecoderBuilder::new(&bytes);
builder.register_type::<Hash256>()?;
builder.register_anonymous_variable_length_item()?;

let mut decoder = builder.build()?;
let block_root = decoder.decode_next()?;
let indices = decoder.decode_next_with(|bytes| DataColumnsByRootIdentifier::from_ssz_bytes(bytes, num_columns))?;
Ok(DataColumnsByRootIdentifier {
    block_root,
    indices,
})

Copy link
Member

@jimmygchen jimmygchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some more comments, let me know what you think. Thanks!

@@ -1781,7 +1793,10 @@ fn default_max_blobs_by_root_request() -> usize {
}

fn default_data_columns_by_root_request() -> usize {
max_data_columns_by_root_request_common(default_max_request_data_column_sidecars())
max_data_columns_by_root_request_common(
default_max_request_data_column_sidecars(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be default_max_request_blocks()?

@@ -2083,6 +2098,7 @@ impl Config {
max_blobs_by_root_request: max_blobs_by_root_request_common(max_request_blob_sidecars),
max_data_columns_by_root_request: max_data_columns_by_root_request_common(
max_request_data_column_sidecars,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_max_request_blocks()

}

impl DataColumnsByRootRequest {
pub fn new(data_column_ids: Vec<DataColumnIdentifier>, spec: &ChainSpec) -> Self {
pub fn new(data_column_ids: Vec<DataColumnsByRootIdentifier>, spec: &ChainSpec) -> Self {
let data_column_ids = RuntimeVariableList::from_vec(
data_column_ids,
spec.max_request_data_column_sidecars as usize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be MAX_REQUEST_BLOCKS_DENEB

for data_column_ids_by_root in request.data_column_ids.as_slice() {
match self.chain.get_data_columns_checking_all_caches(
data_column_ids_by_root.block_root,
&Vec::from(data_column_ids_by_root.indices.clone()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do data_column_ids_by_root.indices.as_slice() here to avoid cloning?

@@ -405,16 +405,18 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
}

/// Fetch a data column from the cache without affecting the LRU ordering
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Fetch a data column from the cache without affecting the LRU ordering
/// Fetch data columns of a given `block_root` from the cache without affecting the LRU ordering

} else if let Some(all_cols) = self.early_attester_cache.get_data_columns(block_root) {
Ok(Some(all_cols))
} else {
self.get_data_columns(&block_root)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to avoid loading all data columns from disk and just load the required one here.

Ok(Some(all_cols))
} else {
self.get_data_columns(&block_root)
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like we need to wrap it with Result here and unwrap it below.

We could simplify this to something like

        let columns = if let Some(all_cols) = self
            .data_availability_checker
            .get_data_columns(block_root)?
        {
            Some(all_cols)
        } else if let Some(all_cols) = self.early_attester_cache.get_data_columns(block_root) {
            Some(all_cols)
        } else {
            self.get_data_columns(&block_root)?
        };

and then return Ok(columns) after filtering.

.iter()
.filter(|col| indices.contains(&col.index))
.cloned()
.collect(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could do into_iter to avoid having to clone the elements

@jimmygchen jimmygchen added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
das Data Availability Sampling waiting-on-author The reviewer has suggested changes and awaits thier implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants