chore: remove serde support from reth-codec (#9570)

This commit is contained in:
nk_ysg
2024-07-17 19:37:45 +08:00
committed by GitHub
parent ffb44e6245
commit 0befab52c9
26 changed files with 116 additions and 42 deletions

View File

@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
/// An Ethereum account.
#[reth_codec]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct Account {
/// Account nonce.
pub nonce: u64,

View File

@ -18,11 +18,12 @@ use bytes::BufMut;
use core::mem;
use reth_codecs::{add_arbitrary_tests, reth_codec, Compact};
use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas};
use serde::{Deserialize, Serialize};
/// Block header
#[reth_codec(no_arbitrary)]
#[add_arbitrary_tests(rlp, 25)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Header {
/// The Keccak 256-bit hash of the parent
/// blocks header, in its entirety; formally Hp.

View File

@ -8,12 +8,13 @@ use bytes::BufMut;
use core::mem;
use derive_more::{AsRef, Deref};
use reth_codecs::{add_arbitrary_tests, reth_codec, Compact};
use serde::{Deserialize, Serialize};
/// A [`Header`] that is sealed at a precalculated hash, use [`SealedHeader::unseal()`] if you want
/// to modify header.
#[reth_codec(no_arbitrary)]
#[add_arbitrary_tests(rlp, compact)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Serialize, Deserialize)]
pub struct SealedHeader {
/// Locked Header hash.
hash: BlockHash,

View File

@ -20,11 +20,14 @@ mod tests {
use proptest::proptest;
use proptest_arbitrary_interop::arb;
use reth_codecs::{reth_codec, Compact};
use serde::{Deserialize, Serialize};
/// This type is kept for compatibility tests after the codec support was added to
/// alloy-primitives Log type natively
#[reth_codec(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)]
#[derive(
Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default, Serialize, Deserialize,
)]
struct Log {
/// Contract that emitted this log.
address: Address,

View File

@ -6,13 +6,27 @@ use alloy_rlp::{Decodable, Encodable};
use derive_more::{Deref, DerefMut, From, IntoIterator};
use reth_codecs::{reth_codec, Compact};
use revm_primitives::Bytes;
use serde::{Deserialize, Serialize};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
/// A list of EIP-7685 requests.
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)]
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Default,
Hash,
Deref,
DerefMut,
From,
IntoIterator,
Serialize,
Deserialize,
)]
pub struct Requests(pub Vec<Request>);
impl Encodable for Requests {

View File

@ -10,6 +10,7 @@ use alloc::vec::Vec;
/// Re-export from `alloy_eips`.
#[doc(inline)]
pub use alloy_eips::eip4895::Withdrawal;
use serde::{Deserialize, Serialize};
/// Represents a collection of Withdrawals.
#[reth_codec]
@ -27,6 +28,8 @@ pub use alloy_eips::eip4895::Withdrawal;
IntoIterator,
RlpEncodableWrapper,
RlpDecodableWrapper,
Serialize,
Deserialize,
)]
#[as_ref(forward)]
pub struct Withdrawals(Vec<Withdrawal>);
@ -93,7 +96,18 @@ mod tests {
/// This type is kept for compatibility tests after the codec support was added to alloy-eips
/// Withdrawal type natively
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, RlpEncodable, RlpDecodable)]
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Default,
Hash,
RlpEncodable,
RlpDecodable,
Serialize,
Deserialize,
)]
struct RethWithdrawal {
/// Monotonically increasing identifier issued by consensus layer.
index: u64,

View File

@ -16,7 +16,9 @@ use alloc::{vec, vec::Vec};
/// Receipt containing result of transaction execution.
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec(no_arbitrary, zstd))]
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests)]
#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
#[derive(
Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable, Serialize, Deserialize,
)]
#[rlp(trailing)]
pub struct Receipt {
/// Receipt type.
@ -141,7 +143,7 @@ impl From<Receipt> for ReceiptWithBloom {
/// [`Receipt`] with calculated bloom filter.
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)]
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct ReceiptWithBloom {
/// Bloom filter build from logs.
pub bloom: Bloom,

View File

@ -12,12 +12,22 @@ mod tests {
use proptest::proptest;
use proptest_arbitrary_interop::arb;
use reth_codecs::{reth_codec, Compact};
use serde::{Deserialize, Serialize};
/// This type is kept for compatibility tests after the codec support was added to alloy-eips
/// AccessList type natively
#[reth_codec(rlp)]
#[derive(
Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper,
Clone,
Debug,
PartialEq,
Eq,
Hash,
Default,
RlpDecodableWrapper,
RlpEncodableWrapper,
Serialize,
Deserialize,
)]
struct RethAccessList(Vec<RethAccessListItem>);
@ -29,7 +39,18 @@ mod tests {
// This
#[reth_codec(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable)]
#[derive(
Clone,
Debug,
PartialEq,
Eq,
Hash,
Default,
RlpDecodable,
RlpEncodable,
Serialize,
Deserialize,
)]
#[serde(rename_all = "camelCase")]
struct RethAccessListItem {
/// Account address that would be loaded at the start of execution

View File

@ -8,10 +8,11 @@ use reth_codecs::Compact;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
/// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)).
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct TxEip1559 {
/// Added as EIP-155: Simple replay attack protection
pub chain_id: ChainId,

View File

@ -8,10 +8,11 @@ use reth_codecs::Compact;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
/// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)).
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct TxEip2930 {
/// Added as EIP-155: Simple replay attack protection
pub chain_id: ChainId,

View File

@ -15,12 +15,13 @@ use crate::kzg::KzgSettings;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
/// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction)
///
/// A transaction with blob hashes and max blob fee
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct TxEip4844 {
/// Added as EIP-155: Simple replay attack protection
pub chain_id: ChainId,

View File

@ -7,6 +7,7 @@ use core::mem;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
#[cfg(any(test, feature = "reth-codec"))]
use reth_codecs::Compact;
@ -15,7 +16,7 @@ use reth_codecs::Compact;
///
/// Set EOA account code for one transaction
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct TxEip7702 {
/// Added as EIP-155: Simple replay attack protection
pub chain_id: ChainId,

View File

@ -7,10 +7,11 @@ use reth_codecs::Compact;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use serde::{Deserialize, Serialize};
/// Legacy transaction.
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::reth_codec)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct TxLegacy {
/// Added as EIP-155: Simple replay attack protection
pub chain_id: Option<ChainId>,

View File

@ -4,11 +4,12 @@ use alloy_rlp::{
};
use bytes::Buf;
use reth_codecs::{reth_codec, Compact};
use serde::{Deserialize, Serialize};
use std::mem;
/// Deposit transactions, also known as deposits are initiated on L1, and executed on L2.
#[cfg_attr(any(test, feature = "reth-codec"), reth_codec)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
pub struct TxDeposit {
/// Hash that uniquely identifies the source of the deposit.
pub source_hash: B256,

View File

@ -1,10 +1,11 @@
use crate::PruneMode;
use alloy_primitives::{BlockNumber, TxNumber};
use reth_codecs::{reth_codec, Compact};
use serde::{Deserialize, Serialize};
/// Saves the pruning progress of a stage.
#[reth_codec]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
#[cfg_attr(test, derive(Default))]
pub struct PruneCheckpoint {
/// Highest pruned block number. If it's [None], the pruning for block `0` is not finished yet.

View File

@ -1,10 +1,11 @@
use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError};
use alloy_primitives::BlockNumber;
use reth_codecs::{reth_codec, Compact};
use serde::{Deserialize, Serialize};
/// Prune mode.
#[reth_codec]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PruneMode {
/// Prune all blocks.

View File

@ -1,11 +1,14 @@
use crate::MINIMUM_PRUNING_DISTANCE;
use derive_more::Display;
use reth_codecs::{reth_codec, Compact};
use serde::{Deserialize, Serialize};
use thiserror::Error;
/// Segment of the data that can be pruned.
#[reth_codec]
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(
Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
)]
pub enum PruneSegment {
/// Prune segment responsible for the `TransactionSenders` table.
SenderRecovery,

View File

@ -2,6 +2,7 @@ use alloy_primitives::{Address, BlockNumber, B256};
use bytes::Buf;
use reth_codecs::{reth_codec, Compact};
use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode};
use serde::{Deserialize, Serialize};
use std::ops::RangeInclusive;
use super::StageId;
@ -75,7 +76,7 @@ impl Compact for MerkleCheckpoint {
/// Saves the progress of AccountHashing stage.
#[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AccountHashingCheckpoint {
/// The next account to start hashing from.
pub address: Option<Address>,
@ -87,7 +88,7 @@ pub struct AccountHashingCheckpoint {
/// Saves the progress of StorageHashing stage.
#[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StorageHashingCheckpoint {
/// The next account to start hashing from.
pub address: Option<Address>,
@ -101,7 +102,7 @@ pub struct StorageHashingCheckpoint {
/// Saves the progress of Execution stage.
#[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExecutionCheckpoint {
/// Block range which this checkpoint is valid for.
pub block_range: CheckpointBlockRange,
@ -111,7 +112,7 @@ pub struct ExecutionCheckpoint {
/// Saves the progress of Headers stage.
#[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HeadersCheckpoint {
/// Block range which this checkpoint is valid for.
pub block_range: CheckpointBlockRange,
@ -121,7 +122,7 @@ pub struct HeadersCheckpoint {
/// Saves the progress of Index History stages.
#[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct IndexHistoryCheckpoint {
/// Block range which this checkpoint is valid for.
pub block_range: CheckpointBlockRange,
@ -131,7 +132,7 @@ pub struct IndexHistoryCheckpoint {
/// Saves the progress of abstract stage iterating over or downloading entities.
#[reth_codec]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
pub struct EntitiesCheckpoint {
/// Number of entities already processed.
pub processed: u64,
@ -159,7 +160,7 @@ impl EntitiesCheckpoint {
/// Saves the block range. Usually, it's used to check the validity of some stage checkpoint across
/// multiple executions.
#[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct CheckpointBlockRange {
/// The first block of the range, inclusive.
pub from: BlockNumber,
@ -181,7 +182,7 @@ impl From<&RangeInclusive<BlockNumber>> for CheckpointBlockRange {
/// Saves the progress of a stage.
#[reth_codec]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
pub struct StageCheckpoint {
/// The maximum block processed by the stage.
pub block_number: BlockNumber,
@ -247,7 +248,7 @@ impl StageCheckpoint {
// is not a Copy type.
/// Stage-specific checkpoint metrics.
#[reth_codec]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
pub enum StageUnitCheckpoint {
/// Saves the progress of AccountHashing stage.
Account(AccountHashingCheckpoint),

View File

@ -45,13 +45,13 @@ pub fn reth_codec(args: TokenStream, input: TokenStream) -> TokenStream {
let compact = if with_zstd {
quote! {
#[derive(CompactZstd, serde::Serialize, serde::Deserialize)]
#[derive(CompactZstd)]
#ast
}
.into()
} else {
quote! {
#[derive(Compact, serde::Serialize, serde::Deserialize)]
#[derive(Compact)]
#ast
}
.into()

View File

@ -3,12 +3,13 @@ use alloy_eips::eip7702::{Authorization as AlloyAuthorization, SignedAuthorizati
use alloy_primitives::{Address, ChainId, U256};
use bytes::Buf;
use reth_codecs_derive::reth_codec;
use serde::{Deserialize, Serialize};
/// Authorization acts as bridge which simplifies Compact implementation for AlloyAuthorization.
///
/// Notice: Make sure this struct is 1:1 with `alloy_eips::eip7702::Authorization`
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
struct Authorization {
chain_id: ChainId,
address: Address,

View File

@ -2,12 +2,13 @@ use crate::Compact;
use alloy_genesis::GenesisAccount as AlloyGenesisAccount;
use alloy_primitives::{Bytes, B256, U256};
use reth_codecs_derive::reth_codec;
use serde::{Deserialize, Serialize};
/// GenesisAccount acts as bridge which simplifies Compact implementation for AlloyGenesisAccount.
///
/// Notice: Make sure this struct is 1:1 with `alloy_genesis::GenesisAccount`
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
struct GenesisAccount {
/// The nonce of the account at genesis.
nonce: Option<u64>,
@ -22,13 +23,13 @@ struct GenesisAccount {
}
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
struct StorageEntries {
entries: Vec<StorageEntry>,
}
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
struct StorageEntry {
key: B256,
value: B256,

View File

@ -2,12 +2,13 @@ use crate::Compact;
use alloy_eips::eip4895::Withdrawal as AlloyWithdrawal;
use alloy_primitives::Address;
use reth_codecs_derive::reth_codec;
use serde::{Deserialize, Serialize};
/// Withdrawal acts as bridge which simplifies Compact implementation for AlloyWithdrawal.
///
/// Notice: Make sure this struct is 1:1 with `alloy_eips::eip4895::Withdrawal`
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
struct Withdrawal {
/// Monotonically increasing identifier issued by consensus layer.
index: u64,

View File

@ -414,6 +414,7 @@ const fn decode_varuint_panic() -> ! {
mod tests {
use super::*;
use alloy_primitives::B256;
use serde::{Deserialize, Serialize};
#[test]
fn compact_bytes() {
@ -556,7 +557,7 @@ mod tests {
}
#[reth_codec]
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
struct TestStruct {
f_u64: u64,
f_u256: U256,
@ -608,7 +609,7 @@ mod tests {
}
#[reth_codec]
#[derive(Debug, PartialEq, Clone, Default)]
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
enum TestEnum {
#[default]
Var0,

View File

@ -2,6 +2,7 @@
use reth_codecs::{reth_codec, Compact};
use reth_primitives::{Header, TxNumber, Withdrawals, B256};
use serde::{Deserialize, Serialize};
use std::ops::Range;
/// Total number of transactions.
@ -11,7 +12,7 @@ pub type NumTransactions = u64;
///
/// It has the pointer to the transaction Number of the first
/// transaction in the block and the total number of transactions.
#[derive(Debug, Default, Eq, PartialEq, Clone)]
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[reth_codec]
pub struct StoredBlockBodyIndices {
/// The number of the first transaction in this block
@ -69,7 +70,7 @@ impl StoredBlockBodyIndices {
///
/// It is stored as the headers of the block's uncles.
#[reth_codec]
#[derive(Debug, Default, Eq, PartialEq, Clone)]
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub struct StoredBlockOmmers {
/// The block headers of this block's uncles.
pub ommers: Vec<Header>,
@ -77,7 +78,7 @@ pub struct StoredBlockOmmers {
/// The storage representation of block withdrawals.
#[reth_codec]
#[derive(Debug, Default, Eq, PartialEq, Clone)]
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)]
pub struct StoredBlockWithdrawals {
/// The block withdrawals.
pub withdrawals: Withdrawals,

View File

@ -9,6 +9,7 @@ use reth_primitives::{Address, B256, *};
use reth_prune_types::{PruneCheckpoint, PruneSegment};
use reth_stages_types::StageCheckpoint;
use reth_trie_common::{StoredNibbles, StoredNibblesSubKey, *};
use serde::{Deserialize, Serialize};
pub mod accounts;
pub mod blocks;
@ -264,7 +265,7 @@ macro_rules! add_wrapper_struct {
$(
/// Wrapper struct so it can use StructFlags from Compact, when used as pure table values.
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct $wrapper(pub $name);
impl From<$name> for $wrapper {

View File

@ -106,7 +106,7 @@ And the corresponding trait implementations are present in the primitives crate.
[File: crates/primitives/src/transaction/mod.rs](https://github.com/paradigmxyz/reth/blob/1563506aea09049a85e5cc72c2894f3f7a371581/crates/primitives/src/transaction/mod.rs)
```rust, ignore
#[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default, Serialize, Deserialize)]
pub struct TransactionSigned {
pub hash: TxHash,
pub signature: Signature,