Skip to content

Commit

Permalink
Added naive algo
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuterin committed Jan 13, 2015
1 parent de2c4bf commit c425818
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions diffadjust/blkdiff.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c425818

Please sign in to comment.