Skip to content
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

custom deserde impl #2017

Merged
merged 9 commits into from
Feb 9, 2025
Merged

Conversation

siosw
Copy link
Contributor

@siosw siosw commented Feb 6, 2025

closing #2015

unsure about the following:

  • maybe there is a way to do this in a less verbose way
  • when adding a V4 struct in the future, a custom deserde for V2 will have to be added. maybe there is a solution that solves this more generally

@@ -373,6 +380,161 @@ impl ExecutionPayloadV1 {
}
}

#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for ExecutionPayloadV1 {
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to touch serde on the versioned types directly but we should implement it like this for the ExecutionPayload enum

deserializing all fields and then selecting the version based on the fields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah fair, and then i guess remove the derived deserialize from the versioned types?

Copy link
Member

@mattsse mattsse Feb 6, 2025

Choose a reason for hiding this comment

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

no we need proper serde on ExecutionPayloadV1 ExecutionPayloadV2 ExecutionPayloadV3 (no changes required)

we only need manual deserde on ExecutionPayload which then is implemented like this draft

@siosw siosw force-pushed the siosw/faulty-roundtrip-fix branch 2 times, most recently from 93096cf to 8e63f18 Compare February 7, 2025 14:13
crates/rpc-types-engine/src/payload.rs Outdated Show resolved Hide resolved
crates/rpc-types-engine/src/payload.rs Outdated Show resolved Hide resolved
@siosw siosw requested a review from mattsse February 7, 2025 14:35
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

nice, tysm

one pedantic test nit

fn serde_payload_input_enum_v3() {
let response_v3 = r#"{"parentHash":"0xe927a1448525fb5d32cb50ee1408461a945ba6c39bd5cf5621407d500ecc8de9","feeRecipient":"0x0000000000000000000000000000000000000000","stateRoot":"0x10f8a0830000e8edef6d00cc727ff833f064b1950afd591ae41357f97e543119","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prevRandao":"0xe0d8b4521a7da1582a713244ffb6a86aa1726932087386e2dc7973f43fc6cb24","blockNumber":"0x1","gasLimit":"0x2ffbd2","gasUsed":"0x0","timestamp":"0x1235","extraData":"0xd883010d00846765746888676f312e32312e30856c696e7578","baseFeePerGas":"0x342770c0","blockHash":"0x44d0fa5f2f73a938ebb96a2a21679eb8dea3e7b7dd8fd9f35aa756dda8bf0a8a","transactions":[],"withdrawals":[],"blobGasUsed":"0x0","excessBlobGas":"0x0"}"#;

let payload: ExecutionPayload = serde_json::from_str(response_v3).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

can we add roundtrips to all of the tests to ensure that payload serializes into the same serde_json::Value as response_v3

transactions,
};

if let Some(withdrawals) = withdrawals {
Copy link
Member

Choose a reason for hiding this comment

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

you can also use

let Some(Some(withdrawals) = withdrawals else {
  return ...
}

syntax here

@siosw siosw force-pushed the siosw/faulty-roundtrip-fix branch from 7dfb114 to e686a2a Compare February 9, 2025 11:09
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm, ty

@mattsse mattsse merged commit dffbe3c into alloy-rs:main Feb 9, 2025
27 checks passed
@siosw siosw deleted the siosw/faulty-roundtrip-fix branch February 9, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants