MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / BitcoinGetNextWorkRequired

Function BitcoinGetNextWorkRequired

src/pow.cpp:173–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173unsigned int BitcoinGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
174{
175 assert(pindexLast != nullptr);
176 unsigned int nProofOfWorkLimit = UintToArith256(params.PowLimit(false)).GetCompact();
177
178 // Only change once per difficulty adjustment interval
179 if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0)
180 {
181 if (params.fPowAllowMinDifficultyBlocks)
182 {
183 // Special difficulty rule for testnet:
184 // If the new block's timestamp is more than 2* 10 minutes
185 // then allow mining of a min-difficulty block.
186 if (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2)
187 return nProofOfWorkLimit;
188 else
189 {
190 // Return the last non-special-min-difficulty-rules-block
191 const CBlockIndex* pindex = pindexLast;
192 while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit)
193 pindex = pindex->pprev;
194 return pindex->nBits;
195 }
196 }
197 return pindexLast->nBits;
198 }
199
200 // Go back by what we want to be 14 days worth of blocks
201 int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1);
202 assert(nHeightFirst >= 0);
203 const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
204 assert(pindexFirst);
205
206 return BitcoinCalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
207}
208
209unsigned int ReduceDifficultyBy(const CBlockIndex* pindexLast, int64_t multiplier, const Consensus::Params& params) {
210 arith_uint256 target;

Callers 1

GetNextWorkRequiredFunction · 0.85

Calls 6

UintToArith256Function · 0.85
GetCompactMethod · 0.80
GetAncestorMethod · 0.80
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected