feat(primitives, storage): save prune checkpoints in database (#3628)

This commit is contained in:
Alexey Shekhirin
2023-07-11 16:12:20 +01:00
committed by GitHub
parent 1763b5ea7a
commit 94129631cb
7 changed files with 54 additions and 6 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -17,7 +17,7 @@ pub enum PruneMode {
#[cfg(test)]
impl Default for PruneMode {
fn default() -> Self {
Self::Distance(0)
Self::Full
}
}

View File

@@ -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
}
}

View File

@@ -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<B: AsRef<[u8]>>(key: B) -> Result<Self, DatabaseError>;
fn decode<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError>;
}
/// Generic trait that enforces the database key to implement [`Encode`] and [`Decode`].

View File

@@ -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<u8>
);
table!(
/// Stores the highest pruned block number and prune mode of each prune part.
( PruneParts ) PrunePart | PruneCheckpoint
);
/// Alias Types
/// List with transaction numbers.

View File

@@ -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<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError> {
let buf = value.as_ref();
Ok(Self::from_compact(buf, buf.len()).0)
}
}