pub struct ConsensusProtocol {
pub proposers: HashSet<NodeId>,
pub acceptors: HashSet<NodeId>,
pub learners: HashSet<NodeId>,
pub promised_proposal: HashMap<NodeId, u64>,
pub accepted_value: HashMap<NodeId, (u64, Vote)>,
pub proposal_counter: u64,
pub quorum_size: usize,
}Expand description
A Paxos-like consensus protocol for ternary votes.
Supports prepare/promise and accept/ack phases. A proposal is accepted when a quorum of acceptors responds. The final value is determined by summing the ternary votes: negative sum → Neg, positive sum → Pos, zero → Zero.
Fields§
§proposers: HashSet<NodeId>§acceptors: HashSet<NodeId>§learners: HashSet<NodeId>§promised_proposal: HashMap<NodeId, u64>§accepted_value: HashMap<NodeId, (u64, Vote)>§proposal_counter: u64§quorum_size: usizeImplementations§
Source§impl ConsensusProtocol
impl ConsensusProtocol
pub fn new(nodes: &[NodeId]) -> Self
pub fn prepare(&mut self, proposer: NodeId) -> u64
pub fn promise(&mut self, acceptor: NodeId, proposal_num: u64) -> bool
pub fn accept( &mut self, acceptor: NodeId, proposal_num: u64, value: Vote, ) -> bool
pub fn decide(&self) -> Option<Vote>
Trait Implementations§
Source§impl Clone for ConsensusProtocol
impl Clone for ConsensusProtocol
Source§fn clone(&self) -> ConsensusProtocol
fn clone(&self) -> ConsensusProtocol
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConsensusProtocol
impl RefUnwindSafe for ConsensusProtocol
impl Send for ConsensusProtocol
impl Sync for ConsensusProtocol
impl Unpin for ConsensusProtocol
impl UnsafeUnpin for ConsensusProtocol
impl UnwindSafe for ConsensusProtocol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more