Bitcoin ABC  0.22.13
P2P Digital Currency
Functions
daa.cpp File Reference
#include <pow/daa.h>
#include <arith_uint256.h>
#include <chain.h>
#include <consensus/params.h>
Include dependency graph for daa.cpp:

Go to the source code of this file.

Functions

static arith_uint256 ComputeTarget (const CBlockIndex *pindexFirst, const CBlockIndex *pindexLast, const Consensus::Params &params)
 Compute a target based on the work done between 2 blocks and the time required to produce that work. More...
 
static const CBlockIndexGetSuitableBlock (const CBlockIndex *pindex)
 To reduce the impact of timestamp manipulation, we select the block we are basing our computation on via a median of 3. More...
 
uint32_t GetNextDAAWorkRequired (const CBlockIndex *pindexPrev, const CBlockHeader *pblock, const Consensus::Params &params)
 Compute the next required proof of work using a weighted average of the estimated hashrate per block. More...
 

Function Documentation

◆ ComputeTarget()

static arith_uint256 ComputeTarget ( const CBlockIndex pindexFirst,
const CBlockIndex pindexLast,
const Consensus::Params params 
)
static

Compute a target based on the work done between 2 blocks and the time required to produce that work.

From the total work done and the time it took to produce that much work, we can deduce how much work we expect to be produced in the targeted time between blocks.

We need to compute T = (2^256 / W) - 1 but 2^256 doesn't fit in 256 bits. By expressing 1 as W / W, we get (2^256 - W) / W, and we can compute 2^256 - W as the complement of W.

Definition at line 15 of file daa.cpp.

Here is the caller graph for this function:

◆ GetNextDAAWorkRequired()

uint32_t GetNextDAAWorkRequired ( const CBlockIndex pindexPrev,
const CBlockHeader pblock,
const Consensus::Params params 
)

Compute the next required proof of work using a weighted average of the estimated hashrate per block.

Using a weighted average ensure that the timestamp parameter cancels out in most of the calculation - except for the timestamp of the first and last block. Because timestamps are the least trustworthy information we have as input, this ensures the algorithm is more resistant to malicious inputs.

Definition at line 91 of file daa.cpp.

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

◆ GetSuitableBlock()

static const CBlockIndex* GetSuitableBlock ( const CBlockIndex pindex)
static

To reduce the impact of timestamp manipulation, we select the block we are basing our computation on via a median of 3.

In order to avoid a block with a very skewed timestamp having too much influence, we select the median of the 3 top most blocks as a starting point.

Definition at line 52 of file daa.cpp.

Here is the caller graph for this function: