Open zawy12 opened 6 years ago
This is the new best one. It is beneficial over simple N=70 only if sudden hash changes are >3x.
# Dynamic EMA difficulty algo (Jacob Eliosoff's EMA and Zawy's adjustable window).
# Bitcoin Cash dev (Amaury?) came up with the median of three to reduce timestamp errors.
# For EMA origins see
# https://en.wikipedia.org/wiki/Moving_average#Application_to_measuring_computer_performance
# "Dynamic" means it triggers to a faster-responding value for N if a substantial change in hashrate
# is detected. It increases from that event back to Nmax
Nmax=70 # max EMA window
Nmin=25 # min EMA window
A=10, B=2, C=0.37 # A,B,C = 10,2,0.37 or 20, 1.65 0.45,
# TS=timestamp, T=target solvetime, i.e. 600 seconds
# Find the most recent unusual 20-block event
for (i=height-Nmax to height) { # height=current block index
if ( (median(TS[i],TS[i-1],TS[i-2]) - median(TS[i-20],TS[i-21],TS[i-22]))/T/A > B
or
(median(TS[i],TS[i-1],TS[i-2]) - median(TS[i-20],TS[i-21],TS[i-22]))/T/A < C )
{ unusual_event=height - i + Nmin }
}
N = min(Nmax, unusual_event))
# now use the EMA difficulty algorithm with this N
Here are some comparisons under sudden hashrate changes and constant hashrate.
I corrected a code error in the previous post.
An updated version of this LWMA is now being used on 5 monero clones.
I recommend one of the two following. They seem pretty much the same when the N of WWHM is 2x the N of EMA. In case I do not keep this page updated, I'll keep this blog post updated.
=======================