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:
enter_view
: called whenPacemaker
causes the replica to enter a new view.on_receive_msg
: called when a newHotStuffMessage
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>
impl<N: Network> HotStuff<N>
sourcepub(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
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.
sourcepub(crate) fn is_view_outdated(&self, new_view_info: &ViewInfo) -> bool
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.
sourcepub(crate) fn enter_view<K: KVStore>(
&mut self,
new_view_info: ViewInfo,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), HotStuffError>
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
sourcepub(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>
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:
- If
msg
is aProposal
or aNudge
, 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. - If the checks pass, call one of the following 4 internal event handlers depending on the variant of the received message:
sourcefn on_receive_proposal<K: KVStore>(
&mut self,
proposal: Proposal,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
app: &mut impl App<K>,
) -> Result<(), HotStuffError>
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
sourcefn on_receive_nudge<K: KVStore>(
&mut self,
nudge: Nudge,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
) -> Result<(), HotStuffError>
fn on_receive_nudge<K: KVStore>( &mut self, nudge: Nudge, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), HotStuffError>
Process the received nudge.
§Preconditions
is_proposer(origin, self.view_info.view, &block_tree.validator_set_state()?)
.