aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-02-16 10:22:31 -0500
committerGavin Andresen <gavinandresen@gmail.com>2012-02-16 11:37:54 -0500
commit0f8cb5db73e8ab06b779b3cf82e26986ccc7c3f8 (patch)
tree7313dd40525ceaf1908db04397ee21bb0804c56d
parentb7c25e0c1346256be12310264ea5cc4ce7794118 (diff)
Fix issue #848 : broken mining on testnet
-rw-r--r--src/bitcoinrpc.cpp4
-rw-r--r--src/main.cpp20
-rw-r--r--src/main.h1
3 files changed, 21 insertions, 4 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index cf5bc64bb9..25a787a7a0 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1816,7 +1816,7 @@ Value getwork(const Array& params, bool fHelp)
}
// Update nTime
- pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
+ pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
// Update nExtraNonce
@@ -1916,7 +1916,7 @@ Value getmemorypool(const Array& params, bool fHelp)
}
// Update nTime
- pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
+ pblock->UpdateTime(pindexPrev);
pblock->nNonce = 0;
Array transactions;
diff --git a/src/main.cpp b/src/main.cpp
index e4c6714eae..ceeefaa058 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();
+ }
}
}
}
diff --git a/src/main.h b/src/main.h
index 908ada7d4f..d9f976c217 100644
--- a/src/main.h
+++ b/src/main.h
@@ -913,6 +913,7 @@ public:
return (int64)nTime;
}
+ void UpdateTime(const CBlockIndex* pindexPrev);
uint256 BuildMerkleTree() const