CBlockIndex::GetBlockWork() + GetProofIncrement(nBits) -> GetBlockProof(CBlockIndex)
This commit is contained in:
parent
22c4272bf4
commit
092b58d13d
4 changed files with 7 additions and 13 deletions
|
@ -217,11 +217,6 @@ public:
|
||||||
return (int64_t)nTime;
|
return (int64_t)nTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 GetBlockWork() const
|
|
||||||
{
|
|
||||||
return GetProofIncrement(nBits);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { nMedianTimeSpan=11 };
|
enum { nMedianTimeSpan=11 };
|
||||||
|
|
||||||
int64_t GetMedianTimePast() const
|
int64_t GetMedianTimePast() const
|
||||||
|
|
|
@ -1205,7 +1205,7 @@ void CheckForkWarningConditions()
|
||||||
if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 72)
|
if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 72)
|
||||||
pindexBestForkTip = NULL;
|
pindexBestForkTip = NULL;
|
||||||
|
|
||||||
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (chainActive.Tip()->GetBlockWork() * 6)))
|
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6)))
|
||||||
{
|
{
|
||||||
if (!fLargeWorkForkFound)
|
if (!fLargeWorkForkFound)
|
||||||
{
|
{
|
||||||
|
@ -1256,7 +1256,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip)
|
||||||
// We define it this way because it allows us to only store the highest fork tip (+ base) which meets
|
// We define it this way because it allows us to only store the highest fork tip (+ base) which meets
|
||||||
// the 7-block condition and from this always have the most-likely-to-cause-warning fork
|
// the 7-block condition and from this always have the most-likely-to-cause-warning fork
|
||||||
if (pfork && (!pindexBestForkTip || (pindexBestForkTip && pindexNewForkTip->nHeight > pindexBestForkTip->nHeight)) &&
|
if (pfork && (!pindexBestForkTip || (pindexBestForkTip && pindexNewForkTip->nHeight > pindexBestForkTip->nHeight)) &&
|
||||||
pindexNewForkTip->nChainWork - pfork->nChainWork > (pfork->GetBlockWork() * 7) &&
|
pindexNewForkTip->nChainWork - pfork->nChainWork > (GetBlockProof(*pfork) * 7) &&
|
||||||
chainActive.Height() - pindexNewForkTip->nHeight < 72)
|
chainActive.Height() - pindexNewForkTip->nHeight < 72)
|
||||||
{
|
{
|
||||||
pindexBestForkTip = pindexNewForkTip;
|
pindexBestForkTip = pindexNewForkTip;
|
||||||
|
@ -2095,7 +2095,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
|
||||||
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
|
||||||
pindexNew->BuildSkip();
|
pindexNew->BuildSkip();
|
||||||
}
|
}
|
||||||
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + pindexNew->GetBlockWork();
|
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
|
||||||
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
|
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
|
||||||
if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
|
if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
|
||||||
pindexBestHeader = pindexNew;
|
pindexBestHeader = pindexNew;
|
||||||
|
@ -2788,7 +2788,7 @@ bool static LoadBlockIndexDB()
|
||||||
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
|
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
|
||||||
{
|
{
|
||||||
CBlockIndex* pindex = item.second;
|
CBlockIndex* pindex = item.second;
|
||||||
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + pindex->GetBlockWork();
|
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
|
||||||
if (pindex->nStatus & BLOCK_HAVE_DATA) {
|
if (pindex->nStatus & BLOCK_HAVE_DATA) {
|
||||||
if (pindex->pprev) {
|
if (pindex->pprev) {
|
||||||
if (pindex->pprev->nChainTx) {
|
if (pindex->pprev->nChainTx) {
|
||||||
|
|
|
@ -97,12 +97,12 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint256 GetProofIncrement(unsigned int nBits)
|
uint256 GetBlockProof(const CBlockIndex& block)
|
||||||
{
|
{
|
||||||
uint256 bnTarget;
|
uint256 bnTarget;
|
||||||
bool fNegative;
|
bool fNegative;
|
||||||
bool fOverflow;
|
bool fOverflow;
|
||||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
|
||||||
if (fNegative || fOverflow || bnTarget == 0)
|
if (fNegative || fOverflow || bnTarget == 0)
|
||||||
return 0;
|
return 0;
|
||||||
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
|
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
|
||||||
|
|
|
@ -16,7 +16,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||||
|
|
||||||
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
|
||||||
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
|
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
|
||||||
|
uint256 GetBlockProof(const CBlockIndex& block);
|
||||||
uint256 GetProofIncrement(unsigned int nBits);
|
|
||||||
|
|
||||||
#endif // BITCOIN_POW_H
|
#endif // BITCOIN_POW_H
|
||||||
|
|
Loading…
Reference in a new issue