Dash Core  0.12.2.1
P2P Digital Currency
miner.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2017 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "miner.h"
8 
9 #include "amount.h"
10 #include "chain.h"
11 #include "chainparams.h"
12 #include "coins.h"
13 #include "consensus/consensus.h"
14 #include "consensus/merkle.h"
15 #include "consensus/validation.h"
16 #include "hash.h"
17 #include "validation.h"
18 #include "net.h"
19 #include "policy/policy.h"
20 #include "pow.h"
21 #include "primitives/transaction.h"
22 #include "script/standard.h"
23 #include "timedata.h"
24 #include "txmempool.h"
25 #include "util.h"
26 #include "utilmoneystr.h"
27 #include "masternode-payments.h"
28 #include "masternode-sync.h"
29 #include "validationinterface.h"
30 
31 #include <boost/thread.hpp>
32 #include <boost/tuple/tuple.hpp>
33 #include <queue>
34 
35 using namespace std;
36 
38 //
39 // DashMiner
40 //
41 
42 //
43 // Unconfirmed transactions in the memory pool often depend on other
44 // transactions in the memory pool. When we select transactions from the
45 // pool, we select by highest priority or fee rate, so we might consider
46 // transactions that depend on transactions that aren't yet in the block.
47 
48 uint64_t nLastBlockTx = 0;
49 uint64_t nLastBlockSize = 0;
50 
52 {
53 public:
55 
57  {
58  return CompareTxMemPoolEntryByScore()(*b,*a); // Convert to less than
59  }
60 };
61 
62 int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
63 {
64  int64_t nOldTime = pblock->nTime;
65  int64_t nNewTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
66 
67  if (nOldTime < nNewTime)
68  pblock->nTime = nNewTime;
69 
70  // Updating time can change work required on testnet:
71  if (consensusParams.fPowAllowMinDifficultyBlocks)
72  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams);
73 
74  return nNewTime - nOldTime;
75 }
76 
77 CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& scriptPubKeyIn)
78 {
79  // Create new block
80  std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
81  if(!pblocktemplate.get())
82  return NULL;
83  CBlock *pblock = &pblocktemplate->block; // pointer for convenience
84 
85  // Create coinbase tx
86  CMutableTransaction txNew;
87  txNew.vin.resize(1);
88  txNew.vin[0].prevout.SetNull();
89  txNew.vout.resize(1);
90  txNew.vout[0].scriptPubKey = scriptPubKeyIn;
91 
92  // Largest block you're willing to create:
93  unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
94  // Limit to between 1K and MAX_BLOCK_SIZE-1K for sanity:
95  nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MaxBlockSize(fDIP0001ActiveAtTip)-1000), nBlockMaxSize));
96 
97  // How much of the block should be dedicated to high-priority transactions,
98  // included regardless of the fees they pay
99  unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
100  nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
101 
102  // Minimum block size you want to create; block will be filled with free transactions
103  // until there are no more or the block reaches this size:
104  unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
105  nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
106 
107  // Collect memory pool transactions into the block
108  CTxMemPool::setEntries inBlock;
109  CTxMemPool::setEntries waitSet;
110 
111  // This vector will be sorted into a priority queue:
112  vector<TxCoinAgePriority> vecPriority;
113  TxCoinAgePriorityCompare pricomparer;
114  std::map<CTxMemPool::txiter, double, CTxMemPool::CompareIteratorByHash> waitPriMap;
115  typedef std::map<CTxMemPool::txiter, double, CTxMemPool::CompareIteratorByHash>::iterator waitPriIter;
116  double actualPriority = -1;
117 
118  std::priority_queue<CTxMemPool::txiter, std::vector<CTxMemPool::txiter>, ScoreCompare> clearedTxs;
119  bool fPrintPriority = GetBoolArg("-printpriority", DEFAULT_PRINTPRIORITY);
120  uint64_t nBlockSize = 1000;
121  uint64_t nBlockTx = 0;
122  unsigned int nBlockSigOps = 100;
123  int lastFewTxs = 0;
124  CAmount nFees = 0;
125 
126  {
127  LOCK(cs_main);
128 
129  CBlockIndex* pindexPrev = chainActive.Tip();
130  const int nHeight = pindexPrev->nHeight + 1;
131  pblock->nTime = GetAdjustedTime();
132  const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast();
133 
134  // Add our coinbase tx as first transaction
135  pblock->vtx.push_back(txNew);
136  pblocktemplate->vTxFees.push_back(-1); // updated at end
137  pblocktemplate->vTxSigOps.push_back(-1); // updated at end
138  pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
139  // -regtest only: allow overriding block.nVersion with
140  // -blockversion=N to test forking scenarios
141  if (chainparams.MineBlocksOnDemand())
142  pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
143 
144  int64_t nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST)
145  ? nMedianTimePast
146  : pblock->GetBlockTime();
147 
148  {
149  LOCK(mempool.cs);
150 
151  bool fPriorityBlock = nBlockPrioritySize > 0;
152  if (fPriorityBlock) {
153  vecPriority.reserve(mempool.mapTx.size());
154  for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin();
155  mi != mempool.mapTx.end(); ++mi)
156  {
157  double dPriority = mi->GetPriority(nHeight);
158  CAmount dummy;
159  mempool.ApplyDeltas(mi->GetTx().GetHash(), dPriority, dummy);
160  vecPriority.push_back(TxCoinAgePriority(dPriority, mi));
161  }
162  std::make_heap(vecPriority.begin(), vecPriority.end(), pricomparer);
163  }
164 
165  CTxMemPool::indexed_transaction_set::nth_index<3>::type::iterator mi = mempool.mapTx.get<3>().begin();
166  CTxMemPool::txiter iter;
167 
168  while (mi != mempool.mapTx.get<3>().end() || !clearedTxs.empty())
169  {
170  bool priorityTx = false;
171  if (fPriorityBlock && !vecPriority.empty()) { // add a tx from priority queue to fill the blockprioritysize
172  priorityTx = true;
173  iter = vecPriority.front().second;
174  actualPriority = vecPriority.front().first;
175  std::pop_heap(vecPriority.begin(), vecPriority.end(), pricomparer);
176  vecPriority.pop_back();
177  }
178  else if (clearedTxs.empty()) { // add tx with next highest score
179  iter = mempool.mapTx.project<0>(mi);
180  mi++;
181  }
182  else { // try to add a previously postponed child tx
183  iter = clearedTxs.top();
184  clearedTxs.pop();
185  }
186 
187  if (inBlock.count(iter))
188  continue; // could have been added to the priorityBlock
189 
190  const CTransaction& tx = iter->GetTx();
191 
192  bool fOrphan = false;
193  BOOST_FOREACH(CTxMemPool::txiter parent, mempool.GetMemPoolParents(iter))
194  {
195  if (!inBlock.count(parent)) {
196  fOrphan = true;
197  break;
198  }
199  }
200  if (fOrphan) {
201  if (priorityTx)
202  waitPriMap.insert(std::make_pair(iter,actualPriority));
203  else
204  waitSet.insert(iter);
205  continue;
206  }
207 
208  unsigned int nTxSize = iter->GetTxSize();
209  if (fPriorityBlock &&
210  (nBlockSize + nTxSize >= nBlockPrioritySize || !AllowFree(actualPriority))) {
211  fPriorityBlock = false;
212  waitPriMap.clear();
213  }
214  if (!priorityTx &&
215  (iter->GetModifiedFee() < ::minRelayTxFee.GetFee(nTxSize) && nBlockSize >= nBlockMinSize)) {
216  break;
217  }
218  if (nBlockSize + nTxSize >= nBlockMaxSize) {
219  if (nBlockSize > nBlockMaxSize - 100 || lastFewTxs > 50) {
220  break;
221  }
222  // Once we're within 1000 bytes of a full block, only look at 50 more txs
223  // to try to fill the remaining space.
224  if (nBlockSize > nBlockMaxSize - 1000) {
225  lastFewTxs++;
226  }
227  continue;
228  }
229 
230  if (!IsFinalTx(tx, nHeight, nLockTimeCutoff))
231  continue;
232 
233  unsigned int nTxSigOps = iter->GetSigOpCount();
234  unsigned int nMaxBlockSigOps = MaxBlockSigOps(fDIP0001ActiveAtTip);
235  if (nBlockSigOps + nTxSigOps >= nMaxBlockSigOps) {
236  if (nBlockSigOps > nMaxBlockSigOps - 2) {
237  break;
238  }
239  continue;
240  }
241 
242  CAmount nTxFees = iter->GetFee();
243  // Added
244  pblock->vtx.push_back(tx);
245  pblocktemplate->vTxFees.push_back(nTxFees);
246  pblocktemplate->vTxSigOps.push_back(nTxSigOps);
247  nBlockSize += nTxSize;
248  ++nBlockTx;
249  nBlockSigOps += nTxSigOps;
250  nFees += nTxFees;
251 
252  if (fPrintPriority)
253  {
254  double dPriority = iter->GetPriority(nHeight);
255  CAmount dummy;
256  mempool.ApplyDeltas(tx.GetHash(), dPriority, dummy);
257  LogPrintf("priority %.1f fee %s txid %s\n",
258  dPriority , CFeeRate(iter->GetModifiedFee(), nTxSize).ToString(), tx.GetHash().ToString());
259  }
260 
261  inBlock.insert(iter);
262 
263  // Add transactions that depend on this one to the priority queue
264  BOOST_FOREACH(CTxMemPool::txiter child, mempool.GetMemPoolChildren(iter))
265  {
266  if (fPriorityBlock) {
267  waitPriIter wpiter = waitPriMap.find(child);
268  if (wpiter != waitPriMap.end()) {
269  vecPriority.push_back(TxCoinAgePriority(wpiter->second,child));
270  std::push_heap(vecPriority.begin(), vecPriority.end(), pricomparer);
271  waitPriMap.erase(wpiter);
272  }
273  }
274  else {
275  if (waitSet.count(child)) {
276  clearedTxs.push(child);
277  waitSet.erase(child);
278  }
279  }
280  }
281  }
282 
283  }
284 
285  // NOTE: unlike in bitcoin, we need to pass PREVIOUS block height here
286  CAmount blockReward = nFees + GetBlockSubsidy(pindexPrev->nBits, pindexPrev->nHeight, Params().GetConsensus());
287 
288  // Compute regular coinbase transaction.
289  txNew.vout[0].nValue = blockReward;
290  txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
291 
292  // Update coinbase transaction with additional info about masternode and governance payments,
293  // get some info back to pass to getblocktemplate
294  FillBlockPayments(txNew, nHeight, blockReward, pblock->txoutMasternode, pblock->voutSuperblock);
295  // LogPrintf("CreateNewBlock -- nBlockHeight %d blockReward %lld txoutMasternode %s txNew %s",
296  // nHeight, blockReward, pblock->txoutMasternode.ToString(), txNew.ToString());
297 
298  nLastBlockTx = nBlockTx;
299  nLastBlockSize = nBlockSize;
300  LogPrintf("CreateNewBlock(): total size %u txs: %u fees: %ld sigops %d\n", nBlockSize, nBlockTx, nFees, nBlockSigOps);
301 
302  // Update block coinbase
303  pblock->vtx[0] = txNew;
304  pblocktemplate->vTxFees[0] = -nFees;
305 
306  // Fill in header
307  pblock->hashPrevBlock = pindexPrev->GetBlockHash();
308  UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
309  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
310  pblock->nNonce = 0;
311  pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
312 
313  CValidationState state;
314  if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) {
315  throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state)));
316  }
317  }
318 
319  return pblocktemplate.release();
320 }
321 
322 void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
323 {
324  // Update nExtraNonce
325  static uint256 hashPrevBlock;
326  if (hashPrevBlock != pblock->hashPrevBlock)
327  {
328  nExtraNonce = 0;
329  hashPrevBlock = pblock->hashPrevBlock;
330  }
331  ++nExtraNonce;
332  unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
333  CMutableTransaction txCoinbase(pblock->vtx[0]);
334  txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
335  assert(txCoinbase.vin[0].scriptSig.size() <= 100);
336 
337  pblock->vtx[0] = txCoinbase;
338  pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
339 }
340 
342 //
343 // Internal miner
344 //
345 
346 // ***TODO*** ScanHash is not yet used in Dash
347 //
348 // ScanHash scans nonces looking for a hash with at least some zero bits.
349 // The nonce is usually preserved between calls, but periodically or if the
350 // nonce is 0xffff0000 or above, the block is rebuilt and nNonce starts over at
351 // zero.
352 //
353 //bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash)
354 //{
355 // // Write the first 76 bytes of the block header to a double-SHA256 state.
356 // CHash256 hasher;
357 // CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
358 // ss << *pblock;
359 // assert(ss.size() == 80);
360 // hasher.Write((unsigned char*)&ss[0], 76);
361 
362 // while (true) {
363 // nNonce++;
364 
365 // // Write the last 4 bytes of the block header (the nonce) to a copy of
366 // // the double-SHA256 state, and compute the result.
367 // CHash256(hasher).Write((unsigned char*)&nNonce, 4).Finalize((unsigned char*)phash);
368 
369 // // Return the nonce if the hash has at least some zero bits,
370 // // caller will check if it has enough to reach the target
371 // if (((uint16_t*)phash)[15] == 0)
372 // return true;
373 
374 // // If nothing found after trying for a while, return -1
375 // if ((nNonce & 0xfff) == 0)
376 // return false;
377 // }
378 //}
379 
380 static bool ProcessBlockFound(const CBlock* pblock, const CChainParams& chainparams)
381 {
382  LogPrintf("%s\n", pblock->ToString());
383  LogPrintf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue));
384 
385  // Found a solution
386  {
387  LOCK(cs_main);
388  if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
389  return error("ProcessBlockFound -- generated block is stale");
390  }
391 
392  // Inform about the new block
393  GetMainSignals().BlockFound(pblock->GetHash());
394 
395  // Process this block the same as if we had received it from another node
396  if (!ProcessNewBlock(chainparams, pblock, true, NULL, NULL))
397  return error("ProcessBlockFound -- ProcessNewBlock() failed, block not accepted");
398 
399  return true;
400 }
401 
402 // ***TODO*** that part changed in bitcoin, we are using a mix with old one here for now
403 void static BitcoinMiner(const CChainParams& chainparams, CConnman& connman)
404 {
405  LogPrintf("DashMiner -- started\n");
407  RenameThread("dash-miner");
408 
409  unsigned int nExtraNonce = 0;
410 
411  boost::shared_ptr<CReserveScript> coinbaseScript;
412  GetMainSignals().ScriptForMining(coinbaseScript);
413 
414  try {
415  // Throw an error if no script was provided. This can happen
416  // due to some internal error but also if the keypool is empty.
417  // In the latter case, already the pointer is NULL.
418  if (!coinbaseScript || coinbaseScript->reserveScript.empty())
419  throw std::runtime_error("No coinbase script available (mining requires a wallet)");
420 
421  while (true) {
422  if (chainparams.MiningRequiresPeers()) {
423  // Busy-wait for the network to come online so we don't waste time mining
424  // on an obsolete chain. In regtest mode we expect to fly solo.
425  do {
426  bool fvNodesEmpty = connman.GetNodeCount(CConnman::CONNECTIONS_ALL) == 0;
427  if (!fvNodesEmpty && !IsInitialBlockDownload() && masternodeSync.IsSynced())
428  break;
429  MilliSleep(1000);
430  } while (true);
431  }
432 
433 
434  //
435  // Create new block
436  //
437  unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
438  CBlockIndex* pindexPrev = chainActive.Tip();
439  if(!pindexPrev) break;
440 
441  std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(chainparams, coinbaseScript->reserveScript));
442  if (!pblocktemplate.get())
443  {
444  LogPrintf("DashMiner -- Keypool ran out, please call keypoolrefill before restarting the mining thread\n");
445  return;
446  }
447  CBlock *pblock = &pblocktemplate->block;
448  IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
449 
450  LogPrintf("DashMiner -- Running miner with %u transactions in block (%u bytes)\n", pblock->vtx.size(),
452 
453  //
454  // Search
455  //
456  int64_t nStart = GetTime();
457  arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
458  while (true)
459  {
460  unsigned int nHashesDone = 0;
461 
462  uint256 hash;
463  while (true)
464  {
465  hash = pblock->GetHash();
466  if (UintToArith256(hash) <= hashTarget)
467  {
468  // Found a solution
470  LogPrintf("DashMiner:\n proof-of-work found\n hash: %s\n target: %s\n", hash.GetHex(), hashTarget.GetHex());
471  ProcessBlockFound(pblock, chainparams);
473  coinbaseScript->KeepScript();
474 
475  // In regression test mode, stop mining after a block is found. This
476  // allows developers to controllably generate a block on demand.
477  if (chainparams.MineBlocksOnDemand())
478  throw boost::thread_interrupted();
479 
480  break;
481  }
482  pblock->nNonce += 1;
483  nHashesDone += 1;
484  if ((pblock->nNonce & 0xFF) == 0)
485  break;
486  }
487 
488  // Check for stop or if block needs to be rebuilt
489  boost::this_thread::interruption_point();
490  // Regtest mode doesn't require peers
491  if (connman.GetNodeCount(CConnman::CONNECTIONS_ALL) == 0 && chainparams.MiningRequiresPeers())
492  break;
493  if (pblock->nNonce >= 0xffff0000)
494  break;
495  if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
496  break;
497  if (pindexPrev != chainActive.Tip())
498  break;
499 
500  // Update nTime every few seconds
501  if (UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev) < 0)
502  break; // Recreate the block if the clock has run backwards,
503  // so that we can use the correct time.
504  if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
505  {
506  // Changing pblock->nTime can change work required on testnet:
507  hashTarget.SetCompact(pblock->nBits);
508  }
509  }
510  }
511  }
512  catch (const boost::thread_interrupted&)
513  {
514  LogPrintf("DashMiner -- terminated\n");
515  throw;
516  }
517  catch (const std::runtime_error &e)
518  {
519  LogPrintf("DashMiner -- runtime error: %s\n", e.what());
520  return;
521  }
522 }
523 
524 void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams& chainparams, CConnman& connman)
525 {
526  static boost::thread_group* minerThreads = NULL;
527 
528  if (nThreads < 0)
529  nThreads = GetNumCores();
530 
531  if (minerThreads != NULL)
532  {
533  minerThreads->interrupt_all();
534  delete minerThreads;
535  minerThreads = NULL;
536  }
537 
538  if (nThreads == 0 || !fGenerate)
539  return;
540 
541  minerThreads = new boost::thread_group();
542  for (int i = 0; i < nThreads; i++)
543  minerThreads->create_thread(boost::bind(&BitcoinMiner, boost::cref(chainparams), boost::ref(connman)));
544 }
boost::signals2::signal< void(boost::shared_ptr< CReserveScript > &)> ScriptForMining
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params, bool fAssumeMasternodeIsUpgraded)
CMasternodeSync masternodeSync
void SetThreadPriority(int nPriority)
Definition: util.cpp:935
void MilliSleep(int64_t n)
Definition: utiltime.cpp:63
static const unsigned int STANDARD_LOCKTIME_VERIFY_FLAGS
Definition: policy.h:50
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev)
Definition: miner.cpp:62
uint64_t nLastBlockSize
Definition: miner.cpp:49
uint256 hashMerkleRoot
Definition: block.h:26
CTxOut txoutMasternode
Definition: block.h:80
unsigned int MaxBlockSize(bool fDIP0001Active)
Definition: consensus.h:12
#define strprintf
Definition: tinyformat.h:1011
unsigned int nBits
Definition: chain.h:143
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:55
bool operator()(const CTxMemPool::txiter a, const CTxMemPool::txiter b)
Definition: miner.cpp:56
bool fPowAllowMinDifficultyBlocks
Definition: params.h:78
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=NULL, bool *pfOverflow=NULL)
CCriticalSection cs_main
Definition: validation.cpp:62
int64_t GetBlockTime() const
Definition: block.h:66
Definition: net.h:108
std::vector< CTxIn > vin
Definition: transaction.h:306
CAmount GetFee(size_t size) const
Definition: amount.cpp:20
std::vector< CTxOut > voutSuperblock
Definition: block.h:81
ScoreCompare()
Definition: miner.cpp:54
uint32_t nTime
Definition: block.h:27
indexed_transaction_set mapTx
Definition: txmempool.h:403
std::pair< double, CTxMemPool::txiter > TxCoinAgePriority
Definition: txmempool.h:650
boost::signals2::signal< void(const uint256 &)> BlockFound
void RenameThread(const char *name)
Definition: util.cpp:873
arith_uint256 UintToArith256(const uint256 &a)
std::vector< CTransaction > vtx
Definition: block.h:77
bool ProcessNewBlock(const CChainParams &chainparams, const CBlock *pblock, bool fForceProcessing, const CDiskBlockPos *dbp, bool *fNewBlock)
size_t GetNodeCount(NumConnections num)
Definition: net.cpp:2429
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta) const
Definition: txmempool.cpp:957
int64_t CAmount
Definition: amount.h:14
uint256 hashPrevBlock
Definition: block.h:25
#define THREAD_PRIORITY_NORMAL
Definition: compat.h:88
CCriticalSection cs
Definition: txmempool.h:402
bool GetBoolArg(const std::string &strArg, bool fDefault)
Definition: util.cpp:455
#define LogPrintf(...)
Definition: util.h:98
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
Definition: txmempool.h:404
#define THREAD_PRIORITY_LOWEST
Definition: compat.h:86
const setEntries & GetMemPoolParents(txiter entry) const
Definition: txmempool.cpp:1060
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:202
CFeeRate minRelayTxFee
Definition: validation.cpp:94
#define LOCK(cs)
Definition: sync.h:168
unsigned int GetNextWorkRequired(const CBlockIndex *pindexLast, const CBlockHeader *pblock, const Consensus::Params &params)
Definition: pow.cpp:172
uint64_t nLastBlockTx
Definition: miner.cpp:48
unsigned int MaxBlockSigOps(bool fDIP0001Active)
Definition: consensus.h:18
static void BitcoinMiner(const CChainParams &chainparams, CConnman &connman)
Definition: miner.cpp:403
void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams &chainparams, CConnman &connman)
Definition: miner.cpp:524
static bool error(const char *format)
Definition: util.h:131
bool IsInitialBlockDownload()
uint32_t nBits
Definition: block.h:28
std::atomic< bool > fDIP0001ActiveAtTip
Definition: validation.cpp:89
CMainSignals & GetMainSignals()
bool AllowFree(double dPriority)
Definition: txmempool.h:31
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
Definition: merkle.cpp:154
static const unsigned int DEFAULT_BLOCK_MAX_SIZE
Definition: policy.h:18
CChain chainActive
Definition: validation.cpp:65
std::string ToString() const
Definition: uint256.cpp:65
CScript COINBASE_FLAGS
Definition: validation.cpp:107
std::string FormatMoney(const CAmount &n)
std::set< txiter, CompareIteratorByHash > setEntries
Definition: txmempool.h:410
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Definition: validation.cpp:417
static const unsigned int DEFAULT_BLOCK_MIN_SIZE
Definition: policy.h:19
static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE
Definition: policy.h:21
std::vector< CTxOut > vout
Definition: transaction.h:307
std::string ToString() const
Definition: block.cpp:18
void IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Definition: miner.cpp:322
std::string FormatStateMessage(const CValidationState &state)
Definition: validation.cpp:541
CTxMemPool mempool
uint32_t nNonce
Definition: block.h:29
const setEntries & GetMemPoolChildren(txiter entry) const
Definition: txmempool.cpp:1068
static bool ProcessBlockFound(const CBlock *pblock, const CChainParams &chainparams)
Definition: miner.cpp:380
const CChainParams & Params()
static const int PROTOCOL_VERSION
Definition: version.h:13
const uint256 & GetHash() const
Definition: transaction.h:262
int64_t GetAdjustedTime()
Definition: timedata.cpp:33
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
uint256 GetBlockHash() const
Definition: chain.h:218
std::string GetHex() const
Definition: uint256.cpp:21
int32_t nVersion
Definition: block.h:24
CBlockIndex * Tip() const
Definition: chain.h:366
int64_t GetMedianTimePast() const
Definition: chain.h:230
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Definition: util.cpp:441
std::string GetHex() const
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:20
int GetNumCores()
Definition: util.cpp:948
bool MiningRequiresPeers() const
Definition: chainparams.h:62
static const bool DEFAULT_PRINTPRIORITY
Definition: miner.h:24
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params &consensusParams, bool fSuperblockPartOnly)
CBlockTemplate * CreateNewBlock(const CChainParams &chainparams, const CScript &scriptPubKeyIn)
Definition: miner.cpp:77
Definition: block.h:73
uint256 GetHash() const
Definition: block.cpp:13
Definition: script.h:44
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:113
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Definition: validation.cpp:200
bool MineBlocksOnDemand() const
Definition: chainparams.h:71
void FillBlockPayments(CMutableTransaction &txNew, int nBlockHeight, CAmount blockReward, CTxOut &txoutMasternodeRet, std::vector< CTxOut > &voutSuperblockRet)
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:360