-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPaxosPluscal.tla
More file actions
2539 lines (2451 loc) · 123 KB
/
Copy pathPaxosPluscal.tla
File metadata and controls
2539 lines (2451 loc) · 123 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--------------------------- MODULE PaxosPluscal -----------------------------
(***************************************************************************)
(* This module contains a version of the Paxos algorithm written in *)
(* PlusCal, with a proof of the consistency property. In this *)
(* specification, the two participants, acceptor and proposer/learner, are *)
(* modeled as disjoint processes, each with their own invariant *)
(* properties. *)
(* *)
(* The goal of this spec and proof is to obtain a low-level model of the *)
(* algorithm, closer to an implementation in an imperative language, with *)
(* disjoint invariants for the proposer and the acceptor, i.e., formulas *)
(* that do not share variables (except one variable representing network *)
(* communication). Consequently, ballots are modeled as tuples of ballot *)
(* number and proposer id, the main processes are enclosed in an infinite *)
(* loop, and proposers have a local variable that keep track of the *)
(* acceptors that replied to it, which is used to compute quorums. *)
(* *)
(* Additionally, this specification includes an optimization that allows a *)
(* proposer to preempt and restart its execution when it receives a *)
(* message from an acceptor with a higher ballot than its own. *)
(* *)
(* This spec was built starting from the simpler TLA+ spec of Paxos by *)
(* Leslie Lamport where only acceptors were modeled. *)
(* *)
(* Proved with TLAPS v1.4.3, CVC4 v1.4, and Z3 v4.3.2. *)
(* *)
(* Author: `^Hern\'an Vanzetto, 2018^'. *)
(***************************************************************************)
EXTENDS Integers, TLAPS, TLC, Sequences, SequenceTheorems
CONSTANTS
Acceptors, \* Set of acceptor ids.
Proposers, \* Set of proposer ids.
Values, \* Set of values that proposers are allowed to vote for.
Quorums \* Set of possible quorums of acceptor ids.
ASSUME QuorumAssumption1 == Quorums \subseteq SUBSET Acceptors
ASSUME QuorumAssumption2 == \A Q1, Q2 \in Quorums : Q1 \cap Q2 # {}
LEMMA QuorumNonEmpty == \A Q \in Quorums : Q # {}
BY QuorumAssumption2
ASSUME ProposersNat == \A p \in Proposers: p \in Nat
(* A ballot is a tuple composed of a ballot number and a proposer id. *)
ValidBallots == Nat \X Proposers
NoBallot == << -1, -1 >>
Ballots == ValidBallots \cup {NoBallot}
USE DEF Ballots
NoValue == CHOOSE v : v \notin Values
LEMMA NoValueNotAValue == NoValue \notin Values
BY NoSetContainsEverything DEF NoValue
Messages ==
[type : {"1a"}, from : Proposers, bal : ValidBallots]
\cup [type : {"1b"}, from : Acceptors, bal : ValidBallots,
to: Proposers, vbal : Ballots, vval : Values \cup {NoValue}]
\cup [type : {"2a"}, from : Proposers, bal : ValidBallots, val : Values]
\cup [type : {"2b"}, from : Acceptors, bal : ValidBallots,
to: Proposers, val : Values \cup {NoValue}]
(*** this is a comment containing the PlusCal code *
--algorithm Paxos
variables
msgs = {} \* The set of messages that have been sent by proposers and acceptors,
\* representing the history of network communication.
define
\* The next ballot of b increases the ballot number by one:
nextBallot(b,p) == IF b = NoBallot THEN << 0, p >> ELSE << b[1] + 1, p >>
\* Lexicographic order of ballots:
a \prec b ==
\/ a[1] < b[1]
\/ a[1] = b[1] /\ a[2] < b[2]
a \preceq b == a \prec b \/ a = b
end define;
macro Send(m) begin msgs := msgs \cup {m}; end macro;
process prop \in Proposers
variables
pBal = NoBallot, \* For each proposer, its ballot number.
pVBal = NoBallot, \* For each proposer, ballot of the highest registered vote.
pVVal = NoValue, \* For each proposer, value of the highest registered vote.
pQ1 = {}, \* Sets of acceptor ids for keeping record of "1b" and "2b"
pQ2 = {}, \* messages, repectively, received by each proposer.
pWr = FALSE, \* pWr[p] = Is proposer p's voted value pVVal written?
pLBal = NoBallot; \* Ballot of the last "2a" message sent by proposer.
begin
P1: while TRUE do
\********************************************************************
\* Proposer step 1 [Set and send ballot]. Set the ballot number to
\* the current number plus one, store that number in pBal, and send a
\* "1a" message to all acceptors.
\*
\* A proposer p can be preempted. Some acceptor may preempt the
\* execution of p by replying to p with a ballot number higher than
\* p's ballot. In this case, p is enabled to execute action P1 again
\* and allowed to set a new ballot number.
\* Resetting the variables pVBal, pVVal, pQ1 and pQ2 is required in
\* case process prop was preempted.
\********************************************************************
when pWr = FALSE;
pBal := nextBallot(pBal,self);
Send([type |-> "1a", from |-> self, bal |-> pBal]);
pVBal := NoBallot;
pVVal := NoValue;
pQ1 := {};
pQ2 := {};
P2:
\********************************************************************
\* Proposer step 2a [Wait]. Receive and process one "1b" message at a
\* time, until a quorum of acceptors have replied. The messages must
\* satisfy the following conditions: p is the message's target, the
\* message has the same ballot as the proposer's. The sender ids (the
\* acceptors ids) are recorded in pQ1, until there is a majority of
\* acceptors in pQ1. If the message's ballot is higher than the
\* current ballot, the execution is aborted and restarted from P1.
\* The variables pVBal and pVVal store the ballot and vote of the
\* highest-seen ballot, discarding the votes that come with the lower
\* ballots.
\********************************************************************
while pQ1 \notin Quorums do
with m \in { x \in msgs : /\ x.type = "1b"
/\ x.to = self
/\ x.from \notin pQ1} do
if m.bal = pBal then
pQ1 := pQ1 \cup {m.from};
if pVBal \prec m.vbal then
pVBal := m.vbal;
pVVal := m.vval;
end if;
elsif pBal \prec m.bal then
goto P1;
end if
end with
end while;
\********************************************************************
\* Proposer step 2b [Select and send value]. Now there is a set of
\* "1a" messages from a quorum of acceptors, whose ids are stored in
\* pQ1 (so pQ1 \in Quorums). This step selects a value to propose in
\* the following way. If pVBal = NoBallot, some value is selected
\* non-deterministically, representing a value passed as an argument
\* to the proposer. Otherwise, if there is a valid ballot in pVBal,
\* the value to be sent is in pVVal.
\* The conditions pQ1 \in Quorums /\ pQ2 = {} /\ pLBal \prec pBal
\* are redundant; they just help simplify the invariants by not
\* relying on the variable pc, specifically the condition pc[p] = "P2".
\********************************************************************
when pQ1 \in Quorums /\ pQ2 = {} /\ pLBal \prec pBal;
with v \in Values do
when pVBal = NoBallot \/ (pVBal \in ValidBallots /\ v = pVVal);
Send([type |-> "2a", from |-> self, bal |-> pBal, val |-> v]);
pLBal := pBal;
end with;
P3:
\********************************************************************
\* Proposer step 3 [Wait and Learn]. Collect "2b" messages while
\* recording the senders in pQ2, until there is a majority of
\* acceptors in pQ2. If there is a majority of "2b" messages, the
\* proposer learns that the selected value has been voted. The
\* proposer takes the vote from the last "2b" message, stores the
\* voted ballot and value, and set it to "written". If the message's
\* ballot is higher than the proposer's ballot, abort the execution
\* and restart from P1.
\********************************************************************
while pQ2 \notin Quorums do
with m \in {x \in msgs : /\ x.type = "2b"
/\ x.to = self
/\ x.from \notin pQ2
/\ x.val \in Values } do
if m.bal = pBal then
pQ2 := pQ2 \cup {m.from};
pVBal := m.bal;
pVVal := m.val;
elsif pBal \prec m.bal then
goto P1;
end if
end with
end while;
pWr := TRUE;
end while
end process;
process acc \in Acceptors
variables
aBal = NoBallot, \* The highest-numbered ballot acceptor acc has participated in.
aVBal = NoBallot, \* The highest ballot in which the acceptor has voted, and
aVVal = NoValue; \* the value it voted for in that ballot.
begin
A1: while TRUE do
with m \in msgs do
either
\****************************************************************
\* Acceptor phase 1 [Promise]. Acceptor acc process a "1a"
\* message only if the message's ballot is strictly higher than
\* the acceptor's current ballot. It updates the highest seen
\* ballot number. In this version of Paxos with preemption, the
\* acceptor always responds with the highest ballot it has seen.
\* If this number is higher than the recipient's ballot, it will
\* cause its preemption. If acceptor and proposer are
\* participating in the same ballot b, the "1b" response is a
\* promise from the acceptor of not accepting any proposals for
\* ballots less than b.
\****************************************************************
when m.type = "1a";
if aBal \prec m.bal then aBal := m.bal; end if;
Send([type |-> "1b", from |-> self, to |-> m.from,
bal |-> aBal, vbal |-> aVBal, vval |-> aVVal]);
or
\****************************************************************
\* Acceptor phase 2 [Vote]: If an acceptor receives a "2a"
\* message for a ballot numbered b, it votes for the message's
\* value in ballot b unless it has already responded to a "1a"
\* request for a ballot number greater than or equal to b.
\* In the latter case, the acceptor responds with a NoValue value
\* to tell the proposer to not use that ballot number.
\****************************************************************
when m.type = "2a";
if aBal \preceq m.bal then
aBal := m.bal;
aVBal := m.bal;
aVVal := m.val;
Send([type |-> "2b", from |-> self, to |-> m.from,
bal |-> m.bal, val |-> m.val]);
else
Send([type |-> "2b", from |-> self, to |-> m.from,
bal |-> aBal, val |-> NoValue]);
end if
end either
end with
end while
end process
end algorithm
*** this ends the comment containg the pluscal code **********)
(***************************************************************************)
(* The following TLA+ spec definitions were automatically translated from *)
(* the PlusCal program above. Do not modify them manually. *)
(***************************************************************************)
\* BEGIN TRANSLATION
VARIABLES msgs, pc
(* define statement *)
nextBallot(b,p) == IF b = NoBallot THEN << 0, p >> ELSE << b[1] + 1, p >>
a \prec b ==
\/ a[1] < b[1]
\/ a[1] = b[1] /\ a[2] < b[2]
a \preceq b == a \prec b \/ a = b
VARIABLES pBal, pVBal, pVVal, pQ1, pQ2, pWr, pLBal, aBal, aVBal, aVVal
vars == << msgs, pc, pBal, pVBal, pVVal, pQ1, pQ2, pWr, pLBal, aBal, aVBal,
aVVal >>
ProcSet == (Proposers) \cup (Acceptors)
Init == (* Global variables *)
/\ msgs = {}
(* Process prop *)
/\ pBal = [self \in Proposers |-> NoBallot]
/\ pVBal = [self \in Proposers |-> NoBallot]
/\ pVVal = [self \in Proposers |-> NoValue]
/\ pQ1 = [self \in Proposers |-> {}]
/\ pQ2 = [self \in Proposers |-> {}]
/\ pWr = [self \in Proposers |-> FALSE]
/\ pLBal = [self \in Proposers |-> NoBallot]
(* Process acc *)
/\ aBal = [self \in Acceptors |-> NoBallot]
/\ aVBal = [self \in Acceptors |-> NoBallot]
/\ aVVal = [self \in Acceptors |-> NoValue]
/\ pc = [self \in ProcSet |-> CASE self \in Proposers -> "P1"
[] self \in Acceptors -> "A1"]
P1(self) == /\ pc[self] = "P1"
/\ pWr[self] = FALSE
/\ pBal' = [pBal EXCEPT ![self] = nextBallot(pBal[self],self)]
/\ msgs' = (msgs \cup {([type |-> "1a", from |-> self, bal |-> pBal'[self]])})
/\ pVBal' = [pVBal EXCEPT ![self] = NoBallot]
/\ pVVal' = [pVVal EXCEPT ![self] = NoValue]
/\ pQ1' = [pQ1 EXCEPT ![self] = {}]
/\ pQ2' = [pQ2 EXCEPT ![self] = {}]
/\ pc' = [pc EXCEPT ![self] = "P2"]
/\ UNCHANGED << pWr, pLBal, aBal, aVBal, aVVal >>
P2(self) == /\ pc[self] = "P2"
/\ IF pQ1[self] \notin Quorums
THEN /\ \E m \in { x \in msgs : /\ x.type = "1b"
/\ x.to = self
/\ x.from \notin pQ1[self]}:
IF m.bal = pBal[self]
THEN /\ pQ1' = [pQ1 EXCEPT ![self] = pQ1[self] \cup {m.from}]
/\ IF pVBal[self] \prec m.vbal
THEN /\ pVBal' = [pVBal EXCEPT ![self] = m.vbal]
/\ pVVal' = [pVVal EXCEPT ![self] = m.vval]
ELSE /\ TRUE
/\ UNCHANGED << pVBal, pVVal >>
/\ pc' = [pc EXCEPT ![self] = "P2"]
ELSE /\ IF pBal[self] \prec m.bal
THEN /\ pc' = [pc EXCEPT ![self] = "P1"]
ELSE /\ pc' = [pc EXCEPT ![self] = "P2"]
/\ UNCHANGED << pVBal, pVVal, pQ1 >>
/\ UNCHANGED << msgs, pLBal >>
ELSE /\ pQ1[self] \in Quorums /\ pQ2[self] = {} /\ pLBal[self] \prec pBal[self]
/\ \E v \in Values:
/\ pVBal[self] = NoBallot \/ (pVBal[self] \in ValidBallots /\ v = pVVal[self])
/\ msgs' = (msgs \cup {([type |-> "2a", from |-> self, bal |-> pBal[self], val |-> v])})
/\ pLBal' = [pLBal EXCEPT ![self] = pBal[self]]
/\ pc' = [pc EXCEPT ![self] = "P3"]
/\ UNCHANGED << pVBal, pVVal, pQ1 >>
/\ UNCHANGED << pBal, pQ2, pWr, aBal, aVBal, aVVal >>
P3(self) == /\ pc[self] = "P3"
/\ IF pQ2[self] \notin Quorums
THEN /\ \E m \in {x \in msgs : /\ x.type = "2b"
/\ x.to = self
/\ x.from \notin pQ2[self]
/\ x.val \in Values }:
IF m.bal = pBal[self]
THEN /\ pQ2' = [pQ2 EXCEPT ![self] = pQ2[self] \cup {m.from}]
/\ pVBal' = [pVBal EXCEPT ![self] = m.bal]
/\ pVVal' = [pVVal EXCEPT ![self] = m.val]
/\ pc' = [pc EXCEPT ![self] = "P3"]
ELSE /\ IF pBal[self] \prec m.bal
THEN /\ pc' = [pc EXCEPT ![self] = "P1"]
ELSE /\ pc' = [pc EXCEPT ![self] = "P3"]
/\ UNCHANGED << pVBal, pVVal, pQ2 >>
/\ pWr' = pWr
ELSE /\ pWr' = [pWr EXCEPT ![self] = TRUE]
/\ pc' = [pc EXCEPT ![self] = "P1"]
/\ UNCHANGED << pVBal, pVVal, pQ2 >>
/\ UNCHANGED << msgs, pBal, pQ1, pLBal, aBal, aVBal, aVVal >>
prop(self) == P1(self) \/ P2(self) \/ P3(self)
A1(self) == /\ pc[self] = "A1"
/\ \E m \in msgs:
\/ /\ m.type = "1a"
/\ IF aBal[self] \prec m.bal
THEN /\ aBal' = [aBal EXCEPT ![self] = m.bal]
ELSE /\ TRUE
/\ aBal' = aBal
/\ msgs' = (msgs \cup {([type |-> "1b", from |-> self, to |-> m.from,
bal |-> aBal'[self], vbal |-> aVBal[self], vval |-> aVVal[self]])})
/\ UNCHANGED <<aVBal, aVVal>>
\/ /\ m.type = "2a"
/\ IF aBal[self] \preceq m.bal
THEN /\ aBal' = [aBal EXCEPT ![self] = m.bal]
/\ aVBal' = [aVBal EXCEPT ![self] = m.bal]
/\ aVVal' = [aVVal EXCEPT ![self] = m.val]
/\ msgs' = (msgs \cup {([type |-> "2b", from |-> self, to |-> m.from,
bal |-> m.bal, val |-> m.val])})
ELSE /\ msgs' = (msgs \cup {([type |-> "2b", from |-> self, to |-> m.from,
bal |-> aBal[self], val |-> NoValue])})
/\ UNCHANGED << aBal, aVBal, aVVal >>
/\ pc' = [pc EXCEPT ![self] = "A1"]
/\ UNCHANGED << pBal, pVBal, pVVal, pQ1, pQ2, pWr, pLBal >>
acc(self) == A1(self)
Next == (\E self \in Proposers: prop(self))
\/ (\E self \in Acceptors: acc(self))
Spec == Init /\ [][Next]_vars
\* END TRANSLATION
-----------------------------------------------------------------------------
(***************************************************************************)
(* Extra spec definitions. We split the specification variables into *)
(* variables that are shared (messages and pc), and variables for *)
(* proposers and for acceptors. *)
(***************************************************************************)
\** shared variables
svars == <<msgs, pc>>
\** proposer variables
pvars == <<pBal, pVBal, pVVal, pWr, pQ1, pQ2, pLBal>>
\** acceptor variables
avars == <<aBal, aVBal, aVVal>>
\** shared variables initial state
SInit ==
/\ msgs = {}
/\ pc = [self \in ProcSet |-> CASE self \in Proposers -> "P1"
[] self \in Acceptors -> "A1"]
\** proposer initial state
PInit ==
/\ pBal = [p \in Proposers |-> NoBallot]
/\ pVBal = [p \in Proposers |-> NoBallot]
/\ pVVal = [p \in Proposers |-> NoValue]
/\ pWr = [p \in Proposers |-> FALSE]
/\ pQ1 = [p \in Proposers |-> {}]
/\ pQ2 = [p \in Proposers |-> {}]
/\ pLBal = [p \in Proposers |-> NoBallot]
\** acceptor initial state
AInit ==
/\ aBal = [a \in Acceptors |-> NoBallot]
/\ aVBal = [a \in Acceptors |-> NoBallot]
/\ aVVal = [a \in Acceptors |-> NoValue]
\** proposer spec
PNext == \E p \in Proposers : P1(p) \/ P2(p) \/ P3(p)
PSpec == (SInit /\ PInit) /\ [][PNext]_(svars \o pvars)
\** acceptor spec
ANext == \E a \in Acceptors : A1(a)
ASpec == (SInit /\ AInit) /\ [][ANext]_(svars \o avars)
Send(m) == msgs' = msgs \cup {m}
-----------------------------------------------------------------------------
(***************************************************************************)
(* Type correctness invariants. *)
(***************************************************************************)
STypeOK ==
/\ msgs \in SUBSET Messages
/\ pc \in [Acceptors \cup Proposers -> {"A1","P1","P2","P3"}]
ATypeOK ==
/\ aBal \in [Acceptors -> Ballots]
/\ aVBal \in [Acceptors -> Ballots]
/\ aVVal \in [Acceptors -> Values \cup {NoValue}]
PTypeOK ==
/\ pBal \in [Proposers -> Ballots]
/\ pVBal \in [Proposers -> Ballots]
/\ pVVal \in [Proposers -> Values \cup {NoValue}]
/\ pWr \in [Proposers -> BOOLEAN]
/\ pQ1 \in [Proposers -> SUBSET Acceptors]
/\ pQ2 \in [Proposers -> SUBSET Acceptors]
/\ pLBal \in [Proposers -> Ballots]
-----------------------------------------------------------------------------
(***************************************************************************)
(* Chosen(v) means that v has been chosen by a majority of acceptors. *)
(***************************************************************************)
VotedForIn(a, v, b) ==
\E m \in msgs : /\ m.type = "2b"
/\ m.from = a
/\ m.val = v
/\ m.bal = b
/\ m.val \in Values \* For preemption, the acceptor sends a "2b" with a NoValue.
ChosenIn(v, b) == \E Q \in Quorums : \A a \in Q : VotedForIn(a, v, b)
Chosen(v) == \E b \in ValidBallots : ChosenIn(v, b)
(***************************************************************************)
(* The consistency condition that a consensus algorithm must satisfy is *)
(* the invariance of the following state predicate Consistency. *)
(***************************************************************************)
AConsistency == \A v1, v2 \in Values : Chosen(v1) /\ Chosen(v2) => (v1 = v2)
-----------------------------------------------------------------------------
(***************************************************************************)
(* DidntVoteIn(a, b) = "acceptor a has not voted in ballot b". *)
(***************************************************************************)
DidntVoteIn(a, b) == \A v \in Values : ~ VotedForIn(a, v, b)
(***************************************************************************)
(* An acceptor a took part in a voting process with ballot d if it *)
(* responded to that ballot, in either of both phases. *)
(***************************************************************************)
ParticipatedIn(a, d) ==
\E m \in msgs: /\ \/ m.type = "1b"
\/ m.type = "2b" /\ m.val \in Values
/\ m.from = a
/\ m.bal = d
(***************************************************************************)
(* An acceptor a won't vote in ballot c if it participates in a ballot d *)
(* greater than c. We will prove later that this is equivalent to the *)
(* formula c < aBal[a]. *)
(***************************************************************************)
WontVoteIn(a, c) == \E d \in ValidBallots: c \prec d /\ ParticipatedIn(a, d)
(***************************************************************************)
(* The predicate SafeAt is a key invariant for the proof. It means that *)
(* it is "safe" for any proposer to vote for value v in ballot b. *)
(* *)
(* Formally, safe means that at each ballot number c that is lower than b, *)
(* we can take a majority of acceptors Q with the following disjunctive *)
(* property. The first possibility is that the acceptor in Q voted in *)
(* that ballot c, in which case it must have voted for value v. Note that *)
(* not necessarilly a majority of acceptors voted in that ballot. The *)
(* second possibility is that the acceptor in Q did not vote in ballot c *)
(* and will not able to vote in c. *)
(* *)
(* The formula SafeAt is a property about sets of acceptor ids and *)
(* messages sent by acceptors. This formula is equivalent to Lamport's, *)
(* but it does not mention acceptor or proposer variables. *)
(***************************************************************************)
SafeAt(v, b) ==
\A c \in ValidBallots: c \prec b =>
\E Q \in Quorums :
\A a \in Q : \/ VotedForIn(a, v, c)
\/ /\ DidntVoteIn(a, c)
/\ WontVoteIn(a, c) \* This last condition is not required
\* for the consistency proofs, but for
\* making the SafeAt predicate inductive.
-----------------------------------------------------------------------------
(***************************************************************************)
(* `^\textbf{Acceptor properties and invariants}^' *)
(***************************************************************************)
(***************************************************************************)
(* AMsgInv: Acceptor's message invariant. How messages "1b" and "2b" sent *)
(* by an acceptor with id m.from are related to other messages. *)
(***************************************************************************)
AMsgInv ==
\A m \in msgs :
/\ (m.type = "1b") =>
/\ AM2(m):: m.vbal \preceq m.bal
/\ AM3(m):: \/ /\ m.vval \in Values
/\ m.vbal \in ValidBallots
/\ VotedForIn(m.from, m.vval, m.vbal)
\/ /\ m.vval = NoValue
/\ m.vbal = NoBallot
/\ AM4(m):: \A c \in ValidBallots:
m.vbal \prec c /\ c \prec m.bal => DidntVoteIn(m.from, c)
/\ (m.type = "2b") /\ (m.val \in Values) =>
/\ AM5(m):: \E mp \in msgs : /\ mp.type = "2a"
/\ mp.from = m.to
/\ mp.bal = m.bal
/\ mp.val = m.val
(***************************************************************************)
(* AStateInv: Inductive invariant about the acceptor variables. Note that *)
(* proposer variables do not appear in this formula. *)
(***************************************************************************)
AStateInv ==
\A a \in Acceptors:
/\ AS1(a):: aVBal[a] = NoBallot <=> aVVal[a] = NoValue
/\ AS2(a):: aVBal[a] \preceq aBal[a]
/\ AS3(a):: aVBal[a] \in ValidBallots => VotedForIn(a, aVVal[a], aVBal[a])
/\ AS4(a):: \A b \in Ballots : aVBal[a] \prec b => DidntVoteIn(a, b)
/\ AS5(a):: \A b \in Ballots : WontVoteIn(a, b) <=> b \prec aBal[a]
/\ AS6(a):: \A m \in msgs: m.from = a /\ (m.type = "1b") => m.bal \preceq aBal[a]
/\ AS7(a):: \A m \in msgs: m.from = a /\ (m.type = "2b") /\ (m.val \in Values)
=> m.bal \preceq aVBal[a]
-----------------------------------------------------------------------------
(***************************************************************************)
(* `^\textbf{Proposer properties and invariants}^' *)
(***************************************************************************)
(***************************************************************************)
(* PKnowsIn(p,v,b): "proposer p knows that value v was chosen at ballot b" *)
(***************************************************************************)
PKnowsIn(p,v,b) == pWr[p] /\ pVBal[p] = b /\ pVVal[p] = v
PKnows(p,v) == \E b \in ValidBallots : PKnowsIn(p, v, b)
PConsistency ==
\A p1, p2 \in Proposers: \A v1, v2 \in Values :
PKnows(p1, v1) /\ PKnows(p1, v2) => (v1 = v2)
(***************************************************************************)
(* PMsgInv: Proposer's message invariant. *)
(***************************************************************************)
PMsgInv ==
\A m \in msgs :
LET p == m.from IN
/\ m.type = "2a" =>
/\ PM1(m):: \A ma \in msgs :
(ma.type = "2a") /\ (ma.bal = m.bal) => (ma.val = m.val)
\* A proposer that attempts to write a value v, it can only write
\* the same value that was attempted before for the same ballot.
\* Required to prove VotedOnce and KnowsSameValue.
/\ PM2(m):: SafeAt(m.val, m.bal)
/\ m.type = "2a" /\ p = pBal[p][2] =>
/\ PM3(m):: m.bal = pBal[p] => pQ1[p] \in Quorums
\* Required in proofs of step P2b.
/\ PM4(m):: m.bal = pBal[p] /\ pVBal[p] \in ValidBallots /\ pQ2[p] \notin Quorums
=> m.val = pVVal[p]
\* Required to prove PS7, step P2b.
/\ PM5(m):: m.type \in {"1a","2a"} => p = m.bal[2]
(***************************************************************************)
(* Msg1bOK(p,S) expresses the relation between proposer p's state *)
(* variables and the messages it received for the first phase. *)
(* *)
(* For proposer p, the "1b" messages received by p satisfy the following *)
(* properties. (1) There is a bijection between the set of "1b" messages *)
(* and the set pQ1[p] of acceptor ids that sent those messages. (2) There *)
(* are two disjoint cases for the messages in S: (2a) If p's current voted *)
(* ballot pVBal[p] contains the initial value, it is because all acceptors *)
(* that replied didn't cast any vote yet. (2b) If p has recorded a valid *)
(* vote <<pVBal[p], pVVal[p]>>, then that vote has the highest ballot *)
(* number of all "1b" replies; moreover, that vote was sent by at least *)
(* one acceptor in a "1b" message --if the proposer didn't learn a value *)
(* yet (~ pWr[p]), because the proposed value in "2a" could come from a *)
(* not yet processed "1b" message. *)
(***************************************************************************)
Msg1bOK(p,S) ==
/\ \A m \in S : m.type = "1b" /\ m.to = p /\ m.bal = pBal[p] /\ m.from \in pQ1[p]
/\ \A a \in pQ1[p] : \E m \in S : m.from = a
/\ IF pVBal[p] = NoBallot
THEN \A m \in S : m.vbal = NoBallot
ELSE /\ \A m \in S : m.vbal \preceq pVBal[p]
/\ ~ pWr[p] => \E m \in S : m.vbal = pVBal[p] /\ m.vval = pVVal[p]
(***************************************************************************)
(* Msg2bOK(p,S) expresses the relation between proposer p's state *)
(* variables and the messages it received for the second phase. *)
(***************************************************************************)
Msg2bOK(p,S) ==
/\ \A m \in S : /\ m.type = "2b" /\ m.to = p /\ m.bal = pBal[p]
/\ m.from \in pQ2[p] /\ m.val \in Values
/\ \A a \in pQ2[p] : \E m \in S : m.from = a
(***************************************************************************)
(* PStateInv: Inductive invariant about the proposer variables. Note that *)
(* acceptor variables do not appear in the formula. *)
(***************************************************************************)
PStateInv ==
\A p \in Proposers:
/\ PS1(p):: pVBal[p] = NoBallot <=> pVVal[p] = NoValue
/\ PS2(p):: pVBal[p] \preceq pBal[p]
/\ PS3(p):: pVBal[p] \in ValidBallots => pBal[p] \in ValidBallots
/\ PS4(p):: pQ1[p] = {} => pVBal[p] = NoBallot /\ pVVal[p] = NoValue
/\ PS5(p):: pQ1[p] # {} /\ pQ2[p] = {} =>
pBal[p] \in ValidBallots /\ \E S \in SUBSET msgs: Msg1bOK(p,S)
/\ PS6(p):: pQ2[p] # {} =>
pVBal[p] = pBal[p] /\ \E S \in SUBSET msgs: Msg2bOK(p,S)
/\ PS7(p):: pVBal[p] \in ValidBallots =>
\A a \in pQ2[p] : VotedForIn(a, pVVal[p], pBal[p]) \* Used in PConsistent.
/\ PS8(p):: pWr[p] => pQ1[p] \in Quorums /\ pQ2[p] \in Quorums /\ pVBal[p] = pBal[p]
/\ PS9(p):: \A a \in pQ1[p], c \in ValidBallots:
pVBal[p] \prec c /\ c \prec pBal[p] =>
DidntVoteIn(a, c) /\ WontVoteIn(a, c) \* For proving SafeAt
/\ PS10(p):: pQ1[p] \notin Quorums => pQ2[p] = {} \* Required for step <4>2 of PS6.
/\ PS11(p):: pLBal[p] \preceq pBal[p]
/\ PS12(p):: \A m \in msgs: m.type = "1a" /\ m.from = p => m.bal \preceq pBal[p]
/\ PS13(p):: \A m \in msgs: m.type = "2a" /\ m.from = p => m.bal \preceq pLBal[p]
/\ PS14(p):: pBal[p] \in ValidBallots => pBal[p][2] = p
-----------------------------------------------------------------------------
(***************************************************************************)
(* Inv is the inductive invariant of the whole system. *)
(***************************************************************************)
\** proposer invariant
PInv == STypeOK /\ PTypeOK /\ PMsgInv /\ PStateInv
\** acceptor invariant
AInv == STypeOK /\ ATypeOK /\ AMsgInv /\ AStateInv
\** whole system's invariant
Inv == PInv /\ AInv
-----------------------------------------------------------------------------
(***************************************************************************)
(* VotedOnce: When two values are voted in the same ballot, then those *)
(* values must be equal, regardless of which acceptor voted. *)
(***************************************************************************)
LEMMA VotedOnce ==
ASSUME AMsgInv, PMsgInv
PROVE \A a1, a2 \in Acceptors, b \in ValidBallots, v1, v2 \in Values :
VotedForIn(a1, v1, b) /\ VotedForIn(a2, v2, b) => (v1 = v2)
BY Z3 DEF PMsgInv, AMsgInv, VotedForIn
\* From VotedForIn(a1, v1, b), there exists a "2a" message for ballot b,
\* by AM5. Equally for VotedForIn(a2, v2, b), there exists another "2a"
\* message for b. Then v1 = v2, by PM1.
(***************************************************************************)
(* KnowsSameValue: If two proposers learn some values in the same ballot, *)
(* then those values must be the same. *)
(***************************************************************************)
LEMMA KnowsSameValue ==
ASSUME AMsgInv, PMsgInv, PStateInv
PROVE \A p1, p2 \in Proposers, b \in ValidBallots, v1, v2 \in Values :
PKnowsIn(p1, v1, b) /\ PKnowsIn(p2, v2, b) => (v1 = v2)
<1> SUFFICES ASSUME NEW p1 \in Proposers, NEW p2 \in Proposers,
NEW b \in ValidBallots,
NEW v1 \in Values, NEW v2 \in Values,
PKnowsIn(p1, v1, b), PKnowsIn(p2, v2, b)
PROVE v1 = v2
OBVIOUS
<1>1. pQ2[p1] \in Quorums /\ \A a \in pQ2[p1]: VotedForIn(a,v1,b)
BY Z3 DEF PKnowsIn, PStateInv
<1>2. pQ2[p2] \in Quorums /\ \A a \in pQ2[p2]: VotedForIn(a,v2,b)
BY Z3 DEF PKnowsIn, PStateInv
<1> QED
BY <1>1, <1>2, QuorumAssumption2, Z3 DEF PKnowsIn, PMsgInv, AMsgInv, VotedForIn
(***************************************************************************)
(* VotedInv: If an acceptor voted for a value, it was because that value *)
(* was safe (at the same ballot as the vote). *)
(***************************************************************************)
LEMMA VotedInv ==
ASSUME AMsgInv, PMsgInv
PROVE \A a \in Acceptors, v \in Values, b \in ValidBallots :
VotedForIn(a, v, b) => SafeAt(v, b)
BY DEF AMsgInv, PMsgInv, VotedForIn, SafeAt
(***************************************************************************)
(* Corollary of PStateInv!PS6 and AMsgInv!AM5. *)
(***************************************************************************)
COROLLARY ExistsQuorum1 ==
ASSUME STypeOK, PStateInv, AMsgInv, PMsgInv
PROVE \A p \in Proposers: pQ2[p] # {} => pQ1[p] \in Quorums
<1> TAKE p \in Proposers
<1> HAVE pQ2[p] # {}
<1> PICK a \in pQ2[p] : TRUE
OBVIOUS
<1> PICK m2b \in msgs : /\ m2b.type = "2b"
/\ m2b.from = a
/\ m2b.to = p
/\ m2b.bal = pBal[p]
/\ m2b.val \in Values
BY DEF STypeOK, Messages, PStateInv, Msg2bOK
<1> PICK m2a \in msgs : /\ m2a.type = "2a"
/\ m2a.from = m2b.to
/\ m2a.bal = m2b.bal
/\ m2a.val = m2b.val
BY DEF STypeOK, Messages, AMsgInv
<1> QED
BY DEF PMsgInv
-----------------------------------------------------------------------------
(***************************************************************************)
(* `^\textbf{Properties about Ballots, ballot order \prec and NoBallot.}^' *)
(***************************************************************************)
LEMMA SpecialPairEqualIffCase1 ==
ASSUME NEW A, NEW B, NEW x, NEW y,
NEW a \in A \X B \cup {<<x,y>>},
NEW b \in A \X B \cup {<<x,y>>}
PROVE a[1] = b[1] /\ a[2] = b[2] => (a = b)
OBVIOUS (*{by (isabelle "(auto simp: fcnEqualIff prod_def)")}*)
THEOREM BallotEq ==
\A a, b \in Ballots: a = b <=> a[1] = b[1] /\ a[2] = b[2]
BY ProposersNat, SpecialPairEqualIffCase1, Zenon DEFS ValidBallots, NoBallot
LEMMA BallotLeRefl == \A b \in Ballots: b \preceq b
BY DEFS ValidBallots, \preceq
LEMMA BallotLtIsLe == \A a, b \in Ballots: a \prec b => a \preceq b
BY DEF \preceq, \prec
LEMMA NoBallotLowest == \A b \in ValidBallots: NoBallot \prec b
BY DEF \prec, NoBallot, ValidBallots
LEMMA NoBallotNotHighest == \A b \in Ballots: ~ (b \prec NoBallot)
BY DEF \prec, NoBallot, ValidBallots
LEMMA BallotTransLtLt == \A x,y,z \in Ballots: x \prec y /\ y \prec z => x \prec z
BY ProposersNat, SMT DEF \prec, NoBallot, ValidBallots
LEMMA BallotTransLeLe == \A x,y,z \in Ballots: x \preceq y /\ y \preceq z => x \preceq z
BY ProposersNat, SMT DEF \preceq, \prec, NoBallot, ValidBallots
LEMMA BallotTransLeLt == \A x,y,z \in Ballots: x \preceq y /\ y \prec z => x \prec z
BY ProposersNat, SMT DEF \prec, \preceq, NoBallot, ValidBallots
LEMMA BallotTransLtLe == \A x,y,z \in Ballots: x \prec y /\ y \preceq z => x \prec z
BY ProposersNat, SMT DEF \prec, \preceq, NoBallot, ValidBallots
LEMMA BallotLtNe == \A x,y \in Ballots: x \prec y => x # y
BY ProposersNat, SMT DEF \prec, NoBallot, ValidBallots
LEMMA BallotLeDef == \A a,b \in Ballots: a \preceq b <=> a \prec b \/ a = b
BY ProposersNat DEF \preceq, \prec, ValidBallots
LEMMA BallotLtTrichotomy == \A a,b \in Ballots: a \prec b \/ a = b \/ b \prec a
BY BallotEq, ProposersNat, Z3 DEF \prec, ValidBallots, NoBallot
LEMMA BallotLtNeg == \A a,b \in Ballots: ~ (a \prec b) => a = b \/ b \prec a
BY BallotEq, ProposersNat, Z3 DEF \prec, ValidBallots, NoBallot
LEMMA BallotLtLtDisjoint == \A x,y \in Ballots : x \prec y /\ y \prec x => FALSE
BY ProposersNat, Z3 DEF \prec, ValidBallots, NoBallot
LEMMA BallotLeLtDisjoint == \A x,y \in Ballots : x \prec y /\ y \preceq x => FALSE
BY BallotLtLtDisjoint, BallotLtNe, BallotLeDef
LEMMA NoBallotNotInValidBallots == NoBallot \notin ValidBallots
BY DEFS NoBallot, ValidBallots
LEMMA BallotLeNegNoBallot == \A x,y \in Ballots: ~ (x \preceq y) => x # NoBallot
BY BallotLtTrichotomy, NoBallotNotHighest, BallotLeDef, Z3 DEF ValidBallots
LEMMA BallotLtNoBallot == \A x, y \in Ballots: x \prec y => y # NoBallot
BY DEFS \prec, NoBallot, ValidBallots
THEOREM BallotLtProps ==
/\ BallotLeRefl
/\ BallotLtIsLe
/\ NoBallotLowest
/\ NoBallotNotHighest
/\ BallotTransLtLt /\ BallotTransLtLe /\ BallotTransLeLt /\ BallotTransLeLe
/\ BallotLtNe
/\ BallotLeDef
/\ BallotLtTrichotomy
/\ BallotLtNeg /\ BallotLtLtDisjoint /\ BallotLeLtDisjoint /\ BallotLeLtDisjoint
/\ BallotLeNegNoBallot /\ BallotLtNoBallot
BY BallotLeRefl, BallotLtIsLe, NoBallotLowest, NoBallotNotHighest,
BallotTransLtLt, BallotTransLtLe, BallotTransLeLt, BallotTransLeLe,
BallotLtNe, BallotLeDef, BallotLtTrichotomy,
BallotLtNeg, BallotLtLtDisjoint, BallotLeLtDisjoint, BallotLeLtDisjoint,
BallotLeNegNoBallot, BallotLtNoBallot
USE DEF BallotLtProps
LEMMA NextBallotGtAll == \A b \in Ballots, p \in Proposers: b \prec nextBallot(b,p)
BY NoBallotNotInValidBallots DEF nextBallot, \prec, ValidBallots, NoBallot
LEMMA NextBallotInValidBallots == \A b \in Ballots, p \in Proposers: nextBallot(b,p) \in ValidBallots
BY DEF nextBallot, ValidBallots
LEMMA NextBallotProj1 == \A b \in ValidBallots, p \in Proposers: nextBallot(b,p)[1] = b[1] + 1
BY NoBallotNotInValidBallots DEF nextBallot, ValidBallots
LEMMA NextBallotProj2 == \A b \in Ballots, p \in Proposers: nextBallot(b,p)[2] = p
BY DEF nextBallot, ValidBallots
THEOREM NextBallotProps ==
/\ NextBallotGtAll
/\ NextBallotInValidBallots
/\ NextBallotProj1
/\ NextBallotProj2
BY NextBallotGtAll, NextBallotInValidBallots, NextBallotProj1, NextBallotProj2
USE DEF NextBallotProps
-----------------------------------------------------------------------------
(***************************************************************************)
(* Theorems PSafeAtStable and ASafeAtStable show that (the invariant *)
(* implies that) the predicate SafeAt(v, b) is stable, meaning that once *)
(* it becomes true, it remains true throughout the rest of the execution. *)
(***************************************************************************)
LEMMA PSafeAtStable ==
ASSUME PNext
PROVE \A v \in Values, b \in ValidBallots: SafeAt(v, b) => SafeAt(v, b)'
BY SMTT(10) DEF PNext, P1, P2, P3,
Send, ValidBallots, SafeAt, DidntVoteIn, VotedForIn,
WontVoteIn, ParticipatedIn
LEMMA ASafeAtStable ==
ASSUME AInv, ANext, ATypeOK'
PROVE \A v \in Values, b \in ValidBallots: SafeAt(v, b) => SafeAt(v, b)'
<1> USE DEF Send, AInv, ValidBallots
<1> SUFFICES ASSUME NEW v \in Values, NEW b \in ValidBallots,
SafeAt(v, b)
PROVE SafeAt(v, b)'
BY Isa
<1>1. SUFFICES ASSUME NEW a \in Acceptors, A1(a) PROVE SafeAt(v, b)'
BY DEF ANext
<1>2. PICK m \in msgs: A1(a)!2!(m)
BY <1>1 DEF A1
<1>a. CASE A1(a)!2!(m)!1
<2> SUFFICES ASSUME m.type = "1a",
IF aBal[a] \prec m.bal
THEN aBal' = [aBal EXCEPT ![a] = m.bal]
ELSE aBal' = aBal,
Send([type |-> "1b", from |-> a, to |-> m.from, bal |-> (aBal')[a],
vbal |-> aVBal[a], vval |-> aVVal[a]]),
UNCHANGED <<aVBal, aVVal>>
PROVE SafeAt(v, b)'
BY <1>a DEF A1
<2> \A aa, vv, cc: VotedForIn(aa, vv, cc)' <=> VotedForIn(aa, vv, cc)
BY NoValueNotAValue DEF A1, VotedForIn, WontVoteIn, ParticipatedIn
<2> QED
BY Z3 DEF A1, WontVoteIn, ParticipatedIn, SafeAt, DidntVoteIn
<1>b. CASE A1(a)!2!(m)!2
<2>0. SUFFICES ASSUME m.type = "2a",
IF aBal[a] \preceq m.bal
THEN /\ aBal' = [aBal EXCEPT ![a] = m.bal]
/\ aVBal' = [aVBal EXCEPT ![a] = m.bal]
/\ aVVal' = [aVVal EXCEPT ![a] = m.val]
/\ Send([type |-> "2b", from |-> a, to |-> m.from,
bal |-> m.bal, val |-> m.val])
ELSE /\ Send([type |-> "2b", from |-> a, to |-> m.from,
bal |-> aBal[a], val |-> NoValue])
/\ UNCHANGED <<aBal, aVBal, aVVal>>,
NEW c \in ValidBallots, c \prec b
PROVE SafeAt(v, b)!(c)'
BY <1>b DEF A1, SafeAt
<2>1. PICK Q \in Quorums : SafeAt(v, b)!(c)!2!(Q)
BY <2>0, Zenon DEF SafeAt
<2> SUFFICES ASSUME NEW a_1 \in Q
PROVE \/ VotedForIn(a_1, v, c)'
\/ DidntVoteIn(a_1, c)' /\ WontVoteIn(a_1, c)'
BY <2>1 DEF SafeAt
<2>a. CASE aBal[a] \preceq m.bal
<3> /\ aBal' = [aBal EXCEPT ![a] = m.bal]
/\ aVBal' = [aVBal EXCEPT ![a] = m.bal]
/\ aVVal' = [aVVal EXCEPT ![a] = m.val]
/\ Send([type |-> "2b", from |-> a, to |-> m.from, bal |-> m.bal, val |-> m.val])
/\ c \prec b
BY <2>0, <2>a
<3>a. CASE VotedForIn(a_1, v, c)
BY <2>a, <3>a, NoValueNotAValue DEFS VotedForIn
<3>b. CASE DidntVoteIn(a_1, c) /\ WontVoteIn(a_1, c)
<4> WontVoteIn(a, m.bal) => m.bal \prec aBal[a]
BY DEF ATypeOK, Messages, AStateInv
<4> QED
BY <2>a, <3>b, BallotLeLtDisjoint
DEFS ATypeOK, DidntVoteIn, VotedForIn, WontVoteIn, ParticipatedIn
<3> QED
BY <3>a, <3>b, <2>1
<2>b. CASE ~ (aBal[a] \preceq m.bal)
<3>1. /\ Send([type |-> "2b", from |-> a, to |-> m.from,
bal |-> aBal[a], val |-> NoValue])
/\ UNCHANGED <<aBal, aVBal, aVVal>>
BY <2>0, <2>b
<3> /\ \A aa, vv, cc: VotedForIn(aa, vv, cc)' <=> VotedForIn(aa, vv, cc)
/\ \A aa, cc: WontVoteIn(aa, cc)' <=> WontVoteIn(aa, cc)
BY <3>1, NoValueNotAValue DEF VotedForIn, WontVoteIn, ParticipatedIn
<3> QED
BY <2>b, NoValueNotAValue, <2>1, Z3
DEFS DidntVoteIn
<2> QED
BY <2>a, <2>b, Zenon
<1> QED
BY <1>2, <1>a, <1>b DEF ANext
THEOREM SafeAtStable ==
ASSUME Inv /\ Next /\ ATypeOK'
PROVE \A v \in Values, b \in ValidBallots: SafeAt(v, b) => SafeAt(v, b)'
BY PSafeAtStable, ASafeAtStable DEF Inv, Next, PNext, ANext, prop, acc
-----------------------------------------------------------------------------
(***************************************************************************)
(* Theorem: the predicate PInv is an inductive invariant in the proposer, *)
(* assuming that the received messages satisfy AMsgInv. *)
(***************************************************************************)
THEOREM PInvariant == ASSUME AMsgInv PROVE PSpec => []PInv
<1> USE DEFS PInv, Send, ProcSet
<1>1. SInit /\ PInit => PInv
<2> HAVE SInit /\ PInit
<2> USE DEFS PInit, SInit
<2>1. STypeOK
BY DEF STypeOK, Messages
<2>2. PTypeOK
BY DEF PTypeOK
<2>3. PMsgInv
BY DEF PMsgInv
<2>4. PStateInv
BY QuorumNonEmpty, BallotLtProps, SMT DEF PStateInv
<2>5. QED
BY <2>1, <2>2, <2>3, <2>4 DEF PInv
<1>2. PInv /\ [PNext]_(svars \o pvars) => PInv'
<2> SUFFICES ASSUME PInv, PNext PROVE PInv'
<3> CASE UNCHANGED (svars \o pvars)
<4> /\ \A aa, vv, cc: VotedForIn(aa, vv, cc)' <=> VotedForIn(aa, vv, cc)
/\ \A aa, cc: WontVoteIn(aa, cc)' <=> WontVoteIn(aa, cc)
BY DEF svars, pvars, VotedForIn, WontVoteIn, ParticipatedIn
<4> USE DEFS svars, pvars, Messages, SafeAt, DidntVoteIn
<4> QED
BY Z3 DEFS STypeOK, PTypeOK, PMsgInv, PStateInv, Msg1bOK, Msg2bOK
<3> QED
OBVIOUS
<2>1. STypeOK' /\ PTypeOK'
<3> USE DEF STypeOK, PTypeOK, Messages
<3>1. CASE \E p \in Proposers: P1(p)
BY <3>1, NextBallotProps, SMT DEF P1, PTypeOK
<3>2. CASE \E p \in Proposers: P2(p) /\ pQ1[p] \notin Quorums
BY <3>2, Z3 DEFS P2
<3>3. CASE \E p \in Proposers: P2(p) /\ pQ1[p] \in Quorums
<4> SUFFICES ASSUME NEW p \in Proposers,
pc[p] = "P2",
pQ1[p] \in Quorums,
pQ2[p] = {},
pLBal[p] \prec pBal[p],
NEW v \in Values,
Send([type |-> "2a", from |-> p, bal |-> pBal[p], val |-> v]),
\/ pVBal[p] = NoBallot
\/ pVBal[p] \in ValidBallots /\ v = pVVal[p],
pLBal' = [pLBal EXCEPT ![p] = pBal[p]],
UNCHANGED <<pBal, pVBal, pVVal, pQ1, pQ2, pWr>>,
pc' = [pc EXCEPT ![p] = "P3"]
PROVE STypeOK' /\ PTypeOK'
BY <3>3 DEF P2
<4>a. CASE pVBal[p] = NoBallot
BY <4>a, QuorumNonEmpty, SMT DEF PStateInv, Msg1bOK \* using pQ2[p] = {}
<4>b. CASE pVBal[p] \in ValidBallots /\ v = pVVal[p]
BY <4>b, Z3 DEFS PStateInv, PTypeOK
<4> QED
BY <4>a, <4>b
<3>4. ASSUME NEW p \in Proposers, P3(p) PROVE <2>1
<4> SUFFICES ASSUME P3(p)!2!2 PROVE <2>1
BY <3>4 DEFS P3
<4> PICK m \in msgs : P3(p)!2!2!1!(m)
BY <3>4 DEFS P3
<4> QED
BY <3>4 DEFS P3
<3> QED
BY <3>1, <3>2, <3>3, <3>4 DEF PNext
<2>2. PMsgInv'
<3> SUFFICES ASSUME NEW m \in msgs' PROVE PMsgInv!(m)!1'
BY DEF PMsgInv
<3>1. m.type \in {"1a","2a"} => m.from = m.bal[2]
<4> HAVE m.type \in {"1a","2a"}
<4>1. CASE \E p \in Proposers: P1(p)
BY <4>1, BallotLtProps, NextBallotProps, Z3
DEF P1, PMsgInv, STypeOK, PTypeOK, Messages
<4>2. CASE \E p \in Proposers: P2(p) /\ pQ1[p] \notin Quorums
BY <4>2 DEF P2, PMsgInv, VotedForIn
<4>3. CASE \E p \in Proposers: P2(p) /\ pQ1[p] \in Quorums
<5>0. SUFFICES
ASSUME NEW p \in Proposers,
pQ1[p] \in Quorums,
pQ2[p] = {},
NEW v \in Values,
pVBal[p] = NoBallot \/ (pVBal[p] \in ValidBallots /\ v = pVVal[p]),