pub struct KvChainStore<'a> { /* private fields */ }kv-chainstore only.Expand description
As for now we use a KV (key/value) database to store the chain data. This struct provides a way to interact with the chain data stored in the KV store. It uses buckets to store and retrieve data concerning headers, indexes, and metadata.
It temporarily caches headers and indexes using a HashMap, which are later persisted.
Implementations§
Source§impl<'a> KvChainStore<'a>
impl<'a> KvChainStore<'a>
Sourcepub fn new(datadir: String) -> Result<KvChainStore<'a>, Error>
pub fn new(datadir: String) -> Result<KvChainStore<'a>, Error>
Creates a new KvChainStore instance in the specified directory path.
Trait Implementations§
Source§impl ChainStore for KvChainStore<'_>
impl ChainStore for KvChainStore<'_>
Source§fn check_integrity(&self) -> Result<(), Self::Error>
fn check_integrity(&self) -> Result<(), Self::Error>
For this ChainStore, since sled already checks integrity implicitly, this is a no-op.
Source§fn load_roots_for_block(
&mut self,
height: u32,
) -> Result<Option<Vec<u8>>, Self::Error>
fn load_roots_for_block( &mut self, height: u32, ) -> Result<Option<Vec<u8>>, Self::Error>
Loads the utreexo roots for a given block.
Source§fn save_roots_for_block(
&mut self,
roots: Vec<u8>,
height: u32,
) -> Result<(), Self::Error>
fn save_roots_for_block( &mut self, roots: Vec<u8>, height: u32, ) -> Result<(), Self::Error>
Saves the utreexo roots for a given block.
Source§fn load_height(&self) -> Result<Option<BestChain>, Self::Error>
fn load_height(&self) -> Result<Option<BestChain>, Self::Error>
Loads the best chain data from the metadata bucket.
Source§fn save_height(&mut self, height: &BestChain) -> Result<(), Self::Error>
fn save_height(&mut self, height: &BestChain) -> Result<(), Self::Error>
Saves the best chain data to the metadata bucket.
Source§fn get_header(
&self,
block_hash: &BlockHash,
) -> Result<Option<DiskBlockHeader>, Self::Error>
fn get_header( &self, block_hash: &BlockHash, ) -> Result<Option<DiskBlockHeader>, Self::Error>
Gets the block header using the provided block hash. If it is on cache, it returns it directly, otherwise it fetches it from the database.
Source§fn save_header(&mut self, header: &DiskBlockHeader) -> Result<(), Self::Error>
fn save_header(&mut self, header: &DiskBlockHeader) -> Result<(), Self::Error>
Saves a header to the database.
Source§fn get_block_hash(&self, height: u32) -> Result<Option<BlockHash>, Self::Error>
fn get_block_hash(&self, height: u32) -> Result<Option<BlockHash>, Self::Error>
Gets a block hash from the database using the provided height. If it’s not found in the cache, it will be fetched from the database.
Source§fn update_block_index(
&mut self,
height: u32,
hash: BlockHash,
) -> Result<(), Self::Error>
fn update_block_index( &mut self, height: u32, hash: BlockHash, ) -> Result<(), Self::Error>
Updates the block index with the provided height and hash.
type Error = Error
Source§fn get_header_by_height(
&self,
height: u32,
) -> Result<Option<DiskBlockHeader>, Self::Error>
fn get_header_by_height( &self, height: u32, ) -> Result<Option<DiskBlockHeader>, Self::Error>
Auto Trait Implementations§
impl<'a> !Freeze for KvChainStore<'a>
impl<'a> !RefUnwindSafe for KvChainStore<'a>
impl<'a> Send for KvChainStore<'a>
impl<'a> Sync for KvChainStore<'a>
impl<'a> Unpin for KvChainStore<'a>
impl<'a> !UnwindSafe for KvChainStore<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more