pub struct Party<V: Value, VS: ValueSelector<V>> {
pub id: u64,
/* private fields */
}Expand description
A participant in the BPCon protocol responsible for executing ballots.
A Party manages the execution of ballots by communicating with other parties, processing incoming messages,
and following the protocol’s steps. It uses an internal state machine to track its progress through the ballot process.
§Communication
msg_in_receiver: Receives incoming messages from other parties.msg_out_sender: Sends outgoing messages to other parties.event_receiver: Receives events that drive the ballot process.event_sender: Sends events to trigger actions in the ballot process.
The Party operates within a BPCon configuration and relies on a ValueSelector to choose values during the consensus process.
A LeaderElector is used to determine the leader for each ballot.
Fields§
§id: u64The identifier of this party.
Implementations§
Source§impl<V: Value, VS: ValueSelector<V>> Party<V, VS>
impl<V: Value, VS: ValueSelector<V>> Party<V, VS>
Sourcepub fn new(
id: u64,
cfg: BPConConfig,
value_selector: VS,
elector: Box<dyn LeaderElector<V, VS>>,
) -> (Self, UnboundedReceiver<MessagePacket>, UnboundedSender<MessagePacket>)
pub fn new( id: u64, cfg: BPConConfig, value_selector: VS, elector: Box<dyn LeaderElector<V, VS>>, ) -> (Self, UnboundedReceiver<MessagePacket>, UnboundedSender<MessagePacket>)
Creates a new Party instance.
This constructor sets up the party with the given ID, BPCon configuration, value selector, and leader elector. It also initializes communication channels for receiving and sending messages and events.
§Parameters
id: The unique identifier for this party.cfg: The BPCon configuration settings.value_selector: The component responsible for selecting values during the consensus process.elector: The component responsible for electing the leader for each ballot.
§Returns
- A tuple containing:
- The new
Partyinstance. - The
UnboundedReceiverfor outgoing messages. - The
UnboundedSenderfor incoming messages.
- The new
Sourcepub fn is_launched(&self) -> bool
pub fn is_launched(&self) -> bool
Checks if the ballot process has been launched.
§Returns
trueif the ballot is currently active;falseotherwise.
Sourcepub fn is_stopped(&self) -> bool
pub fn is_stopped(&self) -> bool
Checks if the ballot process has been stopped.
§Returns
trueif the ballot has finished or failed;falseotherwise.
Sourcepub fn get_value_selected(&self) -> Option<V>
pub fn get_value_selected(&self) -> Option<V>
Retrieves the selected value if the ballot process has finished successfully.
§Returns
Some(V)if the ballot reached a consensus and the value was selected.Noneif the ballot did not reach consensus or is still ongoing.
Sourcepub async fn launch_ballot(&mut self) -> Result<V, LaunchBallotError>
pub async fn launch_ballot(&mut self) -> Result<V, LaunchBallotError>
Launches the ballot process.
This method initiates the ballot process, advancing through the different phases of the protocol by sending and receiving events and messages. It handles timeouts for each phase and processes incoming messages to update the party’s state.
§Returns
Ok(Some(V)): The selected value if the ballot reaches consensus.Ok(None): If the ballot process is terminated without reaching consensus.Err(LaunchBallotError): If an error occurs during the ballot process.