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.

99 lines
3.8 KiB

  1. // model of randomised consensus
  2. mdp
  3. const int N = 3; // num processes
  4. const int MAX = 3; // num rounds (R)
  5. // need to turn these into local copies later so the reading phase is complete?
  6. formula leaders_agree1 = (p1=1 | r1<max(r1,r2,r3)) & (p2=1 | r2<max(r1,r2,r3)) & (p3=1 | r3<max(r1,r2,r3));
  7. formula leaders_agree2 = (p1=2 | r1<max(r1,r2,r3)) & (p2=2 | r2<max(r1,r2,r3)) & (p3=2 | r3<max(r1,r2,r3));
  8. formula decide1 = leaders_agree1 & (p1=1 | r1<max(r1,r2,r3)-1) & (p2=1 | r2<max(r1,r2,r3)-1) & (p3=1 | r3<max(r1,r2,r3)-1);
  9. formula decide2 = leaders_agree2 & (p1=2 | r1<max(r1,r2,r3)-1) & (p2=2 | r2<max(r1,r2,r3)-1) & (p3=2 | r3<max(r1,r2,r3)-1);
  10. module process1
  11. s1 : [0..5]; // local state
  12. // 0 initialise/read registers
  13. // 1 finish reading registers (make a decision)
  14. // 1 warn of change
  15. // 2 enter shared coin protocol
  16. // 4 finished
  17. // 5 error (reached max round and cannot decide)
  18. r1 : [0..MAX]; // round of the process
  19. p1 : [0..2]; // preference (0 corresponds to null)
  20. // nondeterministic choice as to initial preference
  21. [] s1=0 & r1=0 -> (p1'=1) & (r1'=1);
  22. [] s1=0 & r1=0 -> (p1'=2) & (r1'=1);
  23. // read registers (currently does nothing because read vs from other processes
  24. [] s1=0 & r1>0 & r1<=MAX -> (s1'=1);
  25. // maxke a decision
  26. [] s1=1 & decide1 -> (s1'=4) & (p1'=1);
  27. [] s1=1 & decide2 -> (s1'=4) & (p1'=2);
  28. [] s1=1 & r1<MAX & leaders_agree1 & !decide1 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  29. [] s1=1 & r1<MAX & leaders_agree2 & !decide2 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  30. [] s1=1 & r1<MAX & !(leaders_agree1 | leaders_agree2) -> (s1'=2) & (p1'=0);
  31. [] s1=1 & r1=MAX & !(decide1 | decide2) -> (s1'=5); // run out of rounds so error
  32. // enter the coin procotol for the current round
  33. [coin1_s1_start] s1=2 & r1=1 -> (s1'=3);
  34. [coin2_s1_start] s1=2 & r1=2 -> (s1'=3);
  35. // get response from the coin protocol
  36. [coin1_s1_p1] s1=3 & r1=1 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  37. [coin1_s1_p2] s1=3 & r1=1 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  38. [coin2_s1_p1] s1=3 & r1=2 -> (s1'=0) & (p1'=1) & (r1'=r1+1);
  39. [coin2_s1_p2] s1=3 & r1=2 -> (s1'=0) & (p1'=2) & (r1'=r1+1);
  40. // done so loop
  41. [done] s1>=4 -> true;
  42. endmodule
  43. module process2 = process1[ s1=s2,
  44. p1=p2,p2=p3,p3=p1,
  45. r1=r2,r2=r3,r3=r1,
  46. coin1_s1_start=coin1_s2_start,coin2_s1_start=coin2_s2_start,
  47. coin1_s1_p1=coin1_s2_p1,coin2_s1_p1=coin2_s2_p1,
  48. coin1_s1_p2=coin1_s2_p2,coin2_s1_p2=coin2_s2_p2 ]
  49. endmodule
  50. module process3 = process1[ s1=s3,
  51. p1=p3,p2=p1,p3=p2,
  52. r1=r3,r2=r1,r3=r2,
  53. coin1_s1_start=coin1_s3_start,coin2_s1_start=coin2_s3_start,
  54. coin1_s1_p1=coin1_s3_p1,coin2_s1_p1=coin2_s3_p1,
  55. coin1_s1_p2=coin1_s3_p2,coin2_s1_p2=coin2_s3_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_s3_p1] v1=0 -> (v1'=1);
  64. [coin1_s1_p2] v1=0 -> (v1'=2);
  65. [coin1_s2_p2] v1=0 -> (v1'=2);
  66. [coin1_s3_p2] v1=0 -> (v1'=2);
  67. // later values returned
  68. [coin1_s1_p1] v1=1 -> true; // good behaviour
  69. [coin1_s2_p1] v1=1 -> true; // good behaviour
  70. [coin1_s3_p1] v1=1 -> true; // good behaviour
  71. [coin1_s1_p2] v1=2 -> true; // good behaviour
  72. [coin1_s2_p2] v1=2 -> true; // good behaviour
  73. [coin1_s3_p2] v1=2 -> true; // good behaviour
  74. [coin1_s1_p1] v1=2 -> (c1'=1); // error
  75. [coin1_s2_p1] v1=2 -> (c1'=1); // error
  76. [coin1_s3_p1] v1=2 -> (c1'=1); // error
  77. [coin1_s1_p2] v1=1 -> (c1'=1); // error
  78. [coin1_s2_p2] v1=1 -> (c1'=1); // error
  79. [coin1_s3_p2] v1=1 -> (c1'=1); // error
  80. endmodule
  81. // Labels
  82. label "one_proc_err" = (s1=5 | s2=5 | s3=5);
  83. label "one_coin_ok" = (c1=0);