Documentation

CslibFrontier.Computability.Distributed.SetAgreement.AtomicSnapshot.TraceInv

Internal global trace invariant and per-actor frame lemma #

Defines the trace invariant TraceInv and its shared per-actor frame specialization TraceInv.of_actor_step; never re-exported through AtomicSnapshot.

Main definitions #

Main results #

structure Cslib.Distributed.SetAgreement.SnapshotTrace.TraceInv {P : Type u_1} {Data : Type u_2} [Fintype P] [DecidableEq P] {ord : ScanOrder P} {dInit : Data} (τ : SnapshotTrace ord dInit) (t : ℕ) :

Combined trace invariant at step t ≤ τ.events.length powering Lemmas 3.1–3.3 and Theorem 1:

  1. (τ.stateAt t).stepCount = t.
  2. For every register j with ((τ.stateAt t).reg j).seq > 0 whose most recent write occurred at w < t, there exists a serialization state v with τ.lastIdleStep j w + 1 ≤ v ≤ w such that memSnapshot (τ.stateAt v).reg = ((τ.stateAt t).reg j).view.
  3. For every active process i:
    • if proc i = .readyToWrite opId val snap: opId < history.length, history[opId] is pending update val by i with invStep = τ.lastIdleStep i t < t, and there exists v with invStep + 1 ≤ v ≤ t and memSnapshot (τ.stateAt v).reg = snap;
    • if proc i = .scanning st: opId < history.length, history[opId] is pending (scan or update val matching st.mode) by i with invStep = τ.lastIdleStep i t < t, and ScanLoopInv τ (τ.lastIdleStep i t) t st holds.
  4. For every history index id < history.length with record rec:
    • if rec.status = .pending, then proc rec.caller is active with opId = id and rec.invStep = τ.lastIdleStep rec.caller t < t;
    • if rec.status = .doneScan resp snap, then rec.kind = .scan, rec.invStep < resp < t, and there exists v with rec.invStep + 1 ≤ v ≤ resp and memSnapshot (τ.stateAt v).reg = snap;
    • if rec.status = .doneUpdate resp, then rec.kind = .update val (for some val), rec.invStep < resp < t, τ.isWriteStep rec.caller resp, and ((τ.stateAt (resp + 1)).reg rec.caller).data = val;
    • conversely, EVERY isWriteStep τ j w with w < t has a unique id < history.length with caller = j and status = .doneUpdate w.
theorem Cslib.Distributed.SetAgreement.SnapshotTrace.lastIdleStep_keep {P : Type u_1} {Data : Type u_2} [Fintype P] [DecidableEq P] {ord : ScanOrder P} {dInit : Data} (τ : SnapshotTrace ord dInit) (i : P) {t : ℕ} (h0 : (τ.stateAt t).proc i ≠ ProcSnapshotState.idle) (h1 : (τ.stateAt (t + 1)).proc i ≠ ProcSnapshotState.idle) :
τ.lastIdleStep i (t + 1) = τ.lastIdleStep i t

If proc i stays non-idle across t → t + 1, lastIdleStep i is unchanged.

