-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathCRDT.tla
64 lines (46 loc) · 1.84 KB
/
CRDT.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
------------------------------- MODULE CRDT ---------------------------------
EXTENDS Naturals
CONSTANT Node
VARIABLE counter
vars == counter
TypeOK == counter \in [Node -> [Node -> Nat]]
Safety == \A n, o \in Node : counter[n][n] >= counter[o][n]
Monotonic == \A n, o \in Node : counter'[n][o] >= counter[n][o]
Monotonicity == [][Monotonic]_counter
\* Repeatedly, the counters at all nodes are in sync.
Convergence == []<>(\A n, o \in Node : counter[n] = counter[o])
Init == counter = [n \in Node |-> [o \in Node |-> 0]]
Increment(n) == counter' = [counter EXCEPT ![n][n] = @ + 1]
Gossip(n, o) ==
LET Max(a, b) == IF a > b THEN a ELSE b IN
counter' = [
counter EXCEPT ![o] = [
nodeView \in Node |->
Max(counter[n][nodeView], counter[o][nodeView])
]
]
Next ==
\/ \E n \in Node : Increment(n)
\/ \E n, o \in Node : Gossip(n, o)
Spec ==
/\ Init
/\ [][Next]_counter
THEOREM Spec => []Safety
THEOREM Spec => []TypeOK
(***************************************************************************)
(* Fairness and liveness assumptions. *)
(* We assume that Gossip actions will eventually occur when enabled, and *)
(* that from some point onwards, only Gossip actions will be performed. *)
(* In other words, incrementation of counters happens only finitely often. *)
(* Note that the second conjunct is not a standard fairness condition, *)
(* yet the overall specification is machine closed. *)
(***************************************************************************)
Fairness ==
/\ \A n, o \in Node : WF_vars(Gossip(n,o))
/\ <>[][\E n, o \in Node : Gossip(n,o)]_vars
FairSpec ==
/\ Spec
/\ Fairness
THEOREM FairSpec => Convergence
THEOREM FairSpec => Monotonicity
=============================================================================