diff options
| author | Gavin Andresen <[email protected]> | 2012-02-17 13:48:01 -0500 |
|---|---|---|
| committer | Gavin Andresen <[email protected]> | 2012-02-17 13:48:01 -0500 |
| commit | 0a6b081ccaafb57f98098437ee52f7a14b924062 (patch) | |
| tree | 9a4deace8453a5794dff4340825be4153b63439a /src/main.cpp | |
| parent | Merge branch 'threadid' of https://github.com/sipa/bitcoin (diff) | |
| parent | Fix issue #848 : broken mining on testnet (diff) | |
| download | discoin-0a6b081ccaafb57f98098437ee52f7a14b924062.tar.xz discoin-0a6b081ccaafb57f98098437ee52f7a14b924062.zip | |
Merge branch 'testnetmining' of github.com:gavinandresen/bitcoin-git
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index 54538295c..b73037fb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -922,6 +922,15 @@ void static InvalidChainFound(CBlockIndex* pindexNew) printf("InvalidChainFound: WARNING: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n"); } +void CBlock::UpdateTime(const CBlockIndex* pindexPrev) +{ + nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + + // Updating time can change work required on testnet: + if (fTestNet) + nBits = GetNextWorkRequired(pindexPrev, this); +} + @@ -3168,7 +3177,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashMerkleRoot = pblock->BuildMerkleTree(); - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock.get()); pblock->nNonce = 0; @@ -3326,6 +3335,7 @@ void static BitcoinMiner(CWallet *pwallet) FormatHashBuffers(pblock.get(), pmidstate, pdata, phash1); unsigned int& nBlockTime = *(unsigned int*)(pdata + 64 + 4); + unsigned int& nBlockBits = *(unsigned int*)(pdata + 64 + 8); unsigned int& nBlockNonce = *(unsigned int*)(pdata + 64 + 12); @@ -3413,8 +3423,14 @@ void static BitcoinMiner(CWallet *pwallet) break; // Update nTime every few seconds - pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->UpdateTime(pindexPrev); nBlockTime = ByteReverse(pblock->nTime); + if (fTestNet) + { + // Changing pblock->nTime can change work required on testnet: + nBlockBits = ByteReverse(pblock->nBits); + hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); + } } } } |