hotstuff_rs::hotstuff::implementation

Struct HotStuff

source
pub(crate) struct HotStuff<N: Network> {
    config: HotStuffConfiguration,
    view_info: ViewInfo,
    proposal_status: ProposalStatus,
    phase_vote_collectors: ActiveCollectorPair<PhaseVoteCollector>,
    sender_handle: SenderHandle<N>,
    validator_set_update_handle: ValidatorSetUpdateHandle<N>,
    event_publisher: Option<Sender<Event>>,
}
Expand description

A participant in the HotStuff subprotocol.

§Usage

The HotStuff struct is meant to be used in an “event-oriented” fashion (note that “event” here does not refer to the Event enum defined in the events module, but to “event” in the abstract sense).

Reflecting this event-orientation, the two most significant crate-public methods of this struct are “event handlers”, which are to be called when specific things happen to the replica. These methods are:

  1. enter_view: called when Pacemaker causes the replica to enter a new view.
  2. on_receive_msg: called when a new HotStuffMessage is received.

Besides these two, HotStuff has one more crate-public method, namely is_view_outdated. This should be called after querying Pacemaker for the latest ViewInfo to decide whether or not the ViewInfo is truly “new”, that is, whether or not it is more up-to-date than the latest ViewInfo the HotStuff struct has received through its enter_view method.

Fields§

§config: HotStuffConfiguration§view_info: ViewInfo§proposal_status: ProposalStatus§phase_vote_collectors: ActiveCollectorPair<PhaseVoteCollector>§sender_handle: SenderHandle<N>§validator_set_update_handle: ValidatorSetUpdateHandle<N>§event_publisher: Option<Sender<Event>>

Implementations§

source§

impl<N: Network> HotStuff<N>

source

pub(crate) fn new( config: HotStuffConfiguration, view_info: ViewInfo, sender_handle: SenderHandle<N>, validator_set_update_handle: ValidatorSetUpdateHandle<N>, init_validator_set_state: ValidatorSetState, event_publisher: Option<Sender<Event>>, ) -> Self

Create a new HotStuff subprotocol participant.

source

pub(crate) fn is_view_outdated(&self, new_view_info: &ViewInfo) -> bool

Checks whether the HotStuff internal view is outdated with respect to the view from ViewInfo provided by the Pacemaker.

§Next step

If this function returns true, enter_view should be called with the latest ViewInfo at the soonest possible opportunity.

source

pub(crate) fn enter_view<K: KVStore>( &mut self, new_view_info: ViewInfo, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), HotStuffError>

On receiving a new ViewInfo from the Pacemaker, send messages and perform state updates associated with exiting the current view, and update the local view info.

§Precondition

is_view_outdated returns true. This is the case when the Pacemaker has updated ViewInfo but the update has not been made available to the HotStuff struct yet.

§Specification

Enter View.

source

pub(crate) fn on_receive_msg<K: KVStore>( &mut self, msg: HotStuffMessage, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), HotStuffError>

Process a newly received message for the current view according to the HotStuff subprotocol.

§Internal procedure

This function executes the following steps:

  1. If msg is a Proposal or a Nudge, check if the sender is a proposer for the current view and check if the replica is still accepting nudges and proposals. If these checks fail, return immediately.
  2. If the checks pass, call one of the following 4 internal event handlers depending on the variant of the received message:
source

fn on_receive_proposal<K: KVStore>( &mut self, proposal: Proposal, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, app: &mut impl App<K>, ) -> Result<(), HotStuffError>

Process a newly received proposal.

§Preconditions

is_proposer(origin, self.view_info.view, &block_tree.validator_set_state()?).

§Specification

On Receive Proposal.

source

fn on_receive_nudge<K: KVStore>( &mut self, nudge: Nudge, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), HotStuffError>

source

fn on_receive_phase_vote<K: KVStore>( &mut self, phase_vote: PhaseVote, signer: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), HotStuffError>

Process a received phase_vote.

§Specification

On Receive Phase Vote.

source

fn on_receive_new_view<K: KVStore>( &mut self, new_view: NewView, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), HotStuffError>

Process the received NewView.

§Specification

On Receive New View.

Auto Trait Implementations§

§

impl<N> Freeze for HotStuff<N>
where N: Freeze,

§

impl<N> RefUnwindSafe for HotStuff<N>
where N: RefUnwindSafe,

§

impl<N> Send for HotStuff<N>

§

impl<N> Sync for HotStuff<N>
where N: Sync,

§

impl<N> Unpin for HotStuff<N>
where N: Unpin,

§

impl<N> UnwindSafe for HotStuff<N>
where N: 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