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

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