Skip to main content

verify_intersection

Function verify_intersection 

Source
pub fn verify_intersection<A, B>(a: &A, b: &B) -> bool
where A: QuorumSet, B: QuorumSet<Id = A::Id>, A::Id: Ord,
Expand description

Exhaustively check the QuorumIntersection relation between two quorum sets.

Returns true iff every quorum of a intersects every quorum of b. Unlike QuorumIntersection::intersects_with, which may answer None, this check is exact for any two QuorumSet implementations, e.g. a read QuorumTree against a write QuorumTree.

It tests every split of the combined voter IDs U into (S, U ∖ S): a disjoint quorum pair exists iff for some split, S is a quorum of a and U ∖ S is a quorum of b. Quorum sets are upward-closed, so “some quorum of b fits inside U ∖ S” is the same as “U ∖ S is itself a quorum of b”. This argument relies on two QuorumSet rules: implementations are upward-closed, and IDs outside QuorumSet::ids never affect QuorumSet::is_quorum.

The check runs 2^n quorum evaluations for n distinct IDs. It is meant for validating small configurations and as a test oracle.

§Panics

Panics if a and b together track 64 or more distinct IDs.

§Examples

use std::collections::BTreeSet;

use quorum_set::verify_intersection;

let abc = BTreeSet::from([1, 2, 3]);
let de = BTreeSet::from([4, 5]);

// Majorities of one voter set always intersect each other.
assert!(verify_intersection(&abc, &abc));
// Majorities of disjoint voter sets never intersect.
assert!(!verify_intersection(&abc, &de));