theorem Cslib.Distributed.SetAgreement.SnapshotTrace.TraceInv.of_actor_step {P : Type u_1} {Data : Type u_2} [Fintype P] [DecidableEq P] {ord : ScanOrder P} {dInit : Data} {τ : SnapshotTrace ord dInit} {t : ℕ} (inv : τ.TraceInv t) (i : P) (modId : ℕ) (hstepCount : (τ.stateAt (t + 1)).stepCount = t + 1) (hproc_other : ∀ (p : P), p ≠ i → (τ.stateAt (t + 1)).proc p = (τ.stateAt t).proc p) (hhist_len : (τ.stateAt t).history.length ≤ (τ.stateAt (t + 1)).history.length) (hbound_unchanged : ∀ id < (τ.stateAt (t + 1)).history.length, id ≠ modId → id < (τ.stateAt t).history.length) (hhist_unchanged : ∀ (id : ℕ) (h₁ : id < (τ.stateAt (t + 1)).history.length) (h₀ : id < (τ.stateAt t).history.length), id ≠ modId → (τ.stateAt (t + 1)).history[id] = (τ.stateAt t).history[id]) (hmod_old : ∀ (h₀ : modId < (τ.stateAt t).history.length), (τ.stateAt t).history[modId].caller = i ∧ (τ.stateAt t).history[modId].status = SnapshotOpStatus.pending) (hreg_t : ∀ (j : P), τ.isWriteStep j t → ∃ (v : ℕ), τ.lastIdleStep j t + 1 ≤ v ∧ v ≤ t ∧ memSnapshot (τ.stateAt v).reg = ((τ.stateAt (t + 1)).reg j).view) (hready_i : ∀ (opId : ℕ) (val : Data) (snap : P → Data), (τ.stateAt (t + 1)).proc i = ProcSnapshotState.readyToWrite opId val snap → ∃ (hId : opId < (τ.stateAt (t + 1)).history.length), (τ.stateAt (t + 1)).history[opId] = { caller := i, kind := SnapshotOpKind.update val, invStep := τ.lastIdleStep i (t + 1), status := SnapshotOpStatus.pending } ∧ τ.lastIdleStep i (t + 1) < t + 1 ∧ ∃ (v : ℕ), τ.lastIdleStep i (t + 1) + 1 ≤ v ∧ v ≤ t + 1 ∧ memSnapshot (τ.stateAt v).reg = snap) (hscan_i : ∀ (st : ActiveScan P Data), (τ.stateAt (t + 1)).proc i = ProcSnapshotState.scanning st → ∃ (hId : st.opId < (τ.stateAt (t + 1)).history.length), (τ.stateAt (t + 1)).history[st.opId] = { caller := i, kind := match st.mode with | ScanMode.external => SnapshotOpKind.scan | ScanMode.embedded val => SnapshotOpKind.update val, invStep := τ.lastIdleStep i (t + 1), status := SnapshotOpStatus.pending } ∧ τ.lastIdleStep i (t + 1) < t + 1 ∧ τ.ScanLoopInv (τ.lastIdleStep i (t + 1)) (t + 1) st) (hpending_i : ∀ (id : ℕ) (hId : id < (τ.stateAt (t + 1)).history.length), id = modId ∨ (τ.stateAt (t + 1)).history[id].caller = i → (τ.stateAt (t + 1)).history[id].status = SnapshotOpStatus.pending → (τ.stateAt (t + 1)).history[id].invStep = τ.lastIdleStep (τ.stateAt (t + 1)).history[id].caller (t + 1) ∧ (τ.stateAt (t + 1)).history[id].invStep < t + 1 ∧ HasActiveOpId ((τ.stateAt (t + 1)).proc (τ.stateAt (t + 1)).history[id].caller) id) (hdoneScan_mod : ∀ (hId : modId < (τ.stateAt (t + 1)).history.length) (resp : ℕ) (snap : P → Data), (τ.stateAt (t + 1)).history[modId].status = SnapshotOpStatus.doneScan resp snap → (τ.stateAt (t + 1)).history[modId].kind = SnapshotOpKind.scan ∧ (τ.stateAt (t + 1)).history[modId].invStep < resp ∧ resp < t + 1 ∧ ∃ (v : ℕ), (τ.stateAt (t + 1)).history[modId].invStep + 1 ≤ v ∧ v ≤ resp ∧ memSnapshot (τ.stateAt v).reg = snap) (hdoneUpdate_mod : ∀ (hId : modId < (τ.stateAt (t + 1)).history.length) (resp : ℕ), (τ.stateAt (t + 1)).history[modId].status = SnapshotOpStatus.doneUpdate resp → ∃ (val : Data), (τ.stateAt (t + 1)).history[modId].kind = SnapshotOpKind.update val ∧ (τ.stateAt (t + 1)).history[modId].invStep < resp ∧ resp < t + 1 ∧ τ.isWriteStep (τ.stateAt (t + 1)).history[modId].caller resp ∧ (τ.stateAt (resp + 1)).reg (τ.stateAt (t + 1)).history[modId].caller = { data := val, seq := ((τ.stateAt resp).reg (τ.stateAt (t + 1)).history[modId].caller).seq + 1, view := ((τ.stateAt (resp + 1)).reg (τ.stateAt (t + 1)).history[modId].caller).view }) (hwrite_t : ∀ (j : P), τ.isWriteStep j t → ∃ (id : ℕ) (hId : id < (τ.stateAt (t + 1)).history.length), (τ.stateAt (t + 1)).history[id].caller = j ∧ (τ.stateAt (t + 1)).history[id].status = SnapshotOpStatus.doneUpdate t) :
τ.TraceInv (t + 1)

Per-actor frame lemma for TraceInv: given TraceInv τ t, if actor i transitions from t to t + 1 leaving every other process p ≠ i unchanged and modifying history at most at a single index modId (either modId = history.length for an append/no-op, or an existing pending entry of i), then all frame obligations for p ≠ i, id ≠ modId, and w < t follow automatically from TraceInv τ t.