Documentation

CslibFrontier.Computability.Distributed.CRDT.Basic

State-Based and Operation-Based Conflict-Free Replicated Data Types (CvRDT and CmRDT) #

This module formalizes foundational steps toward #7502 for Conflict-Free Replicated Data Types and Strong Eventual Consistency (SEC) (after Shapiro, Preguiça, Baquero, and Zawirski [SPBZ11b], §§2.1–2.4, §3.2, Theorems 2.1–2.2 & 3.1–3.2, and [SPBZ11a], §§2.2–2.4, Propositions 2.1–2.2 & Specifications 3–4):

  1. State-Based Convergent Replicated Data Types (CvRDT): Reuses Mathlib's SemilatticeSup S with binary state merge (· ⊔ ·) and inflationary local updates (s ≤ update op s). Models asynchronous gossip networks (CvRDT.gossipLTS) over an arbitrary directed communication graph Digraph P with out-of-order message arrival, packet drops, and arbitrary packet duplication, proving:

  2. Operation-Based Commutative Replicated Data Types (CmRDT) & CausalBroadcast Bridge: Models two-phase (prepare, effect) replicated objects with concurrent downstream commutativity (ConcurrentCommute: ¬ prec e₁ e₂ → ¬ prec e₂ e₁ → effect (effOf e₁) (effect (effOf e₂) s) = effect (effOf e₂) (effect (effOf e₁) s)), proving:

  3. State/Op Emulation Equivalence (CvRDT.toCmRDT, CmRDT.toCvRDT):

Model scope relative to primary sources #

[SPBZ11b] (§5) and [SPBZ11a] (§§3.2, 3.4–3.5, 4) additionally study LWW-Register, MV-Register, graph and sequence CRDTs (2P2P-Graph, monotonic DAGs, RGA/Treedoc), and Wuu–Bernstein vector-clock garbage collection, which remain open under #7502. Concrete counter and set data types (GCounter, PNCounter, TwoPhaseSet, ORSet) are developed in CslibFrontier.Computability.Distributed.CRDT.DataTypes.

Main definitions #

Main results #

References #

Semilattice list and history folding #

theorem Cslib.Distributed.CRDT.foldl_sup_eq_of_mem_iff {S : Type u_1} {α : Type u_2} [SemilatticeSup S] (s₀ : S) (f : α → S) {l₁ l₂ : List α} (hmem : ∀ (a : α), a ∈ l₁ ↔ a ∈ l₂) :
List.foldl (fun (s : S) (a : α) => s ⊔ f a) s₀ l₁ = List.foldl (fun (s : S) (a : α) => s ⊔ f a) s₀ l₂

Order- and duplicate-independence of semilattice merges: folding (· ⊔ ·) over two lists from s₀ yields the exact same state whenever the lists have the same support set, regardless of arrival order or multiplicity.

def Cslib.Distributed.CRDT.evalHistory {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] (init : S) (post : UId → S) (H : Finset UId) :
S

Evaluate the semilattice supremum of init together with the post-states post u of all update identifiers u ∈ H ([SPBZ11b], §2.1 & §2.3, pp. 5–7).

@[simp]
theorem Cslib.Distributed.CRDT.evalHistory_empty {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] (init : S) (post : UId → S) :
evalHistory init post ∅ = init
theorem Cslib.Distributed.CRDT.evalHistory_le_iff {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] {init : S} {post : UId → S} {H : Finset UId} {b : S} :
evalHistory init post H ≤ b ↔ init ≤ b ∧ ∀ u ∈ H, post u ≤ b

Universal least-upper-bound characterization of evalHistory init post H.

