compute_probabilities_of_finality.py
1 import math 2 BLKTIME = 17 3 X = 0.28 4 5 faclog = [1] 6 for i in range(5000): 7 faclog.append(faclog[-1] * len(faclog)) 8 9 def fac(x): 10 return faclog[x] 11 12 def poisson(expected, actual): 13 if expected == 0: 14 return 1 if actual == 0 else 0 15 return 2.718281828 ** (-expected + actual * math.log(expected) - math.log(fac(actual))) 16 17 def p_we_win(k, x): 18 return 1 - (x / (1.0 - x)) ** k 19 20 def p_we_win_after(s): 21 p = 0 22 for i in range(4000): 23 p += poisson(s * 1.0 / BLKTIME, i) * p_we_win(i, X) 24 return p 25 26 for i in range(0, 7200, 12): 27 print i, p_we_win_after(i)