Permalink
Browse files

Added naive algo

  • Loading branch information...
vbuterin committed Jan 13, 2015
1 parent de2c4bf commit c425818dd695786857b665ef0deddec008ca181f
Showing with 15 additions and 0 deletions.
  1. +15 −0 diffadjust/blkdiff.py
View
@@ -22,6 +22,8 @@
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

0 comments on commit c425818

Please sign in to comment.