GetNextTargetRequired function

From Peercoin Wiki
Jump to: navigation, search

Source

The GetNextTargetRequired function code can be found in the main.cpp file (v0.4.0ppc).

(...)
const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
(...)
int64 nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();

// ppcoin: target change every block
// ppcoin: retarget with exponential moving toward target spacing
CBigNum bnNew;
bnNew.SetCompact(pindexPrev->nBits);
int64 nTargetSpacing = fProofOfStake? STAKE_TARGET_SPACING : min(nTargetSpacingWorkMax, (int64) STAKE_TARGET_SPACING * (1 + pindexLast->nHeight - pindexPrev->nHeight));
int64 nInterval = nTargetTimespan / nTargetSpacing;
bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
bnNew /= ((nInterval + 1) * nTargetSpacing);
(...)
return bnNew.GetCompact();

nTargetTimespan is described here.

Description

<TODO>

Signature

Parameters

Name Type Description
pindexLast const CBlockIndex* The last connected block index
fProofOfStake bool true to get the PoS next required target, false for the PoW one

Return value

Type Description
unsigned int The calculated next required target

FAQ

What is the next required target used for?
<TODO>
What are the STAKE_TARGET_SPACING, nTargetSpacingWorkMax and nTargetTimespan constants?
These constants are described here

Feel free to add your own questions in this FAQ

Links

Related posts on peercointalk