MMruDocs

The quorum crate

The decision core of the shrinking quorum. Each tick it decides what the system may deliver, given what three replicas returned. It also chooses one value from up to three sensor readings of the same quantity.

no_stdno allocationno dependencies9 Kani proofs, 16 with the C interfacev0.9.0

Install

The crate is not on crates.io. Its manifest sets publish = false. Depend on the repository at a tag:

# Cargo.toml
[dependencies]
quorum = { git = "https://github.com/mruspace/flight", tag = "v0.9.0" }

Example

use quorum::{decide, Health, Outcome, Policy, Reply, REPLICAS};

// read_replicas, send and run_known_answer_test are your code.
let mut health = Health::new();
for tick in 0u64.. {
    let replies: [Reply; REPLICAS] = read_replicas(tick);
    let v = decide(Policy::Shrink, &replies);

    if let Outcome::Deliver(x) = v.outcome { send(x); }
    for (i, outvoted) in v.dissent.iter().enumerate() {
        if *outvoted && health.strike(i, tick) { run_known_answer_test(i); }
    }
}

Gate commands on the mode

On one replica, self-check can deliver a few wrong results before the periodic known-answer test catches a stuck fault. Use that mode for data products, not spacecraft commands, unless the mission adds its own command safety layer. This example issues a command only when the mode is Vote or Compare and the outcome is Deliver. See Command path.

//! Gate commands on the mode. Only a result that two or more replicas agree
//! on (vote or compare) may command the spacecraft. A result from the last
//! replica's self-check goes out as a data product only.
use quorum::{decide, Mode, Outcome, Policy, Reply, REPLICAS};

/// What to do with one tick's result.
enum Action {
    /// Agreed by two or more replicas: may be used as a command.
    Command(u64),
    /// Self-check on the last replica: data product only.
    Data(u64),
    /// Nothing to send this tick.
    Hold,
}

fn gate(replies: &[Reply; REPLICAS]) -> Action {
    let verdict = decide(Policy::Shrink, replies);
    match (verdict.mode, verdict.outcome) {
        (Mode::Vote | Mode::Compare, Outcome::Deliver(x)) => Action::Command(x),
        (Mode::SelfCheck, Outcome::Deliver(x)) => Action::Data(x),
        _ => Action::Hold,
    }
}

fn main() {
    use Reply::{Absent, Pair, Single};
    let ticks = [
        [Single(7), Single(7), Single(9)], // vote: two agree on 7
        [Absent, Single(7), Single(7)],    // compare: both say 7
        [Absent, Single(7), Single(9)],    // compare: mismatch
        [Absent, Absent, Pair(7, 7)],      // self-check on the last replica
        [Absent, Absent, Absent],          // nothing left
    ];
    for replies in &ticks {
        match gate(replies) {
            Action::Command(x) => println!("{replies:?}: command {x}"),
            Action::Data(x) => println!("{replies:?}: data product {x}"),
            Action::Hold => println!("{replies:?}: hold"),
        }
    }
}

Its output, from cargo run against v0.9.0:

[Single(7), Single(7), Single(9)]: command 7
[Absent, Single(7), Single(7)]: command 7
[Absent, Single(7), Single(9)]: hold
[Absent, Absent, Pair(7, 7)]: data product 7
[Absent, Absent, Absent]: hold

API

const REPLICAS: usize = 3

Number of replicas.

const STRIKES: usize = 3

Strikes within STRIKE_WINDOW ticks that trigger a diagnosis.

const STRIKE_WINDOW: u64 = 200

Length of the strike window, in ticks.

enum Policy

ShrinkVote on three, compare on two, self-check on one.
TmrVote on three, compare on two, stop on one (classic fixed TMR).

enum Mode

Vote, Compare, SelfCheck (one replica computes everything twice and compares with itself), Halted.

enum Reply

AbsentThe replica is dead or did not answer.
Single(u64)One result.
Pair(u64, u64)Two results of the same computation (self-check).

enum Outcome

Deliver(u64)Deliver this result.
DetectedA disagreement was caught; deliver nothing this tick.
HaltedThe policy cannot continue with the replicas left.

struct Verdict

FieldTypeMeaning
modeModeThe mode used this tick.
outcomeOutcomeWhat to do with this tick.
dissent[bool; 3]Replicas that were outvoted (vote mode only).
diagnoseboolTwo replicas disagree and nothing tells which is wrong: run a known-answer test on both (shrinking quorum only).

