-
Notifications
You must be signed in to change notification settings - Fork 2
/
Paxos.tla
75 lines (62 loc) · 2.3 KB
/
Paxos.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
64
65
66
67
68
69
70
71
72
73
74
75
---- MODULE Paxos ----
EXTENDS Integers, Sequences, FiniteSets, TLC
CONSTANT Value, Acceptor, Quorum
perms == Permutations(Acceptor)
Ballot == 0..2
VARIABLE msgs, maxBal, maxVBal
Send(m) == msgs' = msgs \cup {m}
Phase1a(b) ==
/\ Send([type |-> "1a", bal |-> b])
/\ UNCHANGED <<maxBal, maxVBal>>
Phase1b(a) ==
\E m \in msgs:
/\ m.type = "1a" /\ maxBal[a] < m.bal
/\ maxBal' = [maxBal EXCEPT ![a] = m.bal - 1]
/\ Send([type |-> "1b",
acc |-> a,
bal |-> m.bal,
vbal |-> maxVBal[a]])
/\ UNCHANGED <<maxVBal>>
Phase2a(b, v) ==
/\ ~\E m \in msgs: m.type = "2a" /\ m.bal = b
/\ \E q \in Quorum:
LET
Q1b == { m \in msgs: m.type = "1b" /\ m.acc \in q /\ m.bal = b }
Q1bv == { m \in Q1b: m.vbal[1] >= 0 }
IN
/\ \A a \in q: \E m \in Q1b: m.acc = a
/\ \/ Q1bv = {}
\/ \E m \in Q1bv:
/\ m.vbal[2] = v
/\ \A mm \in Q1bv: m.vbal[1] >= mm.vbal[1]
/\ Send([type |-> "2a", bal |-> b, val |-> v])
/\ UNCHANGED <<maxBal, maxVBal>>
Phase2b(a) ==
\E m \in msgs:
/\ m.type = "2a" /\ maxBal[a] < m.bal
/\ maxBal' = [maxBal EXCEPT ![a] = m.bal]
/\ maxVBal' = [maxVBal EXCEPT ![a] = <<m.bal, m.val>>]
/\ Send([type |-> "2b", acc |-> a, bal |-> m.bal, val |-> m.val])
Init ==
/\ msgs = {}
/\ maxBal = [a \in Acceptor |-> -1]
/\ maxVBal = [a \in Acceptor |-> << -1, -1 >>]
Next ==
\/ \E b \in Ballot:
\/ Phase1a(b)
\/ \E v \in Value: Phase2a(b, v)
\/ \E a \in Acceptor:
\/ Phase1b(a)
\/ Phase2b(a)
chosen == {v \in Value: \E q \in Quorum, b \in Ballot: \A a \in q:
[type |-> "2b", acc |-> a, bal |-> b, val |-> v] \in msgs}
TypeOK ==
/\ msgs \subseteq ([type: {"1a"}, bal: Ballot]
\cup [type: {"1b"}, bal: Ballot, acc: Acceptor, vbal: (Ballot \cup {-1}) \X (Value \cup {-1})]
\cup [type: {"2a"}, bal: Ballot, val: Value]
\cup [type: {"2b"}, bal: Ballot, val: Value, acc: Acceptor])
/\ maxBal \in [Acceptor -> Ballot \cup {-1}]
/\ maxVBal \in [Acceptor -> (Ballot \cup {-1}) \X (Value \cup {-1})]
/\ \A v1, v2 \in chosen: v1 = v2
\* /\ chosen = {}
====