1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 #include "pow/tromp/equi_miner.h"
12 #include "chainparams.h"
13 #include "consensus/consensus.h"
14 #include "consensus/upgrades.h"
15 #include "consensus/validation.h"
17 #include "crypto/equihash.h"
25 #include "primitives/transaction.h"
28 #include "ui_interface.h"
30 #include "utilmoneystr.h"
32 #include "wallet/wallet.h"
37 #include <boost/thread.hpp>
38 #include <boost/tuple/tuple.hpp>
46 //////////////////////////////////////////////////////////////////////////////
52 // Unconfirmed transactions in the memory pool often depend on other
53 // transactions in the memory pool. When we select transactions from the
54 // pool, we select by highest priority or fee rate, so we might consider
55 // transactions that depend on transactions that aren't yet in the block.
56 // The COrphan class keeps track of these 'temporary orphans' while
57 // CreateBlock is figuring out which transactions to include.
62 const CTransaction* ptx;
63 set<uint256> setDependsOn;
67 COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0)
72 uint64_t nLastBlockTx = 0;
73 uint64_t nLastBlockSize = 0;
75 // We want to sort transactions by priority and fee rate, so:
76 typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
77 class TxPriorityCompare
82 TxPriorityCompare(bool _byFee) : byFee(_byFee) { }
84 bool operator()(const TxPriority& a, const TxPriority& b)
88 if (a.get<1>() == b.get<1>())
89 return a.get<0>() < b.get<0>();
90 return a.get<1>() < b.get<1>();
94 if (a.get<0>() == b.get<0>())
95 return a.get<1>() < b.get<1>();
96 return a.get<0>() < b.get<0>();
101 void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
103 pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
105 // Updating time can change work required on testnet:
106 if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) {
107 pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
111 CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
113 const CChainParams& chainparams = Params();
115 std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
116 if(!pblocktemplate.get())
118 CBlock *pblock = &pblocktemplate->block; // pointer for convenience
120 // -regtest only: allow overriding block.nVersion with
121 // -blockversion=N to test forking scenarios
122 if (Params().MineBlocksOnDemand())
123 pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
125 // Add dummy coinbase tx as first transaction
126 pblock->vtx.push_back(CTransaction());
127 pblocktemplate->vTxFees.push_back(-1); // updated at end
128 pblocktemplate->vTxSigOps.push_back(-1); // updated at end
130 // Largest block you're willing to create:
131 unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
132 // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
133 nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize));
135 // How much of the block should be dedicated to high-priority transactions,
136 // included regardless of the fees they pay
137 unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
138 nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
140 // Minimum block size you want to create; block will be filled with free transactions
141 // until there are no more or the block reaches this size:
142 unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
143 nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
145 // Collect memory pool transactions into the block
149 LOCK2(cs_main, mempool.cs);
150 CBlockIndex* pindexPrev = chainActive.Tip();
151 const int nHeight = pindexPrev->nHeight + 1;
152 uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus());
153 pblock->nTime = GetAdjustedTime();
154 const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
155 CCoinsViewCache view(pcoinsTip);
157 SaplingMerkleTree sapling_tree;
158 assert(view.GetSaplingAnchorAt(view.GetBestAnchor(SAPLING), sapling_tree));
160 // Priority order to process transactions
161 list<COrphan> vOrphan; // list memory doesn't move
162 map<uint256, vector<COrphan*> > mapDependers;
163 bool fPrintPriority = GetBoolArg("-printpriority", false);
165 // This vector will be sorted into a priority queue:
166 vector<TxPriority> vecPriority;
167 vecPriority.reserve(mempool.mapTx.size());
168 for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
169 mi != mempool.mapTx.end(); ++mi)
171 const CTransaction& tx = mi->GetTx();
173 int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
175 : pblock->GetBlockTime();
177 if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight))
180 COrphan* porphan = NULL;
181 double dPriority = 0;
182 CAmount nTotalIn = 0;
183 bool fMissingInputs = false;
184 BOOST_FOREACH(const CTxIn& txin, tx.vin)
186 // Read prev transaction
187 if (!view.HaveCoins(txin.prevout.hash))
189 // This should never happen; all transactions in the memory
190 // pool should connect to either transactions in the chain
191 // or other transactions in the memory pool.
192 if (!mempool.mapTx.count(txin.prevout.hash))
194 LogPrintf("ERROR: mempool transaction missing input\n");
195 if (fDebug) assert("mempool transaction missing input" == 0);
196 fMissingInputs = true;
202 // Has to wait for dependencies
205 // Use list for automatic deletion
206 vOrphan.push_back(COrphan(&tx));
207 porphan = &vOrphan.back();
209 mapDependers[txin.prevout.hash].push_back(porphan);
210 porphan->setDependsOn.insert(txin.prevout.hash);
211 nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue;
214 const CCoins* coins = view.AccessCoins(txin.prevout.hash);
217 CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
218 nTotalIn += nValueIn;
220 int nConf = nHeight - coins->nHeight;
222 dPriority += (double)nValueIn * nConf;
224 nTotalIn += tx.GetShieldedValueIn();
226 if (fMissingInputs) continue;
228 // Priority is sum(valuein * age) / modified_txsize
229 unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
230 dPriority = tx.ComputePriority(dPriority, nTxSize);
232 uint256 hash = tx.GetHash();
233 mempool.ApplyDeltas(hash, dPriority, nTotalIn);
235 CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize);
239 porphan->dPriority = dPriority;
240 porphan->feeRate = feeRate;
243 vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
246 // Collect transactions into block
247 uint64_t nBlockSize = 1000;
248 uint64_t nBlockTx = 0;
249 int nBlockSigOps = 100;
250 bool fSortedByFee = (nBlockPrioritySize <= 0);
252 TxPriorityCompare comparer(fSortedByFee);
253 std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
255 while (!vecPriority.empty())
257 // Take highest priority transaction off the priority queue:
258 double dPriority = vecPriority.front().get<0>();
259 CFeeRate feeRate = vecPriority.front().get<1>();
260 const CTransaction& tx = *(vecPriority.front().get<2>());
262 std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
263 vecPriority.pop_back();
266 unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
267 if (nBlockSize + nTxSize >= nBlockMaxSize)
270 // Legacy limits on sigOps:
271 unsigned int nTxSigOps = GetLegacySigOpCount(tx);
272 if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
275 // Skip free transactions if we're past the minimum block size:
276 const uint256& hash = tx.GetHash();
277 double dPriorityDelta = 0;
278 CAmount nFeeDelta = 0;
279 mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
280 if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
283 // Prioritise by fee once past the priority size or we run out of high-priority
286 ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority)))
289 comparer = TxPriorityCompare(fSortedByFee);
290 std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
293 if (!view.HaveInputs(tx))
296 CAmount nTxFees = view.GetValueIn(tx)-tx.GetValueOut();
298 nTxSigOps += GetP2SHSigOpCount(tx, view);
299 if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)
302 // Note that flags: we don't want to set mempool/IsStandard()
303 // policy here, but we still have to ensure that the block we
304 // create only contains transactions that are valid in new blocks.
305 CValidationState state;
306 PrecomputedTransactionData txdata(tx);
307 if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId))
310 UpdateCoins(tx, view, nHeight);
312 BOOST_FOREACH(const OutputDescription &outDescription, tx.vShieldedOutput) {
313 sapling_tree.append(outDescription.cm);
317 pblock->vtx.push_back(tx);
318 pblocktemplate->vTxFees.push_back(nTxFees);
319 pblocktemplate->vTxSigOps.push_back(nTxSigOps);
320 nBlockSize += nTxSize;
322 nBlockSigOps += nTxSigOps;
327 LogPrintf("priority %.1f fee %s txid %s\n",
328 dPriority, feeRate.ToString(), tx.GetHash().ToString());
331 // Add transactions that depend on this one to the priority queue
332 if (mapDependers.count(hash))
334 BOOST_FOREACH(COrphan* porphan, mapDependers[hash])
336 if (!porphan->setDependsOn.empty())
338 porphan->setDependsOn.erase(hash);
339 if (porphan->setDependsOn.empty())
341 vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx));
342 std::push_heap(vecPriority.begin(), vecPriority.end(), comparer);
349 nLastBlockTx = nBlockTx;
350 nLastBlockSize = nBlockSize;
351 LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize);
353 // Create coinbase tx
354 CMutableTransaction txNew = CreateNewContextualCMutableTransaction(chainparams.GetConsensus(), nHeight);
356 txNew.vin[0].prevout.SetNull();
357 txNew.vout.resize(1);
358 txNew.vout[0].scriptPubKey = scriptPubKeyIn;
359 txNew.vout[0].nValue = GetBlockSubsidy(nHeight, chainparams.GetConsensus());
360 // Set to 0 so expiry height does not apply to coinbase txs
361 txNew.nExpiryHeight = 0;
363 if ((nHeight > 0) && (nHeight <= chainparams.GetConsensus().GetLastFoundersRewardBlockHeight())) {
364 // Founders reward is 20% of the block subsidy
365 auto vFoundersReward = txNew.vout[0].nValue / 5;
366 // Take some reward away from us
367 txNew.vout[0].nValue -= vFoundersReward;
369 // And give it to the founders
370 txNew.vout.push_back(CTxOut(vFoundersReward, chainparams.GetFoundersRewardScriptAtHeight(nHeight)));
374 txNew.vout[0].nValue += nFees;
375 txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
377 pblock->vtx[0] = txNew;
378 pblocktemplate->vTxFees[0] = -nFees;
381 arith_uint256 nonce = UintToArith256(GetRandHash());
382 // Clear the top and bottom 16 bits (for local use as thread flags and counters)
385 pblock->nNonce = ArithToUint256(nonce);
388 pblock->hashPrevBlock = pindexPrev->GetBlockHash();
389 pblock->hashFinalSaplingRoot = sapling_tree.root();
390 UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
391 pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
392 pblock->nSolution.clear();
393 pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
395 CValidationState state;
396 if (!TestBlockValidity(state, *pblock, pindexPrev, false, false))
397 throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed");
400 return pblocktemplate.release();
404 boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)
406 boost::optional<CScript> GetMinerScriptPubKey()
410 CTxDestination addr = DecodeDestination(GetArg("-mineraddress", ""));
411 if (IsValidDestination(addr)) {
412 keyID = boost::get<CKeyID>(addr);
416 if (!reservekey.GetReservedKey(pubkey)) {
417 return boost::optional<CScript>();
419 keyID = pubkey.GetID();
421 return boost::optional<CScript>();
425 CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
430 CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
432 boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey(reservekey);
434 CBlockTemplate* CreateNewBlockWithKey()
436 boost::optional<CScript> scriptPubKey = GetMinerScriptPubKey();
442 return CreateNewBlock(*scriptPubKey);
445 //////////////////////////////////////////////////////////////////////////////
452 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
454 // Update nExtraNonce
455 static uint256 hashPrevBlock;
456 if (hashPrevBlock != pblock->hashPrevBlock)
459 hashPrevBlock = pblock->hashPrevBlock;
462 unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
463 CMutableTransaction txCoinbase(pblock->vtx[0]);
464 txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
465 assert(txCoinbase.vin[0].scriptSig.size() <= 100);
467 pblock->vtx[0] = txCoinbase;
468 pblock->hashMerkleRoot = pblock->BuildMerkleTree();
472 static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
474 static bool ProcessBlockFound(CBlock* pblock)
475 #endif // ENABLE_WALLET
477 LogPrintf("%s\n", pblock->ToString());
478 LogPrintf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue));
483 if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
484 return error("ZcashMiner: generated block is stale");
488 if (GetArg("-mineraddress", "").empty()) {
489 // Remove key from key pool
490 reservekey.KeepKey();
493 // Track how many getdata requests this block gets
495 LOCK(wallet.cs_wallet);
496 wallet.mapRequestCount[pblock->GetHash()] = 0;
500 // Process this block the same as if we had received it from another node
501 CValidationState state;
502 if (!ProcessNewBlock(state, NULL, pblock, true, NULL))
503 return error("ZcashMiner: ProcessNewBlock, block not accepted");
505 TrackMinedBlock(pblock->GetHash());
511 void static BitcoinMiner(CWallet *pwallet)
513 void static BitcoinMiner()
516 LogPrintf("ZcashMiner started\n");
517 SetThreadPriority(THREAD_PRIORITY_LOWEST);
518 RenameThread("zcash-miner");
519 const CChainParams& chainparams = Params();
522 // Each thread has its own key
523 CReserveKey reservekey(pwallet);
526 // Each thread has its own counter
527 unsigned int nExtraNonce = 0;
529 unsigned int n = chainparams.EquihashN();
530 unsigned int k = chainparams.EquihashK();
532 std::string solver = GetArg("-equihashsolver", "default");
533 assert(solver == "tromp" || solver == "default");
534 LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k);
537 bool cancelSolver = false;
538 boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
539 [&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
540 std::lock_guard<std::mutex> lock{m_cs};
548 if (chainparams.MiningRequiresPeers()) {
549 // Busy-wait for the network to come online so we don't waste time mining
550 // on an obsolete chain. In regtest mode we expect to fly solo.
556 fvNodesEmpty = vNodes.empty();
558 if (!fvNodesEmpty && !IsInitialBlockDownload())
568 unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
569 CBlockIndex* pindexPrev = chainActive.Tip();
572 unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
574 unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey());
576 if (!pblocktemplate.get())
578 if (GetArg("-mineraddress", "").empty()) {
579 LogPrintf("Error in ZcashMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n");
581 // Should never reach here, because -mineraddress validity is checked in init.cpp
582 LogPrintf("Error in ZcashMiner: Invalid -mineraddress\n");
586 CBlock *pblock = &pblocktemplate->block;
587 IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
589 LogPrintf("Running ZcashMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(),
590 ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));
595 int64_t nStart = GetTime();
596 arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
600 crypto_generichash_blake2b_state state;
601 EhInitialiseState(n, k, state);
603 // I = the block header minus nonce and solution.
604 CEquihashInput I{*pblock};
605 CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
609 crypto_generichash_blake2b_update(&state, (unsigned char*)&ss[0], ss.size());
612 crypto_generichash_blake2b_state curr_state;
614 crypto_generichash_blake2b_update(&curr_state,
615 pblock->nNonce.begin(),
616 pblock->nNonce.size());
618 // (x_1, x_2, ...) = A(I, V, n, k)
619 LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",
620 solver, pblock->nNonce.ToString());
622 std::function<bool(std::vector<unsigned char>)> validBlock =
624 [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams]
626 [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams]
628 (std::vector<unsigned char> soln) {
629 // Write the solution to the hash and compute the result.
630 LogPrint("pow", "- Checking solution against target\n");
631 pblock->nSolution = soln;
632 solutionTargetChecks.increment();
634 if (UintToArith256(pblock->GetHash()) > hashTarget) {
639 SetThreadPriority(THREAD_PRIORITY_NORMAL);
640 LogPrintf("ZcashMiner:\n");
641 LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", pblock->GetHash().GetHex(), hashTarget.GetHex());
643 if (ProcessBlockFound(pblock, *pwallet, reservekey)) {
645 if (ProcessBlockFound(pblock)) {
647 // Ignore chain updates caused by us
648 std::lock_guard<std::mutex> lock{m_cs};
649 cancelSolver = false;
651 SetThreadPriority(THREAD_PRIORITY_LOWEST);
653 // In regression test mode, stop mining after a block is found.
654 if (chainparams.MineBlocksOnDemand()) {
655 // Increment here because throwing skips the call below
656 ehSolverRuns.increment();
657 throw boost::thread_interrupted();
662 std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {
663 std::lock_guard<std::mutex> lock{m_cs};
667 // TODO: factor this out into a function with the same API for each solver.
668 if (solver == "tromp") {
669 // Create solver and initialize it.
671 eq.setstate(&curr_state);
673 // Initialization done, start algo driver.
675 eq.xfull = eq.bfull = eq.hfull = 0;
677 for (u32 r = 1; r < WK; r++) {
678 (r&1) ? eq.digitodd(r, 0) : eq.digiteven(r, 0);
679 eq.xfull = eq.bfull = eq.hfull = 0;
683 ehSolverRuns.increment();
685 // Convert solution indices to byte array (decompress) and pass it to validBlock method.
686 for (size_t s = 0; s < eq.nsols; s++) {
687 LogPrint("pow", "Checking solution %d\n", s+1);
688 std::vector<eh_index> index_vector(PROOFSIZE);
689 for (size_t i = 0; i < PROOFSIZE; i++) {
690 index_vector[i] = eq.sols[s][i];
692 std::vector<unsigned char> sol_char = GetMinimalFromIndices(index_vector, DIGITBITS);
694 if (validBlock(sol_char)) {
695 // If we find a POW solution, do not try other solutions
696 // because they become invalid as we created a new block in blockchain.
702 // If we find a valid block, we rebuild
703 bool found = EhOptimisedSolve(n, k, curr_state, validBlock, cancelled);
704 ehSolverRuns.increment();
708 } catch (EhSolverCancelledException&) {
709 LogPrint("pow", "Equihash solver cancelled\n");
710 std::lock_guard<std::mutex> lock{m_cs};
711 cancelSolver = false;
715 // Check for stop or if block needs to be rebuilt
716 boost::this_thread::interruption_point();
717 // Regtest mode doesn't require peers
718 if (vNodes.empty() && chainparams.MiningRequiresPeers())
720 if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff)
722 if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
724 if (pindexPrev != chainActive.Tip())
727 // Update nNonce and nTime
728 pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
729 UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
730 if (chainparams.GetConsensus().nPowAllowMinDifficultyBlocksAfterHeight != boost::none)
732 // Changing pblock->nTime can change work required on testnet:
733 hashTarget.SetCompact(pblock->nBits);
738 catch (const boost::thread_interrupted&)
742 LogPrintf("ZcashMiner terminated\n");
745 catch (const std::runtime_error &e)
749 LogPrintf("ZcashMiner runtime error: %s\n", e.what());
757 void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
759 void GenerateBitcoins(bool fGenerate, int nThreads)
762 static boost::thread_group* minerThreads = NULL;
765 nThreads = GetNumCores();
767 if (minerThreads != NULL)
769 minerThreads->interrupt_all();
774 if (nThreads == 0 || !fGenerate)
777 minerThreads = new boost::thread_group();
778 for (int i = 0; i < nThreads; i++) {
780 minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
782 minerThreads->create_thread(&BitcoinMiner);
787 #endif // ENABLE_MINING