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

feat(consensus): bincode compatibility for header and transaction types #1397

Merged
merged 13 commits into from
Sep 30, 2024

Conversation

shekhirin
Copy link
Contributor

@shekhirin shekhirin commented Sep 28, 2024

Closes #1349

Introduces the serde-bincode-compat feature that provides bincode-compatible implementations of serde serialization/deserialization to use with serde_as macro.

Example usage

/// ```rust
/// use alloy_consensus::{serde_bincode_compat, Header};
/// use serde::{Deserialize, Serialize};
/// use serde_with::serde_as;
///
/// #[serde_as]
/// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
/// struct Data {
/// #[serde_as(as = "serde_bincode_compat::Header")]
/// header: Header,
/// }
/// ```

@shekhirin shekhirin added the enhancement New feature or request label Sep 28, 2024
@@ -64,3 +67,4 @@ serde = [
"dep:alloy-serde",
"alloy-eips/serde",
]
serde-bincode-compat = ["serde_with"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

open to renaming this feature to something more generic than bincode, because it also unlocks messagepack via https://github.com/3Hren/msgpack-rust

@shekhirin shekhirin marked this pull request as ready for review September 29, 2024 10:24
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.

why is this required for all the tx types?

@shekhirin
Copy link
Contributor Author

why is this required for all the tx types?

they have a skip_serializing_if attribute, and we use tx types in the block body in Reth

@mattsse mattsse merged commit 9f18b7a into alloy-rs:main Sep 30, 2024
26 checks passed
github-merge-queue bot pushed a commit to alloy-rs/op-alloy that referenced this pull request Sep 30, 2024
## Motivation

alloy-rs/alloy#1349

## Solution

Same as alloy-rs/alloy#1397

## PR Checklist

- [x] Added Tests
- [x] Added Documentation
- [ ] Breaking changes
lwedge99 pushed a commit to sentioxyz/alloy that referenced this pull request Oct 8, 2024
…es (alloy-rs#1397)

* fix(serde): encode optional quantity as Some

* use serialize_some

* fix in other types too

* feat(consensus): bincode compatibility for header and transaction types

* add docs

* reorganize modules

* add legacy bincode compat impl, remove comments

* less cows

* fix doctest for legacy tx

* rename feature

* more info about limitation

* remove special treatment for quantity fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Feature] Bincode support for alloy-consensus and alloy-primitive types
2 participants