aboutsummaryrefslogtreecommitdiff
path: root/src/miner.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2015-08-06 11:59:53 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2015-08-06 12:01:21 +0200
commit2f746c6e8a5d10fa2d432de9b43b694f40d5f4a1 (patch)
tree79269aacdc5605b430d60a73a20ed2f52397857d /src/miner.cpp
parent149f96c9b0693a61f27016572a12fb21436a442d (diff)
parentef8dfe41d1eba0de6d6554e25e658169f97313b5 (diff)
Merge pull request #6177
ef8dfe4 Prevent block.nTime from decreasing (Mark Friedenbach)
Diffstat (limited to 'src/miner.cpp')
-rw-r--r--src/miner.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/miner.cpp b/src/miner.cpp
index e44f3392c8..864e4bf31f 100644
--- a/src/miner.cpp
+++ b/src/miner.cpp
@@ -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)
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: