pub struct BlockStore {
pub main: Tree,
pub order: Tree,
pub difficulty: Tree,
pub state_diff: Tree,
}
Expand description
The BlockStore
is a structure representing all sled
trees related
to storing the blockchain’s blocks information.
Fields§
§main: Tree
Main sled
tree, storing all the blockchain’s blocks, where the
key is the blocks’ hash, and value is the serialized block.
order: Tree
The sled
tree storing the order of the blockchain’s blocks,
where the key is the height number, and the value is the blocks’
hash.
difficulty: Tree
The sled
tree storing the difficulty information of the
blockchain’s blocks, where the key is the block height number,
and the value is the blocks’ hash.
state_diff: Tree
The sled
tree storing each blocks’ full database state changes,
where the key is the block height number, and the value is the
serialized database diff.
Implementations§
Source§impl BlockStore
impl BlockStore
Sourcepub fn new(db: &Db) -> Result<Self>
pub fn new(db: &Db) -> Result<Self>
Opens a new or existing BlockStore
on the given sled database.
Sourcepub fn insert(&self, blocks: &[Block]) -> Result<Vec<HeaderHash>>
pub fn insert(&self, blocks: &[Block]) -> Result<Vec<HeaderHash>>
Insert a slice of Block
into the store’s main tree.
Sourcepub fn insert_order(&self, heights: &[u32], hashes: &[HeaderHash]) -> Result<()>
pub fn insert_order(&self, heights: &[u32], hashes: &[HeaderHash]) -> Result<()>
Insert a slice of u32
and block hashes into the store’s
order tree.
Sourcepub fn insert_difficulty(
&self,
block_difficulties: &[BlockDifficulty],
) -> Result<()>
pub fn insert_difficulty( &self, block_difficulties: &[BlockDifficulty], ) -> Result<()>
Insert a slice of BlockDifficulty
into the store’s
difficulty tree.
Sourcepub fn insert_state_diff(
&self,
heights: &[u32],
diffs: &[SledDbOverlayStateDiff],
) -> Result<()>
pub fn insert_state_diff( &self, heights: &[u32], diffs: &[SledDbOverlayStateDiff], ) -> Result<()>
Insert a slice of u32
and block diffs into the store’s
database diffs tree.
Sourcepub fn insert_batch(&self, blocks: &[Block]) -> (Batch, Vec<HeaderHash>)
pub fn insert_batch(&self, blocks: &[Block]) -> (Batch, Vec<HeaderHash>)
Generate the sled batch corresponding to an insert to the main
tree, so caller can handle the write operation.
The block’s hash() function output is used as the key,
while value is the serialized Block
itself.
On success, the function returns the block hashes in the same order.
Sourcepub fn insert_batch_order(
&self,
heights: &[u32],
hashes: &[HeaderHash],
) -> Batch
pub fn insert_batch_order( &self, heights: &[u32], hashes: &[HeaderHash], ) -> Batch
Generate the sled batch corresponding to an insert to the order tree, so caller can handle the write operation. The block height is used as the key, and the block hash is used as value.
Sourcepub fn insert_batch_difficulty(
&self,
block_difficulties: &[BlockDifficulty],
) -> Batch
pub fn insert_batch_difficulty( &self, block_difficulties: &[BlockDifficulty], ) -> Batch
Generate the sled batch corresponding to an insert to the difficulty tree, so caller can handle the write operation. The block’s height number is used as the key, while value is
Sourcepub fn insert_batch_state_diff(
&self,
heights: &[u32],
diffs: &[SledDbOverlayStateDiff],
) -> Batch
pub fn insert_batch_state_diff( &self, heights: &[u32], diffs: &[SledDbOverlayStateDiff], ) -> Batch
Generate the sled batch corresponding to an insert to the database diffs tree, so caller can handle the write operation. The block height is used as the key, and the serialized database diff is used as value.
Sourcepub fn contains(&self, blockhash: &HeaderHash) -> Result<bool>
pub fn contains(&self, blockhash: &HeaderHash) -> Result<bool>
Check if the store’s main tree contains a given block hash.
Sourcepub fn contains_order(&self, height: u32) -> Result<bool>
pub fn contains_order(&self, height: u32) -> Result<bool>
Check if the store’s order tree contains a given height.
Sourcepub fn get(
&self,
block_hashes: &[HeaderHash],
strict: bool,
) -> Result<Vec<Option<Block>>>
pub fn get( &self, block_hashes: &[HeaderHash], strict: bool, ) -> Result<Vec<Option<Block>>>
Fetch given block hashes from the store’s main tree.
The resulting vector contains Option
, which is Some
if the block
was found in the block store, and otherwise it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one block was not found.
Sourcepub fn get_order(
&self,
heights: &[u32],
strict: bool,
) -> Result<Vec<Option<HeaderHash>>>
pub fn get_order( &self, heights: &[u32], strict: bool, ) -> Result<Vec<Option<HeaderHash>>>
Fetch given heights from the store’s order tree.
The resulting vector contains Option
, which is Some
if the height
was found in the block order store, and otherwise it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one height was not found.
Sourcepub fn get_difficulty(
&self,
heights: &[u32],
strict: bool,
) -> Result<Vec<Option<BlockDifficulty>>>
pub fn get_difficulty( &self, heights: &[u32], strict: bool, ) -> Result<Vec<Option<BlockDifficulty>>>
Fetch given block height numbers from the store’s difficulty tree.
The resulting vector contains Option
, which is Some
if the block
height number was found in the block difficulties store, and otherwise
it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one block height number was not found.
Sourcepub fn get_state_diff(
&self,
heights: &[u32],
strict: bool,
) -> Result<Vec<Option<SledDbOverlayStateDiff>>>
pub fn get_state_diff( &self, heights: &[u32], strict: bool, ) -> Result<Vec<Option<SledDbOverlayStateDiff>>>
Fetch given block height numbers from the store’s state diffs tree.
The resulting vector contains Option
, which is Some
if the block
height number was found in the block database diffs store, and otherwise
it is None
, if it has not.
The second parameter is a boolean which tells the function to fail in
case at least one block height number was not found.
Sourcepub fn get_all(&self) -> Result<Vec<(HeaderHash, Block)>>
pub fn get_all(&self) -> Result<Vec<(HeaderHash, Block)>>
Retrieve all blocks from the store’s main tree in the form of a
tuple (hash
, block
).
Be careful as this will try to load everything in memory.
Sourcepub fn get_all_order(&self) -> Result<Vec<(u32, HeaderHash)>>
pub fn get_all_order(&self) -> Result<Vec<(u32, HeaderHash)>>
Retrieve complete order from the store’s order tree in the form
of a vector containing (height
, hash
) tuples.
Be careful as this will try to load everything in memory.
Sourcepub fn get_order_by_range(
&self,
start: u32,
end: u32,
) -> Result<Vec<(u32, HeaderHash)>>
pub fn get_order_by_range( &self, start: u32, end: u32, ) -> Result<Vec<(u32, HeaderHash)>>
Fetches the blocks within a specified range of height from the store’s order tree
returning a collection of block heights with their associated HeaderHash
s.
Sourcepub fn get_all_difficulty(&self) -> Result<Vec<(u32, BlockDifficulty)>>
pub fn get_all_difficulty(&self) -> Result<Vec<(u32, BlockDifficulty)>>
Retrieve all block difficulties from the store’s difficulty tree in
the form of a vector containing (height
, difficulty
) tuples.
Be careful as this will try to load everything in memory.
Sourcepub fn get_before(&self, height: u32, n: usize) -> Result<Vec<HeaderHash>>
pub fn get_before(&self, height: u32, n: usize) -> Result<Vec<HeaderHash>>
Fetch n hashes before given height. In the iteration, if an order height is not found, the iteration stops and the function returns what it has found so far in the store’s order tree.
Sourcepub fn get_all_after(&self, height: u32) -> Result<Vec<HeaderHash>>
pub fn get_all_after(&self, height: u32) -> Result<Vec<HeaderHash>>
Fetch all hashes after given height. In the iteration, if an order height is not found, the iteration stops and the function returns what it has found so far in the store’s order tree.
Sourcepub fn get_first(&self) -> Result<(u32, HeaderHash)>
pub fn get_first(&self) -> Result<(u32, HeaderHash)>
Fetch the first block hash in the order tree, based on the Ord
implementation for Vec<u8>
.
Sourcepub fn get_last(&self) -> Result<(u32, HeaderHash)>
pub fn get_last(&self) -> Result<(u32, HeaderHash)>
Fetch the last block hash in the order tree, based on the Ord
implementation for Vec<u8>
.
Sourcepub fn get_last_n_orders(&self, n: usize) -> Result<Vec<(u32, HeaderHash)>>
pub fn get_last_n_orders(&self, n: usize) -> Result<Vec<(u32, HeaderHash)>>
Fetch the last N records from order tree
Sourcepub fn get_last_difficulty(&self) -> Result<Option<BlockDifficulty>>
pub fn get_last_difficulty(&self) -> Result<Option<BlockDifficulty>>
Fetch the last record in the difficulty tree, based on the Ord
implementation for Vec<u8>
. If the tree is empty,
returns None
.
Sourcepub fn get_last_n_difficulties(&self, n: usize) -> Result<Vec<BlockDifficulty>>
pub fn get_last_n_difficulties(&self, n: usize) -> Result<Vec<BlockDifficulty>>
Fetch the last N records from the store’s difficulty tree, in order.
Sourcepub fn get_difficulties_before(
&self,
height: u32,
n: usize,
) -> Result<Vec<BlockDifficulty>>
pub fn get_difficulties_before( &self, height: u32, n: usize, ) -> Result<Vec<BlockDifficulty>>
Fetch N records before given height from the store’s difficulty tree, in order. In the iteration, if a record height is not found, the iteration stops and the function returns what it has found so far in the store’s difficulty tree.
Sourcepub fn get_state_diffs_after(
&self,
height: u32,
) -> Result<Vec<SledDbOverlayStateDiff>>
pub fn get_state_diffs_after( &self, height: u32, ) -> Result<Vec<SledDbOverlayStateDiff>>
Fetch all state diffs after given height. In the iteration, if a state diff is not found, the iteration stops and the function returns what it has found so far in the store’s state diffs tree.
Trait Implementations§
Source§impl Clone for BlockStore
impl Clone for BlockStore
Source§fn clone(&self) -> BlockStore
fn clone(&self) -> BlockStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for BlockStore
impl !RefUnwindSafe for BlockStore
impl Send for BlockStore
impl Sync for BlockStore
impl Unpin for BlockStore
impl !UnwindSafe for BlockStore
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2where
T: SharedNiching<N1, N2>,
N1: Niching<T>,
N2: Niching<T>,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.