Skip to content

Commit

Permalink
node-data: change QuorumType to reflect new naming
Browse files Browse the repository at this point in the history
See also #1268
  • Loading branch information
herr-seppia committed Feb 12, 2024
1 parent 40943b5 commit fc2c908
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions node-data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,46 +554,34 @@ pub mod payload {
})
}
}
#[derive(Clone, Copy, Default)]
#[derive(Clone, Copy, Debug, Default)]
#[cfg_attr(
any(feature = "faker", test),
derive(fake::Dummy, Eq, PartialEq)
)]
pub enum QuorumType {
/// Quorum on Valid Candidate
ValidQuorum = 0,
// Quorum on Invalid Candidate
InvalidQuorum = 1,
//Quorum on Timeout (NilQuorum)
NilQuorum = 2,
// NoQuorum
/// Supermajority of Valid votes
Valid = 0,
/// Majority of Invalid votes
Invalid = 1,
/// Majority of NoCandidate votes
NoCandidate = 2,
/// No quorum reached (timeout expired)
#[default]
NoQuorum = 255,
}

impl From<u8> for QuorumType {
fn from(v: u8) -> QuorumType {
match v {
0 => QuorumType::ValidQuorum,
1 => QuorumType::InvalidQuorum,
2 => QuorumType::NilQuorum,
0 => QuorumType::Valid,
1 => QuorumType::Invalid,
2 => QuorumType::NoCandidate,
_ => QuorumType::NoQuorum,
}
}
}

impl fmt::Debug for QuorumType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let label = match self {
QuorumType::ValidQuorum => "valid_quorum",
QuorumType::InvalidQuorum => "invalid_quorum",
QuorumType::NilQuorum => "nil_quorum",
QuorumType::NoQuorum => "no_quorum",
};
f.write_str(label)
}
}

#[derive(Debug, Clone, Default)]
#[cfg_attr(
any(feature = "faker", test),
Expand Down Expand Up @@ -1174,7 +1162,7 @@ mod tests {
bitset: 12345,
aggregate_signature: [1; 48].into(),
},
quorum: payload::QuorumType::ValidQuorum,
quorum: payload::QuorumType::Valid,
vote: payload::Vote::Valid([5; 32]),
},
timestamp: 1_000_000,
Expand Down

0 comments on commit fc2c908

Please sign in to comment.