Bitcoin ABC 0.26.3
P2P Digital Currency
|
#include <policy/block/rtt.h>
#include <arith_uint256.h>
#include <blockindex.h>
#include <common/args.h>
#include <consensus/activation.h>
#include <consensus/params.h>
#include <logging.h>
#include <pow/pow.h>
#include <timedata.h>
#include <tinyformat.h>
#include <algorithm>
#include <cmath>
Go to the source code of this file.
Functions | |
std::optional< uint32_t > | GetNextRTTWorkRequired (const CBlockIndex *pprev, int64_t now, const Consensus::Params &consensusParams) |
Compute the real time block hash target given the previous block parameters. | |
bool | isRTTEnabled (const Consensus::Params ¶ms, const CBlockIndex *pprev) |
Whether the RTT feature is enabled. | |
Variables | |
static constexpr double | RTT_K {6.} |
target(t) = target(prev_block) * RTT_CONSTANT_FACTOR * t^(RTT_K - 1) Where t is the time since the previous block timestamp and RTT_K is an arbitrary integer >= 1. | |
static const double | RTT_CONSTANT_FACTOR_2 |
static const double | RTT_CONSTANT_FACTOR_5 |
static const double | RTT_CONSTANT_FACTOR_11 |
static const double | RTT_CONSTANT_FACTOR_17 |
static const std::vector< double > | RTT_CONSTANT_FACTOR |
std::optional< uint32_t > GetNextRTTWorkRequired | ( | const CBlockIndex * | pprev, |
int64_t | now, | ||
const Consensus::Params & | consensusParams | ||
) |
bool isRTTEnabled | ( | const Consensus::Params & | params, |
const CBlockIndex * | pprev | ||
) |
|
static |
|
static |
|
static |
|
static |
|
static |
target(t) = target(prev_block) * RTT_CONSTANT_FACTOR * t^(RTT_K - 1) Where t is the time since the previous block timestamp and RTT_K is an arbitrary integer >= 1.
The factor is computed as: RTT_K * gamma(1 + 1/RTT_K)^RTT_K / (T^(RTT_K-1)) Where T is the target time between blocks, aka 600s.
We apply this formula on a list of previous blocks so we obtain RTT for various windows: 2 blocks, 5 blocks, 11 blocks and 17 blocks. The highest difficulty (the lowest target) over these windows is the one that applies. This is so that the target becomes more constrained as the window increases, but also we have some room for the DAA to take action and let the average difficulty be corrected in both directions.
The windows are selected so they are prime numbers, skipping one between successive windows. This is a best effort to avoid introducing resonant frequencies due to using a series of filters. We stop at 17 blocks because it makes no practical difference to go further, the selectivity of the filter doesn't change by any meaningful amount anymore.
Inspired by the research from https://ledger.pitt.edu/ojs/ledger/article/download/195/187/1008