The quorum crate
The decision core of the shrinking quorum. Each tick it decides what the system may deliver, given what three replicas returned.
Install
The crate is not on crates.io yet. Depend on the repository at a tag:
# Cargo.toml [dependencies] quorum = { git = "https://github.com/mruspace/flight", tag = "v0.3.1" }
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.3.1:
[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
| Shrink | Vote on three, compare on two, self-check on one. |
| Tmr | Vote 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
| Absent | The 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. |
| Detected | A disagreement was caught; deliver nothing this tick. |
| Halted | The policy cannot continue with the replicas left. |
struct Verdict
| Field | Type | Meaning |
|---|---|---|
| mode | Mode | The mode used this tick. |
| outcome | Outcome | What to do with this tick. |
| dissent | [bool; 3] | Replicas that were outvoted (vote mode only). |
| diagnose | bool | Two 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 and quorum_health_clear give this crate's answer.
Kani proofs
Nine proofs: four on the core in quorum, five on the C interface in quorum-ffi. CI runscargo kani -p quorum -p quorum-ffi on every change. In the core proofs, each reply is any ofAbsent, Single or Pair, with any u64 values.
| Proof | Property | Scope |
|---|---|---|
| identical_while_tmr_can_run | With 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_two | With 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_left | The shrinking quorum's outcome is Halted if and only if no reply is present. | Every set of three replies. |
| delivers_only_agreed_values | A delivered value has two agreeing replies, or exactly one replica alive that returned Pair(v, v). | Every set of three replies, under both policies. |
| decide_is_the_core | quorum_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_halts | Any other policy code halts quorum_decide and quorum_mode. | C interface: any policy code above 1. |
| mode_is_the_core | quorum_mode gives the core's mode. | C interface: policy 0 or 1, any u32 count. |
| strike_is_the_core | quorum_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_core | quorum_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. |
Each proof name links to its source at v0.3.1.
Not covered
Healthin 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).
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, asno_std(build only) - Static ARM Linux binaries of the demo, 64-bit and 32-bit (hard and soft float), tested under emulation
Updated October 11, 2026 · Source: quorum/src/lib.rs · Edit on GitHub · Questions? Get in touch
