In order to correct for changes in the network’s total hashing power (i.e. as hardware improves or mining nodes are added to or removed from the network), the amount of work required to mine a block must change.
Nexa solves this by adjusting the target according to an algorithm that looks at recent block timestamps, infers the hashing power that led to those timestamps, and attempts to change the difficulty of mining future blocks accordingly.
The calculation used is referred to as the Difficulty Adjustment Algorithm, or DAA, and is a control theory problem.
The algorithms used is ASERT
Absolutely Scheduled Exponentially Rising Targets (ASERT), more specifically aserti3-2d, was implemented as a part of HF-20201115.
It uses an exponential moving average approach that should theoretically always target a correction toward the correct average block time.
ASERT bases it’s calculations on the following components:
Though this is not used directly in practice, the exponential form of the calculation of the target for the next block is:
exponent = (time_delta - ideal_block_time * (height_delta + 1)) / halflife next_target = anchor_target * 2**(exponent)
anchor_targetis the unsigned 256 bit integer equivalent of the
time_deltais the difference, in signed integer seconds, between the
ideal_block_timeis a constant: 600 seconds, the targeted
height_deltais the difference in block height between the current
halflifeis a constant parameter sometimes referred to as
next_targetis the integer value of the target computed for the block
In order to avoid subtle platform-dependent floating point issues, however, ASERT is instead calculated using fixed-point integer arithmetic with a cubic polynomial approximation of the exponential.
See ASERT:target computeration for the Python reference implementation and additional details on where new implementations of the algorithm must be cautious to ensure full compatibility.