Bugfix: make CreateNewBlock return pindexPrev

This commit is contained in:
Pieter Wuille
2015-03-31 20:35:04 -07:00
parent 6b04508e37
commit e2edf95cd3
4 changed files with 26 additions and 25 deletions

View File

@@ -87,7 +87,7 @@ void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
}
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CBlockIndex*& pindexPrev)
{
// Create new block
auto_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
@@ -132,7 +132,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
{
LOCK2(cs_main, mempool.cs);
CBlockIndex* pindexPrev = chainActive.Tip();
pindexPrev = chainActive.Tip();
const int nHeight = pindexPrev->nHeight + 1;
CCoinsViewCache view(pcoinsTip);
@@ -385,14 +385,14 @@ bool static ScanHash(CBlockHeader *pblock, uint256 *phash)
}
}
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CBlockIndex*& pindexPrev)
{
CPubKey pubkey;
if (!reservekey.GetReservedKey(pubkey))
return NULL;
CScript scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
return CreateNewBlock(scriptPubKey);
return CreateNewBlock(scriptPubKey, pindexPrev);
}
static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
@@ -452,9 +452,9 @@ bool MineBlock(CWallet *pwallet, uint256& hash)
unsigned int nExtraNonce = 0;
while (true) {
CBlockIndex *pindexPrev = chainActive.Tip(); // Actually needs cs_main...
CBlockIndex *pindexPrev;
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey, pindexPrev));
if (!pblocktemplate.get()) {
return false;
}
@@ -497,9 +497,9 @@ void static BitcoinMiner(CWallet *pwallet)
// Create new block
//
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrev = chainActive.Tip(); // Actually needs cs_main...
CBlockIndex* pindexPrev;
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey, pindexPrev));
if (!pblocktemplate.get())
{
LogPrintf("Error in BitcoinMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n");