pub(crate) struct Pacemaker<N: Network> {
config: PacemakerConfiguration,
state: PacemakerState,
view_info: ViewInfo,
sender: SenderHandle<N>,
event_publisher: Option<Sender<Event>>,
}
Expand description
A single participant in the Pacemaker subprotocol.
§Usage
After creating an instance of the Pacemaker
struct using new
, the caller interacts
with it by calling three methods:
After creating an instance of Pacemaker
using new
, the caller should interact with
it by calling three methods:
on_receive_msg
: this method should be called whenever aPacemakerMessage
is received satisfying the method’s preconditions.tick
: this method should be called as often as is practical.query
: wheneveron_receive_msg
ortick
is called, the internal view counter of thePacemaker
may be updated. The caller should callquery
whenever it needs to see this counter.
Fields§
§config: PacemakerConfiguration
§state: PacemakerState
§view_info: ViewInfo
§sender: SenderHandle<N>
§event_publisher: Option<Sender<Event>>
Implementations§
source§impl<N: Network> Pacemaker<N>
impl<N: Network> Pacemaker<N>
sourcepub(crate) fn new(
config: PacemakerConfiguration,
sender: SenderHandle<N>,
init_view: ViewNumber,
init_validator_set_state: &ValidatorSetState,
event_publisher: Option<Sender<Event>>,
) -> Result<Self, PacemakerError>
pub(crate) fn new( config: PacemakerConfiguration, sender: SenderHandle<N>, init_view: ViewNumber, init_validator_set_state: &ValidatorSetState, event_publisher: Option<Sender<Event>>, ) -> Result<Self, PacemakerError>
Create a new Pacemaker
instance..
sourcepub(crate) fn tick<K: KVStore>(
&mut self,
block_tree: &BlockTreeSingleton<K>,
) -> Result<(), PacemakerError>
pub(crate) fn tick<K: KVStore>( &mut self, block_tree: &BlockTreeSingleton<K>, ) -> Result<(), PacemakerError>
Cause the Pacemaker to check the current time (“clock tick”), possibly updating its internal state or causing it to send messages to other replicas.
sourcepub(crate) fn on_receive_msg<K: KVStore>(
&mut self,
msg: PacemakerMessage,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
) -> Result<(), PacemakerError>
pub(crate) fn on_receive_msg<K: KVStore>( &mut self, msg: PacemakerMessage, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), PacemakerError>
Execute the required steps in the Pacemaker subprotocol upon receiving a PacemakerMessage
from the
replica identified by origin
.
§Precondition
msg.view()
must be greater than or equal to the current view.
sourcefn on_receive_timeout_vote<K: KVStore>(
&mut self,
timeout_vote: TimeoutVote,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
) -> Result<(), PacemakerError>
fn on_receive_timeout_vote<K: KVStore>( &mut self, timeout_vote: TimeoutVote, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), PacemakerError>
Execute the required steps in the Pacemaker subprotocol upon receiving a TimeoutVote
message from
the replica identified by origin
.
§Precondition
timeout_vote.view >= self.query().view
sourcefn on_receive_advance_view<K: KVStore>(
&mut self,
advance_view: AdvanceView,
origin: &VerifyingKey,
block_tree: &mut BlockTreeSingleton<K>,
) -> Result<(), PacemakerError>
fn on_receive_advance_view<K: KVStore>( &mut self, advance_view: AdvanceView, origin: &VerifyingKey, block_tree: &mut BlockTreeSingleton<K>, ) -> Result<(), PacemakerError>
Execute the required steps in the Pacemaker protocol upon receiving an AdvanceView
message.
§Preconditions
advance_view.progress_certificate.view() >= self.query().view
sourcefn update_view(
&mut self,
next_view: ViewNumber,
validator_set_state: &ValidatorSetState,
) -> Result<(), PacemakerError>
fn update_view( &mut self, next_view: ViewNumber, validator_set_state: &ValidatorSetState, ) -> Result<(), PacemakerError>
Update the Pacemaker’s state in order to enter a specified next_view
.
§Preconditions
This function should only be called if next_view
is greater than the current view. Otherwise, an
UpdateViewError
will be returned.
sourcefn extend_view(&mut self) -> Result<(), ExtendViewError>
fn extend_view(&mut self) -> Result<(), ExtendViewError>
Extend the timeout of the current view, which must be an Epoch-Change View.
§Errors
This function should only be called if the current view is an Epoch-Change View. Otherwise, an
ExtendViewError
will be returned.