From 554e8b191382718974ec72f78fd597c034c35af3 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Thu, 20 Jun 2024 11:33:53 +0100 Subject: [PATCH] feat(exex): derive serde ser/deser for `ExExNotification` (#8963) --- Cargo.lock | 3 +++ crates/ethereum-forks/Cargo.toml | 4 ++-- crates/evm/execution-types/Cargo.toml | 5 ++++- crates/evm/execution-types/src/chain.rs | 1 + .../evm/execution-types/src/execution_outcome.rs | 1 + crates/exex/exex/Cargo.toml | 5 +++++ crates/exex/exex/src/notification.rs | 1 + crates/net/discv4/Cargo.toml | 2 +- crates/net/eth-wire-types/Cargo.toml | 3 ++- crates/net/eth-wire/Cargo.toml | 2 +- crates/net/network/Cargo.toml | 2 +- crates/primitives-traits/src/lib.rs | 2 +- crates/primitives-traits/src/log.rs | 2 +- crates/primitives/src/receipt.rs | 15 ++++++++++++++- crates/storage/provider/Cargo.toml | 3 ++- crates/transaction-pool/Cargo.toml | 2 +- crates/trie/trie/Cargo.toml | 4 ++++ crates/trie/trie/src/updates.rs | 3 +++ 18 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efd35ee3f..d8642eb7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7174,6 +7174,7 @@ dependencies = [ "reth-primitives", "reth-trie", "revm", + "serde", ] [[package]] @@ -7193,6 +7194,7 @@ dependencies = [ "reth-provider", "reth-tasks", "reth-tracing", + "serde", "tokio", "tokio-util", ] @@ -8440,6 +8442,7 @@ dependencies = [ "reth-storage-errors", "reth-trie-common", "revm", + "serde", "serde_json", "similar-asserts", "tokio", diff --git a/crates/ethereum-forks/Cargo.toml b/crates/ethereum-forks/Cargo.toml index ac9836c54..bcdbc6551 100644 --- a/crates/ethereum-forks/Cargo.toml +++ b/crates/ethereum-forks/Cargo.toml @@ -36,7 +36,7 @@ proptest-derive.workspace = true [features] default = ["std", "serde"] -std = ["thiserror-no-std/std"] -serde = ["dep:serde"] arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"] optimism = [] +serde = ["dep:serde"] +std = ["thiserror-no-std/std"] diff --git a/crates/evm/execution-types/Cargo.toml b/crates/evm/execution-types/Cargo.toml index 0f0ba7547..57181537c 100644 --- a/crates/evm/execution-types/Cargo.toml +++ b/crates/evm/execution-types/Cargo.toml @@ -18,10 +18,13 @@ reth-trie.workspace = true revm.workspace = true +serde = { workspace = true, optional = true } + [dev-dependencies] reth-primitives = { workspace = true, features = ["test-utils"] } alloy-primitives.workspace = true alloy-eips.workspace = true [features] -optimism = ["dep:reth-chainspec"] \ No newline at end of file +optimism = ["dep:reth-chainspec"] +serde = ["dep:serde", "reth-trie/serde", "revm/serde"] diff --git a/crates/evm/execution-types/src/chain.rs b/crates/evm/execution-types/src/chain.rs index 47c3aef2e..8833615bb 100644 --- a/crates/evm/execution-types/src/chain.rs +++ b/crates/evm/execution-types/src/chain.rs @@ -21,6 +21,7 @@ use std::{borrow::Cow, collections::BTreeMap, fmt, ops::RangeInclusive}; /// /// A chain of blocks should not be empty. #[derive(Clone, Debug, Default, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Chain { /// All blocks in this chain. blocks: BTreeMap, diff --git a/crates/evm/execution-types/src/execution_outcome.rs b/crates/evm/execution-types/src/execution_outcome.rs index e7e861cf1..322e397a6 100644 --- a/crates/evm/execution-types/src/execution_outcome.rs +++ b/crates/evm/execution-types/src/execution_outcome.rs @@ -14,6 +14,7 @@ use std::collections::HashMap; /// The `ExecutionOutcome` structure aggregates the state changes over an arbitrary number of /// blocks, capturing the resulting state, receipts, and requests following the execution. #[derive(Default, Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ExecutionOutcome { /// Bundle state with reverts. pub bundle: BundleState, diff --git a/crates/exex/exex/Cargo.toml b/crates/exex/exex/Cargo.toml index 4df59b3fc..5bbf177d0 100644 --- a/crates/exex/exex/Cargo.toml +++ b/crates/exex/exex/Cargo.toml @@ -32,3 +32,8 @@ tokio-util.workspace = true ## misc eyre.workspace = true metrics.workspace = true +serde = { workspace = true, optional = true } + +[features] +default = [] +serde = ["dep:serde", "reth-provider/serde"] diff --git a/crates/exex/exex/src/notification.rs b/crates/exex/exex/src/notification.rs index 9f1beec41..390d9dc66 100644 --- a/crates/exex/exex/src/notification.rs +++ b/crates/exex/exex/src/notification.rs @@ -4,6 +4,7 @@ use reth_provider::{CanonStateNotification, Chain}; /// Notifications sent to an `ExEx`. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum ExExNotification { /// Chain got committed without a reorg, and only the new chain is returned. ChainCommitted { diff --git a/crates/net/discv4/Cargo.toml b/crates/net/discv4/Cargo.toml index 8c823d520..2418f4d63 100644 --- a/crates/net/discv4/Cargo.toml +++ b/crates/net/discv4/Cargo.toml @@ -52,5 +52,5 @@ reth-tracing.workspace = true [features] default = ["serde"] -test-utils = ["dep:rand"] serde = ["dep:serde"] +test-utils = ["dep:rand"] diff --git a/crates/net/eth-wire-types/Cargo.toml b/crates/net/eth-wire-types/Cargo.toml index 09b28e523..d7766043e 100644 --- a/crates/net/eth-wire-types/Cargo.toml +++ b/crates/net/eth-wire-types/Cargo.toml @@ -45,10 +45,11 @@ async-stream.workspace = true [features] default = ["serde"] -serde = ["dep:serde"] arbitrary = [ "reth-primitives/arbitrary", "dep:arbitrary", "dep:proptest", "dep:proptest-derive", ] +serde = ["dep:serde"] + diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index c4015cc9b..0add7b8a5 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -63,7 +63,6 @@ async-stream.workspace = true [features] default = ["serde"] -serde = ["dep:serde"] arbitrary = [ "reth-primitives/arbitrary", "dep:arbitrary", @@ -71,6 +70,7 @@ arbitrary = [ "dep:proptest-derive", ] optimism = ["reth-primitives/optimism"] +serde = ["dep:serde"] [[test]] name = "fuzz_roundtrip" diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index a99dfea97..7d56243f6 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -95,9 +95,9 @@ criterion = { workspace = true, features = ["async_tokio", "html_reports"] } [features] default = ["serde"] +geth-tests = [] serde = ["dep:serde", "dep:humantime-serde", "secp256k1/serde", "enr/serde", "dep:serde_json"] test-utils = ["reth-provider/test-utils", "dep:tempfile", "reth-transaction-pool/test-utils"] -geth-tests = [] [[bench]] name = "bench" diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index e936bbdf1..22d4c86a0 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -34,7 +34,7 @@ mod error; pub use error::{GotExpected, GotExpectedBoxed}; mod log; -pub use log::{logs_bloom, Log}; +pub use log::{logs_bloom, Log, LogData}; mod storage; pub use storage::StorageEntry; diff --git a/crates/primitives-traits/src/log.rs b/crates/primitives-traits/src/log.rs index cb732b47b..823385978 100644 --- a/crates/primitives-traits/src/log.rs +++ b/crates/primitives-traits/src/log.rs @@ -1,5 +1,5 @@ use alloy_primitives::Bloom; -pub use alloy_primitives::Log; +pub use alloy_primitives::{Log, LogData}; /// Calculate receipt logs bloom. pub fn logs_bloom<'a>(logs: impl IntoIterator) -> Bloom { diff --git a/crates/primitives/src/receipt.rs b/crates/primitives/src/receipt.rs index 32d2a4cd8..da84dda8b 100644 --- a/crates/primitives/src/receipt.rs +++ b/crates/primitives/src/receipt.rs @@ -11,6 +11,7 @@ use proptest::strategy::Strategy; #[cfg(feature = "zstd-codec")] use reth_codecs::CompactZstd; use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; +use serde::{Deserialize, Serialize}; #[cfg(not(feature = "std"))] use alloc::{vec, vec::Vec}; @@ -66,7 +67,19 @@ impl Receipt { } /// A collection of receipts organized as a two-dimensional vector. -#[derive(Clone, Debug, PartialEq, Eq, Default, From, Deref, DerefMut, IntoIterator)] +#[derive( + Clone, + Debug, + PartialEq, + Eq, + Default, + Serialize, + Deserialize, + From, + Deref, + DerefMut, + IntoIterator, +)] pub struct Receipts { /// A two-dimensional vector of optional `Receipt` instances. pub receipt_vec: Vec>>, diff --git a/crates/storage/provider/Cargo.toml b/crates/storage/provider/Cargo.toml index c1f87891c..6cf456665 100644 --- a/crates/storage/provider/Cargo.toml +++ b/crates/storage/provider/Cargo.toml @@ -73,5 +73,6 @@ assert_matches.workspace = true rand.workspace = true [features] -test-utils = ["alloy-rlp", "reth-db/test-utils", "reth-nippy-jar/test-utils"] optimism = ["reth-primitives/optimism", "reth-execution-types/optimism"] +serde = ["reth-execution-types/serde"] +test-utils = ["alloy-rlp", "reth-db/test-utils", "reth-nippy-jar/test-utils"] diff --git a/crates/transaction-pool/Cargo.toml b/crates/transaction-pool/Cargo.toml index eee2a0833..d66da4e19 100644 --- a/crates/transaction-pool/Cargo.toml +++ b/crates/transaction-pool/Cargo.toml @@ -67,9 +67,9 @@ serde_json.workspace = true [features] default = ["serde"] +arbitrary = ["proptest", "reth-primitives/arbitrary"] serde = ["dep:serde"] test-utils = ["rand", "paste", "serde"] -arbitrary = ["proptest", "reth-primitives/arbitrary"] [[bench]] name = "truncate" diff --git a/crates/trie/trie/Cargo.toml b/crates/trie/trie/Cargo.toml index d4e9b856b..ea28d1329 100644 --- a/crates/trie/trie/Cargo.toml +++ b/crates/trie/trie/Cargo.toml @@ -40,6 +40,9 @@ metrics = { workspace = true, optional = true } # `test-utils` feature triehash = { version = "0.8", optional = true } +# `serde` feature +serde = { workspace = true, optional = true } + [dev-dependencies] # reth reth-chainspec.workspace = true @@ -67,6 +70,7 @@ criterion.workspace = true [features] metrics = ["reth-metrics", "dep:metrics"] +serde = ["dep:serde"] test-utils = ["triehash", "reth-trie-common/test-utils"] [[bench]] diff --git a/crates/trie/trie/src/updates.rs b/crates/trie/trie/src/updates.rs index 457266eea..39628e6d5 100644 --- a/crates/trie/trie/src/updates.rs +++ b/crates/trie/trie/src/updates.rs @@ -13,6 +13,7 @@ use std::collections::{hash_map::IntoIter, HashMap, HashSet}; /// The key of a trie node. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum TrieKey { /// A node in the account trie. AccountNode(StoredNibbles), @@ -24,6 +25,7 @@ pub enum TrieKey { /// The operation to perform on the trie. #[derive(PartialEq, Eq, Debug, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum TrieOp { /// Delete the node entry. Delete, @@ -40,6 +42,7 @@ impl TrieOp { /// The aggregation of trie updates. #[derive(Debug, Default, Clone, PartialEq, Eq, Deref)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct TrieUpdates { trie_operations: HashMap, }