You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
5.1 KiB

  1. // model of randomised consensus
  2. mdp
  3. const int N = 2; // num processes
  4. const int MAX = 5; // num rounds (R)
  5. const int K = 2; // Parameter for coins
  6. // need to turn these into local copies later so the reading phase is complete?
  7. formula leaders_agree1 = (p1=1 | r1<max(r1,r2)) & (p2=1 | r2<max(r1,r2));
  8. formula leaders_agree2 = (p1=2 | r1<max(r1,r2)) & (p2=2 | r2<max(r1,r2));
  9. formula decide1 = leaders_agree1 & (p1=1 | r1<max(r1,r2)-1) & (p2=1 | r2<max(r1,r2)-1);
  10. formula decide2 = leaders_agree2 & (p1=2 | r1<max(r1,r2)-1) & (p2=2 | r2<max(r1,r2)-1);
  11. module process1
  12. s1 : [0..5]; // local state
  13. // 0 initialise/read registers
  14. // 1 finish reading registers (make a decision)
  15. // 1 warn of change
  16. // 2 enter shared coin protocol
  17. // 4 finished
  18. // 5 error (reached max round and cannot decide)
  19. r1 : [0..MAX]; // round of the process
  20. p1 : [0..2]; // preference (0 corresponds to null)
  21. // nondeterministic choice as to initial preference
  22. [] s1=0 & r1=0 -> (p1'=1) & (r1'=1);
  23. [] s1=0 & r1=0 -> (p1'=2) & (r1'=1);
  24. // read registers (currently does nothing because read vs from other processes
  25. [] s1=0 & r1>0 & r1<=MAX -> (s1'=1);
  26. // maxke a decision
  27. [] s1=1 & decide1 -> (s1'=4) & (p1'=1);
  28. [] s1=1 & decide2 -> (s1'=4) & (p1'=2);
  29. [] s1=1 & r1<MAX & leaders_agree1 & !decide1 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  30. [] s1=1 & r1<MAX & leaders_agree2 & !decide2 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  31. [] s1=1 & r1<MAX & !(leaders_agree1 | leaders_agree2) -> (s1'=2) & (p1'=0);
  32. [] s1=1 & r1=MAX & !(decide1 | decide2) -> (s1'=5); // run out of rounds so error
  33. // enter the coin procotol for the current round
  34. [coin1_s1_start] s1=2 & r1=1 -> (s1'=3);
  35. [coin2_s1_start] s1=2 & r1=2 -> (s1'=3);
  36. [coin3_s1_start] s1=2 & r1=3 -> (s1'=3);
  37. [coin4_s1_start] s1=2 & r1=4 -> (s1'=3);
  38. // get response from the coin protocol
  39. [coin1_s1_p1] s1=3 & r1=1 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  40. [coin1_s1_p2] s1=3 & r1=1 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  41. [coin2_s1_p1] s1=3 & r1=2 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  42. [coin2_s1_p2] s1=3 & r1=2 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  43. [coin3_s1_p1] s1=3 & r1=3 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  44. [coin3_s1_p2] s1=3 & r1=3 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  45. [coin4_s1_p1] s1=3 & r1=4 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  46. [coin4_s1_p2] s1=3 & r1=4 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  47. // done so loop
  48. [done] s1>=4 -> true;
  49. endmodule
  50. module process2 = process1[ s1=s2,
  51. p1=p2,p2=p1,
  52. r1=r2,r2=r1,
  53. coin1_s1_start=coin1_s2_start,coin2_s1_start=coin2_s2_start,coin3_s1_start=coin3_s2_start,coin4_s1_start=coin4_s2_start,
  54. coin1_s1_p1=coin1_s2_p1,coin2_s1_p1=coin2_s2_p1,coin3_s1_p1=coin3_s2_p1,coin4_s1_p1=coin4_s2_p1,
  55. coin1_s1_p2=coin1_s2_p2,coin2_s1_p2=coin2_s2_p2,coin3_s1_p2=coin3_s2_p2,coin4_s1_p2=coin4_s2_p2 ]
  56. endmodule
  57. module coin1_error
  58. c1 : [0..1]; // 1 is the error state
  59. v1 : [0..2]; // value of the coin returned the first time
  60. // first returned value (any processes)
  61. [coin1_s1_p1] v1=0 -> (v1'=1);
  62. [coin1_s2_p1] v1=0 -> (v1'=1);
  63. [coin1_s1_p2] v1=0 -> (v1'=2);
  64. [coin1_s2_p2] v1=0 -> (v1'=2);
  65. // later values returned
  66. [coin1_s1_p1] v1=1 -> true; // good behaviour
  67. [coin1_s2_p1] v1=1 -> true; // good behaviour
  68. [coin1_s1_p2] v1=2 -> true; // good behaviour
  69. [coin1_s2_p2] v1=2 -> true; // good behaviour
  70. [coin1_s1_p1] v1=2 -> (c1'=1); // error
  71. [coin1_s2_p1] v1=2 -> (c1'=1); // error
  72. [coin1_s1_p2] v1=1 -> (c1'=1); // error
  73. [coin1_s2_p2] v1=1 -> (c1'=1); // error
  74. endmodule
  75. // could do with renaming
  76. module coin2_error
  77. c2 : [0..1]; // 1 is the error state
  78. v2 : [0..2]; // value of the coin returned the first time
  79. // first returned value (any processes)
  80. [coin2_s1_p1] v2=0 -> (v2'=1);
  81. [coin2_s2_p1] v2=0 -> (v2'=1);
  82. [coin2_s1_p2] v2=0 -> (v2'=2);
  83. [coin2_s2_p2] v2=0 -> (v2'=2);
  84. // later values returned
  85. [coin2_s1_p1] v2=1 -> true; // good behaviour
  86. [coin2_s2_p1] v2=1 -> true; // good behaviour
  87. [coin2_s1_p2] v2=2 -> true; // good behaviour
  88. [coin2_s2_p2] v2=2 -> true; // good behaviour
  89. [coin2_s1_p1] v2=2 -> (c2'=1); // error
  90. [coin2_s2_p1] v2=2 -> (c2'=1); // error
  91. [coin2_s1_p2] v2=1 -> (c2'=1); // error
  92. [coin2_s2_p2] v2=1 -> (c2'=1); // error
  93. endmodule
  94. // could do with renaming
  95. module coin3_error
  96. c3 : [0..1]; // 1 is the error state
  97. v3 : [0..2]; // value of the coin returned the first time
  98. // first returned value (any processes)
  99. [coin3_s1_p1] v3=0 -> (v3'=1);
  100. [coin3_s2_p1] v3=0 -> (v3'=1);
  101. [coin3_s1_p2] v3=0 -> (v3'=2);
  102. [coin3_s2_p2] v3=0 -> (v3'=2);
  103. // later values returned
  104. [coin3_s1_p1] v3=1 -> true; // good behaviour
  105. [coin3_s2_p1] v3=1 -> true; // good behaviour
  106. [coin3_s1_p2] v3=2 -> true; // good behaviour
  107. [coin3_s2_p2] v3=2 -> true; // good behaviour
  108. [coin3_s1_p1] v3=2 -> (c3'=1); // error
  109. [coin3_s2_p1] v3=2 -> (c3'=1); // error
  110. [coin3_s1_p2] v3=1 -> (c3'=1); // error
  111. [coin3_s2_p2] v3=1 -> (c3'=1); // error
  112. endmodule
  113. // coin 4 is of no use because of number of rounds
  114. // Labels
  115. label "one_proc_err" = (s1=5 | s2=5);
  116. label "one_coin_ok" = (c1=0 | c2=0 | c3=0);