analytical.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #!/usr/bin/env python3
  2. # Compute analytical formulas for the bytes used per epoch by the
  3. # various modes
  4. import sympy
  5. A, R_B, R_N, R, logR, C_B, C_N, C, gamma, circ, P_Delta, \
  6. DirAuthConsensusMsg, DirAuthENDIVEDiffMsg, DirAuthGetConsensusMsg, \
  7. DirAuthGetENDIVEDiffMsg, DirAuthUploadDescMsg, DirAuthENDIVEMsg, \
  8. DirAuthGetENDIVEMsg, DirAuthUploadDescMsg, RelayConsensusMsg, \
  9. RelayDescMsg, RelayGetConsensusMsg, RelayGetDescMsg, \
  10. SinglePassCreateCircuitMsgNotLast, SinglePassCreateCircuitMsgLast, \
  11. SinglePassCreatedCircuitCellLast, SinglePassCreatedCircuitCellMiddle, \
  12. SinglePassCreatedCircuitCellFirst, TelescopingCreateCircuitMsg, \
  13. TelescopingCreatedCircuitCell, TelescopingExtendCircuitCell, \
  14. TelescopingExtendedCircuitCell, VanillaCreateCircuitMsg, \
  15. VanillaCreatedCircuitCell, VanillaExtendCircuitCell, \
  16. VanillaExtendedCircuitCell, DirAuthGetConsensusDiffMsg, \
  17. DirAuthConsensusDiffMsg, RelayGetConsensusDiffMsg, \
  18. RelayConsensusDiffMsg \
  19. = sympy.symbols("""
  20. A, R_B, R_N, R, logR, C_B, C_N, C, gamma, circ, P_Delta,
  21. DirAuthConsensusMsg, DirAuthENDIVEDiffMsg, DirAuthGetConsensusMsg,
  22. DirAuthGetENDIVEDiffMsg, DirAuthUploadDescMsg, DirAuthENDIVEMsg,
  23. DirAuthGetENDIVEMsg, DirAuthUploadDescMsg, RelayConsensusMsg,
  24. RelayDescMsg, RelayGetConsensusMsg, RelayGetDescMsg,
  25. SinglePassCreateCircuitMsgNotLast, SinglePassCreateCircuitMsgLast,
  26. SinglePassCreatedCircuitCellLast, SinglePassCreatedCircuitCellMiddle,
  27. SinglePassCreatedCircuitCellFirst, TelescopingCreateCircuitMsg,
  28. TelescopingCreatedCircuitCell, TelescopingExtendCircuitCell,
  29. TelescopingExtendedCircuitCell, VanillaCreateCircuitMsg,
  30. VanillaCreatedCircuitCell, VanillaExtendCircuitCell,
  31. VanillaExtendedCircuitCell, DirAuthGetConsensusDiffMsg,
  32. DirAuthConsensusDiffMsg, RelayGetConsensusDiffMsg,
  33. RelayConsensusDiffMsg
  34. """)
  35. globalsubs = [
  36. (A , 9),
  37. (R_N , R - R_B),
  38. (R_B , 0.010 * R),
  39. (C_N , C - C_B),
  40. (C_B , 0.16 * C),
  41. (circ , gamma * C),
  42. (gamma , 8.9),
  43. (C , 2500000*R/6500),
  44. (P_Delta, 0.019),
  45. ]
  46. # The actual sizes in bytes of each message type were logged by
  47. # uncommenting this line in network.py:
  48. # logging.info("%s size %d", type(self).__name__, sz)
  49. singlepass_merkle_subs = [
  50. (DirAuthConsensusMsg, 877),
  51. (DirAuthGetConsensusMsg, 41),
  52. (DirAuthGetENDIVEMsg, 38),
  53. (DirAuthGetENDIVEDiffMsg, 42),
  54. (DirAuthENDIVEDiffMsg, (P_Delta * DirAuthENDIVEMsg).subs(globalsubs)),
  55. (DirAuthENDIVEMsg, 274 * R),
  56. (DirAuthUploadDescMsg, 425),
  57. (RelayConsensusMsg, 873),
  58. (RelayDescMsg, 415),
  59. (RelayGetConsensusMsg, 37),
  60. (RelayGetDescMsg, 32),
  61. (SinglePassCreateCircuitMsgLast, 187),
  62. (SinglePassCreateCircuitMsgNotLast, 239),
  63. (SinglePassCreatedCircuitCellFirst, 1426+82*logR),
  64. (SinglePassCreatedCircuitCellMiddle, 903+41*logR),
  65. (SinglePassCreatedCircuitCellLast, 190),
  66. ]
  67. singlepass_threshsig_subs = [
  68. (DirAuthConsensusMsg, 789),
  69. (DirAuthGetConsensusMsg, 41),
  70. (DirAuthGetENDIVEMsg, 38),
  71. (DirAuthGetENDIVEDiffMsg, 42),
  72. (DirAuthENDIVEDiffMsg, DirAuthENDIVEMsg),
  73. (DirAuthENDIVEMsg, 348*R),
  74. (DirAuthUploadDescMsg, 425),
  75. (RelayConsensusMsg, 784),
  76. (RelayDescMsg, 415),
  77. (RelayGetConsensusMsg, 37),
  78. (RelayGetDescMsg, 32),
  79. (SinglePassCreateCircuitMsgLast, 187),
  80. (SinglePassCreateCircuitMsgNotLast, 239),
  81. (SinglePassCreatedCircuitCellFirst, 1554),
  82. (SinglePassCreatedCircuitCellMiddle, 969),
  83. (SinglePassCreatedCircuitCellLast, 190),
  84. ]
  85. telescoping_merkle_subs = [
  86. (DirAuthConsensusMsg, 877),
  87. (DirAuthGetConsensusMsg, 41),
  88. (DirAuthGetENDIVEMsg, 38),
  89. (DirAuthGetENDIVEDiffMsg, 42),
  90. (DirAuthENDIVEDiffMsg, (P_Delta * DirAuthENDIVEMsg).subs(globalsubs)),
  91. (DirAuthENDIVEMsg, 234 * R),
  92. (DirAuthUploadDescMsg, 372),
  93. (RelayConsensusMsg, 873),
  94. (RelayGetConsensusMsg, 37),
  95. (RelayGetDescMsg, 32),
  96. (RelayDescMsg, 362),
  97. (TelescopingCreateCircuitMsg, 120),
  98. (TelescopingCreatedCircuitCell, 179),
  99. (TelescopingExtendCircuitCell, 122),
  100. (TelescopingExtendedCircuitCell, 493+41*logR),
  101. ]
  102. telescoping_threshsig_subs = [
  103. (DirAuthConsensusMsg, 789),
  104. (DirAuthGetConsensusMsg, 41),
  105. (DirAuthGetENDIVEMsg, 38),
  106. (DirAuthGetENDIVEDiffMsg, 42),
  107. (DirAuthENDIVEDiffMsg, DirAuthENDIVEMsg),
  108. (DirAuthENDIVEMsg, 307*R),
  109. (DirAuthUploadDescMsg, 372),
  110. (RelayConsensusMsg, 788),
  111. (RelayGetConsensusMsg, 37),
  112. (RelayGetDescMsg, 32),
  113. (RelayDescMsg, 362),
  114. (TelescopingCreateCircuitMsg, 120),
  115. (TelescopingCreatedCircuitCell, 179),
  116. (TelescopingExtendCircuitCell, 122),
  117. (TelescopingExtendedCircuitCell, 556),
  118. ]
  119. vanilla_subs = [
  120. (DirAuthConsensusDiffMsg, (P_Delta * DirAuthConsensusMsg).subs(globalsubs)),
  121. (DirAuthConsensusMsg, RelayConsensusMsg),
  122. (DirAuthGetConsensusDiffMsg, 45),
  123. (DirAuthGetConsensusMsg, 41),
  124. (DirAuthUploadDescMsg, 372),
  125. (RelayConsensusDiffMsg, (P_Delta * RelayConsensusMsg).subs(globalsubs)),
  126. (RelayConsensusMsg, 219*R),
  127. (RelayGetConsensusDiffMsg, 41),
  128. (RelayGetConsensusMsg, 37),
  129. (VanillaCreateCircuitMsg, 116),
  130. (VanillaCreatedCircuitCell, 175),
  131. (VanillaExtendCircuitCell, 157),
  132. (VanillaExtendedCircuitCell, 176),
  133. ]
  134. # The formulas were output by bytecounts.py
  135. singlepass_totrelay = \
  136. R_N * ( DirAuthConsensusMsg + DirAuthENDIVEDiffMsg + DirAuthGetConsensusMsg + DirAuthGetENDIVEDiffMsg + A*DirAuthUploadDescMsg ) \
  137. + R_B * ( DirAuthConsensusMsg + DirAuthENDIVEMsg + DirAuthGetConsensusMsg + DirAuthGetENDIVEMsg + A*DirAuthUploadDescMsg ) \
  138. + C * ( RelayConsensusMsg + RelayDescMsg + RelayGetConsensusMsg + RelayGetDescMsg ) \
  139. + circ * ( 3*SinglePassCreateCircuitMsgNotLast + 2*SinglePassCreateCircuitMsgLast + 2*SinglePassCreatedCircuitCellLast + 2*SinglePassCreatedCircuitCellMiddle + SinglePassCreatedCircuitCellFirst + 20 )
  140. singlepass_totclient = \
  141. C * ( RelayConsensusMsg + RelayDescMsg + RelayGetConsensusMsg + RelayGetDescMsg ) \
  142. + circ * ( SinglePassCreateCircuitMsgNotLast + SinglePassCreatedCircuitCellFirst + 4 )
  143. telescoping_totrelay = \
  144. R_N * ( DirAuthConsensusMsg + DirAuthENDIVEDiffMsg + DirAuthGetConsensusMsg + DirAuthGetENDIVEDiffMsg + A*DirAuthUploadDescMsg ) \
  145. + R_B * ( DirAuthConsensusMsg + DirAuthENDIVEMsg + DirAuthGetConsensusMsg + DirAuthGetENDIVEMsg + A*DirAuthUploadDescMsg ) \
  146. + C * ( RelayConsensusMsg + RelayDescMsg + RelayGetConsensusMsg + RelayGetDescMsg ) \
  147. + circ * ( 5*TelescopingCreateCircuitMsg + 5*TelescopingCreatedCircuitCell + 4*TelescopingExtendCircuitCell + 4*TelescopingExtendedCircuitCell + 52 )
  148. telescoping_totclient = \
  149. C * ( RelayConsensusMsg + RelayDescMsg + RelayGetConsensusMsg + RelayGetDescMsg ) \
  150. + circ * ( TelescopingCreateCircuitMsg + TelescopingCreatedCircuitCell + 2*TelescopingExtendCircuitCell + 2*TelescopingExtendedCircuitCell + 20 )
  151. vanilla_totrelay = \
  152. R_N * ( DirAuthConsensusDiffMsg + DirAuthGetConsensusDiffMsg + A*DirAuthUploadDescMsg ) \
  153. + R_B * ( DirAuthConsensusMsg + DirAuthGetConsensusMsg + A*DirAuthUploadDescMsg ) \
  154. + C_N * ( RelayConsensusDiffMsg + RelayGetConsensusDiffMsg ) \
  155. + C_B * ( RelayConsensusMsg + RelayGetConsensusMsg ) \
  156. + circ * ( 5*VanillaCreateCircuitMsg + 5*VanillaCreatedCircuitCell + 4*VanillaExtendCircuitCell + 4*VanillaExtendedCircuitCell + 52 )
  157. vanilla_totclient = \
  158. C_N * ( RelayConsensusDiffMsg + RelayGetConsensusDiffMsg ) \
  159. + C_B * ( RelayConsensusMsg + RelayGetConsensusMsg ) \
  160. + circ * ( VanillaCreateCircuitMsg + VanillaCreatedCircuitCell + 2*VanillaExtendCircuitCell + 2*VanillaExtendedCircuitCell + 20 )
  161. # Copy the output into plotdats.py, replacing 'R' by 'x' and 'logR' by
  162. # 'cail(log(x)/log(2))'
  163. print('singlepass_merkle_relay =', (singlepass_totrelay/C).subs(globalsubs).subs(singlepass_merkle_subs).simplify())
  164. print('singlepass_merkle_client =', (singlepass_totclient/C).subs(globalsubs).subs(singlepass_merkle_subs).simplify())
  165. print('singlepass_threshsig_relay =', (singlepass_totrelay/C).subs(globalsubs).subs(singlepass_threshsig_subs).simplify())
  166. print('singlepass_threshsig_client =', (singlepass_totclient/C).subs(globalsubs).subs(singlepass_threshsig_subs).simplify())
  167. print('telescoping_merkle_relay =', (telescoping_totrelay/C).subs(globalsubs).subs(telescoping_merkle_subs).simplify())
  168. print('telescoping_merkle_client =', (telescoping_totclient/C).subs(globalsubs).subs(telescoping_merkle_subs).simplify())
  169. print('telescoping_threshsig_relay =', (telescoping_totrelay/C).subs(globalsubs).subs(telescoping_threshsig_subs).simplify())
  170. print('telescoping_threshsig_client =', (telescoping_totclient/C).subs(globalsubs).subs(telescoping_threshsig_subs).simplify())
  171. print('vanilla_relay =', (vanilla_totrelay/C).subs(globalsubs).subs(vanilla_subs).simplify())
  172. print('vanilla_client =', (vanilla_totclient/C).subs(globalsubs).subs(vanilla_subs).simplify())