diff --git a/Cargo.lock b/Cargo.lock index 0f320b2334c9..1c7c3ac78bbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7382,8 +7382,8 @@ dependencies = [ "reth-tasks", "reth-testing-utils", "reth-tracing", + "rmp-serde", "secp256k1", - "serde_json", "tempfile", "tokio", "tokio-util", @@ -9294,6 +9294,28 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "rmp" +version = "0.8.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "228ed7c16fa39782c3b3468e974aec2795e9089153cd08ee2e9aefb3613334c4" +dependencies = [ + "byteorder", + "num-traits", + "paste", +] + +[[package]] +name = "rmp-serde" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e599a477cf9840e92f2cde9a7189e67b42c57532749bf90aea6ec10facd4db" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + [[package]] name = "roaring" version = "0.10.6" diff --git a/crates/exex/exex/Cargo.toml b/crates/exex/exex/Cargo.toml index 9c3d47365d19..6a3815e4045b 100644 --- a/crates/exex/exex/Cargo.toml +++ b/crates/exex/exex/Cargo.toml @@ -17,7 +17,7 @@ reth-chain-state.workspace = true reth-chainspec.workspace = true reth-config.workspace = true reth-evm.workspace = true -reth-exex-types = { workspace = true, features = ["serde"] } +reth-exex-types = { workspace = true, features = ["serde", "serde-bincode-compat"] } reth-fs-util.workspace = true reth-metrics.workspace = true reth-node-api.workspace = true @@ -46,7 +46,7 @@ eyre.workspace = true itertools.workspace = true metrics.workspace = true parking_lot.workspace = true -serde_json.workspace = true +rmp-serde = "1.3" tracing.workspace = true [dev-dependencies] diff --git a/crates/exex/exex/src/wal/storage.rs b/crates/exex/exex/src/wal/storage.rs index 7ae98077e63d..63b65f71e4b8 100644 --- a/crates/exex/exex/src/wal/storage.rs +++ b/crates/exex/exex/src/wal/storage.rs @@ -116,8 +116,11 @@ impl Storage { Err(err) => return Err(err.into()), }; - // TODO(alexey): use rmp-serde when Alloy and Reth serde issues are resolved - Ok(serde_json::from_reader(&mut file)?) + // Deserialize using the bincode- and msgpack-compatible serde wrapper + let notification: reth_exex_types::serde_bincode_compat::ExExNotification<'_> = + rmp_serde::decode::from_read(&mut file)?; + + Ok(Some(notification.into())) } /// Writes the notification to the file with the given ID. @@ -130,9 +133,12 @@ impl Storage { let file_path = self.file_path(file_id); debug!(?file_path, "Writing notification to WAL"); + // Serialize using the bincode- and msgpack-compatible serde wrapper + let notification = + reth_exex_types::serde_bincode_compat::ExExNotification::from(notification); + Ok(reth_fs_util::atomic_write_file(&file_path, |file| { - // TODO(alexey): use rmp-serde when Alloy and Reth serde issues are resolved - serde_json::to_writer(file, notification) + rmp_serde::encode::write(file, ¬ification) })?) } } diff --git a/crates/primitives-traits/src/header/mod.rs b/crates/primitives-traits/src/header/mod.rs index 8793ad41bb69..fa9c33245359 100644 --- a/crates/primitives-traits/src/header/mod.rs +++ b/crates/primitives-traits/src/header/mod.rs @@ -11,8 +11,9 @@ pub use alloy_consensus::Header; use alloy_primitives::{Address, BlockNumber, B256, U256}; +/// Bincode-compatible header type serde implementations. #[cfg(feature = "serde-bincode-compat")] -pub(super) mod serde_bincode_compat { +pub mod serde_bincode_compat { pub use super::sealed::serde_bincode_compat::SealedHeader; } diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs index b77fc7f0579e..9b11f080a462 100644 --- a/crates/primitives-traits/src/header/sealed.rs +++ b/crates/primitives-traits/src/header/sealed.rs @@ -153,14 +153,14 @@ pub(super) mod serde_bincode_compat { /// /// Intended to use with the [`serde_with::serde_as`] macro in the following way: /// ```rust - /// use reth_primitives_traits::{header::SealedHeader, serde_bincode_compat}; + /// use reth_primitives_traits::{serde_bincode_compat, SealedHeader}; /// use serde::{Deserialize, Serialize}; /// use serde_with::serde_as; /// /// #[serde_as] /// #[derive(Serialize, Deserialize)] /// struct Data { - /// #[serde_as(as = "serde_bincode_compat::header::SealedHeader")] + /// #[serde_as(as = "serde_bincode_compat::SealedHeader")] /// header: SealedHeader, /// } /// ``` diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index d16fee91faba..ccc3ea13baf6 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -53,5 +53,5 @@ pub use header::{BlockHeader, Header, HeaderError, SealedHeader}; /// Read more: #[cfg(feature = "serde-bincode-compat")] pub mod serde_bincode_compat { - pub use super::header::serde_bincode_compat::*; + pub use super::header::{serde_bincode_compat as header, serde_bincode_compat::*}; } diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index a1e070e28a14..bde2cf21e2bd 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1995,7 +1995,7 @@ pub mod serde_bincode_compat { /// /// Intended to use with the [`serde_with::serde_as`] macro in the following way: /// ```rust - /// use reth_primitives_traits::{serde_bincode_compat, Transaction}; + /// use reth_primitives::{serde_bincode_compat, Transaction}; /// use serde::{Deserialize, Serialize}; /// use serde_with::serde_as; /// @@ -2069,7 +2069,7 @@ pub mod serde_bincode_compat { /// /// Intended to use with the [`serde_with::serde_as`] macro in the following way: /// ```rust - /// use reth_primitives_traits::{serde_bincode_compat, TransactionSigned}; + /// use reth_primitives::{serde_bincode_compat, TransactionSigned}; /// use serde::{Deserialize, Serialize}; /// use serde_with::serde_as; ///