fn mode(policy, alive) -> Mode

The mode a policy runs in with alive live replicas.

fn decide(policy, &[Reply; 3]) -> Verdict

Decide what to deliver from the replicas' replies.

struct Health

Strike record per replica. Health::new() is const. strike(i, tick) returns true when replica i has three strikes inside the window and must be diagnosed. clear(i) forgets its strikes after it passes. to_raw() and Health::from_raw(strikes, count) turn the record into plain arrays and back, to save it across a reset or hand it to C.

From C or C++, use the C interface, quorum.h. Kani proves that quorum_mode, quorum_decide, quorum_health_strike, quorum_health_clear, quorum_sensor_select and quorum_sensor_observe give this crate's answer. The last two are the C side of sensor selection.

Sensor selection

decide() needs results that match exactly. Readings of one quantity by three sensors never do: noise, calibration and timing make them differ a little. The module quorum::sensor compares readings within a tolerance, tol, in the same units as the readings.

Readings inValue chosenOtherwise
ThreeThe median, if at least one other reading is within tol of it.Disagree: nothing delivered.
TwoTheir midpoint, rounded down, if they are within tol of each other.Disagree: nothing says which is right, so nothing is delivered.
OneThe reading, as Unchecked, since nothing checks it.Not applicable.
NoneNothing.Not applicable.

From the module comment and select() in quorum/src/sensor.rs at v0.9.0.

With three readings and an agreed value, a reading more than tol from that value is an outlier. observe() separates a short spike from a sensor that has failed: it excludes a sensor only after limit outlier cycles in a row. Pass None for an excluded sensor.

The F´ component SensorVoter calls this module through quorum_sensor_select. It has run in the OPS-SAT run 4 package on the ground, not in orbit. The module does not make every replica's input equal before the replicas compute. That step is not built.

const SENSORS: usize = 3

Number of sensors of one quantity.

enum Selected

What select chose.

Agreed(i32)A value two or more readings agree on, within the tolerance.
Unchecked(i32)The only reading: not cross-checked.
DisagreeThe readings differ by more than the tolerance and nothing says which one is right. Nothing is delivered.
NothingNo reading.

struct Selection

The choice for one cycle.

FieldTypeMeaning
selectedSelectedThe value chosen, or why there is none.
outlier[bool; 3]Readings more than the tolerance away from the agreed value. Set only when three readings give Selected::Agreed.

fn close(a: i32, b: i32, tol: u32) -> bool

Whether two readings are within tol of each other, with no overflow.

fn select(readings: &[Option<i32>; SENSORS], tol: u32) -> Selection

Choose one value from the readings of the sensors in use (None: no reading, or a sensor excluded), with tolerance tol.

fn observe(run: u8, outlier: bool, limit: u8) -> (u8, bool)

One cycle of a sensor's outlier count: run is its outlier cycles in a row so far. Returns the new count, and whether the sensor must now be excluded: after limit outlier cycles in a row (never when limit is 0). Call it only in cycles with an agreed value; in others, keep the count.

Example

use quorum::sensor::{observe, select};

fn main() {
    let tol = 10;
    let cycles = [
        [Some(100), Some(104), Some(98)],  // three agree: the median
        [Some(100), Some(5000), Some(98)], // a spike on sensor 1
        [Some(100), None, Some(105)],      // two agree: the midpoint
        [Some(100), None, Some(200)],      // two disagree
        [None, Some(7), None],             // one reading
    ];
    for r in &cycles {
        let s = select(r, tol);
        println!("{r:?}: {:?} {:?}", s.selected, s.outlier);
    }

    // Exclude a sensor after 3 outlier cycles in a row.
    let mut run = 0;
    for outlier in [true, true, false, true, true, true] {
        let (r, exclude) = observe(run, outlier, 3);
        run = r;
        println!("outlier {outlier}: run {run}, exclude {exclude}");
    }
}

Its output, from cargo run against v0.9.0:

[Some(100), Some(104), Some(98)]: Agreed(100) [false, false, false]
[Some(100), Some(5000), Some(98)]: Agreed(100) [false, true, false]
[Some(100), None, Some(105)]: Agreed(102) [false, false, false]
[Some(100), None, Some(200)]: Disagree [false, false, false]
[None, Some(7), None]: Unchecked(7) [false, false, false]
outlier true: run 1, exclude false
outlier true: run 2, exclude false
outlier false: run 0, exclude false
outlier true: run 1, exclude false
outlier true: run 2, exclude false
outlier true: run 3, exclude true