theorem Cslib.Distributed.CRDT.init_le_evalHistory {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] (init : S) (post : UId → S) (H : Finset UId) :
init ≤ evalHistory init post H
theorem Cslib.Distributed.CRDT.mem_le_evalHistory {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] {init : S} {post : UId → S} {H : Finset UId} {u : UId} (hu : u ∈ H) :
post u ≤ evalHistory init post H
@[simp]
theorem Cslib.Distributed.CRDT.evalHistory_insert {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] [DecidableEq UId] (init : S) (post : UId → S) (u : UId) (H : Finset UId) :
evalHistory init post (insert u H) = post u ⊔ evalHistory init post H
@[simp]
theorem Cslib.Distributed.CRDT.evalHistory_union {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] [DecidableEq UId] (init : S) (post : UId → S) (H₁ H₂ : Finset UId) :
evalHistory init post (H₁ ∪ H₂) = evalHistory init post H₁ ⊔ evalHistory init post H₂
theorem Cslib.Distributed.CRDT.evalHistory_congr {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] (init : S) {post₁ post₂ : UId → S} {H : Finset UId} (h : ∀ u ∈ H, post₁ u = post₂ u) :
evalHistory init post₁ H = evalHistory init post₂ H
theorem Cslib.Distributed.CRDT.foldl_sup_eq_evalHistory {S : Type u_1} {UId : Type u_3} [SemilatticeSup S] (init : S) (post : UId → S) (l : List UId) (H : Finset UId) (hmem : ∀ (u : UId), u ∈ l ↔ u ∈ H) :
List.foldl (fun (s : S) (u : UId) => s ⊔ post u) init l = evalHistory init post H

State-based Convergent Replicated Data Types (CvRDT) #

structure Cslib.Distributed.CRDT.CvRDT (S : Type u_1) (Op : Type u_2) (Q : Type u_3) [SemilatticeSup S] :
Type (max (max u_1 u_2) u_3)

A state-based Convergent Replicated Data Type (CvRDT) (monotonic semilattice object, after [SPBZ11b], §2.3, Definition 2.4, p. 6; [SPBZ11a], §2.3.1, p. 10) over Mathlib's SemilatticeSup S: replicas start at init, answer local queries via query, merge remote payloads via semilattice supremum (· ⊔ ·), and advance monotonically across local updates (s ≤ update op s).

  • init : S

    Initial state s⁰ of every replica.

  • query : S → Q

    Side-effect-free local query q : S → Q.

  • update : Op → S → S

    Local mutating update operation u : Op → S → S.

  • update_infl (op : Op) (s : S) : s ≤ self.update op s

    Monotonicity (inflationarity) of updates in the semilattice: s ≤ update op s.

structure Cslib.Distributed.CRDT.GossipPacket (P : Type u_1) (UId : Type u_2) (S : Type u_3) :
Type (max (max u_1 u_2) u_3)

An in-flight gossip packet addressed to dest, carrying state payload : S together with the ghost causal history ghostHist of update identifiers reflected in payload ([SPBZ11b], §2.1, Definition 2.1, p. 5). Note that replica merge steps inspect only dest and payload; ghostHist is purely a specification field.

  • dest : P

    Recipient replica identity.

  • payload : S

    Transmitted semilattice state payload.

  • ghostHist : Finset UId

    Ghost causal history of updates reflected in payload (never read by protocol logic).

theorem Cslib.Distributed.CRDT.GossipPacket.ext {P : Type u_1} {UId : Type u_2} {S : Type u_3} {x y : GossipPacket P UId S} (dest : x.dest = y.dest) (payload : x.payload = y.payload) (ghostHist : x.ghostHist = y.ghostHist) :
x = y
theorem Cslib.Distributed.CRDT.GossipPacket.ext_iff {P : Type u_1} {UId : Type u_2} {S : Type u_3} {x y : GossipPacket P UId S} :
@[instance_reducible]
instance Cslib.Distributed.CRDT.instDecidableEqGossipPacket {P✝ : Type u_1} {UId✝ : Type u_2} {S✝ : Type u_3} [DecidableEq P✝] [DecidableEq UId✝] [DecidableEq S✝] :
DecidableEq (GossipPacket P✝ UId✝ S✝)
def Cslib.Distributed.CRDT.instDecidableEqGossipPacket.decEq {P✝ : Type u_1} {UId✝ : Type u_2} {S✝ : Type u_3} [DecidableEq P✝] [DecidableEq UId✝] [DecidableEq S✝] (x✝ x✝¹ : GossipPacket P✝ UId✝ S✝) :
Decidable (x✝ = x✝¹)
structure Cslib.Distributed.CRDT.GossipState (P : Type u_1) (UId : Type u_2) (S : Type u_3) :
Type (max (max u_1 u_2) u_3)

