1# @ajax/mesh-fleet-core
23The fleet's election and commit state machine (`mfc_core`), sans-IO: Raft's rules for a replicated
4document sent whole (so the log is one (term, version) pair), with PreVote (a member that was cut off
5cannot disturb a working leader when it returns), CheckQuorum (a leader that loses its majority steps
6down), one change in flight at a time, catch-up of members that were away, and a fixed coordinator for
7a pair (N = 2 has no majority after a loss). `mfc_durable` writes every Persist before anything after
8it goes out, and stops at the first failed write (fail-stop).
910The shell (`@ajax/mesh-peer-relay`) feeds it link changes, ticks and messages; the messages' wire
11form is `@ajax/mesh-peer-codec`.
1213## Ported from
1415[alpha-rust-mesh](https://github.com/rsafier/alpha-rust-mesh) `crates/mesh-host/src/fleet.rs`: `Msg`,
16`Role`, `Config`, `Out`, `durable`, `Core`.
1718## Tests
1920- `tests/election.c`: the Rust's simulated network, ported (`Sim`): a leader is elected and commits
21 (N = 3, 4, 5), a minority refuses changes, a 2 + 2 split has no leader, the pair's fixed coordinator,
22 terms and votes survive restarts, and the randomised run over 300 seeds (partitions, crashes,
23 restarts, message loss, disks that fill up) asserting at most one leader per term, one document per
24 committed version and per accepted (term, version), no committed change lost, no committed document
25 going back. `election 2000` runs the Rust's ignored 2000-seed variant (7469 leaderships, 23538
26 committed versions, 1308 fail-stops, no invariant broken).
27- `tests/catchup.c`: the Rust's three catch-up scenarios after leader changes (review finding 1) and
28 `nothing_leaves_without_its_persist` (review finding 4).
2930## Licence
3132MIT. See the repository's LICENSE.