Browse Source

Merge pull request #6177

ef8dfe4 Prevent block.nTime from decreasing (Mark Friedenbach)
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
2f746c6e8a
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 14
      src/miner.cpp
  2. 2
      src/miner.h

14
src/miner.cpp

@ -84,13 +84,19 @@ public: @@ -84,13 +84,19 @@ public:
}
};
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
{
pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
int64_t nOldTime = pblock->nTime;
int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
if (nOldTime < nNewTime)
pblock->nTime = nNewTime;
// Updating time can change work required on testnet:
if (consensusParams.fPowAllowMinDifficultyBlocks)
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
return nNewTime - nOldTime;
}
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
@ -521,7 +527,9 @@ void static BitcoinMiner(const CChainParams& chainparams) @@ -521,7 +527,9 @@ void static BitcoinMiner(const CChainParams& chainparams)
break;
// Update nTime every few seconds
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
if (UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev) < 0)
break; // Recreate the block if the clock has run backwards,
// so that we can use the correct time.
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
{
// Changing pblock->nTime can change work required on testnet:

2
src/miner.h

@ -30,6 +30,6 @@ void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams& chainpar @@ -30,6 +30,6 @@ void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams& chainpar
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
/** Modify the extranonce in a block */
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
#endif // BITCOIN_MINER_H

Loading…
Cancel
Save