Skip to main content

QuorumTree

Struct QuorumTree 

Source
pub struct QuorumTree<ID>
where ID: Ord,
{ /* private fields */ }
Expand description

A single quorum rule represented as a tree.

QuorumTree models one side of a quorum configuration. A consensus implementation should usually build one tree for read quorums and another tree for write quorums, then ensure every read quorum intersects every write quorum.

A child node is selected when it is either an included node ID or a nested quorum tree whose own quorum rule is satisfied.

§Invariants

  • A QuorumTree represents exactly one quorum rule.
  • Child nodes are unique and traversal order is deterministic according to Node ordering.
  • quorum_size never exceeds the number of child nodes: construction rejects duplicate children and unsatisfiable quorum sizes.
  • Equality and ordering for QuorumTree are based only on its canonical ID.
  • Canonical IDs are stable identifiers. std::fmt::Display is human-readable output and is not a serialization format.

Implementations§

Source§

impl<ID> QuorumTree<ID>
where ID: Ord,

Source

pub fn new( quorum_size: u64, nodes: impl IntoIterator<Item = Node<ID>>, ) -> Result<Self, QuorumTreeError>
where ID: CanonicalId,

Builds a quorum tree from a quorum size and child nodes.

quorum_size is the number of child nodes that must be selected for this tree to be selected. A child can be a single ID or another quorum tree. If quorum_size is 0, every input satisfies the tree.

§Errors
§Examples
use quorum_set::{Node, QuorumSet, QuorumTree, QuorumTreeError};

let tree = QuorumTree::new(2, [
    Node::Id(1),
    Node::Id(2),
    Node::Id(3),
]).unwrap();

assert!(tree.is_quorum([1, 2].iter()));
assert!(!tree.is_quorum([1].iter()));

let err = QuorumTree::new(1, [Node::Id(1), Node::Id(1)]).unwrap_err();
assert_eq!(
    QuorumTreeError::DuplicateChild { canonical_id: "Id=1".to_string() },
    err
);
Source

pub fn quorum_size(&self) -> u64

Returns the number of selected child nodes required to satisfy this tree.

Source

pub fn children(&self) -> impl Iterator<Item = &Node<ID>>

Returns this tree’s child nodes in canonical order.

Children are unique: construction rejects duplicate child nodes.

Source

pub fn canonical_id(&self) -> &str

Returns the canonical ID of this tree.

The canonical ID decides equality and ordering. It is computed once at construction, so this accessor does not allocate.

Trait Implementations§

Source§

impl<ID> CanonicalId for QuorumTree<ID>
where ID: Ord + CanonicalId,

Source§

fn fmt_canonical_id<W>(&self, f: &mut W) -> Result
where W: Write + ?Sized,

Writes this value’s canonical ID into f. Read more
Source§

fn canonical_id(&self) -> String

Returns this value’s canonical ID as a String.
Source§

impl<ID> Clone for QuorumTree<ID>
where ID: Ord + Clone,

Source§

fn clone(&self) -> QuorumTree<ID>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<ID> Debug for QuorumTree<ID>
where ID: Ord + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<ID> Display for QuorumTree<ID>
where ID: Ord + Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<ID> Eq for QuorumTree<ID>
where ID: Ord,

Source§

impl<ID> Hash for QuorumTree<ID>
where ID: Ord,

Hashing is based solely on canonical_id, consistent with equality.

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<ID> Ord for QuorumTree<ID>
where ID: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<ID> PartialEq for QuorumTree<ID>
where ID: Ord,

Equality and ordering are decided solely by canonical_id.

new() is the sole constructor and canonical_id is the cached canonical representation of the quorum tree spec. A single string comparison keeps BTreeSet operations cheap; no recursive structural comparison is needed.

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<ID> PartialOrd for QuorumTree<ID>
where ID: Ord,

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<ID> QuorumSet for QuorumTree<ID>
where ID: Ord + Clone + 'static,

Hierarchical quorum implementation for QuorumTree.

Evaluation follows the tree structure. ids() returns all leaf IDs once, even when the same node appears in more than one subtree.

Source§

type Id = ID

Node ID type in this quorum set.
Source§

type Iter = IntoIter<ID>

Iterator over every voter ID tracked by this quorum set. Read more
Source§

fn is_quorum<'a, I: Iterator<Item = &'a ID> + Clone>(&self, ids: I) -> bool

Return true if the candidate IDs satisfy this quorum rule.
Source§

fn ids(&self) -> Self::Iter

Return all voter IDs in this quorum set.

Auto Trait Implementations§

§

impl<ID> Freeze for QuorumTree<ID>

§

impl<ID> RefUnwindSafe for QuorumTree<ID>
where ID: RefUnwindSafe,

§

impl<ID> Send for QuorumTree<ID>
where ID: Send,

§

impl<ID> Sync for QuorumTree<ID>
where ID: Sync,

§

impl<ID> Unpin for QuorumTree<ID>

§

impl<ID> UnsafeUnpin for QuorumTree<ID>

§

impl<ID> UnwindSafe for QuorumTree<ID>
where ID: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.