-
Notifications
You must be signed in to change notification settings - Fork 745
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
Add Changes to BlobSidecars Endpoint #4455
Conversation
Hey @realbigsean, only the rename has been merged, right? The query part is yet to be added. |
Hey! @jimmygchen, I have added the required changes. But I think my work lacks code quality. Do you have any suggestions to improve it? |
beacon_node/http_api/src/lib.rs
Outdated
let mut list = Vec::new(); | ||
for i in vec.iter() { | ||
list.push(blob_sidecar_list.get(*i as usize).unwrap().clone()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions:
1 . Blobs are quite big so we'd want to avoid cloning as much as possible. Instead of iterating using iter
, you could use .into_iter
(which moves and consumes the original values), and then use .filter
to retain the requested indices, and finally collect the blob sidecar(s) into a vec using .collect
.
2. Always avoid using unwrap
in production code, as it can panic
and cause Lighthouse to crash. Generally we handle the error by either logging or returning an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this current logic, if user sends 1,1,1
as inputs, it would result in the endpoint returning 3 blob sidecars. But I think it you go with using the above approach and iterate using blob_sidecar_list.into_iter()
, this shouldn't be an issue.
A small bonus would be to move this filtering logic into a function in block_id.rs
, to keep this already huge file from growing further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback !
beacon_node/http_api/src/lib.rs
Outdated
// None => { | ||
// blob_sidecar_list | ||
// }, | ||
// }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented code.
Just a minor comment on naming of blob_sidecar_list_indexed
, I think it's slightly confusing because it's just a list (potentially filtered), maybe blob_sidecar_list_filtered
or something similar would be clearer?
beacon_node/http_api/src/block_id.rs
Outdated
Some(vec) => { | ||
let list = blob_sidecar_list.into_iter() | ||
.enumerate() | ||
.filter(|(index, _)| vec.contains(index)) |
There was a problem hiding this comment.
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 more accurate to filter using the blob_sidecar.index
instead, in case if it's somehow not the same order in the list. This means we can also get rid of .enumerate
and map
.
beacon_node/http_api/src/block_id.rs
Outdated
.map(|(_, blob)| blob) | ||
.collect(); | ||
let indexed_list = BlobSidecarList::new(list); | ||
indexed_list.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is an unexpected scenario, we should always avoid using unwrap
in production code. In this case it's probably best to return a server error, something like:
BlobSidecarList::new(list)
.map_err(|e| warp_utils::reject::custom_server_error(format!("{e:?}")))?
The map_err
function maps the ssz Error
type into the required warp::Rejection
error type, and the ?
allow the error to be automatically propagated / returned.
beacon_node/http_api/src/block_id.rs
Outdated
let blob_sidecar_list_indexed = match indices.indices { | ||
Some(vec) => { | ||
let list = blob_sidecar_list.into_iter() | ||
.enumerate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code formatting seems a bit off here and will fail our CI tests, you can fix it by running
cargo fmt --all
You may also want to run clippy
to ensure the changes passes our CI. Some guidelines here in case you haven't seen it:
https://lighthouse-book.sigmaprime.io/contributing.html?highlight=fmt#rust
We'll kick off a CI workflow once this is fixed!
Hey @Gua00va, thanks for the quick fixes! 🙏 I've left a few more comments. |
beacon_node/http_api/src/block_id.rs
Outdated
let filtered_list = BlobSidecarList::new(list) | ||
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e))); | ||
filtered_list.unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .unwrap
call can be removed and return the error to the caller using ?
let filtered_list = BlobSidecarList::new(list) | |
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e))); | |
filtered_list.unwrap() | |
BlobSidecarList::new(list) | |
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e)))? |
@@ -648,6 +648,12 @@ pub struct ValidatorBalancesQuery { | |||
pub id: Option<Vec<ValidatorId>>, | |||
} | |||
|
|||
#[derive(Clone, Deserialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth adding a deny_unknown_fields
attribute here for consistency with other endpoints and return error if user provided some unknown parameters.
#[derive(Clone, Deserialize)] | |
#[derive(Clone, Deserialize)] | |
#[serde(deny_unknown_fields)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, we're close! Just two small comments and we should be good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Issue Addressed
Addresses Issue #4317
Update the getBlobSidecars endpoint as of ethereum/beacon-APIs#286.