mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-04-30 03:01:58 -04:00
chore(sdk): Define MaybeSerde (#12577)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@@ -40,7 +40,8 @@ serde = [
|
||||
"revm/serde",
|
||||
"alloy-eips/serde",
|
||||
"alloy-primitives/serde",
|
||||
"rand/serde"
|
||||
"rand/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
serde-bincode-compat = [
|
||||
"reth-primitives/serde-bincode-compat",
|
||||
|
||||
@@ -78,5 +78,6 @@ serde = [
|
||||
"alloy-primitives/serde",
|
||||
"parking_lot/serde",
|
||||
"rand/serde",
|
||||
"secp256k1/serde"
|
||||
"secp256k1/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
|
||||
@@ -65,4 +65,5 @@ serde = [
|
||||
"alloy-primitives/serde",
|
||||
"bytes/serde",
|
||||
"rand/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
|
||||
@@ -87,7 +87,8 @@ serde = [
|
||||
"rand/serde",
|
||||
"secp256k1/serde",
|
||||
"reth-codecs/serde",
|
||||
"alloy-chains/serde"
|
||||
"alloy-chains/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
|
||||
[[test]]
|
||||
|
||||
@@ -121,6 +121,7 @@ serde = [
|
||||
"rand/serde",
|
||||
"smallvec/serde",
|
||||
"url/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
test-utils = [
|
||||
"dep:reth-provider",
|
||||
|
||||
@@ -119,5 +119,6 @@ serde = [
|
||||
"alloy-primitives/serde",
|
||||
"op-alloy-consensus?/serde",
|
||||
"reth-execution-types/serde",
|
||||
"reth-provider/serde"
|
||||
"reth-provider/serde",
|
||||
"reth-optimism-primitives/serde",
|
||||
]
|
||||
|
||||
@@ -12,21 +12,44 @@ description = "OP primitive types"
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
alloy-primitives.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
op-alloy-consensus.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
alloy-rlp.workspace = true
|
||||
derive_more.workspace = true
|
||||
bytes.workspace = true
|
||||
# reth
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-codecs = { workspace = true, optional = true }
|
||||
reth-primitives = { workspace = true, features = ["reth-codec"], optional = true }
|
||||
|
||||
[features]
|
||||
default = ["reth-codec"]
|
||||
reth-codec = ["dep:reth-codecs", "dep:reth-primitives"]
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
alloy-rlp.workspace = true
|
||||
|
||||
# op
|
||||
op-alloy-consensus.workspace = true
|
||||
|
||||
# codec
|
||||
bytes.workspace = true
|
||||
serde = { workspace = true, optional = true }
|
||||
|
||||
# misc
|
||||
derive_more.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
reth-codecs = { workspace = true, features = ["test-utils"] }
|
||||
rstest.workspace = true
|
||||
rstest.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["reth-codec"]
|
||||
reth-codec = [
|
||||
"dep:reth-codecs",
|
||||
"dep:reth-primitives"
|
||||
]
|
||||
serde = [
|
||||
"dep:serde",
|
||||
"reth-primitives-traits/serde",
|
||||
"alloy-primitives/serde",
|
||||
"alloy-consensus/serde",
|
||||
"alloy-eips/serde",
|
||||
"bytes/serde",
|
||||
"reth-codecs/serde",
|
||||
"op-alloy-consensus/serde",
|
||||
]
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
//! This type is required because a `Compact` impl is needed on the deposit tx type.
|
||||
|
||||
use core::fmt::Debug;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[cfg(feature = "reth-codec")]
|
||||
use alloy_consensus::constants::EIP7702_TX_TYPE_ID;
|
||||
use alloy_primitives::{U64, U8};
|
||||
use alloy_rlp::{Decodable, Encodable, Error};
|
||||
use bytes::BufMut;
|
||||
@@ -13,10 +14,6 @@ use derive_more::{
|
||||
Display,
|
||||
};
|
||||
use op_alloy_consensus::OpTxType as AlloyOpTxType;
|
||||
use reth_primitives_traits::{InMemorySize, TxType};
|
||||
|
||||
#[cfg(feature = "reth-codec")]
|
||||
use alloy_consensus::constants::EIP7702_TX_TYPE_ID;
|
||||
#[cfg(feature = "reth-codec")]
|
||||
use op_alloy_consensus::DEPOSIT_TX_TYPE_ID;
|
||||
#[cfg(feature = "reth-codec")]
|
||||
@@ -24,8 +21,9 @@ use reth_primitives::transaction::{
|
||||
COMPACT_EXTENDED_IDENTIFIER_FLAG, COMPACT_IDENTIFIER_EIP1559, COMPACT_IDENTIFIER_EIP2930,
|
||||
COMPACT_IDENTIFIER_LEGACY,
|
||||
};
|
||||
use reth_primitives_traits::{InMemorySize, TxType};
|
||||
|
||||
/// Wrapper type for `AlloyOpTxType` to implement `TxType` trait.
|
||||
/// Wrapper type for [`op_alloy_consensus::OpTxType`] to implement [`TxType`] trait.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Display, Ord, Hash, From, Into)]
|
||||
#[into(u8)]
|
||||
pub struct OpTxType(AlloyOpTxType);
|
||||
|
||||
@@ -12,15 +12,16 @@ description = "Common types in reth."
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-codecs.workspace = true
|
||||
|
||||
alloy-consensus = { workspace = true, features = ["serde"] }
|
||||
# ethereum
|
||||
alloy-consensus.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
alloy-genesis.workspace = true
|
||||
alloy-primitives.workspace = true
|
||||
alloy-rlp.workspace = true
|
||||
|
||||
revm-primitives = { workspace = true, features = ["serde"] }
|
||||
revm-primitives.workspace = true
|
||||
|
||||
# misc
|
||||
byteorder = "1"
|
||||
@@ -76,7 +77,19 @@ arbitrary = [
|
||||
"reth-codecs/arbitrary"
|
||||
]
|
||||
serde-bincode-compat = [
|
||||
"serde",
|
||||
"serde_with",
|
||||
"alloy-consensus/serde-bincode-compat",
|
||||
"alloy-eips/serde-bincode-compat"
|
||||
]
|
||||
serde = [
|
||||
"alloy-consensus/serde",
|
||||
"alloy-eips/serde",
|
||||
"alloy-primitives/serde",
|
||||
"bytes/serde",
|
||||
"rand/serde",
|
||||
"reth-codecs/serde",
|
||||
"revm-primitives/serde",
|
||||
"roaring/serde",
|
||||
"revm-primitives/serde",
|
||||
]
|
||||
@@ -6,7 +6,6 @@ use bytes::Buf;
|
||||
use derive_more::Deref;
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, BytecodeDecodeError, JumpTable};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Identifier for [`LegacyRaw`](RevmBytecode::LegacyRaw).
|
||||
const LEGACY_RAW_BYTECODE_ID: u8 = 0;
|
||||
@@ -24,7 +23,8 @@ const EOF_BYTECODE_ID: u8 = 3;
|
||||
const EIP7702_BYTECODE_ID: u8 = 4;
|
||||
|
||||
/// An Ethereum account.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Serialize, Deserialize, Compact)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Compact)]
|
||||
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
pub struct Account {
|
||||
@@ -60,7 +60,8 @@ impl Account {
|
||||
/// Bytecode for an account.
|
||||
///
|
||||
/// A wrapper around [`revm::primitives::Bytecode`][RevmBytecode] with encoding/decoding support.
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Deref)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Deref)]
|
||||
pub struct Bytecode(pub RevmBytecode);
|
||||
|
||||
impl Bytecode {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Block body abstraction.
|
||||
|
||||
use crate::InMemorySize;
|
||||
use crate::{InMemorySize, MaybeSerde};
|
||||
use alloc::fmt;
|
||||
use alloy_consensus::Transaction;
|
||||
|
||||
@@ -15,11 +15,10 @@ pub trait BlockBody:
|
||||
+ fmt::Debug
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ serde::Serialize
|
||||
+ for<'de> serde::Deserialize<'de>
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ InMemorySize
|
||||
+ MaybeSerde
|
||||
{
|
||||
/// Ordered list of signed transactions as committed in block.
|
||||
// todo: requires trait for signed transaction
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
//! Block header data primitive.
|
||||
|
||||
use crate::InMemorySize;
|
||||
use alloy_primitives::Sealable;
|
||||
use core::fmt;
|
||||
|
||||
use alloy_primitives::Sealable;
|
||||
use reth_codecs::Compact;
|
||||
|
||||
use crate::{InMemorySize, MaybeSerde};
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block header to support full node
|
||||
/// operations.
|
||||
pub trait FullBlockHeader: BlockHeader + Compact {}
|
||||
@@ -26,6 +28,7 @@ pub trait BlockHeader:
|
||||
+ alloy_consensus::BlockHeader
|
||||
+ Sealable
|
||||
+ InMemorySize
|
||||
+ MaybeSerde
|
||||
{
|
||||
}
|
||||
|
||||
@@ -38,12 +41,11 @@ impl<T> BlockHeader for T where
|
||||
+ fmt::Debug
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ serde::Serialize
|
||||
+ for<'de> serde::Deserialize<'de>
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ alloy_consensus::BlockHeader
|
||||
+ Sealable
|
||||
+ InMemorySize
|
||||
+ MaybeSerde
|
||||
{
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use alloc::fmt;
|
||||
|
||||
use reth_codecs::Compact;
|
||||
|
||||
use crate::{BlockHeader, FullBlockHeader, InMemorySize};
|
||||
use crate::{BlockHeader, FullBlockHeader, InMemorySize, MaybeSerde};
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
||||
pub trait FullBlock: Block<Header: Compact> + Compact {}
|
||||
@@ -20,17 +20,7 @@ impl<T> FullBlock for T where T: Block<Header: FullBlockHeader> + Compact {}
|
||||
// senders
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait Block:
|
||||
Send
|
||||
+ Sync
|
||||
+ Unpin
|
||||
+ Clone
|
||||
+ Default
|
||||
+ fmt::Debug
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ serde::Serialize
|
||||
+ for<'a> serde::Deserialize<'a>
|
||||
+ InMemorySize
|
||||
Send + Sync + Unpin + Clone + Default + fmt::Debug + PartialEq + Eq + InMemorySize + MaybeSerde
|
||||
{
|
||||
/// Header part of the block.
|
||||
type Header: BlockHeader + 'static;
|
||||
|
||||
@@ -92,3 +92,16 @@ pub trait MaybeArbitrary {}
|
||||
impl<T> MaybeArbitrary for T where T: for<'a> arbitrary::Arbitrary<'a> {}
|
||||
#[cfg(not(any(feature = "test-utils", feature = "arbitrary")))]
|
||||
impl<T> MaybeArbitrary for T {}
|
||||
|
||||
/// Helper trait that requires de-/serialize implementation since `serde` feature is enabled.
|
||||
#[cfg(feature = "serde")]
|
||||
pub trait MaybeSerde: serde::Serialize + for<'de> serde::Deserialize<'de> {}
|
||||
/// Noop. Helper trait that would require de-/serialize implementation if `serde` feature were
|
||||
/// enabled.
|
||||
#[cfg(not(feature = "serde"))]
|
||||
pub trait MaybeSerde {}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
impl<T> MaybeSerde for T where T: serde::Serialize + for<'de> serde::Deserialize<'de> {}
|
||||
#[cfg(not(feature = "serde"))]
|
||||
impl<T> MaybeSerde for T {}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use core::fmt;
|
||||
|
||||
use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx, FullTxType};
|
||||
use crate::{BlockBody, FullBlock, FullReceipt, FullSignedTx, FullTxType, MaybeSerde};
|
||||
|
||||
/// Configures all the primitive types of the node.
|
||||
pub trait NodePrimitives: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static {
|
||||
/// Block primitive.
|
||||
type Block: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static;
|
||||
type Block: Send + Sync + Unpin + Clone + Default + fmt::Debug + MaybeSerde + 'static;
|
||||
/// Signed version of the transaction type.
|
||||
type SignedTx: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static;
|
||||
type SignedTx: Send + Sync + Unpin + Clone + Default + fmt::Debug + MaybeSerde + 'static;
|
||||
/// Transaction envelope type ID.
|
||||
type TxType: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static;
|
||||
/// A receipt.
|
||||
type Receipt: Send + Sync + Unpin + Clone + Default + fmt::Debug + 'static;
|
||||
type Receipt: Send + Sync + Unpin + Clone + Default + fmt::Debug + MaybeSerde + 'static;
|
||||
}
|
||||
|
||||
impl NodePrimitives for () {
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
//! Receipt abstraction
|
||||
|
||||
use crate::{InMemorySize, MaybeSerde};
|
||||
use alloc::vec::Vec;
|
||||
use alloy_consensus::TxReceipt;
|
||||
use alloy_primitives::B256;
|
||||
use core::fmt;
|
||||
use reth_codecs::Compact;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::InMemorySize;
|
||||
|
||||
/// Helper trait that unifies all behaviour required by receipt to support full node operations.
|
||||
pub trait FullReceipt: Receipt + Compact {}
|
||||
@@ -26,9 +24,8 @@ pub trait Receipt:
|
||||
+ TxReceipt
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ Serialize
|
||||
+ MaybeSerde
|
||||
+ InMemorySize
|
||||
+ for<'de> Deserialize<'de>
|
||||
{
|
||||
/// Returns transaction type.
|
||||
fn tx_type(&self) -> u8;
|
||||
|
||||
@@ -6,9 +6,8 @@ use core::{fmt, hash::Hash};
|
||||
|
||||
use alloy_primitives::B256;
|
||||
use reth_codecs::Compact;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{FullTxType, InMemorySize, MaybeArbitrary, TxType};
|
||||
use crate::{FullTxType, InMemorySize, MaybeArbitrary, MaybeSerde, TxType};
|
||||
|
||||
/// Helper trait that unifies all behaviour required by transaction to support full node operations.
|
||||
pub trait FullTransaction: Transaction<Type: FullTxType> + Compact {}
|
||||
@@ -26,10 +25,9 @@ pub trait Transaction:
|
||||
+ Eq
|
||||
+ PartialEq
|
||||
+ Hash
|
||||
+ Serialize
|
||||
+ for<'de> Deserialize<'de>
|
||||
+ TransactionExt
|
||||
+ InMemorySize
|
||||
+ MaybeSerde
|
||||
+ MaybeArbitrary
|
||||
{
|
||||
}
|
||||
@@ -44,10 +42,9 @@ impl<T> Transaction for T where
|
||||
+ Eq
|
||||
+ PartialEq
|
||||
+ Hash
|
||||
+ Serialize
|
||||
+ for<'de> Deserialize<'de>
|
||||
+ TransactionExt
|
||||
+ InMemorySize
|
||||
+ MaybeSerde
|
||||
+ MaybeArbitrary
|
||||
{
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256};
|
||||
use reth_codecs::Compact;
|
||||
use revm_primitives::TxEnv;
|
||||
|
||||
use crate::{FullTransaction, InMemorySize, MaybeArbitrary, Transaction};
|
||||
use crate::{FullTransaction, InMemorySize, MaybeArbitrary, MaybeSerde, Transaction};
|
||||
|
||||
/// Helper trait that unifies all behaviour required by block to support full node operations.
|
||||
pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + Compact {}
|
||||
@@ -27,13 +27,12 @@ pub trait SignedTransaction:
|
||||
+ PartialEq
|
||||
+ Eq
|
||||
+ Hash
|
||||
+ serde::Serialize
|
||||
+ for<'a> serde::Deserialize<'a>
|
||||
+ alloy_rlp::Encodable
|
||||
+ alloy_rlp::Decodable
|
||||
+ Encodable2718
|
||||
+ Decodable2718
|
||||
+ alloy_consensus::Transaction
|
||||
+ MaybeSerde
|
||||
+ MaybeArbitrary
|
||||
+ InMemorySize
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
reth-ethereum-forks.workspace = true
|
||||
reth-static-file-types.workspace = true
|
||||
revm-primitives = { workspace = true, features = ["serde"] }
|
||||
|
||||
@@ -59,4 +59,5 @@ serde = [
|
||||
"alloy-eips/serde",
|
||||
"alloy-primitives/serde",
|
||||
"alloy-consensus/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
|
||||
@@ -81,7 +81,7 @@ serde = [
|
||||
"alloy-primitives/serde",
|
||||
"alloy-trie?/serde",
|
||||
"bytes/serde",
|
||||
"op-alloy-consensus?/serde"
|
||||
"op-alloy-consensus?/serde",
|
||||
]
|
||||
arbitrary = [
|
||||
"alloy-consensus?/arbitrary",
|
||||
|
||||
@@ -16,7 +16,7 @@ workspace = true
|
||||
reth-codecs.workspace = true
|
||||
reth-db-models.workspace = true
|
||||
reth-primitives = { workspace = true, features = ["reth-codec"] }
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
reth-prune-types.workspace = true
|
||||
reth-stages-types.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
|
||||
@@ -14,7 +14,7 @@ workspace = true
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-codecs.workspace = true
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
|
||||
@@ -15,7 +15,7 @@ workspace = true
|
||||
# reth
|
||||
reth-db-api.workspace = true
|
||||
reth-primitives = { workspace = true, features = ["reth-codec"] }
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
reth-fs-util.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
reth-nippy-jar.workspace = true
|
||||
|
||||
@@ -110,6 +110,7 @@ serde = [
|
||||
"rand/serde",
|
||||
"revm/serde",
|
||||
"reth-codecs/serde",
|
||||
"reth-optimism-primitives?/serde",
|
||||
]
|
||||
test-utils = [
|
||||
"reth-db/test-utils",
|
||||
|
||||
@@ -88,6 +88,7 @@ serde = [
|
||||
"rand?/serde",
|
||||
"revm/serde",
|
||||
"smallvec/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
]
|
||||
test-utils = [
|
||||
"rand",
|
||||
|
||||
@@ -12,7 +12,7 @@ description = "Commonly used types for trie usage in reth."
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
reth-codecs.workspace = true
|
||||
|
||||
alloy-primitives.workspace = true
|
||||
|
||||
Reference in New Issue
Block a user