Skip to content

Best difficulty algorithm so far #28

@zawy12

Description

@zawy12

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.

#  Weighted-Weighted Harmonic Mean (WWHM) difficulty algorithm
# Original idea from Tom Harding (Deger8) called "WT-144"  
# No limits, filtering, or tempering should be attempted.
# MTP should not be used.

# set constants
N=60 
T=600 # coin's Target solvetime. Value can be anything.
adjust=0.99 # 0.98 for N=30, 0.99 for N=60
k = (N+1)/2 *adjust * T

# algorithm
previous_max=timestamp[height - N] 
for ( i = height-N+1; i < height+1; i++) {  # (N most recent blocks)
    max_timestamp=max(timestamp[i], previous_max)
    solvetime = max_timestamp - previous_max
    solvetime=1 if solvetime < 1
    solvetime = 10*T if solvetime > 10*T 
    previous_max=max_timestamp
    j++
    t +=  solvetime * j # give more weight to recent blocks
    d +=D[i] # sum the difficulties
}  # next i
t=T*N if t < T*N  # in case of startup weirdness keep t sane
next_D = d * k / t 
# limits do not need to be used because of the above solvetime restrictions
# but if you still want limits on D's change per block & expect max 5x hash rate
# changes or want to replace the solvetime restrictions, use
# limit = 5^(3/N)
# next_D = previous_D*limit if next_D > previous_D*limit
# next_D = previous_D/limit if next_D > previous_D/limit

=======================

# Jacob Eliosoff's EMA (exponential moving average)
# see https://en.wikipedia.org/wiki/Moving_average#Application_to_measuring_computer_performance
# ST = previous solvetime
# N=35 to 100 seems possible.  Small N for small coins. N=70 for all might be best.
# MTP should not be used

ST = previous timestamp - timestamp before that
ST = max(T/100,min(T*10, ST))
next_D = previous_D * ( T/ST + e^(-ST/T/N) * (1-T/ST) )

zawy_spreadsheet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions