Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A stable election is won once the votes of a quorum are counted

Proved
OpenSearchProgress.election_won

by pitimespi · Nov 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

cluster-coordinationconsensuselasticsearchformal-verificationleader-electionlivenessmessage-passingopensearchpartial-synchronypaxosprogresspublicationraftzen2

For every payload type V, cluster parameters P with P.InitCompatible and P.strategy = ElectionStrategy.DEFAULT_INSTANCE, every cluster W with Reachable P W, every node c, term t and list of node ids Q such that

  • c and every member of Q are cluster-manager-eligible;
  • Q is a quorum of both of c's configurations: (W.node c).lastCommittedConfiguration.hasQuorum Q = true and (W.node c).lastAcceptedConfiguration.hasQuorum Q = true;
  • c and every member of Q are in a term below t: (W.node q).currentTerm < t for q = c and for every q ∈ Q;

and every cluster W' with ElectionExec P c t Q (W.node c).lastAcceptedTerm (W.node c).lastAcceptedVersion W W' such that (W'.node c).currentTerm = t and every member of Q is among c's join votes (q ∈ (W'.node c).joinVotes.nodes for every q ∈ Q): (W'.node c).electionWon = true.

No hypothesis on the voters' accepted states is needed: the votes are already counted. During the period c's committed configuration may change by a commit, but only to its accepted configuration, of which Q is also a quorum.

Preamble
import Definitions.Def_OpenSearchProgress
open OpenSearchCoordination OpenSearchSafety OpenSearchProgress
Formal statement
theorem OpenSearchProgress.election_won {V : Type} (P : Params) (hP : P.InitCompatible)
    (hes : P.strategy = ElectionStrategy.DEFAULT_INSTANCE) (W : Cluster V) (hW : Reachable P W)
    (c : NodeId) (t : Nat) (Q : List NodeId) (hc : P.eligible c = true) (hQ : ∀ q ∈ Q, P.eligible q = true)
    (hquorum : (W.node c).lastCommittedConfiguration.hasQuorum Q = true ∧
      (W.node c).lastAcceptedConfiguration.hasQuorum Q = true)
    (hterm : ∀ q, q = c ∨ q ∈ Q → (W.node q).currentTerm < t)
    (W' : Cluster V)
    (hE : ElectionExec P c t Q (W.node c).lastAcceptedTerm (W.node c).lastAcceptedVersion W W')
    (hct : (W'.node c).currentTerm = t) (hvotes : ∀ q ∈ Q, q ∈ (W'.node c).joinVotes.nodes) :
    (W'.node c).electionWon = true := by sorry
Source
OpenSearch b2a54ba5c0defba3d1d20423e911d4bf920bab19: Coordinator (handlePublishRequest lines 454-526 with ensureTermAtLeast at 512, startElection 583-602, ensureTermAtLeast 635-641, joinLeaderInTerm 643-657, handleJoin 1267-1287 with handleJoinIgnoringExceptions 1289-1299, publish 1350 with the handleClientValue call at 1404, CoordinatorPublication.handlePublishResponse 1871-1875): https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/Coordinator.java; CoordinationState (isPublishQuorum lines 156-158, handleStartJoin 213-255, handleJoin 264-339, handleClientValue 348-407, handlePublishRequest 416-460, handlePublishResponse 471-515, handleCommit 523-573) as transcribed by the OpenSearchCoordination mission: https://github.com/opensearch-project/OpenSearch/blob/b2a54ba5c0defba3d1d20423e911d4bf920bab19/server/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java; the cluster model, the safety vocabulary and the inductive invariant of the OpenSearchSafety mission (Step, Reachable, Committed, Inv, reachable_inv); for why progress needs a stable period: M. J. Fischer, N. A. Lynch, M. S. Paterson, Impossibility of distributed consensus with one faulty process, J. ACM 32(2), 1985, and C. Dwork, N. Lynch, L. Stockmeyer, Consensus in the presence of partial synchrony, J. ACM 35(2), 1988
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5 (independent sub-agent, blind: Lean code + auditor instructions only)

Read-back: OpenSearchProgress.election_won

Notions used

The full expansions are in readback_Def_OpenSearchProgress.md.

Node-state notation. For a node state σ\sigmaσ:

  • cur(σ)\mathrm{cur}(\sigma)cur(σ) is the current term;
  • lat(σ)\mathrm{lat}(\sigma)lat(σ) and lav(σ)\mathrm{lav}(\sigma)lav(σ) are the term and version of its last accepted state;
  • lcc(σ)\mathrm{lcc}(\sigma)lcc(σ) and lac(σ)\mathrm{lac}(\sigma)lac(σ) are that state's last committed and last accepted configurations;
  • jv(σ)\mathrm{jv}(\sigma)jv(σ) is the list of ids in the join votes, and won(σ)\mathrm{won}(\sigma)won(σ) is electionWon.

For a configuration XXX (a strictly increasing list of ids) and a list LLL of ids, Quorum(X,L)\mathrm{Quorum}(X, L)Quorum(X,L) (X.hasQuorum L = true) means 2⋅∣{x∈X:x∈L}∣>∣X∣2\cdot|\{x \in X : x \in L\}| > |X|2⋅∣{x∈X:x∈L}∣>∣X∣. It is false when XXX is empty or L=[ ]L = [\,]L=[], and it is monotone in LLL.

Reachable clusters and the election period. These are as in the read-back of election_vote_accepted. ElectionExec(P,c,t,Q,kt,kv)(W,W′)\mathrm{ElectionExec}(P, c, t, Q, k_t, k_v)(W, W')ElectionExec(P,c,t,Q,kt​,kv​)(W,W′) is a finite, possibly empty, sequence of Steps. Compared with an arbitrary Step, the period imposes these restrictions:

  • no new publication request is sent;
  • a start-join at any node on a request in term t′t't′ requires t′<tt' < tt′<t, or requester ccc and t′=tt' = tt′=t;
  • ccc and the voters do not bootstrap and are not restarted, except that a non-eligible node may restartAny;
  • ccc and the voters accept only publications with key ⪯(kt,kv)\preceq (k_t, k_v)⪯(kt​,kv​).

In this theorem, (kt,kv)=(lat,lav)(k_t, k_v) = (\mathrm{lat}, \mathrm{lav})(kt​,kv​)=(lat,lav) of W.node cW.\mathrm{node}\ cW.node c.

How electionWon changes. Each successful handleJoin sets it to isElectionQuorum(P.strategy,σ,v)\mathrm{isElectionQuorum}(P.\mathrm{strategy}, \sigma, v)isElectionQuorum(P.strategy,σ,v), where vvv is the new vote list. Under the default strategy that value is Quorum(lcc(σ),v)∧Quorum(lac(σ),v)\mathrm{Quorum}(\mathrm{lcc}(\sigma), v) \land \mathrm{Quorum}(\mathrm{lac}(\sigma), v)Quorum(lcc(σ),v)∧Quorum(lac(σ),v), computed with the node's configurations at that moment. handleStartJoin and both kinds of restart set it to false. No other handler changes it. Join votes are cleared by handleStartJoin and by restarts, and grow only through handleJoin.

1. Declaration

The universally quantified variables and hypotheses, in order:

NameType / statement
V (implicit)Type
PParams
hPP.InitCompatibleP.\mathrm{InitCompatible}P.InitCompatible
hesP.strategy=DEFAULT_INSTANCEP.\mathrm{strategy} = \mathrm{DEFAULT\_INSTANCE}P.strategy=DEFAULT_INSTANCE
WCluster V (start of the period)
hWReachable(P,W)\mathrm{Reachable}(P, W)Reachable(P,W)
cnode id (candidate)
tN\mathbb{N}N (election term)
Qlist of node ids (voters)
hcP.eligible(c)=trueP.\mathrm{eligible}(c) = \mathrm{true}P.eligible(c)=true
hQ∀q∈Q, P.eligible(q)=true\forall q \in Q,\ P.\mathrm{eligible}(q) = \mathrm{true}∀q∈Q, P.eligible(q)=true
hquorumQuorum(lcc(W.node c),Q)∧Quorum(lac(W.node c),Q)\mathrm{Quorum}(\mathrm{lcc}(W.\mathrm{node}\ c), Q) \land \mathrm{Quorum}(\mathrm{lac}(W.\mathrm{node}\ c), Q)Quorum(lcc(W.node c),Q)∧Quorum(lac(W.node c),Q)
hterm∀q, (q=c∨q∈Q)→cur(W.node q)<t\forall q,\ (q = c \lor q \in Q) \to \mathrm{cur}(W.\mathrm{node}\ q) < t∀q, (q=c∨q∈Q)→cur(W.node q)<t
W'Cluster V
hEElectionExec(P,c,t,Q,lat(W.node c),lav(W.node c))(W,W′)\mathrm{ElectionExec}(P, c, t, Q, \mathrm{lat}(W.\mathrm{node}\ c), \mathrm{lav}(W.\mathrm{node}\ c))(W, W')ElectionExec(P,c,t,Q,lat(W.node c),lav(W.node c))(W,W′)
hctcur(W′.node c)=t\mathrm{cur}(W'.\mathrm{node}\ c) = tcur(W′.node c)=t
hvotes∀q∈Q, q∈jv(W′.node c)\forall q \in Q,\ q \in \mathrm{jv}(W'.\mathrm{node}\ c)∀q∈Q, q∈jv(W′.node c)

Conclusion. won(W′.node c)=true\mathrm{won}(W'.\mathrm{node}\ c) = \mathrm{true}won(W′.node c)=true.

What this amounts to. hterm and hct together show that ccc entered term ttt during the period, by a start-join that cleared its votes and set won:=false\mathrm{won} := \mathrm{false}won:=false. ccc cannot be restarted during the period, so the flag at W′W'W′ is the value computed by the last successful handleJoin at ccc after that start-join; such a call exists because hvotes and Q≠[ ]Q \ne [\,]Q=[] make the vote list non-empty. The theorem asserts that this value is true. The hypothesis hquorum refers to ccc's configurations at the start WWW. The hypothesis hvotes refers to ccc's join votes at the end W′W'W′.

2. What is not constrained

  • Non-emptiness. hquorum forces Q≠[ ]Q \ne [\,]Q=[] and both of ccc's configurations at WWW to be non-empty, since Quorum\mathrm{Quorum}Quorum is false for an empty configuration and for an empty list.

  • No freshness or hconf. There is no freshness hypothesis and no hconf. Whether voters' joins could be accepted does not matter here, because hvotes assumes the votes are present. The theorem does not derive the votes.

  • Every member of QQQ must have voted. hvotes requires every member of QQQ to be among ccc's join votes, not merely a quorum's worth, so members of QQQ outside ccc's configurations must also have voted. Since QQQ can be chosen as a minimal quorum, this concerns how the theorem is applied, not its content. ccc's votes may also include nodes outside QQQ.

  • Start configurations versus end configurations. hquorum speaks of ccc's configurations at WWW, not at W′W'W′. The following is derived, not stated:

    • during the period ccc accepts no publication, so lac(c)\mathrm{lac}(c)lac(c) is fixed;
    • a commit at ccc while ccc is still in its old term can replace lcc(c)\mathrm{lcc}(c)lcc(c) by lac(c)\mathrm{lac}(c)lac(c), which hquorum's second conjunct covers;
    • once ccc is in term ttt, no commit can apply at ccc, because lat(c)<t\mathrm{lat}(c) < tlat(c)<t.

    The theorem thus implicitly claims that ccc's configurations, at the moment it computes its last won flag, are still covered by QQQ.

  • Nothing beyond the flag. The theorem says nothing about how the votes were obtained, about lpv\mathrm{lpv}lpv or publish votes, or about other nodes. Those may be in any term, including ≥t\ge t≥t, at WWW.

  • Implicit claim about other winners. The conclusion makes ccc a winner of term ttt in a reachable cluster. The Safety definitions' invariant field Inv.won_unique says at most one node wins each term. So the theorem implicitly asserts that its hypotheses exclude another node having won term ttt before or during the period. No hypothesis says so directly; it would have to follow from hquorum, hterm (no voter is in term ttt at WWW), hvotes and reachability.

  • Empty execution. hterm and hct exclude the empty execution and force t≥1t \ge 1t≥1.

  • Vacuity. The hypotheses are satisfiable, using the two-node example of the election_vote_accepted read-back with Q=[1,2]Q = [1, 2]Q=[1,2] and c=1c = 1c=1, t=1t = 1t=1:

    1. node 1 start-joins on its own request for term 1, sending a join to itself;
    2. node 2 start-joins on node 1's request;
    3. node 1 handles its own join, giving votes [1][1][1], not yet a quorum of {1,2}\{1, 2\}{1,2};
    4. node 1 handles node 2's join, giving votes [2,1][2, 1][2,1].

    Then hvotes holds, hquorum holds ({1,2}\{1, 2\}{1,2} is a quorum of {1,2}\{1, 2\}{1,2}), and the conclusion is a real claim.

3. Plain-language summary

Take any stable election period that starts in a reachable cluster where:

  • the eligible candidate ccc and the voters QQQ are in terms below ttt;
  • QQQ is a majority of both of ccc's configurations, under the default election strategy.

If ccc ends the period in term ttt holding join votes from every member of QQQ, then ccc's electionWon flag is set. This is the "the votes suffice" half of election progress. It assumes the votes rather than deriving them.

Human review
  • Endorsed by Shuze Chen · Nov 1, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Nov 1, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me