pub struct NonFinalizedState {
pub network: Network,
/* private fields */
}
Expand description
The state of the chains in memory, including queued blocks.
Clones of the non-finalized state contain independent copies of the chains.
This is different from FinalizedState::clone()
,
which returns a shared reference to the database.
Most chain data is clone-on-write using Arc
.
Fields§
§network: Network
The configured Zcash network.
Implementations§
Source§impl NonFinalizedState
impl NonFinalizedState
Sourcepub fn new(network: &Network) -> NonFinalizedState
pub fn new(network: &Network) -> NonFinalizedState
Returns a new non-finalized state for network
.
Sourcepub fn chain_iter(&self) -> impl Iterator<Item = &Arc<Chain>>
pub fn chain_iter(&self) -> impl Iterator<Item = &Arc<Chain>>
Returns an iterator over the non-finalized chains, with the best chain first.
Sourcepub fn finalize(&mut self) -> FinalizableBlock
pub fn finalize(&mut self) -> FinalizableBlock
Finalize the lowest height block in the non-finalized portion of the best chain and update all side-chains to match.
Sourcepub fn commit_block(
&mut self,
prepared: SemanticallyVerifiedBlock,
finalized_state: &ZebraDb,
) -> Result<(), ValidateContextError>
pub fn commit_block( &mut self, prepared: SemanticallyVerifiedBlock, finalized_state: &ZebraDb, ) -> Result<(), ValidateContextError>
Commit block to the non-finalized state, on top of:
- an existing chain’s tip, or
- a newly forked chain.
Sourcepub fn invalidate_block(&mut self, block_hash: Hash) -> Result<Hash, BoxError>
pub fn invalidate_block(&mut self, block_hash: Hash) -> Result<Hash, BoxError>
Invalidate block with hash block_hash
and all descendants from the non-finalized state. Insert
the new chain into the chain_set and discard the previous.
Sourcepub fn reconsider_block(
&mut self,
block_hash: Hash,
finalized_state: &ZebraDb,
) -> Result<Vec<Hash>, ReconsiderError>
pub fn reconsider_block( &mut self, block_hash: Hash, finalized_state: &ZebraDb, ) -> Result<Vec<Hash>, ReconsiderError>
Reconsiders a previously invalidated block and its descendants into the non-finalized state based on a block_hash. Reconsidered blocks are inserted into the previous chain and re-inserted into the chain_set.
Sourcepub fn commit_new_chain(
&mut self,
prepared: SemanticallyVerifiedBlock,
finalized_state: &ZebraDb,
) -> Result<(), ValidateContextError>
pub fn commit_new_chain( &mut self, prepared: SemanticallyVerifiedBlock, finalized_state: &ZebraDb, ) -> Result<(), ValidateContextError>
Commit block to the non-finalized state as a new chain where its parent is the finalized tip.
Sourcepub fn best_chain_len(&self) -> Option<u32>
pub fn best_chain_len(&self) -> Option<u32>
Returns the length of the non-finalized portion of the current best chain
or None
if the best chain has no blocks.
Sourcepub fn root_height(&self) -> Option<Height>
pub fn root_height(&self) -> Option<Height>
Returns the root height of the non-finalized state, if the non-finalized state is not empty.
Sourcepub fn any_chain_contains(&self, hash: &Hash) -> bool
pub fn any_chain_contains(&self, hash: &Hash) -> bool
Returns true
if hash
is contained in the non-finalized portion of any
known chain.
Sourcepub fn find_chain<P>(&self, predicate: P) -> Option<Arc<Chain>>
pub fn find_chain<P>(&self, predicate: P) -> Option<Arc<Chain>>
Returns the first chain satisfying the given predicate.
If multiple chains satisfy the predicate, returns the chain with the highest difficulty. (Using the tip block hash tie-breaker.)
Sourcepub fn any_utxo(&self, outpoint: &OutPoint) -> Option<Utxo>
pub fn any_utxo(&self, outpoint: &OutPoint) -> Option<Utxo>
Returns the transparent::Utxo
pointed to by the given
transparent::OutPoint
if it is present in any chain.
UTXOs are returned regardless of whether they have been spent.
Sourcepub fn any_block_by_hash(&self, hash: Hash) -> Option<Arc<Block>>
pub fn any_block_by_hash(&self, hash: Hash) -> Option<Arc<Block>>
Returns the block
with the given hash in any chain.
Sourcepub fn any_prev_block_hash_for_hash(&self, hash: Hash) -> Option<Hash>
pub fn any_prev_block_hash_for_hash(&self, hash: Hash) -> Option<Hash>
Returns the previous block hash for the given block hash in any chain.
Sourcepub fn best_hash(&self, height: Height) -> Option<Hash>
pub fn best_hash(&self, height: Height) -> Option<Hash>
Returns the hash for a given block::Height
if it is present in the best chain.
Sourcepub fn best_tip_block(&self) -> Option<&ContextuallyVerifiedBlock>
pub fn best_tip_block(&self) -> Option<&ContextuallyVerifiedBlock>
Returns the block at the tip of the best chain.
Sourcepub fn best_height_by_hash(&self, hash: Hash) -> Option<Height>
pub fn best_height_by_hash(&self, hash: Hash) -> Option<Height>
Returns the height of hash
in the best chain.
Sourcepub fn any_height_by_hash(&self, hash: Hash) -> Option<Height>
pub fn any_height_by_hash(&self, hash: Hash) -> Option<Height>
Returns the height of hash
in any chain.
Sourcepub fn best_chain(&self) -> Option<&Arc<Chain>>
pub fn best_chain(&self) -> Option<&Arc<Chain>>
Return the non-finalized portion of the current best chain.
Sourcepub fn chain_count(&self) -> usize
pub fn chain_count(&self) -> usize
Return the number of chains.
Sourcepub fn invalidated_blocks(
&self,
) -> IndexMap<Height, Arc<Vec<ContextuallyVerifiedBlock>>>
pub fn invalidated_blocks( &self, ) -> IndexMap<Height, Arc<Vec<ContextuallyVerifiedBlock>>>
Return the invalidated blocks.
Sourcepub fn disable_metrics(&mut self)
pub fn disable_metrics(&mut self)
Stop tracking metrics for this non-finalized state and all its chains.
Trait Implementations§
Source§impl Clone for NonFinalizedState
impl Clone for NonFinalizedState
Source§impl Debug for NonFinalizedState
impl Debug for NonFinalizedState
Auto Trait Implementations§
impl Freeze for NonFinalizedState
impl RefUnwindSafe for NonFinalizedState
impl Send for NonFinalizedState
impl Sync for NonFinalizedState
impl Unpin for NonFinalizedState
impl UnwindSafe for NonFinalizedState
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§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 moreSource§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 moreSource§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
Source§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
Source§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.Source§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.Source§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.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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 moreSource§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.Source§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.Source§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.Source§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.Source§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.Source§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.Source§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.