Struct KvChainStore

Source
pub struct KvChainStore<'a> { /* private fields */ }
Available on crate feature 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>

Source

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<'_>

Source§

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>

Loads the utreexo roots for a given block.

Source§

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>

Loads the best chain data from the metadata bucket.

Source§

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>

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 flush(&mut self) -> Result<(), Self::Error>

Flushes the cache to the database.

Source§

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>

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>

Updates the block index with the provided height and hash.

Source§

type Error = Error

Source§

fn get_header_by_height( &self, height: u32, ) -> Result<Option<DiskBlockHeader>, Self::Error>

Get a block header by its height in our database.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more