Added naive algo

This commit is contained in:
Vitalik Buterin 2015-01-13 00:59:53 -05:00
parent de2c4bffa3
commit c425818dd6

View File

@ -22,6 +22,8 @@ BOUNDED_ADJUST_THRESHOLD = 1.3
BOUNDED_ADJUST_FACTOR = 0.01
# How many blocks back to look
BLKS_BACK = 10
# Naive difficulty adjustment factor
NAIVE_ADJUST_FACTOR = 1/1024.
# Produces a value according to the exponential distribution; used
@ -82,6 +84,19 @@ def bounded_adjust(timestamps, diffs):
return diffs[-1] * fac
# Old Ethereum algorithm
def old_adjust(timestamps, diffs):
if len(timestamps) < 2:
return diffs[-1]
delta = timestamps[-1] - timestamps[-2]
expected = TARGET * 0.693
if delta > expected:
fac = 1 - NAIVE_ADJUST_FACTOR
else:
fac = 1 + NAIVE_ADJUST_FACTOR
return diffs[-1] * fac
def test(source, adjust):
# Variables to keep track of for stats purposes
ema = maxema = minema = TARGET