hotstuff_rs::block_tree::accessors::internal

Struct BlockTreeSingleton

source
pub struct BlockTreeSingleton<K: KVStore>(K);
Expand description

Read and write handle into the block tree that should be owned exclusively by the algorithm thread.

§Categories of methods

BlockTreeSingleton has a large number of methods. To improve understandability, these methods are grouped into five categories, with methods in each separate category being defined in a separate impl block. These five categories are:

  1. Lifecycle methods.
  2. Top-level state updaters.
  3. Helper functions called by BlockTree::update.
  4. Basic state getters.
  5. Extra state getters.

Tuple Fields§

§0: K

Implementations§

source§

impl<K: KVStore> BlockTreeSingleton<K>

Lifecycle methods.

These are methods for creating and initializing a BlockTreeSingleton, as well as for using it to create and consume other block tree-related types, namely, BlockTreeSnapshot, BlockTreeWriteBatch, and AppBlockTreeView.

source

pub(crate) fn new(kv_store: K) -> Self

Create a new instance of BlockTreeSingleton on top of kv_store.

This constructor is private (pub(crate)). To create an instance of BlockTreeSingleton as a library user, use new_unsafe.

source

pub unsafe fn new_unsafe(kv_store: K) -> Self

Create a new instance of BlockTreeSingleton on top of kv_store.

§Safety

Read mutating the block tree directly from user code.

source

pub fn initialize( &mut self, initial_app_state: &AppStateUpdates, initial_validator_set_state: &ValidatorSetState, ) -> Result<(), BlockTreeError>

Initialize the block tree variables listed in initial state.

This function must be called exactly once on a BlockTreeSingleton with an empty backing kv_store, before any of the other functions (except the constructors new or new_unsafe) are called.

source

pub fn snapshot(&self) -> BlockTreeSnapshot<K::Snapshot<'_>>

Create a BlockTreeSnapshot.

source

pub fn write(&mut self, write_batch: BlockTreeWriteBatch<K::WriteBatch>)

Atomically write the changes in write_batch into the BlockTreeSingleton.

source

pub fn app_view<'a>( &'a self, parent: Option<&CryptoHash>, ) -> Result<AppBlockTreeView<'a, K>, BlockTreeError>

Create an AppBlockTreeView which sees the app state as it will be right after parent becomes committed.

source§

impl<K: KVStore> BlockTreeSingleton<K>

Top-level state updaters.

These are the methods that mutate the block tree that are called directly by code in the subprotocols (i.e., hotstuff, block_sync, and pacemaker). Mutating methods outside of this impl and the lifecycle methods impl above are only used internally in this module.

source

pub fn insert( &mut self, block: &Block, app_state_updates: Option<&AppStateUpdates>, validator_set_updates: Option<&ValidatorSetUpdates>, ) -> Result<(), BlockTreeError>

Insert into the block tree a block that will cause the provided app_state_updates and validator_set_updates to be applied when it is committed in the future.

§Relationship with update

insert does not internally call update. Calling code is responsible for calling update on block.justify after calling insert.

§Precondition

safe_block is true for block.

source

pub(crate) fn update( &mut self, justify: &PhaseCertificate, event_publisher: &Option<Sender<Event>>, ) -> Result<Option<ValidatorSetUpdates>, BlockTreeError>

Update the block tree upon seeing a safe justify in a Nudge or a Block.

§Updates

Depending on the specific Phase Certificate received and the state of the Block Tree, the updates that this function performs will include:

  1. Updating the Highest PC if justify.view > highest_pc.view.
  2. Updating the Locked PC if appropriate, as determined by the pc_to_lock helper.
  3. Committing a block and all of its ancestors if appropriate, as determined by the block_to_commit helper.
  4. Marking the latest validator set updates as decided if justify is a Decide PC.
§Preconditions

The Block or Nudge containing justify must satisfy safe_block or safe_nudge, respectively.

source

pub fn set_highest_tc( &mut self, tc: &TimeoutCertificate, ) -> Result<(), BlockTreeError>

Set the highest TimeoutCertificate to be tc.

§Preconditions

TODO.

source

pub fn set_highest_view_entered( &mut self, view: ViewNumber, ) -> Result<(), BlockTreeError>

Set the highest view entered to be view.

§Preconditions

view >= self.highest_view_entered().

source

pub fn set_highest_view_phase_voted( &mut self, view: ViewNumber, ) -> Result<(), BlockTreeError>

Set the highest view phase-voted to be view.

§Preconditions

view >= self.highest_view_voted().

source§

impl<K: KVStore> BlockTreeSingleton<K>

Helper functions called by [BlockTree::update].

source

pub fn commit( &mut self, wb: &mut BlockTreeWriteBatch<K::WriteBatch>, block: &CryptoHash, ) -> Result<Vec<(CryptoHash, Option<ValidatorSetUpdates>)>, BlockTreeError>

Commit block and all of its ancestors, if they have not already been committed.

§Return value

Returns the hashes of the newly committed blocks, along with the updates each caused to the validator set, in order from the newly committed block with the lowest height to the newly committed block with the highest height.

§Preconditions

block_to_commit returns block.

source

pub fn delete_siblings( &mut self, wb: &mut BlockTreeWriteBatch<K::WriteBatch>, block: &CryptoHash, ) -> Result<(), BlockTreeError>