Global configuration of an asynchronous state-based CvRDT gossip network.

  • replica : P → S

    Current semilattice state at each replica.

  • history : P → Finset UId

    Ghost causal history c_p of update identifiers delivered at each replica.

  • inFlight : Multiset (GossipPacket P UId S)

    Unordered multiset of in-flight state gossip packets.

  • generated : Finset UId

    Ghost set of unique update identifiers generated so far across all replicas.

  • postState : UId → S

    Ghost map recording the post-update state created when each uid executed at its source.

theorem Cslib.Distributed.CRDT.GossipState.ext {P : Type u_1} {UId : Type u_2} {S : Type u_3} {x y : GossipState P UId S} (replica : x.replica = y.replica) (history : x.history = y.history) (inFlight : x.inFlight = y.inFlight) (generated : x.generated = y.generated) (postState : x.postState = y.postState) :
x = y
inductive Cslib.Distributed.CRDT.GossipAction (P : Type u_1) (UId : Type u_2) (Op : Type u_3) (S : Type u_4) :
Type (max (max (max u_1 u_2) u_3) u_4)

Transition labels of the asynchronous CvRDT gossip network: local updates, point-to-point state gossip sends, consuming merges, duplicate-preserving merges, and packet drops.

@[instance_reducible]
instance Cslib.Distributed.CRDT.instDecidableEqGossipAction {P✝ : Type u_1} {UId✝ : Type u_2} {Op✝ : Type u_3} {S✝ : Type u_4} [DecidableEq P✝] [DecidableEq UId✝] [DecidableEq Op✝] [DecidableEq S✝] :
DecidableEq (GossipAction P✝ UId✝ Op✝ S✝)
def Cslib.Distributed.CRDT.instDecidableEqGossipAction.decEq {P✝ : Type u_1} {UId✝ : Type u_2} {Op✝ : Type u_3} {S✝ : Type u_4} [DecidableEq P✝] [DecidableEq UId✝] [DecidableEq Op✝] [DecidableEq S✝] (x✝ x✝¹ : GossipAction P✝ UId✝ Op✝ S✝) :
Decidable (x✝ = x✝¹)
def Cslib.Distributed.CRDT.CvRDT.gossipInit {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [SemilatticeSup S] (C : CvRDT S Op Q) :
GossipState P UId S

Initial global gossip configuration for C : CvRDT S Op Q: all replicas start at C.init with empty causal histories and empty channels.

def Cslib.Distributed.CRDT.CvRDT.gossipStep {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (s : GossipState P UId S) :
GossipAction P UId Op S → GossipState P UId S

Deterministic state update for one GossipAction of C : CvRDT S Op Q.

def Cslib.Distributed.CRDT.CvRDT.GossipEnabled {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [SemilatticeSup S] (_C : CvRDT S Op Q) (G : Digraph P) (s : GossipState P UId S) :
GossipAction P UId Op S → Prop

Enabledness guard for GossipAction over directed communication graph G : Digraph P.

Instances For
    @[instance_reducible]
    instance Cslib.Distributed.CRDT.instDecidablePredGossipActionGossipEnabledOfDecidableRelAdj {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (G : Digraph P) [DecidableRel G.Adj] (s : GossipState P UId S) :
    def Cslib.Distributed.CRDT.CvRDT.gossipLTS {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (G : Digraph P) :
    LTS (GossipState P UId S) (GossipAction P UId Op S)

    Asynchronous gossip labelled transition system (Cslib.LTS) of C : CvRDT S Op Q over communication graph G : Digraph P.

    def Cslib.Distributed.CRDT.CvRDT.gossipRun {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (s₀ : GossipState P UId S) (xl : List (GossipAction P UId Op S)) :
    GossipState P UId S

    Fold a finite list of GossipActions starting from s₀.

    def Cslib.Distributed.CRDT.CvRDT.gossipValidTrace {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (G : Digraph P) :
    GossipState P UId S → List (GossipAction P UId Op S) → Prop

    Check whether every action in xl is enabled from s₀ over communication graph G.

    Instances For
      @[instance_reducible]
      instance Cslib.Distributed.CRDT.instDecidableGossipValidTrace {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (G : Digraph P) [DecidableRel G.Adj] (s : GossipState P UId S) (xl : List (GossipAction P UId Op S)) :
      theorem Cslib.Distributed.CRDT.CvRDT.gossipLTS_mTr_iff {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) (G : Digraph P) (s₀ : GossipState P UId S) (xl : List (GossipAction P UId Op S)) (s : GossipState P UId S) :
      (C.gossipLTS G).MTr s₀ xl s ↔ C.gossipValidTrace G s₀ xl ∧ s = C.gossipRun s₀ xl

      Equivalence between LTS.MTr on C.gossipLTS G and C.gossipValidTrace + C.gossipRun.

      theorem Cslib.Distributed.CRDT.CvRDT.replica_eq_evalHistory {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) {G : Digraph P} {xl : List (GossipAction P UId Op S)} {s : GossipState P UId S} (hmtr : (C.gossipLTS G).MTr C.gossipInit xl s) (p : P) :

      Semilattice causal-history invariant step (toward #7502, after [SPBZ11b], §2.3, Theorem 2.1, pp. 6–7): in any finite execution of C.gossipLTS G from C.gossipInit, each replica's concrete payload equals the semilattice supremum evalHistory C.init s.postState (s.history p) of its delivered update history.

      theorem Cslib.Distributed.CRDT.CvRDT.strong_convergence {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] (C : CvRDT S Op Q) {G : Digraph P} {xl : List (GossipAction P UId Op S)} {s : GossipState P UId S} (hmtr : (C.gossipLTS G).MTr C.gossipInit xl s) {p q : P} (hhist : s.history p = s.history q) :
      s.replica p = s.replica q ∧ C.query (s.replica p) = C.query (s.replica q)

      State-based Strong Eventual Consistency (SEC) strong-convergence step (toward #7502, after [SPBZ11b], §2.2 Definition 2.3 & §2.3 Theorem 2.1, pp. 5–7): along any finite execution of C.gossipLTS G (allowing arbitrary packet delay, reordering, loss, and duplication), any two replicas p and q that have delivered the same update set (s.history p = s.history q) have identical states (s.replica p = s.replica q) and identical query results.

      theorem Cslib.Distributed.CRDT.CvRDT.converge_of_allPairsReachable {P : Type u_1} {UId : Type u_2} {S : Type u_3} {Op : Type u_4} {Q : Type u_5} [DecidableEq P] [DecidableEq UId] [DecidableEq S] [SemilatticeSup S] [Fintype P] [Nonempty P] (C : CvRDT S Op Q) {G : Digraph P} (hreach : ∀ (p q : P), Relation.ReflTransGen G.Adj p q) (s : GossipState P UId S) :
      ∃ (xl : List (GossipAction P UId Op S)) (s' : GossipState P UId S), (C.gossipLTS G).MTr s xl s' ∧ s'.generated = s.generated ∧ (∀ (p : P), s'.replica p = Finset.univ.sup' ⋯ s.replica) ∧ ∀ (p : P), s'.history p = Finset.univ.biUnion s.history

      Strongly connected gossip eventual-convergence step (toward #7502, after [SPBZ11b], §2.3 Theorem 2.1, pp. 6–7; [SPBZ11a], §2.3.1 Proposition 2.1, p. 10): from any state s over a finite strongly connected graph G : Digraph P (∀ p q, Relation.ReflTransGen G.Adj p q), there exists a finite gossip wave with no new client updates reaching s' where every replica holds the global supremum Finset.univ.sup' Finset.univ_nonempty s.replica and the global history union Finset.univ.biUnion s.history.

      Operation-based Commutative Replicated Data Types (CmRDT) #

      structure Cslib.Distributed.CRDT.CmRDT (S : Type u_1) (Op : Type u_2) (Eff : Type u_3) (Q : Type u_4) :
      Type (max (max (max u_1 u_2) u_3) u_4)

      An operation-based Commutative Replicated Data Type (CmRDT) (after [SPBZ11b], §2.4, pp. 7–8; [SPBZ11a], §2.2.2 & §2.3.2, pp. 8–11): local updates execute a side-effect-free prepare : Op → S → Eff at the originating replica to produce a downstream effect payload Eff, which is then applied via effect : Eff → S → S at all replicas in causal order.

      • init : S

        Initial state s⁰ of every replica.

      • query : S → Q

        Side-effect-free local query q : S → Q.

      • prepare : Op → S → Eff

        Source-local phase computing the downstream effect payload from (op, sourceState).

      • effect : Eff → S → S

        Downstream state transformer applied at every replica upon delivery.

      def Cslib.Distributed.CRDT.EffectsCommute {S : Type u_1} {Eff : Type u_2} (effect : Eff → S → S) :

      Unconditional downstream commutativity: all effect payloads commute on every state s.

      def Cslib.Distributed.CRDT.ConcurrentCommute {S : Type u_1} {Ev : Type u_2} {Eff : Type u_3} (effect : Eff → S → S) (prec : Ev → Ev → Prop) (effOf : Ev → Eff) (H : Set Ev) :

      Concurrent downstream commutativity over an event set H with causal precedence prec ([SPBZ11b], §2.4 Definition 2.6 & Theorem 2.2, p. 8): any two distinct concurrent events e₁, e₂ ∈ H (¬ prec e₁ e₂ and ¬ prec e₂ e₁) have commuting downstream effects.

      theorem Cslib.Distributed.CRDT.EffectsCommute.concurrentCommute {S : Type u_1} {Ev : Type u_2} {Eff : Type u_3} {effect : Eff → S → S} (hcomm : EffectsCommute effect) (prec : Ev → Ev → Prop) (effOf : Ev → Eff) (H : Set Ev) :
      ConcurrentCommute effect prec effOf H
      def Cslib.Distributed.CRDT.IsCausallyClosed {Ev : Type u_1} (prec : Ev → Ev → Prop) (H : Finset Ev) :

      Set H is causally closed (downward closed) with respect to causal precedence prec.

      theorem Cslib.Distributed.CRDT.isCausallyClosed_empty {Ev : Type u_1} (prec : Ev → Ev → Prop) :
      theorem Cslib.Distributed.CRDT.IsCausallyClosed.union {Ev : Type u_1} [DecidableEq Ev] {prec : Ev → Ev → Prop} {H₁ H₂ : Finset Ev} (h₁ : IsCausallyClosed prec H₁) (h₂ : IsCausallyClosed prec H₂) :
      IsCausallyClosed prec (H₁ ∪ H₂)
      def Cslib.Distributed.CRDT.IsCausalLinearization {Ev : Type u_1} [DecidableEq Ev] (prec : Ev → Ev → Prop) (H : Finset Ev) (l : List Ev) :

      List l is a duplicate-free causal linearization of finite event set H with respect to prec: l.Nodup, l has the same elements as H, and prec e₁ e₂ implies e₁ appears strictly before e₂ in l (l.idxOf e₁ < l.idxOf e₂).

      theorem Cslib.Distributed.CRDT.CmRDT.causalLinearization_eq {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) {prec : Ev → Ev → Prop} {effOf : Ev → Eff} {H : Finset Ev} {l₁ l₂ : List Ev} (hcomm : ConcurrentCommute C.effect prec effOf ↑H) (hl₁ : IsCausalLinearization prec H l₁) (hl₂ : IsCausalLinearization prec H l₂) :
      List.foldl (fun (s : S) (e : Ev) => C.effect (effOf e) s) C.init l₁ = List.foldl (fun (s : S) (e : Ev) => C.effect (effOf e) s) C.init l₂

      Op-based Strong Eventual Consistency (SEC) strong-convergence step (toward #7502, after [SPBZ11b], §2.4 Theorem 2.2, p. 8; [SPBZ11a], §2.3.2 Proposition 2.2, p. 11): for any finite event set H : Finset Ev whose concurrent events commute under C.effect, any two causal linearizations l₁ and l₂ of H evaluate from C.init to the exact same state.

      Bridge to Cslib.Distributed.CausalBroadcast (CBCAST) #

      def Cslib.Distributed.CRDT.CmRDT.bssReplicaState {P : Type u_1} {S : Type u_2} {Op : Type u_3} {Eff : Type u_4} {Q : Type u_5} (C : CmRDT S Op Eff Q) (s : CausalBroadcast.BSSState P Eff) (q : P) :
      S

      Replica state of C : CmRDT S Op Eff Q at process q : P induced by applying C.effect along q's causally delivered packet log (s.proc q).delivered in Cslib.Distributed.CausalBroadcast.BSSState P Eff.

      Every process's delivered log in bssLTS F forms a causally closed, duplicate-free IsCausalLinearization of (s.proc q).delivered.toFinset under CausalPrec xl.

      theorem Cslib.Distributed.CRDT.CmRDT.bss_strong_convergence {P : Type u_1} {S : Type u_2} {Op : Type u_3} {Eff : Type u_4} {Q : Type u_5} [Fintype P] [DecidableEq P] [DecidableEq Eff] (C : CmRDT S Op Eff Q) {F : Set P} {xl : List (CausalBroadcast.BSSAction P Eff)} {s : CausalBroadcast.BSSState P Eff} (hmtr : (CausalBroadcast.bssLTS F).MTr (CausalBroadcast.bssInit P Eff) xl s) (hcomm : ConcurrentCommute C.effect (CausalBroadcast.CausalPrec xl) CausalBroadcast.Packet.payload (CausalBroadcast.BroadcastIn xl)) {p q : P} (hsame : ∀ (pkt : CausalBroadcast.Packet P Eff), pkt ∈ (s.proc p).delivered ↔ pkt ∈ (s.proc q).delivered) :

      Causal-broadcast to CmRDT strong-convergence bridge step (toward #7502, connecting Cslib.Distributed.CausalBroadcast.bssLTS of [BSS91], §5.1, directly to [SPBZ11b], §2.4 Theorem 2.2, p. 8): for any static crash-fault set F : Set P, in any finite execution of bssLTS F, if concurrent broadcasts in BroadcastIn xl have commuting downstream effects under C.effect, then any two processes p and q (faulty or correct) that have delivered the same set of packets have identical CmRDT states and query outputs.

      theorem Cslib.Distributed.CRDT.CmRDT.bss_quiescent_convergence {P : Type u_1} {S : Type u_2} {Op : Type u_3} {Eff : Type u_4} {Q : Type u_5} [Fintype P] [DecidableEq P] [DecidableEq Eff] (C : CmRDT S Op Eff Q) {F : Set P} {ss : ωSequence (CausalBroadcast.BSSState P Eff)} {xs : ωSequence (CausalBroadcast.BSSAction P Eff)} (hinit : ss 0 = CausalBroadcast.bssInit P Eff) (he : (CausalBroadcast.bssLTS F).OmegaExecution ss xs) (hfair : CausalBroadcast.BSSFair F ss xs) (hatomic : ∀ (k : ℕ), CausalBroadcast.IsAtomicMulticastAction (xs k)) {K : ℕ} (hquiesce : ∀ (k : ℕ), K ≤ k → CausalBroadcast.emittedPacket (ss k) (xs k) = none) (hcomm : ∀ (k : ℕ), ConcurrentCommute C.effect (CausalBroadcast.CausalPrec (xs.extract 0 k)) CausalBroadcast.Packet.payload (CausalBroadcast.BroadcastIn (xs.extract 0 k))) :
      ∃ (M : ℕ), K ≤ M ∧ ∀ (k : ℕ), M ≤ k → ∀ p ∉ F, ∀ q ∉ F, C.bssReplicaState (ss k) p = C.bssReplicaState (ss k) q

      Causal-broadcast to CmRDT quiescent eventual-convergence bridge step (toward #7502, combining bss_live_of_atomic_multicast and CmRDT.bss_strong_convergence): in any fair infinite execution (ss, xs) of bssLTS F with atomic multicast steps (∀ k, IsAtomicMulticastAction (xs k)), if no new broadcasts occur from step K onward (∀ k ≥ K, emittedPacket (ss k) (xs k) = none) and concurrent broadcasts commute under C.effect, then there exists a convergence step M ≥ K after which all non-crashed replicas p ∉ F, q ∉ F permanently share identical CmRDT states (∀ k ≥ M, C.bssReplicaState (ss k) p = C.bssReplicaState (ss k) q).

      Shapiro et al.'s CvRDT ↔ CmRDT Emulation Equivalence #

      def Cslib.Distributed.CRDT.CvRDT.toCmRDT {S : Type u_1} {Op : Type u_2} {Q : Type u_3} [SemilatticeSup S] (C : CvRDT S Op Q) :
      CmRDT S Op S Q

      Operation-based emulation of a state-based CvRDT (step toward #7502, after [SPBZ11b], §3.2.1 Theorem 3.1, p. 9; [SPBZ11a], §2.4.1 Specification 3, p. 12): prepare computes the post-update state C.update op s at the source replica, and effect merges received states downstream via semilattice supremum (· ⊔ ·).

      State-to-op emulation commutativity step (toward #7502, after [SPBZ11b], §3.2.1 Theorem 3.1, p. 9): the downstream merge effects of C.toCmRDT commute unconditionally on every state, requiring not even causal delivery order.

      @[simp]
      theorem Cslib.Distributed.CRDT.CvRDT.toCmRDT_source_step {S : Type u_1} {Op : Type u_2} {Q : Type u_3} [SemilatticeSup S] (C : CvRDT S Op Q) (op : Op) (s : S) :
      C.toCmRDT.effect (C.toCmRDT.prepare op s) s = C.update op s

      Executing prepare followed immediately by effect at the source replica in C.toCmRDT produces the exact same local state C.update op s as C itself.

      theorem Cslib.Distributed.CRDT.CvRDT.toCmRDT_foldl_eq_evalHistory {S : Type u_1} {Op : Type u_2} {Q : Type u_3} {UId : Type u_4} [SemilatticeSup S] (C : CvRDT S Op Q) (post : UId → S) (l : List UId) (H : Finset UId) (hmem : ∀ (u : UId), u ∈ l ↔ u ∈ H) :
      List.foldl (fun (s : S) (u : UId) => C.toCmRDT.effect (post u) s) C.toCmRDT.init l = evalHistory C.init post H

      Evaluating C.toCmRDT along any event sequence l whose set of events is H yields the exact same semilattice state evalHistory C.init post H as state-based C.

      theorem Cslib.Distributed.CRDT.exists_causalLinearization {Ev : Type u_1} [DecidableEq Ev] (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (H : Finset Ev) :
      ∃ (l : List Ev), IsCausalLinearization prec H l

      Every finite event set H : Finset Ev equipped with a strict partial order prec admits a causal linearization l : List Ev (IsCausalLinearization prec H l).

      noncomputable def Cslib.Distributed.CRDT.CmRDT.evalCausalSet {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (effOf : Ev → Eff) (H : Finset Ev) :
      S

      Evaluate C : CmRDT S Op Eff Q on a finite event set H : Finset Ev ordered by strict partial order prec via causal linearization ([SPBZ11b], §3.2.2 Theorem 3.2, pp. 9–10). Under ConcurrentCommute, CmRDT.evalCausalSet_eq_foldl proves this value is independent of the chosen causal linearization.

      theorem Cslib.Distributed.CRDT.CmRDT.evalCausalSet_eq_foldl {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (effOf : Ev → Eff) {H : Finset Ev} {l : List Ev} (hcomm : ConcurrentCommute C.effect prec effOf ↑H) (hl : IsCausalLinearization prec H l) :
      C.evalCausalSet prec effOf H = List.foldl (fun (s : S) (e : Ev) => C.effect (effOf e) s) C.init l

      Under ConcurrentCommute, C.evalCausalSet prec effOf H agrees with folding C.effect over any causal linearization l of H.

      @[simp]
      theorem Cslib.Distributed.CRDT.CmRDT.evalCausalSet_empty {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (effOf : Ev → Eff) :
      C.evalCausalSet prec effOf ∅ = C.init
      theorem Cslib.Distributed.CRDT.CmRDT.evalCausalSet_insert_max {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (effOf : Ev → Eff) {H : Finset Ev} {e : Ev} (he_not : e ∉ H) (hmax : ∀ x ∈ H, ¬prec e x) (hcomm : ConcurrentCommute C.effect prec effOf ↑(insert e H)) :
      C.evalCausalSet prec effOf (insert e H) = C.effect (effOf e) (C.evalCausalSet prec effOf H)

      Adding a fresh causally maximal event e ∉ H (∀ x ∈ H, ¬ prec e x) advances C.evalCausalSet by applying C.effect (effOf e) directly to C.evalCausalSet prec effOf H.

      def Cslib.Distributed.CRDT.deliverableIter {Ev : Type u_1} [DecidableEq Ev] (deps : Ev → Finset Ev) (M : Finset Ev) :
      ℕ → Finset Ev

      Iterated causal-readiness step starting from ∅: after n rounds against known-event pool M and explicit dependency map deps : Ev → Finset Ev, returns the subset of events in M whose transitive deps chains of depth < n all lie inside M ([SPBZ11b], §3.2.2 Theorem 3.2, pp. 9–10; [SPBZ11a], §2.4.2 Specification 4, p. 13).

      def Cslib.Distributed.CRDT.deliverableEvents {Ev : Type u_1} [DecidableEq Ev] (deps : Ev → Finset Ev) (M : Finset Ev) :

      Maximal deps-closed subset D ⊆ M of causally deliverable events in M, computed in M.card iterations of deliverableIter.

      theorem Cslib.Distributed.CRDT.deliverableEvents_subset {Ev : Type u_1} [DecidableEq Ev] (deps : Ev → Finset Ev) (M : Finset Ev) :
      deliverableEvents deps M ⊆ M
      theorem Cslib.Distributed.CRDT.deliverableEvents_mono {Ev : Type u_1} [DecidableEq Ev] (deps : Ev → Finset Ev) {M₁ M₂ : Finset Ev} (hM : M₁ ⊆ M₂) :
      deliverableEvents deps M₁ ⊆ deliverableEvents deps M₂

      Monotonicity of deliverableEvents: growing the known-event pool M₁ ⊆ M₂ monotonically grows the causally deliverable subset.

      theorem Cslib.Distributed.CRDT.deliverableEvents_eq_self_of_closed {Ev : Type u_1} [DecidableEq Ev] (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (deps : Ev → Finset Ev) (hdeps_prec : ∀ (e x : Ev), x ∈ deps e → prec x e) {M : Finset Ev} (hclosed : ∀ e ∈ M, deps e ⊆ M) :

      When M is already closed under deps (∀ e ∈ M, deps e ⊆ M) and prec is a strict partial order with ∀ e x, x ∈ deps e → prec x e, every event in M becomes causally deliverable within M.card steps (deliverableEvents deps M = M).

      noncomputable def Cslib.Distributed.CRDT.CmRDT.toCvRDT {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (deps : Ev → Finset Ev) (effOf : Ev → Eff) :
      CvRDT (Finset Ev) Ev Q

      State-based CvRDT emulation of an operation-based CmRDT (step toward #7502, after [SPBZ11b], §3.2.2 Theorem 3.2, pp. 9–10; [SPBZ11a], §2.4.2 Specification 4, p. 13): replicas maintain known unique events M : Finset Ev ordered by (⊆) with merge (· ∪ ·), update locally by inserting a newly generated event insert e M, and answer queries by evaluating C over the causally deliverable subset deliverableEvents deps M.

      theorem Cslib.Distributed.CRDT.CmRDT.toCvRDT_query_eq {S : Type u_1} {Op : Type u_2} {Eff : Type u_3} {Q : Type u_4} {Ev : Type u_5} [DecidableEq Ev] (C : CmRDT S Op Eff Q) (prec : Ev → Ev → Prop) [IsStrictOrder Ev prec] (deps : Ev → Finset Ev) (hdeps_prec : ∀ (e x : Ev), x ∈ deps e → prec x e) (effOf : Ev → Eff) {M : Finset Ev} (hclosed : ∀ e ∈ M, deps e ⊆ M) {l : List Ev} (hcomm : ConcurrentCommute C.effect prec effOf ↑M) (hl : IsCausalLinearization prec M l) :
      (C.toCvRDT prec deps effOf).query M = C.query (List.foldl (fun (s : S) (e : Ev) => C.effect (effOf e) s) C.init l)

      On any deps-closed known-event history M whose concurrent events commute, the state-based emulation (C.toCvRDT prec deps effOf).query M returns the exact same query result as applying C along any causal linearization l of M.