mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(exex): use rmp-serde for WAL storage (#11353)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -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"
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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)
|
||||
})?)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@ -53,5 +53,5 @@ pub use header::{BlockHeader, Header, HeaderError, SealedHeader};
|
||||
/// Read more: <https://github.com/bincode-org/bincode/issues/326>
|
||||
#[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::*};
|
||||
}
|
||||
|
||||
@ -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;
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user