mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: add codec and serde features to prune types (#14327)
This commit is contained in:
@ -13,7 +13,7 @@ workspace = true
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-network-types = { workspace = true, features = ["serde"] }
|
||||
reth-prune-types.workspace = true
|
||||
reth-prune-types = { workspace = true, features = ["serde"] }
|
||||
reth-stages-types = { workspace = true, features = ["serde"] }
|
||||
|
||||
# serde
|
||||
|
||||
@ -78,4 +78,5 @@ serde = [
|
||||
"rand/serde",
|
||||
"secp256k1/serde",
|
||||
"reth-primitives-traits/serde",
|
||||
"reth-prune-types/serde",
|
||||
]
|
||||
|
||||
@ -12,16 +12,22 @@ description = "Commonly used types for prune usage in reth."
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
reth-codecs.workspace = true
|
||||
reth-codecs = { workspace = true, optional = true }
|
||||
|
||||
alloy-primitives.workspace = true
|
||||
derive_more.workspace = true
|
||||
modular-bitfield.workspace = true
|
||||
serde.workspace = true
|
||||
thiserror.workspace = true
|
||||
|
||||
modular-bitfield = { workspace = true, optional = true }
|
||||
serde = { workspace = true, features = ["derive"], optional = true }
|
||||
arbitrary = { workspace = true, features = ["derive"], optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
reth-codecs.workspace = true
|
||||
|
||||
alloy-primitives = { workspace = true, features = ["serde"] }
|
||||
serde.workspace = true
|
||||
modular-bitfield.workspace = true
|
||||
arbitrary = { workspace = true, features = ["derive"] }
|
||||
assert_matches.workspace = true
|
||||
proptest.workspace = true
|
||||
@ -33,9 +39,18 @@ toml.workspace = true
|
||||
[features]
|
||||
test-utils = [
|
||||
"dep:arbitrary",
|
||||
"reth-codecs/test-utils",
|
||||
"reth-codecs?/test-utils",
|
||||
]
|
||||
arbitrary = [
|
||||
"alloy-primitives/arbitrary",
|
||||
"reth-codecs/arbitrary",
|
||||
"reth-codecs?/arbitrary",
|
||||
]
|
||||
reth-codec = [
|
||||
"dep:reth-codecs",
|
||||
"dep:modular-bitfield",
|
||||
]
|
||||
serde = [
|
||||
"dep:serde",
|
||||
"alloy-primitives/serde",
|
||||
"reth-codecs?/serde",
|
||||
]
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use crate::PruneMode;
|
||||
use alloy_primitives::{BlockNumber, TxNumber};
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Saves the pruning progress of a stage.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Compact)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
#[cfg_attr(any(test, feature = "test-utils"), derive(Default, arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct PruneCheckpoint {
|
||||
/// Highest pruned block number. If it's [None], the pruning for block `0` is not finished yet.
|
||||
pub block_number: Option<BlockNumber>,
|
||||
|
||||
@ -23,7 +23,6 @@ pub use pruner::{
|
||||
SegmentOutputCheckpoint,
|
||||
};
|
||||
pub use segment::{PrunePurpose, PruneSegment, PruneSegmentError};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
pub use target::{PruneModes, MINIMUM_PRUNING_DISTANCE};
|
||||
|
||||
@ -31,7 +30,8 @@ use alloy_primitives::{Address, BlockNumber};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// Configuration for pruning receipts not associated with logs emitted by the specified contracts.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct ReceiptsLogPruneConfig(pub BTreeMap<Address, PruneMode>);
|
||||
|
||||
impl ReceiptsLogPruneConfig {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError};
|
||||
use alloy_primitives::BlockNumber;
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Prune mode.
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Compact)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
#[cfg_attr(any(test, feature = "test-utils"), derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(any(test, feature = "serde"), serde(rename_all = "lowercase"))]
|
||||
pub enum PruneMode {
|
||||
/// Prune all blocks.
|
||||
Full,
|
||||
|
||||
@ -1,26 +1,13 @@
|
||||
use crate::MINIMUM_PRUNING_DISTANCE;
|
||||
use derive_more::Display;
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Segment of the data that can be pruned.
|
||||
#[derive(
|
||||
Debug,
|
||||
Display,
|
||||
Clone,
|
||||
Copy,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
Hash,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Compact,
|
||||
)]
|
||||
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
#[cfg_attr(test, derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum PruneSegment {
|
||||
/// Prune segment responsible for the `TransactionSenders` table.
|
||||
SenderRecovery,
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use crate::{PruneMode, ReceiptsLogPruneConfig};
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
/// Minimum distance from the tip necessary for the node to work correctly:
|
||||
/// 1. Minimum 2 epochs (32 blocks per epoch) required to handle any reorg according to the
|
||||
@ -9,32 +8,42 @@ use serde::{Deserialize, Deserializer, Serialize};
|
||||
pub const MINIMUM_PRUNING_DISTANCE: u64 = 32 * 2 + 10_000;
|
||||
|
||||
/// Pruning configuration for every segment of the data that can be pruned.
|
||||
#[derive(Debug, Clone, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(default)]
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq)]
|
||||
#[cfg_attr(any(test, feature = "serde"), derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(any(test, feature = "serde"), serde(default))]
|
||||
pub struct PruneModes {
|
||||
/// Sender Recovery pruning configuration.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(any(test, feature = "serde"), serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub sender_recovery: Option<PruneMode>,
|
||||
/// Transaction Lookup pruning configuration.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[cfg_attr(any(test, feature = "serde"), serde(skip_serializing_if = "Option::is_none"))]
|
||||
pub transaction_lookup: Option<PruneMode>,
|
||||
/// Receipts pruning configuration. This setting overrides `receipts_log_filter`
|
||||
/// and offers improved performance.
|
||||
#[serde(
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<MINIMUM_PRUNING_DISTANCE, _>"
|
||||
#[cfg_attr(
|
||||
any(test, feature = "serde"),
|
||||
serde(
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<MINIMUM_PRUNING_DISTANCE, _>"
|
||||
)
|
||||
)]
|
||||
pub receipts: Option<PruneMode>,
|
||||
/// Account History pruning configuration.
|
||||
#[serde(
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<MINIMUM_PRUNING_DISTANCE, _>"
|
||||
#[cfg_attr(
|
||||
any(test, feature = "serde"),
|
||||
serde(
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<MINIMUM_PRUNING_DISTANCE, _>"
|
||||
)
|
||||
)]
|
||||
pub account_history: Option<PruneMode>,
|
||||
/// Storage History pruning configuration.
|
||||
#[serde(
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<MINIMUM_PRUNING_DISTANCE, _>"
|
||||
#[cfg_attr(
|
||||
any(test, feature = "serde"),
|
||||
serde(
|
||||
skip_serializing_if = "Option::is_none",
|
||||
deserialize_with = "deserialize_opt_prune_mode_with_min_blocks::<MINIMUM_PRUNING_DISTANCE, _>"
|
||||
)
|
||||
)]
|
||||
pub storage_history: Option<PruneMode>,
|
||||
/// Receipts pruning configuration by retaining only those receipts that contain logs emitted
|
||||
@ -82,9 +91,15 @@ impl PruneModes {
|
||||
/// 2. For [`PruneMode::Distance(distance`)], it fails if `distance < MIN_BLOCKS + 1`. `+ 1` is
|
||||
/// needed because `PruneMode::Distance(0)` means that we leave zero blocks from the latest,
|
||||
/// meaning we have one block in the database.
|
||||
fn deserialize_opt_prune_mode_with_min_blocks<'de, const MIN_BLOCKS: u64, D: Deserializer<'de>>(
|
||||
#[cfg(any(test, feature = "serde"))]
|
||||
fn deserialize_opt_prune_mode_with_min_blocks<
|
||||
'de,
|
||||
const MIN_BLOCKS: u64,
|
||||
D: serde::Deserializer<'de>,
|
||||
>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<PruneMode>, D::Error> {
|
||||
use serde::Deserialize;
|
||||
let prune_mode = Option::<PruneMode>::deserialize(deserializer)?;
|
||||
|
||||
match prune_mode {
|
||||
|
||||
@ -17,8 +17,8 @@ reth-codecs.workspace = true
|
||||
reth-db-models.workspace = true
|
||||
reth-primitives = { workspace = true, features = ["reth-codec"] }
|
||||
reth-primitives-traits = { workspace = true, features = ["serde", "reth-codec"] }
|
||||
reth-prune-types.workspace = true
|
||||
reth-stages-types = { workspace = true, features = ["serde", "reth-codec"] }
|
||||
reth-prune-types = { workspace = true, features = ["reth-codec"] }
|
||||
reth-storage-errors.workspace = true
|
||||
reth-trie-common.workspace = true
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ reth-primitives-traits = { workspace = true, features = ["reth-codec"] }
|
||||
reth-fs-util.workspace = true
|
||||
reth-storage-errors.workspace = true
|
||||
reth-nippy-jar.workspace = true
|
||||
reth-prune-types.workspace = true
|
||||
reth-prune-types = { workspace = true, features = ["reth-codec", "serde"] }
|
||||
reth-stages-types.workspace = true
|
||||
reth-trie-common = { workspace = true, features = ["serde"] }
|
||||
reth-tracing.workspace = true
|
||||
|
||||
@ -100,6 +100,7 @@ serde = [
|
||||
"reth-trie-db/serde",
|
||||
"reth-trie/serde",
|
||||
"reth-stages-types/serde",
|
||||
"reth-prune-types/serde",
|
||||
]
|
||||
test-utils = [
|
||||
"reth-db/test-utils",
|
||||
|
||||
Reference in New Issue
Block a user