Delete the “siblings” of the specified block, along with all of its associated data (e.g., pending app state updates, validator set updates).

“Siblings” refer to other blocks that share the same parent as the specified block.

§Precondition

block is in its parents’ (or the genesis) children list.

§Error

Returns an error if the block is not in the block tree, or if the block’s parent (or genesis) does not have a children list.

source

pub fn delete_branch( &mut self, wb: &mut BlockTreeWriteBatch<K::WriteBatch>, root: &CryptoHash, )

Deletes all data of blocks in a branch starting from (and including) a given root block.

source

pub fn blocks_in_branch( &self, root: CryptoHash, ) -> impl Iterator<Item = CryptoHash>

Perform depth-first search to collect the hashes of all blocks in the branch rooted at root into a single iterator.

source

fn publish_update_block_tree_events( event_publisher: &Option<Sender<Event>>, update_highest_pc: Option<PhaseCertificate>, update_locked_pc: Option<PhaseCertificate>, committed_blocks: &Vec<(CryptoHash, Option<ValidatorSetUpdates>)>, )

Publish all events resulting from calling update. These events have to do with changing persistent state, and possibly include: UpdateHighestPCEvent, UpdateLockedPCEvent, PruneBlockEvent, CommitBlockEvent, UpdateValidatorSetEvent.

Invariant: this method must only be invoked after the associated changes are persistently written to the BlockTreeSingleton.

source§

impl<K: KVStore> BlockTreeSingleton<K>

“Basic” state getters.

Each basic state getter calls a corresponding provided method of KVGet and return whatever they return.

The exact same set of basic state getters are also defined on BlockTreeSnapshot.

source

pub fn block(&self, block: &CryptoHash) -> Result<Option<Block>, BlockTreeError>

source

pub fn block_height( &self, block: &CryptoHash, ) -> Result<Option<BlockHeight>, BlockTreeError>

source

pub fn block_data_hash( &self, block: &CryptoHash, ) -> Result<Option<CryptoHash>, BlockTreeError>

source

pub fn block_justify( &self, block: &CryptoHash, ) -> Result<PhaseCertificate, BlockTreeError>

source

pub fn block_data_len( &self, block: &CryptoHash, ) -> Result<Option<DataLen>, BlockTreeError>

source

pub fn block_data( &self, block: &CryptoHash, ) -> Result<Option<Data>, BlockTreeError>

source

pub fn block_datum(&self, block: &CryptoHash, datum_index: u32) -> Option<Datum>

source

pub fn block_at_height( &self, height: BlockHeight, ) -> Result<Option<CryptoHash>, BlockTreeError>

source

pub fn children( &self, block: &CryptoHash, ) -> Result<ChildrenList, BlockTreeError>

source

pub fn committed_app_state(&self, key: &[u8]) -> Option<Vec<u8>>

source

pub fn pending_app_state_updates( &self, block: &CryptoHash, ) -> Result<Option<AppStateUpdates>, BlockTreeError>

source

pub fn committed_validator_set(&self) -> Result<ValidatorSet, BlockTreeError>

source

pub fn validator_set_updates_status( &self, block: &CryptoHash, ) -> Result<ValidatorSetUpdatesStatus, BlockTreeError>

source

pub fn locked_pc(&self) -> Result<PhaseCertificate, BlockTreeError>

source

pub fn highest_view_entered(&self) -> Result<ViewNumber, BlockTreeError>

source

pub fn highest_pc(&self) -> Result<PhaseCertificate, BlockTreeError>

source

pub fn highest_committed_block( &self, ) -> Result<Option<CryptoHash>, BlockTreeError>

source

pub fn highest_tc(&self) -> Result<Option<TimeoutCertificate>, BlockTreeError>

source

pub fn validator_set_state(&self) -> Result<ValidatorSetState, BlockTreeError>

source

pub fn highest_view_voted(&self) -> Result<Option<ViewNumber>, BlockTreeError>

source§

impl<K: KVStore> BlockTreeSingleton<K>

“Extra” state getters.

Extra state getters call basic state getters and aggregate or modify what they return into forms that are more convenient to use.

Unlike basic state getters, these functions are not defined on BlockTreeSnapshot.

source

pub fn contains(&self, block: &CryptoHash) -> bool

Check whether block exists on the block tree.

source

pub fn highest_view_with_progress(&self) -> Result<ViewNumber, BlockTreeError>

Get the maximum of:

This is useful for deciding which view to initially enter after starting or restarting a replica.

source

pub fn highest_committed_block_height( &self, ) -> Result<Option<BlockHeight>, BlockTreeError>

Get the height of the highest committed block.

Auto Trait Implementations§

§

impl<K> Freeze for BlockTreeSingleton<K>
where K: Freeze,

§

impl<K> RefUnwindSafe for BlockTreeSingleton<K>
where K: RefUnwindSafe,

§

impl<K> Send for BlockTreeSingleton<K>

§

impl<K> Sync for BlockTreeSingleton<K>
where K: Sync,

§

impl<K> Unpin for BlockTreeSingleton<K>
where K: Unpin,

§

impl<K> UnwindSafe for BlockTreeSingleton<K>
where K: UnwindSafe,

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.

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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V