-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpireTlaps.tla
1611 lines (1582 loc) · 84.9 KB
/
SpireTlaps.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
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 SpireTlaps ----
(*****************************************************************************)
(* The complete safety proof of the Spire consensus algorithm. *)
(*****************************************************************************)
EXTENDS Spire, TLAPS, NaturalsInduction, FiniteSetTheorems
(*****************************************************************************)
(* No quorum may be empty. *)
(*****************************************************************************)
LEMMA QuorumNonEmpty == \A Q \in Quorums : Q # {}
BY QuorumAssumption
(*****************************************************************************)
(* The symbol `None' is not in the set of `Values'. *)
(*****************************************************************************)
LEMMA NoneNotAValue == None \notin Values
BY NoSetContainsEverything DEF None
(*****************************************************************************)
(* For a superset of quorum-answers obtained by `QuorumAnswers(Q)', each *)
(* set of answers `A' is non-empty if and only if `Q' is non-empty. *)
(*****************************************************************************)
LEMMA AnswersNonEmpty ==
\A Q \in Quorums : \A A \in QuorumAnswers(Q) : Q # {} <=> A # {}
BY DEF QuorumAnswers, Answers
(*****************************************************************************)
(* The image of `PickRound(M)' is a single element in *)
(* `{m.lastRound : m \in M}' if `M' is a non-empty set of messages. *)
(*****************************************************************************)
LEMMA PickRoundImage ==
\A M \in SUBSET Messages : M # {} => PickRound(M) \in {m.lastRound : m \in M}
BY DEF PickRound, Messages
(*****************************************************************************)
(* The image of `PickValue(M)' is a single element in *)
(* `{m.lastVal : m \in M}' if `M' is a non-empty set of messages. *)
(*****************************************************************************)
LEMMA PickValueImage ==
\A M \in SUBSET Messages : M # {} => PickValue(M) \in {m.lastVal : m \in M}
BY DEF PickValue, Messages
(*****************************************************************************)
(* Determines whether the given finite set `S' of naturals contains an *)
(* element that is greater or equal to all other elements. This seemingly *)
(* frivolous result is required for the proof of *)
(* `AllNonEmptyFiniteNaturalsHaveMax' by finite set induction. *)
(*****************************************************************************)
HasMax(S) ==
S \in SUBSET Nat /\ S # {} => \E n1 \in S : \A n2 \in S : n1 >= n2
(*****************************************************************************)
(* Every non-empty finite set of naturals `S' has a maximum *)
(* within `S' — an element that is greater than all other elements in `S'. *)
(* *)
(* Proof is by finite set induction: the predicate `HasMax({})' holds, and *)
(* the addition of a natural number `x' to some set of naturals `R', where *)
(* `x' is not already in `R' and `HasMax(R)', preserves *)
(* `HasMax(R \union {x})'. *)
(*****************************************************************************)
LEMMA AllNonEmptyFiniteNaturalsHaveMax ==
ASSUME NEW S \in SUBSET Nat,
S # {},
IsFiniteSet(S),
HasMax({})
PROVE HasMax(S)
<1> DEFINE Q(T) == HasMax(T)
<1> SUFFICES Q(S)
BY DEF HasMax
<1>1 Q({})
OBVIOUS
<1>2 ASSUME NEW R, NEW x, Q(R), x \notin R
PROVE Q(R \cup {x})
BY <1>2 DEF HasMax
<1> HIDE DEF Q
<1> QED
BY <1>1, <1>2, FS_Induction, IsaM("blast") DEF HasMax
(*****************************************************************************)
(* The image of `MaxLastRound(M)' is a single element in *)
(* `{m.lastRound : m \in M}' if `M' is a non-empty set of messages. *)
(*****************************************************************************)
LEMMA MaxLastRoundImage ==
\A M \in SUBSET Messages : M # {} => MaxLastRound(M) \in {m.lastRound : m \in M}
<1> SUFFICES ASSUME NEW M \in SUBSET Messages,
M # {}
PROVE MaxLastRound(M) \in {m.lastRound : m \in M}
OBVIOUS
<1> USE DEF MaxLastRound
<1>1 MaxLastRound(M) \in {m.lastRound : m \in M}
BY AllNonEmptyFiniteNaturalsHaveMax DEF MaxLastRound, SetMax
<1>2 QED
BY <1>1
(*****************************************************************************)
(* The image of `MaxLastRound(M)' is in the powerset of *)
(* `{m.lastVal : m \in M}' if `M' is a non-empty set of messages. *)
(*****************************************************************************)
LEMMA SuccessorValuesImage ==
\A M \in SUBSET Messages : M # {} => SuccessorValues(M) \in SUBSET {m.lastVal : m \in M}
<1> SUFFICES ASSUME NEW M \in SUBSET Messages,
M # {},
SuccessorValues(M) =
LET highestRound == MaxLastRound(M)
highestRoundAnswers == {m \in M : m.lastRound = highestRound}
highestRoundPrimedAnswers == {m \in highestRoundAnswers : m.lastPrimed}
IN IF highestRoundPrimedAnswers # {} THEN
{PickValue(highestRoundPrimedAnswers)}
ELSE
{a.lastVal : a \in highestRoundAnswers}
PROVE \A v \in SuccessorValues(M) : v \in {m.lastVal : m \in M}
BY DEF SuccessorValues
<1>1 DEFINE highestRound == MaxLastRound(M)
<1>2 DEFINE highestRoundAnswers == {m \in M : m.lastRound = highestRound}
<1>3 DEFINE highestRoundPrimedAnswers == {m \in highestRoundAnswers : m.lastPrimed}
<1>4 \A a \in highestRoundAnswers : a \in M
OBVIOUS
<1>5 CASE highestRoundPrimedAnswers # {}
BY <1>5, PickValueImage DEF PickValue
<1>6 CASE highestRoundPrimedAnswers = {}
BY <1>6
<1>7 QED
BY <1>5, <1>6
(*****************************************************************************)
(* A uniform (same round number, same value), non-empty set of answers *)
(* leads to a single successor value. *)
(*****************************************************************************)
LEMMA SingularityOfSuccessorsToUniformAnswers ==
\A M \in SUBSET Messages : M # {} /\ AllIdenticalRounds(M) /\ AllIdenticalValues(M)
=> SuccessorValues(M) = {PickValue(M)}
BY DEF SuccessorValues, AllIdenticalRounds, AllIdenticalValues, MaxLastRound, SetMax, PickValue
(*****************************************************************************)
(* A primed offer bearing a value `v' in round `r' implies that a uniform *)
(* set of answers exists in `r-1' for `v' for at least one complete quorum. *)
(* *)
(* The proof follows from `MsgInv' for the case *)
(* `\A m \in msgs : m.type = "Offer" /\ m.round # 0 /\ m.primed'. *)
(*****************************************************************************)
LEMMA PrimedOfferFollowsUniformAnswers ==
TypeOK /\ MsgInv =>
\A o \in msgs : o.type = "Offer" /\ o.primed =>
\E Q \in Quorums : \E A \in QuorumAnswers(Q):
\A a \in A : a.lastRound = o.round - 1 /\ a.lastVal = o.val
<1> SUFFICES ASSUME MsgInv, TypeOK,
NEW o \in msgs,
o.type = "Offer" /\ o.primed
PROVE \E Q \in Quorums : \E A \in QuorumAnswers(Q):
\A a \in A : a.lastRound = o.round - 1 /\ a.lastVal = o.val
OBVIOUS
<1>1 \E Q \in Quorums : \E A \in QuorumAnswers(Q) :
/\ A # {}
/\ AllIdenticalRounds(A) /\ AllIdenticalValues(A)
/\ o.val = PickValue(A)
/\ o.round = PickRound(A) + 1
BY AnswersNonEmpty, QuorumAssumption DEF MsgInv
<1>2 \E Q \in Quorums : \E A \in QuorumAnswers(Q) :
/\ A # {}
/\ AllIdenticalRounds(A) /\ AllIdenticalValues(A)
/\ o.val = PickValue(A)
/\ o.round - 1 = PickRound(A)
BY <1>1, PickRoundImage DEF Messages, TypeOK, QuorumAnswers, Answers, Rounds
<1>3 PICK R \in Quorums : \E A \in QuorumAnswers(R) :
/\ A # {}
/\ AllIdenticalRounds(A) /\ AllIdenticalValues(A)
/\ o.val = PickValue(A)
/\ o.round - 1 = PickRound(A)
BY <1>2
<1>4 PICK B \in QuorumAnswers(R) :
/\ B # {}
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ o.val = PickValue(B)
/\ o.round - 1 = PickRound(B)
BY <1>3
<1>5 /\ B # {}
/\ AllIdenticalRounds(B)
/\ PickRound(B) \in {a.lastRound : a \in B}
/\ o.round - 1 \in {a.lastRound : a \in B}
/\ \A a \in B : a.lastRound = o.round - 1
BY <1>4, PickRoundImage DEF AllIdenticalRounds, TypeOK, QuorumAnswers, Answers
<1>6 /\ B # {}
/\ AllIdenticalValues(B)
/\ o.val = PickValue(B)
/\ o.val \in {a.lastVal : a \in B}
/\ \A a \in B : a.lastVal = o.val
BY <1>4, PickValueImage DEF AllIdenticalValues, TypeOK, QuorumAnswers, Answers
<1>7 \E Q \in Quorums : \E A \in QuorumAnswers(Q):
/\ \A a \in A : a.lastRound = o.round - 1
/\ \A a \in A : a.lastVal = o.val
BY <1>5, <1>6
<1>8 QED
BY <1>7
(*****************************************************************************)
(* All primed answers in a given round must refer to the same value. *)
(* *)
(* The proof follows from a combination of `PrimedOfferFollowsUniformAnswer' *)
(* and the quorum intersection property. *)
(*****************************************************************************)
LEMMA SingularityOfPrimedRoundAnswers ==
TypeOK /\ MsgInv /\ ConsInv =>
\A m1, m2 \in msgs :
m1.type = "Answer" /\ m1.lastPrimed /\ m2.type = "Answer" /\ m2.lastPrimed /\
m1.lastRound = m2.lastRound
=> m1.lastVal = m2.lastVal
<1> SUFFICES ASSUME TypeOK /\ MsgInv /\ ConsInv,
NEW m1 \in msgs, NEW m2 \in msgs,
m1.type = "Answer", m2.type = "Answer",
m1.lastPrimed, m2.lastPrimed,
m1.lastRound = m2.lastRound
PROVE m1.lastVal = m2.lastVal
OBVIOUS
<1>1 \E o \in msgs : o.type = "Offer" /\ o.round = m1.lastRound /\ o.primed /\ o.val = m1.lastVal
BY DEF MsgInv
<1>2 \E o \in msgs : o.type = "Offer" /\ o.round = m2.lastRound /\ o.primed /\ o.val = m2.lastVal
BY DEF MsgInv
<1>3 PICK o1 \in msgs : o1.type = "Offer" /\ o1.round = m1.lastRound /\ o1.primed /\ o1.val = m1.lastVal
BY <1>1
<1>4 PICK o2 \in msgs : o2.type = "Offer" /\ o2.round = m2.lastRound /\ o2.primed /\ o2.val = m2.lastVal
BY <1>2
<1>5 \E R \in Quorums : \E B \in QuorumAnswers(R) :
\A a \in B : a.lastRound = o1.round - 1 /\ a.lastVal = o1.val
BY <1>1, <1>3, PrimedOfferFollowsUniformAnswers
<1>6 \E R \in Quorums : \E B \in QuorumAnswers(R) :
\A a \in B : a.lastRound = o2.round - 1 /\ a.lastVal = o2.val
BY <1>2, <1>4, PrimedOfferFollowsUniformAnswers
<1>7 \E R \in Quorums : \E B \in QuorumAnswers(R) :
\A a \in B : a.lastRound = m1.lastRound - 1 /\ a.lastVal = m1.lastVal /\ a.type = "Answer"
BY <1>1, <1>3, <1>5 DEF QuorumAnswers, Answers
<1>8 PICK R1 \in Quorums : \E B \in QuorumAnswers(R1) :
\A a \in B : a.lastRound = m1.lastRound - 1 /\ a.lastVal = m1.lastVal /\ a.cons \in R1
BY <1>7 DEF QuorumAnswers, Answers
<1>9 \E R \in Quorums : \E B \in QuorumAnswers(R) :
\A a \in B : a.lastRound = m1.lastRound - 1 /\ a.lastVal = m2.lastVal /\ a.type = "Answer"
BY <1>2, <1>4, <1>6 DEF QuorumAnswers, Answers
<1>10 PICK R2 \in Quorums : \E B \in QuorumAnswers(R2) :
\A a \in B : a.lastRound = m1.lastRound - 1 /\ a.lastVal = m2.lastVal /\ a.cons \in R2
BY <1>9 DEF QuorumAnswers, Answers
<1>11 PICK c \in Consenters : c \in R1 /\ c \in R2
BY <1>8, <1>10, QuorumAssumption
<1>12 \E B \in QuorumAnswers(R1) : \E a \in B :
a.lastRound = m1.lastRound - 1 /\ a.lastVal = m1.lastVal /\ a.cons = c
BY <1>8, <1>11 DEF QuorumAnswers, Answers
<1>13 \E B \in QuorumAnswers(R2) : \E a \in B :
a.lastRound = m1.lastRound - 1 /\ a.lastVal = m2.lastVal /\ a.cons = c
BY <1>10, <1>11 DEF QuorumAnswers, Answers
<1>14 QED
BY <1>12, <1>13 DEF QuorumAnswers, Answers, ConsInv
(*****************************************************************************)
(* A set of quorum-answers of primed values for identical rounds is uniform. *)
(*****************************************************************************)
LEMMA PrimedRoundQuorumAnswersAreUniform ==
TypeOK /\ MsgInv /\ ConsInv =>
\A Q \in Quorums : \A A \in QuorumAnswers(Q) :
AllPrimed(A) /\ AllIdenticalRounds(A) => \A m1, m2 \in A : m1.lastVal = m2.lastVal
<1> SUFFICES ASSUME TypeOK, MsgInv, ConsInv,
NEW Q \in Quorums,
NEW A \in QuorumAnswers(Q),
AllPrimed(A) /\ AllIdenticalRounds(A),
NEW m1 \in A, NEW m2 \in A
PROVE m1.lastVal = m2.lastVal
OBVIOUS
<1>1 /\ m1 \in msgs /\ m2 \in msgs
/\ m1.type = "Answer" /\ m2.type = "Answer"
/\ m1.lastPrimed /\ m2.lastPrimed
/\ m1.lastRound = m2.lastRound
BY DEF QuorumAnswers, Answers, AllPrimed, AllIdenticalRounds
<1> QED
BY <1>1, SingularityOfPrimedRoundAnswers
(*****************************************************************************)
(* Whether the value `v' was chosen in round `r'. *)
(*****************************************************************************)
ChosenIn(r, v) ==
\E Q \in Quorums :
\E A \in QuorumAnswers(Q) :
/\ AllIdenticalRounds(A)
/\ AllPrimed(A)
/\ \E m \in A : m.lastVal = v /\ m.lastRound = r
(*****************************************************************************)
(* Whether the set of values `V' was not among those offered in round *)
(* `r'. *)
(*****************************************************************************)
NotOfferedIn(r, V) ==
~\E m \in msgs : m.type = "Offer" /\ m.round = r /\ m.val \in V
(*****************************************************************************)
(* Whether the value `v' was offered in round `r'. *)
(*****************************************************************************)
OfferedIn(r, v) ==
\E o \in msgs : o.type = "Offer" /\ o.round = r /\ o.val = v
(*****************************************************************************)
(* Whether an answer in round `r' referred to the value `v'. *)
(*****************************************************************************)
AnsweredIn(r, v) ==
\E o \in msgs : o.type = "Answer" /\ o.lastRound = r /\ o.lastVal = v
(*****************************************************************************)
(* A value that was chosen in a round must be among those values that were *)
(* offered in that round. *)
(*****************************************************************************)
LEMMA ChosenFromOffer ==
MsgInv =>
\A r \in Rounds, v \in Values : ChosenIn(r, v) => OfferedIn(r, v)
<1> SUFFICES ASSUME MsgInv,
NEW r \in Rounds, NEW v \in Values,
NEW Q \in Quorums,
NEW A \in QuorumAnswers(Q),
AllIdenticalRounds(A),
AllPrimed(A),
NEW m \in A,
m.lastVal = v /\ m.lastRound = r
PROVE OfferedIn(r, v)
BY DEF ChosenIn
<1>1 \E a \in A : a.lastRound = r
BY DEF ChosenIn, AllIdenticalRounds
<1>2 \E o \in msgs : o.type = "Offer" /\ o.round = m.lastRound /\ o.val = m.lastVal
BY DEF MsgInv, QuorumAnswers, Answers
<1>3 QED
BY <1>1, <1>2 DEF OfferedIn
(*****************************************************************************)
(* An offer in a non-zero round `r' must source its value from an answer *)
(* in `r - 1'. *)
(*****************************************************************************)
LEMMA ValuePropagation ==
TypeOK /\ MsgInv =>
\A r \in Rounds, v \in Values : r # 0 /\ OfferedIn(r, v) => AnsweredIn(r - 1, v)
<1> SUFFICES ASSUME MsgInv, TypeOK,
NEW r \in Rounds, NEW v \in Values,
r # 0,
NEW o \in msgs,
o.type = "Offer" /\ o.round = r /\ o.val = v
PROVE AnsweredIn(r - 1, v)
BY DEF OfferedIn
<1>1 \A n \in msgs : n.type = "Offer" /\ n.round = r /\ n.val = v =>
/\ n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1
/\ ~n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
/\ \E a \in msgs : a.type = "Answer" /\ a.lastRound = r - 1 /\ a.lastVal = v
<2> SUFFICES ASSUME NEW n \in msgs,
n.type = "Offer" /\ n.round = r /\ n.val = v,
n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1,
~n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
PROVE \E a \in msgs : a.type = "Answer" /\ a.lastRound = r - 1 /\ a.lastVal = v
BY DEF MsgInv, Rounds
<2>1.CASE n.primed
<3>1 PICK R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1
BY <2>1
<3>2 PICK B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1
BY <3>1
<3>3 \A m1, m2 \in B : m1.lastRound = m2.lastRound
BY <3>2 DEF AllIdenticalRounds
<3>4 B # {}
BY <3>2, QuorumAssumption DEF QuorumAnswers, Answers
<3>5 PickRound(B) \in {mmm.lastRound : mmm \in B}
BY <3>2, <3>4, PickRoundImage DEF PickRound
<3>6 \A b \in B : b.type = "Answer" /\ b.lastRound \in Rounds
BY <3>2 DEF QuorumAnswers, Answers, TypeOK, Messages
<3>7 PickRound(B) \in Rounds
BY <3>2, <3>4, <3>6, PickRoundImage DEF PickRound
<3>8 n.round - 1 \in {mmm.lastRound : mmm \in B}
BY <3>5, <3>2, <3>7 DEF Rounds
<3>9 \A b \in B : b.lastRound = r - 1
BY <3>2, <3>3, <3>5, <3>8 DEF Rounds
<3>10 \E b \in B : b.lastVal = n.val
BY <3>2, <3>4, PickValueImage DEF PickValue
<3>11 QED
BY <3>9, <3>10 DEF QuorumAnswers, Answers
<2>2 CASE ~n.primed
<3>1 PICK R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
BY <2>2
<3>2 PICK B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
BY <3>1
<3>3 \A m1, m2 \in B : m1.lastRound = m2.lastRound
BY <3>2 DEF AllIdenticalRounds
<3>4 B # {}
BY <3>2, QuorumAssumption DEF QuorumAnswers, Answers
<3>5 PickRound(B) \in {mmm.lastRound : mmm \in B}
BY <3>2, <3>4, PickRoundImage DEF PickRound
<3>6 \A b \in B : b.type = "Answer" /\ b.lastRound \in Rounds
BY <3>2 DEF QuorumAnswers, Answers, TypeOK, Messages
<3>7 PickRound(B) \in Rounds
BY <3>2, <3>4, <3>6, PickRoundImage DEF PickRound, QuorumAnswers, Answers
<3>8 n.round - 1 \in {mmm.lastRound : mmm \in B}
BY <3>5, <3>2, <3>7 DEF Rounds
<3>9 \A b \in B : b.lastRound = r - 1
BY <3>2, <3>3, <3>8
<3>10 \A b \in B : b \in Messages
BY <3>2 DEF TypeOK, QuorumAnswers, Answers
<3>11 n.val \in {b.lastVal : b \in B}
BY <3>2, <3>4, <3>10, SuccessorValuesImage
<3>12 QED
BY <3>9, <3>11 DEF QuorumAnswers, Answers
<2>3 QED
BY <2>1, <2>2
<1>2 QED
BY <1>1 DEF AnsweredIn
(*****************************************************************************)
(* If a set of values `V' is not offered in round `r', then it is also not *)
(* offered in `r + 1'. This is a set-oriented variant of `ValuePropagation' *)
(* that is used to support the proof of `NotOfferedInSuffix' by induction. *)
(*****************************************************************************)
LEMMA NotOfferedInCarry ==
TypeOK /\ MsgInv =>
\A r \in Nat, V \in SUBSET Values : NotOfferedIn(r, V) => NotOfferedIn(r + 1, V)
<1> SUFFICES ASSUME MsgInv, TypeOK,
NEW r \in Nat, NEW V \in SUBSET Values,
NotOfferedIn(r, V)
PROVE NotOfferedIn(r + 1, V)
OBVIOUS
<1>1 USE DEF NotOfferedIn
<1>2 ~\E o \in msgs : o.type = "Offer" /\ o.round = r /\ o.val \in V
OBVIOUS
<1>3 ~\E a \in msgs : a.type = "Answer" /\ a.lastRound = r /\ a.lastVal \in V
BY <1>2 DEF MsgInv
<1>4 \A a \in msgs : a.type = "Answer" /\ a.lastRound = r => a.lastVal \notin V
BY <1>3
<1>5 \A o \in msgs : o.type = "Offer" /\ o.round = r + 1 =>
\E a \in msgs : a.type = "Answer" /\ a.lastRound = r /\ a.lastVal = o.val
BY ValuePropagation DEF OfferedIn, AnsweredIn, Messages, TypeOK
<1>6 \A o \in msgs : o.type = "Offer" /\ o.round = r + 1 =>
\E a \in msgs : a.type = "Answer" /\ a.lastRound = r /\ a.lastVal = o.val /\ a.lastVal \notin V
BY <1>5, <1>4
<1>7 QED
BY <1>6
(*****************************************************************************)
(* If a set of values `V' is not offered in some round `r1', then it is not *)
(* offered in any round `r2', where `r2' is greater than or equal to `r1'. *)
(* *)
(* The proof is by naturals induction of `NotOfferedInCarry'. *)
(*****************************************************************************)
LEMMA NotOfferedInSuffix ==
ASSUME TypeOK, MsgInv,
NEW r \in Rounds,
NEW V \in SUBSET Values,
NotOfferedIn(r, V)
PROVE \A i \in Rounds : i >= r => NotOfferedIn(i, V)
<1> DEFINE Q(i) == i \in Rounds /\ i >= r => NotOfferedIn(i, V)
<1> SUFFICES \A i \in Rounds : Q(i)
OBVIOUS
<1>1 Q(0)
BY DEF Rounds
<1>2 \A i \in Rounds : Q(i) => Q(i + 1)
BY NotOfferedInCarry DEF Rounds
<1> HIDE DEF Q
<1> QED
BY <1>1, <1>2, NatInduction DEF Rounds
(*****************************************************************************)
(* Any set of quorum-answers in round `r' overlaps with every other set *)
(* in `r' by at least one answer. *)
(* *)
(* Proof is straightforward by the quorum intersection property and the *)
(* invariant that a consenter may vote at most once in any given round. *)
(*****************************************************************************)
LEMMA RoundAnswersOverlap ==
ConsInv =>
\A Q, R \in Quorums : \A A \in QuorumAnswers(Q), B \in QuorumAnswers(R) :
(\A a \in A, b \in B : a.lastRound = b.lastRound) =>
\E a \in A, b \in B : a = b
BY QuorumAssumption DEF ConsInv, QuorumAnswers, Answers
(*****************************************************************************)
(* If a value `v' is chosen in round `r', then only `v' may be offered in *)
(* the successor round `r + 1'. *)
(*****************************************************************************)
LEMMA ChosenCarry ==
TypeOK /\ MsgInv /\ ConsInv =>
\A r \in Rounds, v1, v2 \in Values : ChosenIn(r, v1) /\ OfferedIn(r + 1, v2) => v1 = v2
<1> SUFFICES ASSUME TypeOK, MsgInv, ConsInv,
NEW r \in Rounds, NEW v1 \in Values, NEW v2 \in Values,
NEW Q \in Quorums,
NEW A \in QuorumAnswers(Q),
AllIdenticalRounds(A),
AllPrimed(A),
NEW m \in A,
m.lastVal = v1 /\ m.lastRound = r,
NEW o \in msgs,
o.type = "Offer" /\ o.round = (r + 1) /\ o.val = v2
PROVE v1 = v2
BY DEF ChosenIn, OfferedIn
<1>1 \A mmm \in A : mmm.type = "Answer" /\ mmm.lastRound = r /\ mmm.lastPrimed
BY DEF QuorumAnswers, Answers, AllIdenticalRounds, AllPrimed
<1>2 \A mmm \in A : mmm.lastVal = v1
BY PrimedRoundQuorumAnswersAreUniform
<1>3 \A n \in msgs : n.type = "Offer" /\ n.round = r + 1 =>
/\ n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1
/\ ~n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
/\ n.val = v1
<2> SUFFICES ASSUME NEW n \in msgs,
n.type = "Offer" /\ n.round = r + 1,
n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1,
~n.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
PROVE n.val = v1
BY DEF MsgInv, Rounds
\* Where the next-round `r + 1' offer is primed, the quorum-answers in `r' must
\* have been uniform. Because `r' contained the chosen answer `v1', every
\* set of quorum-answers in `r' must contain at least one answer with `v1' by
\* lemma `RoundAnswersOverlap'. Seeing that `B' is uniform, then all answers in
\* `B' contain `v1'.
<2>1.CASE n.primed
<3>1 PICK R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1
BY <2>1
<3>2 PICK B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ n.val = PickValue(B)
/\ n.round = PickRound(B) + 1
BY <3>1
<3>3 \A m1, m2 \in B : m1.lastRound = m2.lastRound
BY <3>2 DEF AllIdenticalRounds
<3>4 B # {}
BY <3>2, QuorumAssumption DEF QuorumAnswers, Answers
<3>5 PickRound(B) \in {mmm.lastRound : mmm \in B}
BY <3>2, <3>4, PickRoundImage DEF PickRound
<3>6 \A b \in B : b.type = "Answer" /\ b.lastRound \in Rounds
BY <3>2 DEF QuorumAnswers, Answers, TypeOK, Messages
<3>7 PickRound(B) \in Rounds
BY <3>2, <3>4, <3>6, PickRoundImage DEF PickRound
<3>8 n.round - 1 \in {mmm.lastRound : mmm \in B}
BY <2>1, <3>5, <3>2, <3>7 DEF Rounds
<3>9 \A b \in B : b.lastRound = r
BY <2>1, <3>2, <3>3, <3>5, <3>8 DEF Rounds
<3>10 \A a \in A, b \in B : a.lastRound = b.lastRound
BY <1>1, <3>9
<3>11 \E a \in A, b \in B : a = b
BY <3>9, <3>10, RoundAnswersOverlap
<3>12 \A b \in B : b.lastVal = v1
BY <1>2, <3>2, <3>11 DEF AllIdenticalValues
<3>13 QED
BY <3>2, <3>4, <3>12, PickValueImage DEF PickValue
\* When the next-round `r + 1' offer is unprimed, the quorum-answers in `r' may
\* contain a mix of values. Because `r' contained the chosen answer `v1', every
\* set of quorum-answers in `r' must contain a primed `v1' by lemma
\* `RoundAnswersOverlap'. Furthermore, by
\* lemma `SingularityOfPrimedRoundAnswers', no value other than `v1' may be primed
\* in `r'. By the image of `SuccessorValues', the sole successor value must be `v1'.
<2>2 CASE ~n.primed
<3>1 PICK R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
BY <2>2
<3>2 PICK B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ n.val \in SuccessorValues(B)
/\ n.round = PickRound(B) + 1
BY <3>1
<3>3 B # {}
BY <3>2, QuorumAssumption DEF QuorumAnswers, Answers
<3>4 \A b \in B : b.type = "Answer" /\ b.lastRound \in Rounds
BY <3>2 DEF QuorumAnswers, Answers, TypeOK, Messages
<3>5 \A m1, m2 \in B : m1.lastRound = m2.lastRound
BY <3>2 DEF AllIdenticalRounds
<3>6 PickRound(B) \in {mmm.lastRound : mmm \in B}
BY <3>2, <3>3, PickRoundImage DEF PickRound
<3>7 PickRound(B) \in Rounds
BY <3>2, <3>3, <3>4, PickRoundImage DEF PickRound, QuorumAnswers, Answers
<3>8 n.round - 1 \in {mmm.lastRound : mmm \in B}
BY <2>2, <3>2, <3>4, <3>6 DEF Rounds
<3>9 \A b \in B : b.lastRound = r
BY <2>2, <3>2, <3>3, <3>5, <3>8 DEF Rounds
<3>10 \A a \in A, b \in B : a.lastRound = b.lastRound
BY <1>1, <3>9
<3>11 \E a \in A, b \in B : a = b
BY <3>9, <3>10, RoundAnswersOverlap
<3>12 \E b \in B : b.lastVal = v1 /\ b.lastPrimed
BY <1>2, <3>11 DEF AllPrimed
<3>13 PICK p \in B : p.lastVal = v1 /\ p.lastPrimed
BY <3>12
<3>14 MaxLastRound(B) = r
BY <3>3, <3>9 DEF MaxLastRound, SetMax
<3>15 DEFINE highestRoundAnswers == {b \in B : b.lastRound = MaxLastRound(B)}
<3>16 highestRoundAnswers = B
BY <3>9, <3>14
<3>17 \A b \in B : b \in msgs
BY <3>1, <3>2 DEF QuorumAnswers, Answers
<3>18 \A b \in B : b.lastPrimed /\ b.lastRound = r => b.lastVal = v1
BY <3>4, <3>9, <3>13, <3>17, SingularityOfPrimedRoundAnswers
<3>19 DEFINE highestRoundPrimedAnswers == {b \in highestRoundAnswers : b.lastPrimed}
<3>20 highestRoundPrimedAnswers = {b \in B : b.lastPrimed}
BY <3>16
<3>21 highestRoundPrimedAnswers # {}
BY <3>12, <3>18, <3>20
<3>22 \A mmm \in highestRoundPrimedAnswers : mmm.lastVal = v1
BY <3>9, <3>18
<3>23 \A v \in SuccessorValues(B) : v = v1
BY <3>21, <3>22 DEF SuccessorValues, PickValue
<3>24 HIDE DEF highestRoundAnswers, highestRoundPrimedAnswers
<3>25 QED
BY <3>2, <3>23
<2>3 QED
BY <2>1, <2>2
<1>4 QED
BY <1>3
(*****************************************************************************)
(* Stability of value selection. *)
(* *)
(* For any two rounds `r1' and `r2', where `r1 < r2', if some value `v' is *)
(* chosen in `r1' then only `v' may be offered in `r2'. *)
(* *)
(* The proof is assembled in two tranches. First, we prove that if `v' is *)
(* chosen in `r1', then only `v' may be offered in `r1 + 1' by lemma *)
(* `ChosenCarry'. Second, if `v' is offered in `r1 + 1', then only `v' may *)
(* be offered in all future rounds following `r1 + 1'. The latter is *)
(* accomplished by rewriting the obligations in terms of what cannot be *)
(* offered, which is the set `Values \ {v}', and using the inductive lemma *)
(* `NotOfferedInSuffix' to project that `Values \ {v}' cannot be offered in *)
(* all subsequent rounds, leaving only `v' as a candidate value in `r2'. *)
(*****************************************************************************)
LEMMA Stability ==
TypeOK /\ MsgInv /\ ConsInv =>
\A r1, r2 \in Rounds, v1, v2 \in Values : r1 < r2 /\ ChosenIn(r1, v1) /\ OfferedIn(r2, v2)
=> v1 = v2
<1> SUFFICES ASSUME TypeOK, MsgInv, ConsInv,
NEW r1 \in Rounds, NEW r2 \in Rounds,
NEW v1 \in Values, NEW v2 \in Values,
r1 < r2,
NEW Q \in Quorums,
NEW A \in QuorumAnswers(Q),
AllIdenticalRounds(A),
AllPrimed(A),
NEW m \in A,
m.lastVal = v1 /\ m.lastRound = r1,
NEW o \in msgs,
o.type = "Offer" /\ o.round = r2 /\ o.val = v2
PROVE v1 = v2
BY DEF ChosenIn, OfferedIn
<1>1 \E mmm \in msgs : mmm.type = "Offer" /\ mmm.round = r1 + 1 => mmm.val = v1
BY ChosenCarry DEF ChosenIn, OfferedIn
<1>2 \A v \in Values : OfferedIn(r1 + 1, v) => v = v1
BY ChosenCarry DEF ChosenIn, OfferedIn
<1>3 \A mmm \in msgs : mmm.type = "Offer" /\ mmm.round = r1 + 1 => mmm.val = v1
BY <1>2 DEF OfferedIn, Messages, TypeOK
<1>4 NotOfferedIn(r1 + 1, Values \ {v1})
BY <1>3 DEF NotOfferedIn
<1>5 NotOfferedIn(r2, Values \ {v1})
BY <1>4, NotOfferedInSuffix DEF Rounds
<1>6 QED
BY <1>5 DEF NotOfferedIn, OfferedIn
(*****************************************************************************)
(* The initial state satisfies the inductive invariant `Inv'. *)
(*****************************************************************************)
LEMMA Initial == Init => Inv
BY DEF Init, Inv, MsgInv, ConsInv
(*****************************************************************************)
(* All states that satisfy the inductive invariant `Inv' also *)
(* satisfy the `Consistency' invariant. *)
(*****************************************************************************)
LEMMA Consistent == Inv => Consistency
<1> SUFFICES ASSUME Inv,
NEW v1 \in Values, NEW v2 \in Values,
NEW Q \in Quorums, NEW R \in Quorums,
NEW A \in QuorumAnswers(Q), NEW B \in QuorumAnswers(R),
AllIdenticalRounds(A), AllIdenticalRounds(B),
AllPrimed(A), AllPrimed(B),
NEW m \in A, NEW n \in B,
m.lastVal = v1, n.lastVal = v2
PROVE v1 = v2
BY DEF Chosen, Consistency
<1> USE DEF Inv, Consistency
<1>1 /\ m.type = "Answer" /\ m.lastRound \in Rounds /\ n.type = "Answer" /\ n.lastRound \in Rounds
/\ m.lastVal \in Values /\ n.lastVal \in Values
BY DEF Messages, QuorumAnswers, Answers
<1>2 (\A mmm \in A : mmm.lastVal = v1) /\ (\A mmm \in B : mmm.lastVal = v2)
BY PrimedRoundQuorumAnswersAreUniform DEF TypeOK
\* Where the two messages `m' from `A' and `n' from `B' are in the same round,
\* and `AllIdenticalRounds' holds for both answer sets `A' and `B', then there
\* must be a common answer in their intersection by lemma `RoundAnswersOverlap'.
<1>3 CASE m.lastRound = n.lastRound
<2>1 \A ma \in A, mb \in B : ma.lastRound = mb.lastRound
BY <1>3 DEF AllIdenticalRounds
<2>2 \E ma \in A, mb \in B : ma.lastVal = mb.lastVal
BY <2>1, RoundAnswersOverlap
<2>3 QED
BY <1>2, <1>3, <2>2
\* Where the two messages `m' from `A' and `n' from `B' are in different rounds
\* and `AllIdenticalRounds' holds for both `A' and `B', then either `m' precedes
\* `n' or `n' precedes `m'. Both sub-cases are interchangeable and proven by lemmas
\* `Stability' and `ChosenFromOffer'.
<1>4 CASE m.lastRound # n.lastRound
BY <1>1, <1>4, Stability, ChosenFromOffer DEF ChosenIn, OfferedIn, TypeOK, Rounds
<1>5 QED
BY <1>1, <1>3, <1>4 DEF Rounds
(*****************************************************************************)
(* The inductive invariant `Inv' is preserved when `vars' is unchanged. *)
(* *)
(* The result is trivially determined and has been extracted into a *)
(* separate lemma for convenience and reuse. *)
(*****************************************************************************)
LEMMA InvariantPreservedOnUnchanged ==
Inv /\ UNCHANGED vars => Inv'
<1> SUFFICES ASSUME Inv /\ UNCHANGED vars
PROVE Inv'
OBVIOUS
<1> USE DEF Inv, vars
<1>1 (msgs \in SUBSET Messages)'
OBVIOUS
<1>2 MsgInv'
BY DEF MsgInv, QuorumAnswers, Answers
<1>3 (lastVal \in [Consenters -> Values \union {None}])'
OBVIOUS
<1>4 (lastRound \in [Consenters -> Rounds \union {-1}])'
OBVIOUS
<1>5 (lastPrimed \in [Consenters -> BOOLEAN])'
OBVIOUS
<1>6 ConsInv'
BY DEF ConsInv
<1>7 QED
BY <1>1, <1>2, <1>3, <1>4, <1>5, <1>6 DEF Inv
(*****************************************************************************)
(* Preservation of the inductive invariant. *)
(* *)
(* Starting from any state that satisfies the inductive invariant `Inv', all *)
(* transitions will result in a successor state that also satisfies `Inv'. *)
(*****************************************************************************)
LEMMA Inductive == Inv /\ Next => Inv'
<1> SUFFICES ASSUME Inv,
Next
PROVE Inv'
OBVIOUS
<1> USE DEF Inv, Next
<1>1 CASE Offer
<2> USE DEF Offer
<2>1 (msgs \in SUBSET Messages)'
<3>1 ASSUME NEW Q \in Quorums,
NEW A \in QuorumAnswers(Q),
IF AllIdenticalRounds(A) THEN
IF AllPrimed(A) THEN
FALSE
ELSE IF AllIdenticalValues(A) THEN
LET nextRound == PickRound(A) + 1
IN /\ nextRound \in Rounds
/\ TrySend([type |-> "Offer", val |-> PickValue(A),
round |-> nextRound, primed |-> TRUE])
ELSE
LET nextRound == PickRound(A) + 1
IN /\ nextRound \in Rounds
/\ \E v \in SuccessorValues(A) :
TrySend([type |-> "Offer", val |-> v,
round |-> nextRound, primed |-> FALSE])
ELSE
\E v \in SuccessorValues(A) :
TrySend([type |-> "Offer", val |-> v,
round |-> MaxLastRound(A), primed |-> FALSE])
PROVE (msgs \in SUBSET Messages)'
<4>1 A \in SUBSET Messages /\ A # {}
BY QuorumAssumption DEF QuorumAnswers, Answers
<4>2 PickRound(A) \in Rounds
BY <3>1, <4>1, PickRoundImage DEF QuorumAnswers, Answers, Messages
<4>3 SuccessorValues(A) \in SUBSET Values
BY <3>1, <4>1, SuccessorValuesImage DEF QuorumAnswers, Answers, Messages
<4>4 CASE AllIdenticalRounds(A)
<5>1 CASE AllIdenticalValues(A)
<6>1 PickValue(A) \in Values
BY <3>1, <4>1, PickValueImage DEF QuorumAnswers, Answers, Messages
<6>2 DEFINE n == [type |-> "Offer", val |-> PickValue(A),
round |-> PickRound(A) + 1, primed |-> TRUE]
<6>3 n \in Messages
BY <4>2, <6>1 DEF Messages, Rounds
<6>4 QED
BY <3>1, <4>4, <5>1, <6>3 DEF TrySend, Send
<5>2 CASE ~AllIdenticalValues(A)
<6>1 PICK v \in SuccessorValues(A) :
TrySend([type |-> "Offer", val |-> v, round |-> PickRound(A) + 1, primed |-> FALSE])
BY <3>1, <4>4, <5>2
<6>2 DEFINE n == [type |-> "Offer", val |-> v, round |-> PickRound(A) + 1, primed |-> FALSE]
<6>3 n \in Messages
BY <4>2, <4>3 DEF Messages, Rounds
<6>4 QED
BY <3>1, <4>4, <5>2, <6>1, <6>3 DEF TrySend, Send
<5>3 QED
BY <1>1, <3>1, <4>4, <5>1, <5>2
<4>5 CASE ~AllIdenticalRounds(A)
<5>1 \A mmm \in A : mmm.lastRound \in Rounds
BY <3>1, <4>1 DEF Messages, QuorumAnswers, Answers
<5>2 MaxLastRound(A) \in {m.lastRound : m \in A}
BY <3>1, <4>1, MaxLastRoundImage
<5>3 MaxLastRound(A) \in Rounds
BY <5>1, <5>2
<5>4 PICK v \in SuccessorValues(A) :
TrySend([type |-> "Offer", val |-> v, round |-> MaxLastRound(A), primed |-> FALSE])
BY <3>1, <4>4, <4>5
<5>5 DEFINE n == [type |-> "Offer", val |-> v, round |-> MaxLastRound(A), primed |-> FALSE]
<5>6 n \in Messages
BY <4>3, <5>3, <5>4 DEF Messages, Rounds
<5>7 QED
BY <1>1, <3>1, <4>5, <5>4, <5>6 DEF TrySend, Send
<4>6 QED
BY <1>1, <3>1, <4>4, <4>5
<3>2 ASSUME NEW v \in Values,
TrySend([type |-> "Offer", val |-> v, round |-> 0, primed |-> FALSE])
PROVE (msgs \in SUBSET Messages)'
<4>1 DEFINE n == [type |-> "Offer", val |-> v, round |-> 0, primed |-> FALSE]
<4>2 n \in Messages
BY DEF Messages, Rounds
<4>3 QED
BY <1>1, <3>2, <4>2 DEF Messages, TrySend, Send
<3>3 QED
BY <1>1, <3>1, <3>2
<2>2 MsgInv'
<3> USE DEF MsgInv
<3>1 ASSUME NEW Q \in Quorums,
NEW A \in QuorumAnswers(Q),
IF AllIdenticalRounds(A) THEN
IF AllPrimed(A) THEN
FALSE
ELSE IF AllIdenticalValues(A) THEN
LET nextRound == PickRound(A) + 1
IN /\ nextRound \in Rounds
/\ TrySend([type |-> "Offer", val |-> PickValue(A),
round |-> nextRound, primed |-> TRUE])
ELSE
LET nextRound == PickRound(A) + 1
IN /\ nextRound \in Rounds
/\ \E v \in SuccessorValues(A) :
TrySend([type |-> "Offer", val |-> v,
round |-> nextRound, primed |-> FALSE])
ELSE
\E v \in SuccessorValues(A) :
TrySend([type |-> "Offer", val |-> v,
round |-> MaxLastRound(A), primed |-> FALSE])
PROVE MsgInv'
<4>4 CASE AllIdenticalRounds(A)
<5>1 CASE AllIdenticalValues(A)
<6> SUFFICES ASSUME NEW m \in msgs'
PROVE (/\ m.type = "Offer" =>
/\ m.round = 0 => ~m.primed
/\ m.round # 0 =>
/\ m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ m.val = PickValue(B)
/\ m.round = PickRound(B) + 1
/\ ~m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ m.val \in SuccessorValues(B)
/\ m.round = PickRound(B) + 1
/\ m.type = "Answer" =>
\E o \in msgs :
/\ o.type = "Offer"
/\ o.round = m.lastRound
/\ o.val = m.lastVal
/\ o.primed = m.lastPrimed)'
BY DEF MsgInv
<6>1 (m.type = "Offer" =>
/\ m.round = 0 => ~m.primed
/\ m.round # 0 =>
/\ m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ m.val = PickValue(B)
/\ m.round = PickRound(B) + 1
/\ ~m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ m.val \in SuccessorValues(B)
/\ m.round = PickRound(B) + 1)'
<7>1 msgs' = msgs \union {[type |-> "Offer", val |-> PickValue(A),
round |-> PickRound(A) + 1, primed |-> TRUE]}
BY <3>1, <4>4, <5>1 DEF TrySend, Send
\* Round-zero case holds for existing messages. For new messages, a round-zero offer is
\* never issued in the case of `AllIdenticalRounds(A) /\ AllIdenticalValues(A)'
\* because `PickRound(A) + 1' results in a round number that exceeds 0.
<7>2 CASE m.type = "Offer" /\ m.round = 0
<8>1 A \in SUBSET Messages /\ A # {} /\ \A a \in A : a.lastRound \in Rounds
BY <3>1, QuorumAssumption DEF QuorumAnswers, Answers, Messages
<8>2 PickRound(A) \in Rounds
BY <8>1, PickRoundImage
<8>3 PickRound(A) + 1 > 0
BY <8>2 DEF Rounds
<8>4 QED
BY <7>1, <7>2, <8>3
\* Non-zero round with a primed offer: either `m' is in `msgs' (invariant is preserved) or,
\* if `m' is the newly sent message, by a simple consequence of the definition of `Offer'.
<7>3 CASE m.type = "Offer" /\ m.round # 0 /\ m.primed
<8>1 CASE m \in msgs
BY <7>1, <7>3, <8>1 DEF QuorumAnswers, Answers
<8>2 CASE m \notin msgs
BY <3>1, <4>4, <5>1, <7>1, <7>3, <8>2 DEF QuorumAnswers, Answers
<8>3 QED
BY <8>1, <8>2
\* Non-zero round with an unprimed offer: either `m' is in `msgs' (the invariant is
\* implicitly preserved), or the newly sent message `m' is primed — a contradiction of
\* the ` ~m.primed' conjunct in this case.
<7>4 CASE m.type = "Offer" /\ m.round # 0 /\ ~m.primed
<8>2 CASE m \in msgs
<9>1 ~m.primed
BY <7>4
<9>2 QED
BY <7>1, <9>1 DEF QuorumAnswers, Answers
<8>3 CASE m \notin msgs
BY <3>1, <4>4, <7>1, <7>4, <8>3 DEF QuorumAnswers, Answers
<8>4 QED
BY <8>2, <8>3, <7>4
<7>5 QED
BY <7>2, <7>3, <7>4
<6>2 (m.type = "Answer" =>
\E o \in msgs :
/\ o.type = "Offer"
/\ o.round = m.lastRound
/\ o.val = m.lastVal
/\ o.primed = m.lastPrimed)'
BY <3>1, <4>4, <5>1 DEF TrySend, Send
<6>3 QED
BY <6>1, <6>2
<5>2 CASE ~AllIdenticalValues(A)
<6> SUFFICES ASSUME NEW m \in msgs'
PROVE (/\ m.type = "Offer" =>
/\ m.round = 0 => ~m.primed
/\ m.round # 0 =>
/\ m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ m.val = PickValue(B)
/\ m.round = PickRound(B) + 1
/\ ~m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ m.val \in SuccessorValues(B)
/\ m.round = PickRound(B) + 1
/\ m.type = "Answer" =>
\E o \in msgs :
/\ o.type = "Offer"
/\ o.round = m.lastRound
/\ o.val = m.lastVal
/\ o.primed = m.lastPrimed)'
BY DEF MsgInv
<6>1 (m.type = "Offer" =>
/\ m.round = 0 => ~m.primed
/\ m.round # 0 =>
/\ m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B) /\ AllIdenticalValues(B)
/\ m.val = PickValue(B)
/\ m.round = PickRound(B) + 1
/\ ~m.primed =>
\E R \in Quorums : \E B \in QuorumAnswers(R) :
/\ AllIdenticalRounds(B)
/\ m.val \in SuccessorValues(B)
/\ m.round = PickRound(B) + 1)'
<7>1 \E v \in SuccessorValues(A) :