Bitcoin ABC 0.30.7
P2P Digital Currency
Functions | Variables
rtt.cpp File Reference
#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>
Include dependency graph for rtt.cpp:

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. More...
 
bool isRTTEnabled (const Consensus::Params &params, const CBlockIndex *pprev)
 Whether the RTT feature is enabled. More...
 

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. More...
 
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
 

Function Documentation

◆ GetNextRTTWorkRequired()

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.

Definition at line 102 of file rtt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRTTEnabled()

bool isRTTEnabled ( const Consensus::Params params,
const CBlockIndex pprev 
)

Whether the RTT feature is enabled.

Definition at line 150 of file rtt.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ RTT_CONSTANT_FACTOR

const std::vector<double> RTT_CONSTANT_FACTOR
static
Initial value:
= {
0., 0., 0.,
0., 0., 0.,
}
static const double RTT_CONSTANT_FACTOR_5
Definition: rtt.cpp:83
static const double RTT_CONSTANT_FACTOR_11
Definition: rtt.cpp:86
static const double RTT_CONSTANT_FACTOR_17
Definition: rtt.cpp:89
static const double RTT_CONSTANT_FACTOR_2
Definition: rtt.cpp:80

Definition at line 92 of file rtt.cpp.

◆ RTT_CONSTANT_FACTOR_11

const double RTT_CONSTANT_FACTOR_11
static
Initial value:
=
RTT_K * std::pow(std::tgamma(1. + 1. / RTT_K), RTT_K) /
std::pow(6000., RTT_K - 1.)
static constexpr double RTT_K
target(t) = target(prev_block) * RTT_CONSTANT_FACTOR * t^(RTT_K - 1) Where t is the time since the pr...
Definition: rtt.cpp:78

Definition at line 86 of file rtt.cpp.

◆ RTT_CONSTANT_FACTOR_17

const double RTT_CONSTANT_FACTOR_17
static
Initial value:
=
RTT_K * std::pow(std::tgamma(1. + 1. / RTT_K), RTT_K) /
std::pow(9600., RTT_K - 1.)

Definition at line 89 of file rtt.cpp.

◆ RTT_CONSTANT_FACTOR_2

const double RTT_CONSTANT_FACTOR_2
static
Initial value:
=
RTT_K * std::pow(std::tgamma(1. + 1. / RTT_K), RTT_K) /
std::pow(600., RTT_K - 1.)

Definition at line 80 of file rtt.cpp.

◆ RTT_CONSTANT_FACTOR_5

const double RTT_CONSTANT_FACTOR_5
static
Initial value:
=
RTT_K * std::pow(std::tgamma(1. + 1. / RTT_K), RTT_K) /
std::pow(2400., RTT_K - 1.)

Definition at line 83 of file rtt.cpp.

◆ RTT_K

constexpr double RTT_K {6.}
staticconstexpr

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

Definition at line 78 of file rtt.cpp.