-
Notifications
You must be signed in to change notification settings - Fork 877
Refactored ForkVersionedResponse and ForkVersionDeserialize #7337
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
base: unstable
Are you sure you want to change the base?
Refactored ForkVersionedResponse and ForkVersionDeserialize #7337
Conversation
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.
Hi @PoulavBhowmick03 thanks for working on this! Your PR does seem to make the version
field in ForkVersionResponse
response mandatory but this issue is a bit more involved than that.
What we're looking for is to remove the need for types that implement ForkVersionDeserialize
to also implement DeserializeOwned
So I think step 1 is remove DeserializeOwned
from this trait definition
pub trait ForkVersionDeserialize: Sized + DeserializeOwned
and Step 2 is go through each type that implements ForkVersionDeserialize
and remove Deserialize
i.e. we'd want to remove Deserialize
from this derive macro since BlockContents also implements ForkVersionDeserialize
#[derive(Debug, Clone, Serialize, Deserialize, Encode)]
#[serde(bound = "E: EthSpec")]
pub struct BlockContents<E: EthSpec> {
pub block: BeaconBlock<E>,
pub kzg_proofs: KzgProofs<E>,
#[serde(with = "ssz_types::serde_utils::list_of_hex_fixed_vec")]
pub blobs: BlobsList<E>,
}
ah okay, got it! working on this |
@eserilev once i remove the the trait bound `SsePayloadAttributesV1: DeserializeOwned` is not satisfied
the following other types implement trait `Deserialize<'de>`:
&'a Path
&'a [u8]
&'a serde_json::value::RawValue
&'a str
()
(T,)
(T0, T1)
(T0, T1, T2)
and 798 others
required for `SsePayloadAttributesV1` to implement `DeserializeOwned`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20[0]?0#file:///home/odinson/lighthouse/common/eth2/src/types.rs)
mod.rs(1032, 8): required by a bound in `from_value`
the trait bound `SsePayloadAttributesV1: DeserializeOwned` is not satisfied
the following other types implement trait `lighthouse::_::_serde::Deserialize<'de>`:
&'a Path
&'a [u8]
&'a serde_json::value::RawValue
&'a str
()
(T,)
(T0, T1)
(T0, T1, T2)
and 798 others
required for `SsePayloadAttributesV1` to implement `DeserializeOwned`rustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20[1]?1#file:///home/odinson/lighthouse/common/eth2/src/types.rs)
mod.rs(1032, 8): required by a bound in `from_value` |
@PoulavBhowmick03 See my comment below. If it doesn't make sense you can push up what you have so far and I can put together a quick example |
For many of our types we use this crate called superstruct. This allows us to create variants of a type for each fork. The goal here is to remove inheriting As a more tangible example: lighthouse/common/eth2/src/types.rs Lines 1026 to 1032 in bf955c7
I think you can remove the And then in impl ForkVersionDeserialize for SsePayloadAttributes {
fn deserialize_by_fork<'de, D: serde::Deserializer<'de>>(
value: serde_json::value::Value,
fork_name: ForkName,
) -> Result<Self, D::Error> {
match fork_name {
ForkName::Bellatrix => SsePayloadAttributes::V1(serde_json::from_value(value))
.map_err(serde::de::Error::custom),
...
}
}
} That way only the superstruct fork variants implement |
@eserilev thanks! made the changes in types.rs where |
I've pushed up a commit that removes
We use this crate called We have a custom warp filter for requests that include json in the request body lighthouse/common/warp_utils/src/json.rs Lines 19 to 33 in bf955c7
This filter requires that the type being deserialized inherits The new filter
I was able to remove the Theres other types that now need to have their If you still have time to continue working on this issue, I'll leave the rest to you. Happy to work through any questions/feedback if the changes I made don't make sense. Thanks for all your work so far! The code at the moment wont compile until we fix the |
969bba4
to
51f4c32
Compare
gm. apologies for the late reply, yes i went through the changes and now it makes sense. i am working on it step by step |
@eserilev gm, so i have made changes to around 20 files in the consensus part, but there seems to be errors in the tests directory because of these changes. should I push my code for you to look at the implementation/ changes, and the next steps? |
51f4c32
to
76a8caf
Compare
@PoulavBhowmick03 yeah go ahead and push your code and i'll take a look. thanks! |
76a8caf
to
51a002c
Compare
@eserilev do take a look. i have managed to fix the errors, there just seems to be one error from the first commit of mine, for the version being mandatory now, other than that, if there is anything else to fix or any changes to be made, do let me know. thanks! |
Noting this here: ethereum/beacon-APIs#428 |
Another note: We had some weird logic where a |
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 so far! I'll do a bit more of a thorough review next week and probably get another set of eyes on this PR as well. Just one small nit for now
SsePayloadDeserializationError(String), | ||
FullPayloadDeserializationError(String), |
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.
We don't need these two error variants
ef_tests are failing, will take a deeper look there |
Alrighty! Thank you |
Sure! I'm having a look at it aswell, in case I can figure it out |
26d11db
to
c26e9f8
Compare
Hi @PoulavBhowmick03 — thanks so much for diving into this and putting in the effort. Just a heads-up: after you started working on it, I realized the underlying issue is more complex than we initially thought. It turns out we need a deeper refactor of the trait to properly unblock the EF tests for I’ve started working on that in a separate PR: Really appreciate your work here — sorry for the overlap and change in direction. |
Ah I see... Thank you for the application! It was amazing being new and a first time to work and also get such insights and help from @eserilev |
@PoulavBhowmick03 there might still be some useful things in this PR so I'll keep this open for now. We'll merge #7372 first and revisit this one afterwards. Thanks again for all your help! |
Alright! Thank you so much, and also for your help. meanwhile will try to look for other stuffs to work on |
…tored respective code in other areas
c26e9f8
to
e871c43
Compare
This pull request has merge conflicts. Could you please resolve them @PoulavBhowmick03? 🙏 |
Issue Addressed
Fixes #7286
Proposed Changes
Additional Info
Currently, only one test is failing, at
beacon_node/http_api/tests/tests.rs
at line 1621, all other tests pass