Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
double dHashesPerSec = 0.0;
int64_t nHPSTimerStart = 0;

CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet, bool fProofOfStake)
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet)
{
CPubKey pubkey;
if (!reservekey.GetReservedKey(pubkey))
Expand All @@ -586,15 +586,16 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet,
static int nLastPOWBlock = Params().LAST_POW_BLOCK();

// If we're building a late PoW block, don't continue
if ((nHeightNext > nLastPOWBlock) && !fProofOfStake) {
// PoS blocks are built directly with CreateNewBlock
if ((nHeightNext > nLastPOWBlock)) {
LogPrintf("%s: Aborting PoW block creation during PoS phase\n", __func__);
// sleep 1/2 a block time so we don't go into a tight loop.
MilliSleep((Params().TargetSpacing() * 1000) >> 1);
return nullptr;
}

CScript scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
return CreateNewBlock(scriptPubKey, pwallet, fProofOfStake);
return CreateNewBlock(scriptPubKey, pwallet, false);
}

bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
Expand Down Expand Up @@ -709,7 +710,9 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
if (!pindexPrev)
continue;

std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey, pwallet, fProofOfStake));
std::unique_ptr<CBlockTemplate> pblocktemplate(
fProofOfStake ? CreateNewBlock(CScript(), pwallet, fProofOfStake) : CreateNewBlockWithKey(reservekey, pwallet)
);
if (!pblocktemplate.get())
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void UpdateTime(CBlockHeader* block, const CBlockIndex* pindexPrev);
/** Run the miner threads */
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads);
/** Generate a new block, without valid proof-of-work */
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet, bool fProofOfStake);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet);

void BitcoinMiner(CWallet* pwallet, bool fProofOfStake);
void ThreadStakeMinter();
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ UniValue generate(const UniValue& params, bool fHelp)
while (nHeight < nHeightEnd)
{

std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey, pwalletMain, fPoS));
std::unique_ptr<CBlockTemplate> pblocktemplate(
fPoS ? CreateNewBlock(CScript(), pwalletMain, fPoS) : CreateNewBlockWithKey(reservekey, pwalletMain)
);
if (!pblocktemplate.get())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
CBlock *pblock = &pblocktemplate->block;
Expand Down