mirror of
https://github.com/status-im/research.git
synced 2025-02-04 11:13:43 +00:00
Added naive algo
This commit is contained in:
parent
de2c4bffa3
commit
c425818dd6
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user