diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 6e96a36b8db5..753c1435fe73 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -78,7 +78,7 @@ pub use net::{ SEPOLIA_BOOTNODES, }; pub use peer::{PeerId, WithPeerId}; -pub use prune::{PruneCheckpoint, PruneMode, PruneTargets}; +pub use prune::{PruneCheckpoint, PruneMode, PrunePart, PruneTargets}; pub use receipt::{Receipt, ReceiptWithBloom, ReceiptWithBloomRef}; pub use revm_primitives::JumpMap; pub use serde_helper::JsonU256; diff --git a/crates/primitives/src/prune/mod.rs b/crates/primitives/src/prune/mod.rs index 18cb943fb975..510bc40b6e5d 100644 --- a/crates/primitives/src/prune/mod.rs +++ b/crates/primitives/src/prune/mod.rs @@ -1,7 +1,9 @@ mod checkpoint; mod mode; +mod part; mod target; pub use checkpoint::PruneCheckpoint; pub use mode::PruneMode; +pub use part::PrunePart; pub use target::PruneTargets; diff --git a/crates/primitives/src/prune/mode.rs b/crates/primitives/src/prune/mode.rs index 3fba10fe59af..b62a39041b8c 100644 --- a/crates/primitives/src/prune/mode.rs +++ b/crates/primitives/src/prune/mode.rs @@ -17,7 +17,7 @@ pub enum PruneMode { #[cfg(test)] impl Default for PruneMode { fn default() -> Self { - Self::Distance(0) + Self::Full } } diff --git a/crates/primitives/src/prune/part.rs b/crates/primitives/src/prune/part.rs new file mode 100644 index 000000000000..caa176b86a28 --- /dev/null +++ b/crates/primitives/src/prune/part.rs @@ -0,0 +1,24 @@ +use reth_codecs::{main_codec, Compact}; + +/// Part of the data that can be pruned. +#[main_codec] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)] +pub enum PrunePart { + /// Prune part responsible for the `TxSenders` table. + SenderRecovery, + /// Prune part responsible for the `TxHashNumber` table. + TransactionLookup, + /// Prune part responsible for the `Receipts` table. + Receipts, + /// Prune part responsible for the `AccountChangeSet` and `AccountHistory` tables. + AccountHistory, + /// Prune part responsible for the `StorageChangeSet` and `StorageHistory` tables. + StorageHistory, +} + +#[cfg(test)] +impl Default for PrunePart { + fn default() -> Self { + Self::SenderRecovery + } +} diff --git a/crates/storage/db/src/abstraction/table.rs b/crates/storage/db/src/abstraction/table.rs index 65d611f86856..18e66fe0e179 100644 --- a/crates/storage/db/src/abstraction/table.rs +++ b/crates/storage/db/src/abstraction/table.rs @@ -49,7 +49,7 @@ pub trait Encode: Send + Sync + Sized + Debug { /// Trait that will transform the data to be read from the DB. pub trait Decode: Send + Sync + Sized + Debug { /// Decodes data coming from the database. - fn decode>(key: B) -> Result; + fn decode>(value: B) -> Result; } /// Generic trait that enforces the database key to implement [`Encode`] and [`Decode`]. diff --git a/crates/storage/db/src/tables/mod.rs b/crates/storage/db/src/tables/mod.rs index ba44ce1ea032..924095ca71df 100644 --- a/crates/storage/db/src/tables/mod.rs +++ b/crates/storage/db/src/tables/mod.rs @@ -37,8 +37,8 @@ use crate::{ use reth_primitives::{ stage::StageCheckpoint, trie::{BranchNodeCompact, StorageTrieEntry, StoredNibbles, StoredNibblesSubKey}, - Account, Address, BlockHash, BlockNumber, Bytecode, Header, IntegerList, Receipt, StorageEntry, - TransactionSignedNoHash, TxHash, TxNumber, H256, + Account, Address, BlockHash, BlockNumber, Bytecode, Header, IntegerList, PruneCheckpoint, + PrunePart, Receipt, StorageEntry, TransactionSignedNoHash, TxHash, TxNumber, H256, }; /// Enum for the types of tables present in libmdbx. @@ -415,6 +415,11 @@ table!( ( SyncStageProgress ) StageId | Vec ); +table!( + /// Stores the highest pruned block number and prune mode of each prune part. + ( PruneParts ) PrunePart | PruneCheckpoint +); + /// Alias Types /// List with transaction numbers. diff --git a/crates/storage/db/src/tables/models/mod.rs b/crates/storage/db/src/tables/models/mod.rs index da746efda686..3bfd0fbfe95f 100644 --- a/crates/storage/db/src/tables/models/mod.rs +++ b/crates/storage/db/src/tables/models/mod.rs @@ -6,7 +6,7 @@ use crate::{ use reth_codecs::Compact; use reth_primitives::{ trie::{StoredNibbles, StoredNibblesSubKey}, - Address, H256, + Address, PrunePart, H256, }; pub mod accounts; @@ -135,3 +135,20 @@ impl Decode for StoredNibblesSubKey { Ok(Self::from_compact(buf, buf.len()).0) } } + +impl Encode for PrunePart { + type Encoded = [u8; 1]; + + fn encode(self) -> Self::Encoded { + let mut buf = [0u8]; + self.to_compact(&mut buf.as_mut()); + buf + } +} + +impl Decode for PrunePart { + fn decode>(value: B) -> Result { + let buf = value.as_ref(); + Ok(Self::from_compact(buf, buf.len()).0) + } +}