Move CBlockIndex::GetBlockWork() to pow::GetProofIncrement(nBits)
This commit is contained in:
parent
c2c02f3fa9
commit
b343c1a1e3
13
src/main.h
13
src/main.h
@ -14,6 +14,7 @@
|
|||||||
#include "coins.h"
|
#include "coins.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "pow.h"
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
#include "txmempool.h"
|
#include "txmempool.h"
|
||||||
@ -792,17 +793,7 @@ public:
|
|||||||
|
|
||||||
uint256 GetBlockWork() const
|
uint256 GetBlockWork() const
|
||||||
{
|
{
|
||||||
uint256 bnTarget;
|
return GetProofIncrement(nBits);
|
||||||
bool fNegative;
|
|
||||||
bool fOverflow;
|
|
||||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
|
||||||
if (fNegative || fOverflow || bnTarget == 0)
|
|
||||||
return 0;
|
|
||||||
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
|
|
||||||
// as it's too large for a uint256. However, as 2**256 is at least as large
|
|
||||||
// as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
|
|
||||||
// or ~bnTarget / (nTarget+1) + 1.
|
|
||||||
return (~bnTarget / (bnTarget + 1)) + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { nMedianTimeSpan=11 };
|
enum { nMedianTimeSpan=11 };
|
||||||
|
15
src/pow.cpp
15
src/pow.cpp
@ -127,3 +127,18 @@ void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
|
|||||||
if (Params().AllowMinDifficultyBlocks())
|
if (Params().AllowMinDifficultyBlocks())
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 GetProofIncrement(unsigned int nBits)
|
||||||
|
{
|
||||||
|
uint256 bnTarget;
|
||||||
|
bool fNegative;
|
||||||
|
bool fOverflow;
|
||||||
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||||
|
if (fNegative || fOverflow || bnTarget == 0)
|
||||||
|
return 0;
|
||||||
|
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
|
||||||
|
// as it's too large for a uint256. However, as 2**256 is at least as large
|
||||||
|
// as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
|
||||||
|
// or ~bnTarget / (nTarget+1) + 1.
|
||||||
|
return (~bnTarget / (bnTarget + 1)) + 1;
|
||||||
|
}
|
||||||
|
@ -22,4 +22,6 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime);
|
|||||||
|
|
||||||
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
|
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
|
||||||
|
|
||||||
|
uint256 GetProofIncrement(unsigned int nBits);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user