Skip to content

Commit f2ada13

Browse files
committed
Merge pull request #5170
092b58d CBlockIndex::GetBlockWork() + GetProofIncrement(nBits) -> GetBlockProof(CBlockIndex) (jtimon) 22c4272 MOVEONLY: Move void UpdateTime() from pow.o to miner.o (plus fix include main.h -> chain.h) (jtimon)
2 parents ca6fb4e + 092b58d commit f2ada13

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

src/chain.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ class CBlockIndex
220220
return (int64_t)nTime;
221221
}
222222

223-
uint256 GetBlockWork() const
224-
{
225-
return GetProofIncrement(nBits);
226-
}
227-
228223
enum { nMedianTimeSpan=11 };
229224

230225
int64_t GetMedianTimePast() const

src/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ void CheckForkWarningConditions()
12261226
if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 72)
12271227
pindexBestForkTip = NULL;
12281228

1229-
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (chainActive.Tip()->GetBlockWork() * 6)))
1229+
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6)))
12301230
{
12311231
if (!fLargeWorkForkFound)
12321232
{
@@ -1277,7 +1277,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip)
12771277
// We define it this way because it allows us to only store the highest fork tip (+ base) which meets
12781278
// the 7-block condition and from this always have the most-likely-to-cause-warning fork
12791279
if (pfork && (!pindexBestForkTip || (pindexBestForkTip && pindexNewForkTip->nHeight > pindexBestForkTip->nHeight)) &&
1280-
pindexNewForkTip->nChainWork - pfork->nChainWork > (pfork->GetBlockWork() * 7) &&
1280+
pindexNewForkTip->nChainWork - pfork->nChainWork > (GetBlockProof(*pfork) * 7) &&
12811281
chainActive.Height() - pindexNewForkTip->nHeight < 72)
12821282
{
12831283
pindexBestForkTip = pindexNewForkTip;
@@ -2118,7 +2118,7 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block)
21182118
pindexNew->nHeight = pindexNew->pprev->nHeight + 1;
21192119
pindexNew->BuildSkip();
21202120
}
2121-
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + pindexNew->GetBlockWork();
2121+
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
21222122
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
21232123
if (pindexBestHeader == NULL || pindexBestHeader->nChainWork < pindexNew->nChainWork)
21242124
pindexBestHeader = pindexNew;
@@ -2816,7 +2816,7 @@ bool static LoadBlockIndexDB()
28162816
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
28172817
{
28182818
CBlockIndex* pindex = item.second;
2819-
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + pindex->GetBlockWork();
2819+
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
28202820
if (pindex->nStatus & BLOCK_HAVE_DATA) {
28212821
if (pindex->pprev) {
28222822
if (pindex->pprev->nChainTx) {

src/miner.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "main.h"
1313
#include "net.h"
1414
#include "pow.h"
15+
#include "timedata.h"
1516
#include "util.h"
1617
#include "utilmoneystr.h"
1718
#ifdef ENABLE_WALLET
@@ -78,6 +79,15 @@ class TxPriorityCompare
7879
}
7980
};
8081

82+
void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
83+
{
84+
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
85+
86+
// Updating time can change work required on testnet:
87+
if (Params().AllowMinDifficultyBlocks())
88+
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
89+
}
90+
8191
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
8292
{
8393
// Create new block

src/miner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdint.h>
1010

1111
class CBlock;
12+
class CBlockHeader;
1213
class CBlockIndex;
1314
class CReserveKey;
1415
class CScript;
@@ -25,6 +26,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);
2526
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
2627
/** Check mined block */
2728
bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
29+
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
2830

2931
extern double dHashesPerSec;
3032
extern int64_t nHPSTimerStart;

src/pow.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
#include "pow.h"
77

8+
#include "chain.h"
89
#include "chainparams.h"
910
#include "core/block.h"
10-
#include "main.h"
11-
#include "timedata.h"
1211
#include "uint256.h"
1312
#include "util.h"
1413

@@ -98,21 +97,12 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
9897
return true;
9998
}
10099

101-
void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
102-
{
103-
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
104-
105-
// Updating time can change work required on testnet:
106-
if (Params().AllowMinDifficultyBlocks())
107-
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
108-
}
109-
110-
uint256 GetProofIncrement(unsigned int nBits)
100+
uint256 GetBlockProof(const CBlockIndex& block)
111101
{
112102
uint256 bnTarget;
113103
bool fNegative;
114104
bool fOverflow;
115-
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
105+
bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
116106
if (fNegative || fOverflow || bnTarget == 0)
117107
return 0;
118108
// We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256

src/pow.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
1616

1717
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
1818
bool CheckProofOfWork(uint256 hash, unsigned int nBits);
19-
20-
void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
21-
22-
uint256 GetProofIncrement(unsigned int nBits);
19+
uint256 GetBlockProof(const CBlockIndex& block);
2320

2421
#endif // BITCOIN_POW_H

0 commit comments

Comments
 (0)