Kani proofs

16 proofs in the workspace. Nine are on the crate: four on decide() and five on sensor selection inquorum::sensor. Seven are on the C interface in quorum-ffi. CI runscargo kani -p quorum -p quorum-ffi on every change. On the v0.9.0 commit it verified all 16, with 0 failures. In the decide() proofs, each reply is any of Absent, Single orPair, with any u64 values.

ProofPropertyScope
identical_while_tmr_can_runWith two or more replies present, both policies give the same outcome.Every set of three replies with two or more present. Outcome only, not mode or diagnose.
tmr_stops_below_twoWith fewer than two replies present, fixed TMR's outcome is Halted.Every set of three replies with fewer than two present.
shrink_halts_only_with_nothing_leftThe shrinking quorum's outcome is Halted if and only if no reply is present.Every set of three replies.
delivers_only_agreed_valuesA delivered value has two agreeing replies, or exactly one replica alive that returned Pair(v, v).Every set of three replies, under both policies.
agreed_values_are_agreed_and_in_rangeAn agreed value has at least two readings within the tolerance of it, and lies between the smallest and the largest reading.Every set of three readings, each absent or any i32, and every tolerance.
outliers_are_never_chosenAn outlier is a reading of an agreed cycle more than the tolerance away from the value chosen, so it is never the value delivered. With three readings in, every other reading is within the tolerance.Every set of three readings, each absent or any i32, and every tolerance.
median_is_the_medianThe median of three is one of the three values, with at least two of them on each side of it (itself counted).Every three i32 values, ties included.
unchecked_only_with_one_readingUnchecked comes only from exactly one reading, and Nothing only from none. Every other result has two or more readings in.Every set of three readings, each absent or any i32, and every tolerance.
excluded_only_after_limit_outliers_in_a_rowobserve excludes a sensor exactly when its last limit cycles were all outliers. A spike shorter than the limit never excludes it.Every limit from 1 to 6, every sequence of six cycles.
decide_is_the_corequorum_decide gives the core's verdict. An unknown reply kind counts as absent.C interface: policy 0 or 1, any reply kind and values.
bad_policy_haltsAny other policy code halts quorum_decide and quorum_mode.C interface: any policy code above 1.
mode_is_the_corequorum_mode gives the core's mode.C interface: policy 0 or 1, any u32 count.
strike_is_the_corequorum_health_strike gives the core's answer and record. A replica above 2 changes nothing.C interface: any record with counts in the u32 range, any replica and cycle.
clear_is_the_corequorum_health_clear gives the core's record. A replica above 2 changes nothing.C interface: any record with counts in the u32 range, any replica.
sensor_select_is_the_corequorum_sensor_select gives the core's selection. A reading with present false counts as no reading.C interface: any three readings, any tolerance.
sensor_observe_is_the_corequorum_sensor_observe gives the core's count and exclusion.C interface: any count, outlier flag and limit.

Each proof name links to its source at v0.9.0.

Not covered

  • Health in the core. Unit tests only.
  • Diagnosis and the known-answer test. They run in the demo and in F´, not in the core.
  • Timing. The proofs say what decide() returns, not how long it takes. Thebench measures that.
  • The system over a run. Never less than fixed TMR over a whole run is tested, not proved. SeeTested (per run).
  • Sensor values against the truth. The proofs say which reading select() chooses, not how close it is to the true value. The F´ test component SensorSim scores that.

Targets and builds

CI builds and tests on every change:

  • Linux ARM64, Linux x86_64 and macOS (Apple silicon)
  • Bare-metal ARM Cortex-M, thumbv7em-none-eabihf, as no_std (build only)
  • Static Linux binaries of the demo and the bench: 64-bit ARM, 32-bit ARM (hard and soft float) and x86_64. CI runs the scenario tests on each in a container, the ARM ones under emulation.
  • The F´ components and deployments, which call the crate through quorum.h: build, unit tests and end-to-end runs
  • The native cFS mission (cFE, OSAL and PSP of cFS v7.0.1, and the Mru app), which also calls the crate through quorum.h. CI builds it and runs it in the run 4 package.

Updated November 18, 2026 · Source: quorum/src/lib.rs, quorum/src/sensor.rs · Edit on GitHub · Questions? Get in touch