diff options
author | jtimon <jtimon@monetize.io> | 2014-06-28 14:03:06 +0200 |
---|---|---|
committer | jtimon <jtimon@monetize.io> | 2014-08-23 13:21:50 +0200 |
commit | c2c02f3fa99385f5a5be722fda6f71522c93bdaa (patch) | |
tree | 608b76aa8e523a4118f569518bf5150e85d77c48 /src | |
parent | 92b3d3630d6d63305bec136a23c7be4cb2bb2652 (diff) |
Move UpdateTime to pow
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 28 | ||||
-rw-r--r-- | src/main.h | 2 | ||||
-rw-r--r-- | src/miner.cpp | 4 | ||||
-rw-r--r-- | src/pow.cpp | 10 | ||||
-rw-r--r-- | src/pow.h | 2 | ||||
-rw-r--r-- | src/rpcmining.cpp | 2 |
6 files changed, 15 insertions, 33 deletions
diff --git a/src/main.cpp b/src/main.cpp index d7543e3f13..fab5af73bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1419,25 +1419,6 @@ void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state } } -void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev) -{ - block.nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - - // Updating time can change work required on testnet: - if (Params().AllowMinDifficultyBlocks()) - block.nBits = GetNextWorkRequired(pindexPrev, &block); -} - - - - - - - - - - - void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight) { bool ret; @@ -3291,15 +3272,6 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) return nLoaded > 0; } - - - - - - - - - ////////////////////////////////////////////////////////////////////////////// // // CAlert diff --git a/src/main.h b/src/main.h index 886cac1507..adb7d68bcf 100644 --- a/src/main.h +++ b/src/main.h @@ -163,8 +163,6 @@ bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, b bool ActivateBestChain(CValidationState &state); int64_t GetBlockValue(int nHeight, int64_t nFees); -void UpdateTime(CBlockHeader& block, const CBlockIndex* pindexPrev); - /** Create a new block index entry for a given block hash */ CBlockIndex * InsertBlockIndex(uint256 hash); /** Verify a signature */ diff --git a/src/miner.cpp b/src/miner.cpp index 06acff1c33..97b74695a7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -305,7 +305,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); - UpdateTime(*pblock, pindexPrev); + UpdateTime(pblock, pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock); pblock->nNonce = 0; pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); @@ -538,7 +538,7 @@ void static BitcoinMiner(CWallet *pwallet) break; // Update nTime every few seconds - UpdateTime(*pblock, pindexPrev); + UpdateTime(pblock, pindexPrev); if (Params().AllowMinDifficultyBlocks()) { // Changing pblock->nTime can change work required on testnet: diff --git a/src/pow.cpp b/src/pow.cpp index c0d0a7ca20..a99c582d7d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -8,6 +8,7 @@ #include "chainparams.h" #include "core.h" #include "main.h" +#include "timedata.h" #include "uint256.h" unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock) @@ -117,3 +118,12 @@ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime) bnResult = bnLimit; return bnResult.GetCompact(); } + +void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev) +{ + pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + + // Updating time can change work required on testnet: + if (Params().AllowMinDifficultyBlocks()) + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock); +} @@ -20,4 +20,6 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits); /** Calculate the minimum amount of work a received block needs, without knowing its direct parent */ unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime); +void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev); + #endif diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index edab427cbf..429d789278 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -457,7 +457,7 @@ Value getblocktemplate(const Array& params, bool fHelp) CBlock* pblock = &pblocktemplate->block; // pointer for convenience // Update nTime - UpdateTime(*pblock, pindexPrev); + UpdateTime(pblock, pindexPrev); pblock->nNonce = 0; Array transactions; |