Skip to content

Instantly share code, notes, and snippets.

@ksaynice
Forked from lrettig/iceage.py
Created January 22, 2019 10:52
Show Gist options
  • Save ksaynice/74285ba9ebf1b1bbf2e81feaed47ce60 to your computer and use it in GitHub Desktop.
Save ksaynice/74285ba9ebf1b1bbf2e81feaed47ce60 to your computer and use it in GitHub Desktop.
Simulation script for ice age block times
# Date, blocknum, difficulty as of 2019-01-18
# Script by vbuterin, slightly modified by lrettig
import random
import datetime
import sys
def calc_bomb(i):
period = i // 100000
if (period > 0):
# Subtract 2, this is the original formula
# Subtract another 30, this is the Byzantium delay
return 2**(period - 32)
return 0
def calc_difficulty_byzantium(i, cur_time, prev_diff, prev_time):
new_diff = prev_diff + prev_diff // 2048 * max(1 - (cur_time - prev_time) // 9, -99)
new_diff += calc_bomb(i)
return new_diff
first_block = 7_087_671
times = [1547823394]
#diffs = [3_033_556_249_786_083]
diffs = [2_580_831_000_000_000]
hashpower = diffs[0] / 14
for i in range(first_block, 10_000_000):
blocktime = random.expovariate(hashpower / diffs[-1])
new_time = times[-1] + blocktime
new_diff = calc_difficulty_byzantium(i, new_time, diffs[-1], times[-1])
times.append(new_time)
diffs.append(new_diff)
predicted_avg_blocktime = diffs[-1] / hashpower
if i % 10000 == 0:
print('Block %d, time %r blocktime %.2f diffratio %.4f' % (
i,
datetime.datetime.utcfromtimestamp(times[-1]).isoformat().replace('T',' '),
predicted_avg_blocktime,
calc_bomb(i) / diffs[-1],
))
if predicted_avg_blocktime > 60:
sys.exit('Predicted block time exceeded 60s')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment