PRCYCoin  2.0.0.7rc1
P2P Digital Currency
miner.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2018 The PIVX developers
5 // Copyright (c) 2018-2020 The DAPS Project developers
6 // Copyright (c) 2020-2022 The PRivaCY Coin Developers
7 // Distributed under the MIT/X11 software license, see the accompanying
8 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
9 
10 
11 #include "miner.h"
12 
13 #include "amount.h"
14 #include "blocksignature.h"
15 #include "consensus/merkle.h"
16 #include "consensus/tx_verify.h"
17 #include "hash.h"
18 #include "invalid.h"
19 #include "main.h"
20 #include "masternode-sync.h"
21 #include "net.h"
22 #include "poa.h"
23 #include "primitives/block.h"
24 #include "primitives/transaction.h"
25 #include "timedata.h"
26 #include "util.h"
27 #include "utilmoneystr.h"
28 #ifdef ENABLE_WALLET
29 #include "wallet/wallet.h"
30 extern CWallet* pwalletMain;
31 #endif
32 #include "masternode-payments.h"
33 #include "validationinterface.h"
34 
35 #include <boost/thread.hpp>
36 #include <boost/tuple/tuple.hpp>
37 
38 
40 //
41 // PRCYcoinMiner
42 //
43 
44 //
45 // Unconfirmed transactions in the memory pool often depend on other
46 // transactions in the memory pool. When we select transactions from the
47 // pool, we select by highest priority or fee rate, so we might consider
48 // transactions that depend on transactions that aren't yet in the block.
49 // The COrphan class keeps track of these 'temporary orphans' while
50 // CreateBlock is figuring out which transactions to include.
51 //
52 class COrphan
53 {
54 public:
55  const CTransaction* ptx;
56  std::set<uint256> setDependsOn;
58  double dPriority;
59 
60  COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0)
61  {
62  }
63 };
64 
65 uint64_t nLastBlockTx = 0;
66 uint64_t nLastBlockSize = 0;
68 int64_t nDefaultMinerSleep = 0;
69 //int64_t nConsolidationTime = 0;
70 
71 // We want to sort transactions by priority and fee rate, so:
72 typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
74 {
75  bool byFee;
76 
77 public:
78  TxPriorityCompare(bool _byFee) : byFee(_byFee) {}
79 
80  bool operator()(const TxPriority& a, const TxPriority& b)
81  {
82  if (byFee) {
83  if (a.get<1>() == b.get<1>())
84  return a.get<0>() < b.get<0>();
85  return a.get<1>() < b.get<1>();
86  } else {
87  if (a.get<0>() == b.get<0>())
88  return a.get<1>() < b.get<1>();
89  return a.get<0>() < b.get<0>();
90  }
91  }
92 };
93 
94 void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
95 {
96  pblock->nTime = std::max(pindexPrev->GetMedianTimePast() + 1, GetAdjustedTime());
97 
98  // Updating time can change work required on testnet:
99  if (Params().AllowMinDifficultyBlocks())
100  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
101 }
102 
103 uint32_t GetListOfPoSInfo(uint32_t currentHeight, std::vector<PoSBlockSummary>& audits)
104 {
105  //A PoA block should be mined only after at least 59 PoS blocks have not been audited
106  //Look for the previous PoA block
107  uint32_t nloopIdx = currentHeight;
108  while (nloopIdx >= Params().START_POA_BLOCK()) {
109  if (chainActive[nloopIdx]->GetBlockHeader().IsPoABlockByVersion()) {
110  break;
111  }
112  nloopIdx--;
113  }
114  if (nloopIdx <= Params().START_POA_BLOCK()) {
115  //this is the first PoA block ==> take all PoS blocks from LAST_POW_BLOCK up to currentHeight - 60 inclusive
116  for (int i = Params().LAST_POW_BLOCK() + 1; i <= Params().LAST_POW_BLOCK() + (size_t)Params().MAX_NUM_POS_BLOCKS_AUDITED(); i++) {
117  PoSBlockSummary pos;
118  pos.hash = chainActive[i]->GetBlockHash();
119  CBlockIndex* pindex = mapBlockIndex[pos.hash];
120  pos.nTime = ReVerifyPoSBlock(pindex) ? chainActive[i]->GetBlockHeader().nTime : 0;
121  pos.height = i;
122  audits.push_back(pos);
123  }
124  } else {
125  //Find the previous PoA block
126  uint32_t start = nloopIdx;
127  if (start > Params().START_POA_BLOCK()) {
128  CBlockIndex* pblockindex = chainActive[start];
129  CBlock block;
130  if (!ReadBlockFromDisk(block, pblockindex))
131  throw std::runtime_error("Can't read block from disk");
132  PoSBlockSummary back = block.posBlocksAudited.back();
133  uint32_t lastAuditedHeight = back.height;
134  uint32_t nextAuditHeight = lastAuditedHeight + 1;
135 
136  while (nextAuditHeight <= currentHeight) {
137  CBlockIndex* posIndex = chainActive[nextAuditHeight];
138  CBlock posBlock;
139  if (!ReadBlockFromDisk(posBlock, posIndex))
140  throw std::runtime_error("Can't read block from disk");
141  if (posBlock.IsProofOfStake()) {
142  PoSBlockSummary pos;
143  pos.hash = chainActive[nextAuditHeight]->GetBlockHash();
144  CBlockIndex* pindex = mapBlockIndex[pos.hash];
145  pos.nTime = ReVerifyPoSBlock(pindex) ? chainActive[nextAuditHeight]->GetBlockHeader().nTime : 0;
146  pos.height = nextAuditHeight;
147  audits.push_back(pos);
148  }
149  //The current number of PoS blocks audited in a PoA block is changed from 59 to MAX
150  if (audits.size() == (size_t)Params().MAX_NUM_POS_BLOCKS_AUDITED()) {
151  break;
152  }
153  nextAuditHeight++;
154  }
155  }
156  }
157  return nloopIdx;
158 }
159 
160 CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, const CPubKey& txPub, const CKey& txPriv, CWallet* pwallet, bool fProofOfStake)
161 {
162  CReserveKey reservekey(pwallet);
163 
164  // Create new block
165  std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
166  if (!pblocktemplate.get())
167  return NULL;
168 
169  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
170 
171  // Tip
172  CBlockIndex* pindexPrev = nullptr;
173  { // Don't keep cs_main locked
174  LOCK(cs_main);
175  pindexPrev = chainActive.Tip();
176  }
177 
178  const int nHeight = pindexPrev->nHeight + 1;
179 
180  pblock->nVersion = 5; // Supports CLTV activation
181 
182  // -regtest only: allow overriding block.nVersion with
183  // -blockversion=N to test forking scenarios
184  if (Params().MineBlocksOnDemand())
185  pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
186 
187  // Create coinbase tx
188  CMutableTransaction txNew;
189  txNew.vin.resize(1);
190  txNew.vin[0].prevout.SetNull();
191  txNew.vout.resize(1);
192  txNew.vout[0].scriptPubKey = scriptPubKeyIn;
193  std::copy(txPub.begin(), txPub.end(), std::back_inserter(txNew.vout[0].txPub));
194  std::copy(txPriv.begin(), txPriv.end(), std::back_inserter(txNew.vout[0].txPriv));
195 
196  CBlockIndex* prev = chainActive.Tip();
197  CAmount nValue = GetBlockValue(prev->nHeight);
198  txNew.vout[0].nValue = nValue;
199 
200  pblock->vtx.push_back(txNew);
201  pblocktemplate->vTxFees.push_back(-1); // updated at end
202  pblocktemplate->vTxSigOps.push_back(-1); // updated at end
203 
204  // ppcoin: if coinstake available add coinstake tx
205  static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // only initialized at startup
206 
207  if (fProofOfStake) {
208  boost::this_thread::interruption_point();
209  pblock->nTime = GetAdjustedTime();
210  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
211 
212  int64_t nSearchTime = pblock->nTime; // search to current time
213  bool fStakeFound = false;
214  if (nSearchTime >= nLastCoinStakeSearchTime) {
215  unsigned int nTxNewTime = 0;
216  CMutableTransaction txCoinStake;
217  if (pwallet->CreateCoinStake(*pwallet, pblock->nBits, nSearchTime - nLastCoinStakeSearchTime, txCoinStake, nTxNewTime)) {
218  pblock->nTime = nTxNewTime;
219  pblock->vtx[0].vout[0].SetEmpty();
220  CTransaction copied(txCoinStake);
221  pblock->vtx.push_back(copied);
222  fStakeFound = true;
223  }
224 
226  nLastCoinStakeSearchTime = nSearchTime;
227  }
228 
229  if (!fStakeFound) {
230  LogPrint(BCLog::STAKING, "CreateNewBlock(): stake not found\n");
231  return NULL;
232  }
233  }
234 
235  // Largest block you're willing to create:
236  unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
237  // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity:
238  unsigned int nBlockMaxSizeNetwork = MAX_BLOCK_SIZE_CURRENT;
239  nBlockMaxSize = std::max((unsigned int)1000, std::min((nBlockMaxSizeNetwork - 1000), nBlockMaxSize));
240 
241  // How much of the block should be dedicated to high-priority transactions,
242  // included regardless of the fees they pay
243  unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE);
244  nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize);
245 
246  // Minimum block size you want to create; block will be filled with free transactions
247  // until there are no more or the block reaches this size:
248  unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE);
249  nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
250 
251  // Collect memory pool transactions into the block
252  CAmount nFees = 0;
253 
254  {
256 
257  CBlockIndex* pindexPrev = chainActive.Tip();
258  const int nHeight = pindexPrev->nHeight + 1;
260 
261  // Priority order to process transactions
262  std::list<COrphan> vOrphan; // list memory doesn't move
263  std::map<uint256, std::vector<COrphan*> > mapDependers;
264  bool fPrintPriority = GetBoolArg("-printpriority", false);
265 
266  // This vector will be sorted into a priority queue:
267  std::vector<TxPriority> vecPriority;
268  vecPriority.reserve(mempool.mapTx.size());
269  std::set<CKeyImage> keyImages;
270  for (std::map<uint256, CTxMemPoolEntry>::iterator mi = mempool.mapTx.begin();
271  mi != mempool.mapTx.end(); ++mi) {
272  const CTransaction& tx = mi->second.GetTx();
273  if (tx.IsCoinBase() || tx.IsCoinStake() || !IsFinalTx(tx, nHeight)) {
274  continue;
275  }
276  bool fKeyImageCheck = true;
277  // Check key images not duplicated with what in db
278  for (const CTxIn& txin : tx.vin) {
279  const CKeyImage& keyImage = txin.keyImage;
280  if (IsSpentKeyImage(keyImage.GetHex(), UINT256_ZERO)) {
281  fKeyImageCheck = false;
282  break;
283  }
284  //Check for invalid/fraudulent inputs. They shouldn't make it through mempool, but check anyways.
286  LogPrintf("%s : found invalid input %s in tx %s", __func__, txin.prevout.ToString(), tx.GetHash().ToString());
287  break;
288  }
289  }
290 
291  if (!fKeyImageCheck) {
292  continue;
293  }
294 
295  if (!CheckHaveInputs(view, tx)) continue;
296 
297  COrphan* porphan = NULL;
298  double dPriority = 0;
299  CAmount nTotalIn = 0;
300 
301  // Priority is sum(valuein * age) / modified_txsize
302  unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
303  dPriority = GetPriority(tx, chainActive.Height());
304 
305  uint256 hash = tx.GetHash();
306  mempool.ApplyDeltas(hash, dPriority, nTotalIn);
307 
308  CFeeRate feeRate(tx.nTxFee, nTxSize);
309 
310  bool isDuplicate = false;
311  for (const CTxIn& txin : tx.vin) {
312  const CKeyImage& keyImage = txin.keyImage;
313  if (keyImages.count(keyImage)) {
314  isDuplicate = true;
315  break;
316  }
317  keyImages.insert(keyImage);
318  }
319  if (isDuplicate) continue;
320  vecPriority.push_back(TxPriority(dPriority, feeRate, &mi->second.GetTx()));
321  }
322 
323  LogPrint(BCLog::STAKING, "Selecting %d transactions from mempool\n", vecPriority.size());
324  // Collect transactions into block
325  uint64_t nBlockSize = 1000;
326  uint64_t nBlockTx = 0;
327  int nBlockSigOps = 100;
328  bool fSortedByFee = (nBlockPrioritySize <= 0);
329 
330  TxPriorityCompare comparer(fSortedByFee);
331  std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
332 
333  std::vector<CBigNum> vBlockSerials;
334  std::vector<CBigNum> vTxSerials;
335  while (!vecPriority.empty()) {
336  // Take highest priority transaction off the priority queue:
337  double dPriority = vecPriority.front().get<0>();
338  CFeeRate feeRate = vecPriority.front().get<1>();
339  const CTransaction& tx = *(vecPriority.front().get<2>());
340 
341  std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer);
342  vecPriority.pop_back();
343 
344  // Size limits
345  unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
346  if (nBlockSize + nTxSize >= nBlockMaxSize)
347  continue;
348 
349  // Skip free transactions if we're past the minimum block size:
350  const uint256& hash = tx.GetHash();
351  double dPriorityDelta = 0;
352  CAmount nFeeDelta = 0;
353  mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
354  CFeeRate customMinRelayTxFee = CFeeRate(5000);
355  if (fSortedByFee && (feeRate < customMinRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
356  continue;
357 
358  // Prioritise by fee once past the priority size or we run out of high-priority
359  // transactions:
360  if (!fSortedByFee &&
361  ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) {
362  fSortedByFee = true;
363  comparer = TxPriorityCompare(fSortedByFee);
364  std::make_heap(vecPriority.begin(), vecPriority.end(), comparer);
365  }
366 
367  if (!CheckHaveInputs(view, tx))
368  continue;
369 
370  CAmount nTxFees = tx.nTxFee;
371 
372  // Note that flags: we don't want to set mempool/IsStandard()
373  // policy here, but we still have to ensure that the block we
374  // create only contains transactions that are valid in new blocks.
375 
376  CValidationState state;
377  if (!CheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true))
378  continue;
379 
380  CTxUndo txundo;
381  if (tx.IsCoinStake()) {
382  UpdateCoins(tx, view, txundo, nHeight);
383  }
384 
385  // Added
386  pblock->vtx.push_back(tx);
387  pblocktemplate->vTxFees.push_back(nTxFees);
388  pblocktemplate->vTxSigOps.push_back(0);
389  nBlockSize += nTxSize;
390  ++nBlockTx;
391  nFees += nTxFees;
392 
393  for (const CBigNum& bnSerial : vTxSerials)
394  vBlockSerials.emplace_back(bnSerial);
395 
396  if (fPrintPriority) {
397  LogPrintf("priority %.1f fee %s txid %s\n",
398  dPriority, feeRate.ToString(), tx.GetHash().ToString());
399  }
400 
401  // Add transactions that depend on this one to the priority queue
402  if (mapDependers.count(hash)) {
403  for (COrphan* porphan : mapDependers[hash]) {
404  if (!porphan->setDependsOn.empty()) {
405  porphan->setDependsOn.erase(hash);
406  if (porphan->setDependsOn.empty()) {
407  vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx));
408  std::push_heap(vecPriority.begin(), vecPriority.end(), comparer);
409  }
410  }
411  }
412  }
413  }
414 
415  if (!fProofOfStake) {
416  //Masternode and general budget payments
417  FillBlockPayee(txNew, nFees, fProofOfStake);
418 
419  //Make payee
420  if (txNew.vout.size() > 1) {
421  pblock->payee = txNew.vout[1].scriptPubKey;
422  } else {
423  CAmount blockValue = nFees + GetBlockValue(pindexPrev->nHeight);
424  txNew.vout[0].nValue = blockValue;
425  txNew.vin[0].scriptSig = CScript() << nHeight << OP_0;
426  }
427  }
428 
429  nLastBlockTx = nBlockTx;
430  nLastBlockSize = nBlockSize;
431 
432  // Compute final coinbase transaction.
433  pblock->vtx[0].vin[0].scriptSig = CScript() << nHeight << OP_0;
434  pblock->vtx[0].txType = TX_TYPE_REVEAL_AMOUNT;
435  if (!fProofOfStake) {
436  pblock->vtx[0].vout[0].nValue += nFees;
437  pblocktemplate->vTxFees[0] = nFees;
438  } else {
439  pblock->vtx[1].vout[2].nValue += nFees;
440  pblocktemplate->vTxFees[0] = nFees;
441  }
442 
443  CPubKey sharedSec;
444  sharedSec.Set(txPub.begin(), txPub.end());
445  //compute commitment
446  unsigned char zeroBlind[32];
447  memset(zeroBlind, 0, 32);
448  if (pblock->IsProofOfWork()) {
449  pwallet->EncodeTxOutAmount(pblock->vtx[0].vout[0], pblock->vtx[0].vout[0].nValue, sharedSec.begin());
450  nValue = pblock->vtx[0].vout[0].nValue;
451  if (!pwallet->CreateCommitment(zeroBlind, nValue, pblock->vtx[0].vout[0].commitment)) {
452  return NULL;
453  }
454  } else {
455  pblock->vtx[1].vout[1].nValue += pblock->vtx[1].vout[2].nValue;
456  pblock->vtx[1].vout[2].SetEmpty();
457  sharedSec.Set(pblock->vtx[1].vout[1].txPub.begin(), pblock->vtx[1].vout[1].txPub.end());
458  pwallet->EncodeTxOutAmount(pblock->vtx[1].vout[1], pblock->vtx[1].vout[1].nValue, sharedSec.begin());
459  nValue = pblock->vtx[1].vout[1].nValue;
460  pblock->vtx[1].vout[1].commitment.clear();
461  if (!pwallet->CreateCommitment(zeroBlind, nValue, pblock->vtx[1].vout[1].commitment)) {
462  return NULL;
463  }
464 
465  //Shnorr sign
466  if (!pwalletMain->MakeShnorrSignature(pblock->vtx[1])) {
467  LogPrintf("%s : failed to make Shnorr signature\n", __func__);
468  return NULL;
469  }
470 
471  //Test verify shnorr signature
472  if (!VerifyShnorrKeyImageTx(pblock->vtx[1])) {
473  LogPrintf("%s: Failed to verify shnorr key image\n", __func__);
474  return NULL;
475  }
476  pwalletMain->IsTransactionForMe(pblock->vtx[1]);
477  }
478 
479  // Fill in header
480  pblock->hashPrevBlock = pindexPrev->GetBlockHash();
481  if (!fProofOfStake)
482  UpdateTime(pblock, pindexPrev);
483  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
484  pblock->nNonce = 0;
485  uint256 nCheckpoint = 0;
486  pblock->nAccumulatorCheckpoint = nCheckpoint;
487  pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
488 
489  if (fProofOfStake) {
490  unsigned int nExtraNonce = 0;
491  IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
492  LogPrintf("CPUMiner : proof-of-stake block found %s \n", pblock->GetHash().ToString().c_str());
493  if (!SignBlock(*pblock, *pwallet)) {
494  LogPrintf("%s: Signing new block failed, computing private key \n", __func__);
495  if (pblock->vtx.size() > 1 && pblock->vtx[1].vout.size() > 1) {
496  pwallet->AddComputedPrivateKey(pblock->vtx[1].vout[1]);
497  }
498  if (!SignBlock(*pblock, *pwallet)) {
499  LogPrintf("%s: Signing new block with UTXO key failed \n", __func__);
500  return NULL;
501  }
502  }
503  }
504  }
505 
506  return pblocktemplate.release();
507 }
508 
509 CBlockTemplate* CreateNewPoABlock(const CScript& scriptPubKeyIn, const CPubKey& txPub, const CKey& txPriv, CWallet* pwallet)
510 {
511  CReserveKey reservekey(pwallet);
512 
513  if (chainActive.Tip()->nHeight < Params().START_POA_BLOCK()) {
514  return NULL;
515  }
516 
517  // Create new block
518  std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
519  if (!pblocktemplate.get())
520  return NULL;
521  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
522 
523  pblock->SetNull();
524  // Create coinbase tx
525  CMutableTransaction txNew;
526  txNew.vin.resize(1);
527  txNew.vin[0].prevout.SetNull();
528  txNew.vout.resize(1);
529  //Value of this vout coinbase will be computed based on the number of audited PoS blocks
530  //This will be computed later
531  txNew.vout[0].scriptPubKey = scriptPubKeyIn;
532  std::copy(txPub.begin(), txPub.end(), std::back_inserter(txNew.vout[0].txPub));
533  std::copy(txPriv.begin(), txPriv.end(), std::back_inserter(txNew.vout[0].txPriv));
534 
535  pblock->vtx.push_back(txNew);
536  pblocktemplate->vTxFees.push_back(-1); // updated at end
537  pblocktemplate->vTxSigOps.push_back(-1); // updated at end
538 
539  boost::this_thread::interruption_point();
540  pblock->nTime = GetAdjustedTime();
541  CBlockIndex* pindexPrev = chainActive.Tip();
542  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
543 
544  int nprevPoAHeight;
545 
546  nprevPoAHeight = GetListOfPoSInfo(pindexPrev->nHeight, pblock->posBlocksAudited);
547 
548  if (pblock->posBlocksAudited.size() == 0) {
549  return NULL;
550  }
551 
552  // Set block version to differentiate PoA blocks from PoS blocks
553  pblock->SetVersionPoABlock();
554  pblock->nTime = GetAdjustedTime();
555 
556  //compute PoA block reward
557  CAmount nReward;
558  if (pindexPrev->nHeight >= Params().HardFork()) {
559  nReward = pblock->posBlocksAudited.size() * 0.25 * COIN;
560  } else {
561  nReward = pblock->posBlocksAudited.size() * 0.5 * COIN;
562  }
563  pblock->vtx[0].vout[0].nValue = nReward;
564  pblock->vtx[0].txType = TX_TYPE_REVEAL_AMOUNT;
565 
566  CPubKey sharedSec;
567  sharedSec.Set(txPub.begin(), txPub.end());
568  unsigned char zeroBlind[32];
569  memset(zeroBlind, 0, 32);
570  pwallet->EncodeTxOutAmount(pblock->vtx[0].vout[0], pblock->vtx[0].vout[0].nValue, sharedSec.begin());
571  if (!pwallet->CreateCommitment(zeroBlind, pblock->vtx[0].vout[0].nValue, pblock->vtx[0].vout[0].commitment)) {
572  LogPrintf("%s: unable to create commitment to 0\n", __func__);
573  return NULL;
574  }
575  pwallet->EncodeTxOutAmount(pblock->vtx[0].vout[0], pblock->vtx[0].vout[0].nValue, sharedSec.begin());
576 
577  //Comment out all previous code, because a PoA block does not verify any transaction, except reward transactions to miners
578  // No need to collect memory pool transactions into the block
579  const int nHeight = pindexPrev->nHeight + 1;
580 
581  // Fill in header
582  pblock->hashPrevBlock = pindexPrev->GetBlockHash();
583  if (nprevPoAHeight >= Params().START_POA_BLOCK()) {
584  pblock->hashPrevPoABlock = *(chainActive[nprevPoAHeight]->phashBlock);
585  } else {
586  pblock->hashPrevPoABlock.SetNull();
587  }
588 
589  //ATTENTION: This is used for setting always the easiest difficulty for PoA miners
590  pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
591  pblock->nNonce = 0;
592 
593  pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
594 
595  // Compute final coinbase transaction.
596  CMutableTransaction txCoinbase(pblock->vtx[0]);
597  txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(1)) + COINBASE_FLAGS;
598  assert(txCoinbase.vin[0].scriptSig.size() <= 100);
599 
600  pblock->vtx[0] = txCoinbase;
601  pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
602 
603  pblock->hashPoAMerkleRoot = pblock->ComputePoAMerkleTree();
604  pblock->minedHash = pblock->ComputeMinedHash();
605 
606  return pblocktemplate.release();
607 }
608 
609 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
610 {
611  // Update nExtraNonce
612  static uint256 hashPrevBlock;
613  if (hashPrevBlock != pblock->hashPrevBlock) {
614  nExtraNonce = 0;
615  hashPrevBlock = pblock->hashPrevBlock;
616  }
617  ++nExtraNonce;
618  unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2
619  CMutableTransaction txCoinbase(pblock->vtx[0]);
620  txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
621  assert(txCoinbase.vin[0].scriptSig.size() <= 100);
622 
623  pblock->vtx[0] = txCoinbase;
624  pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
625 }
626 
627 #ifdef ENABLE_WALLET
628 //
630 // Internal miner
631 //
632 double dHashesPerSec = 0.0;
633 int64_t nHPSTimerStart = 0;
634 
635 CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet, bool fProofOfStake)
636 {
637  CPubKey pubkey, txPub;
638  CKey priv;
639  if (!pwallet->GenerateAddress(pubkey, txPub, priv))
640  return nullptr;
641 
642  const int nHeightNext = chainActive.Tip()->nHeight + 1;
643  static int nLastPOWBlock = Params().LAST_POW_BLOCK();
644 
645  // If we're building a late PoW block, don't continue
646  if ((nHeightNext > nLastPOWBlock) && !fProofOfStake) {
647  LogPrintf("%s: Aborting PoW block creation during PoS phase\n", __func__);
648  // sleep 1/2 a block time so we don't go into a tight loop.
649  MilliSleep((Params().TargetSpacing() * 1000) >> 1);
650  return nullptr;
651  }
652 
653  CScript scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
654  return CreateNewBlock(scriptPubKey, txPub, priv, pwallet, fProofOfStake);
655 }
656 
657 CBlockTemplate* CreateNewPoABlockWithKey(CReserveKey& reservekey, CWallet* pwallet)
658 {
659  CPubKey pubkey, txPub;
660  CKey txPriv;
661  if (!pwallet->GenerateAddress(pubkey, txPub, txPriv))
662  return NULL;
663 
664  CScript scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
665  return CreateNewPoABlock(scriptPubKey, txPub, txPriv, pwallet);
666 }
667 
668 bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
669 {
670  LogPrintf("%s\n", pblock->ToString());
671 
672  // Found a solution
673  {
675  if (pblock->hashPrevBlock != g_best_block)
676  return error("PRCYcoinMiner : generated block is stale");
677  }
678 
679  // Remove key from key pool
680  reservekey.KeepKey();
681 
682  // Track how many getdata requests this block gets
683  {
684  LOCK(wallet.cs_wallet);
685  wallet.mapRequestCount[pblock->GetHash()] = 0;
686  }
687 
688  // Inform about the new block
689  GetMainSignals().BlockFound(pblock->GetHash());
690 
691  // Process this block the same as if we had received it from another node
692  CValidationState state;
693  if (!ProcessNewBlock(state, NULL, pblock))
694  return error("PRCYcoinMiner : ProcessNewBlock, block not accepted");
695 
696  for (CNode* node : vNodes) {
697  node->PushInventory(CInv(MSG_BLOCK, pblock->GetHash()));
698  }
699 
700  return true;
701 }
702 
703 bool fGeneratePrcycoins = false;
704 bool fMintableCoins = false;
705 int nMintableLastCheck = 0;
706 
707 // ***TODO*** that part changed in bitcoin, we are using a mix with old one here for now
708 
709 void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
710 {
711  LogPrintf("PRCYcoinMiner started\n");
713  util::ThreadRename("prcycoin-miner");
714  fGeneratePrcycoins = true;
715  // Each thread has its own key and counter
716  CReserveKey reservekey(pwallet);
717  unsigned int nExtraNonce = 0;
718  bool fLastLoopOrphan = false;
719  while (fGeneratePrcycoins || fProofOfStake) {
720  if (chainActive.Tip()->nHeight >= Params().LAST_POW_BLOCK()) fProofOfStake = true;
721  if (fProofOfStake) {
722  //control the amount of times the client will check for mintable coins
723  if ((GetTime() - nMintableLastCheck > 5 * 60)) // 5 minute check time
724  {
725  nMintableLastCheck = GetTime();
726  fMintableCoins = pwallet->MintableCoins();
727  }
728 
729  while (vNodes.empty() || pwallet->IsLocked() || !fMintableCoins ||
730  nReserveBalance >= pwallet->GetBalance() || !masternodeSync.IsSynced()) {
732  MilliSleep(5000);
733  // Do a separate 1 minute check here to ensure fMintableCoins is updated
734  if (!fMintableCoins && (GetTime() - nMintableLastCheck > 1 * 60)) // 1 minute check time
735  {
736  nMintableLastCheck = GetTime();
737  fMintableCoins = pwallet->MintableCoins();
738  }
739  if (!fGeneratePrcycoins) {
740  break;
741  }
742  }
743 
744  if (!fGeneratePrcycoins) {
745  LogPrintf("Stopping staking or mining\n");
747  break;
748  }
749 
750  //search our map of hashed blocks, see if bestblock has been hashed yet
751  if (mapHashedBlocks.count(chainActive.Tip()->nHeight) && !fLastLoopOrphan)
752  {
753  // wait half of the nHashDrift with max wait of 3 minutes
754  if (GetTime() - mapHashedBlocks[chainActive.Tip()->nHeight] < std::max(pwallet->nHashInterval, (unsigned int)1))
755  {
756  MilliSleep(5000);
757  continue;
758  }
759  }
760  } else { // PoW
761  if ((chainActive.Tip()->nHeight - 6) > Params().LAST_POW_BLOCK())
762  {
763  // Run for a little while longer, just in case there is a rewind on the chain.
764  LogPrintf("%s: Exiting Proof of Work Mining Thread at height: %d\n",
765  __func__, chainActive.Tip()->nHeight);
766  return;
767  }
768  }
769 
770  //
771  // Create new block
772  //
773  unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
774  CBlockIndex* pindexPrev;
775  {
776  LOCK(cs_main);
777  pindexPrev = chainActive.Tip();
778  }
779  if (!pindexPrev)
780  continue;
781 
782  std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey, pwallet, fProofOfStake));
783  if (!pblocktemplate.get())
784  continue;
785 
786  CBlock* pblock = &pblocktemplate->block;
787  IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
788 
789  //Stake miner main
790  if (fProofOfStake) {
791  LogPrintf("CPUMiner : proof-of-stake block found %s \n", pblock->GetHash().ToString().c_str());
792  if (!SignBlock(*pblock, *pwallet)) {
793  LogPrintf("%s: Signing new block failed, computing private key \n", __func__);
794  if (pblock->vtx.size() > 1 && pblock->vtx[1].vout.size() > 1) {
795  pwallet->AddComputedPrivateKey(pblock->vtx[1].vout[1]);
796  }
797  if (!SignBlock(*pblock, *pwallet)) {
798  LogPrintf("%s: Signing new block with UTXO key failed \n", __func__);
799  continue;
800  }
801  }
802 
803  LogPrintf("CPUMiner : proof-of-stake block was signed %s \n", pblock->GetHash().ToString().c_str());
805  if (!ProcessBlockFound(pblock, *pwallet, reservekey)) {
806  continue;
807  }
809 
810  continue;
811  }
812 
813  LogPrint(BCLog::STAKING, "Running PRCYcoinMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(),
814  ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));
815 
816  //
817  // Search
818  //
819  int64_t nStart = GetTime();
820  uint256 hashTarget = uint256().SetCompact(pblock->nBits);
821  while (true) {
822  unsigned int nHashesDone = 0;
823 
824  uint256 hash;
825  while (true) {
826  hash = pblock->GetHash();
827  if (hash <= hashTarget) {
828  // Found a solution
830  ProcessBlockFound(pblock, *pwallet, reservekey);
831  if (!ProcessBlockFound(pblock, *pwallet, reservekey)) {
832  fLastLoopOrphan = true;
833  continue;
834  }
836 
837  // In regression test mode, stop mining after a block is found. This
838  // allows developers to controllably generate a block on demand.
839  if (Params().MineBlocksOnDemand()) {
840  throw boost::thread_interrupted();
841  }
842 
843  break;
844  }
845  pblock->nNonce += 1;
846  nHashesDone += 1;
847  if ((pblock->nNonce & 0xFF) == 0)
848  break;
849  }
850 
851  // Meter hashes/sec
852  static int64_t nHashCounter;
853  if (nHPSTimerStart == 0) {
855  nHashCounter = 0;
856  } else
857  nHashCounter += nHashesDone;
858  if (GetTimeMillis() - nHPSTimerStart > 4000) {
859  static RecursiveMutex cs;
860  {
861  LOCK(cs);
862  if (GetTimeMillis() - nHPSTimerStart > 4000) {
863  dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart);
865  nHashCounter = 0;
866  static int64_t nLogTime;
867  if (GetTime() - nLogTime > 30 * 60) {
868  nLogTime = GetTime();
869  LogPrintf("hashmeter %6.0f khash/s\n", dHashesPerSec / 1000.0);
870  }
871  }
872  }
873  }
874 
875  // Check for stop or if block needs to be rebuilt
876  boost::this_thread::interruption_point();
877  // Regtest mode doesn't require peers
878  if (vNodes.empty() && Params().MiningRequiresPeers())
879  break;
880  if (pblock->nNonce >= 0xffff0000)
881  break;
882  if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
883  break;
884  if (pindexPrev != chainActive.Tip())
885  break;
886 
887  // Update nTime every few seconds
888  UpdateTime(pblock, pindexPrev);
889  if (Params().AllowMinDifficultyBlocks()) {
890  // Changing pblock->nTime can change work required on testnet:
891  hashTarget.SetCompact(pblock->nBits);
892  }
893  }
894  }
895 }
896 
897 void static ThreadBitcoinMiner(void* parg)
898 {
899  boost::this_thread::interruption_point();
900  CWallet* pwallet = (CWallet*)parg;
901  try {
902  if (chainActive.Tip()->nHeight >= Params().LAST_POW_BLOCK()) {
903  BitcoinMiner(pwallet, true);
904  } else {
905  BitcoinMiner(pwallet, false);
906  }
907  boost::this_thread::interruption_point();
908  } catch (const std::exception& e) {
909  LogPrintf("PRCYcoinMiner exception\n");
910  } catch (...) {
911  LogPrintf("PRCYcoinMiner exception\n");
912  }
913 
914  LogPrintf("PRCYcoinMiner exiting\n");
915 }
916 
917 void static ThreadPrcycoinMiner(void* parg)
918 {
919  boost::this_thread::interruption_point();
920  try {
921  //create a PoA after every 3 minute if enough PoS blocks created
922  while (true) {
923  boost::this_thread::sleep_for(boost::chrono::milliseconds(180 * 1000));
924  //TODO: call CreateNewPoABlock function to create PoA blocks
925  }
926  boost::this_thread::interruption_point();
927  } catch (const std::exception& e) {
928  LogPrintf("ThreadBitcoinMiner() exception: %s \n", e.what());
929  } catch (...) {
930  LogPrintf("ThreadBitcoinMiner() error \n");
931  }
932 
933  LogPrintf("ThreadBitcoinMiner exiting\n");
934 }
935 
936 void GeneratePoAPrcycoin(CWallet* pwallet, int period)
937 {
938  static boost::thread_group* minerThreads = NULL;
939 
940  if (minerThreads != NULL) {
941  minerThreads->interrupt_all();
942  delete minerThreads;
943  minerThreads = NULL;
944  }
945 
946  minerThreads = new boost::thread_group();
947  minerThreads->create_thread(boost::bind(&ThreadPrcycoinMiner, pwallet));
948 }
949 
950 void GeneratePrcycoins(bool fGenerate, CWallet* pwallet, int nThreads)
951 {
952  static boost::thread_group* minerThreads = NULL;
953  fGeneratePrcycoins = fGenerate;
954 
955  if (nThreads < 0) {
956  // In regtest threads defaults to 1
957  if (Params().DefaultMinerThreads())
958  nThreads = Params().DefaultMinerThreads();
959  else
960  nThreads = boost::thread::hardware_concurrency();
961  }
962 
963  if (minerThreads != NULL) {
964  minerThreads->interrupt_all();
965  delete minerThreads;
966  minerThreads = NULL;
967  }
968 
969  if (nThreads == 0 || !fGenerate)
970  return;
971 
972  minerThreads = new boost::thread_group();
973  for (int i = 0; i < nThreads; i++)
974  minerThreads->create_thread(boost::bind(&ThreadBitcoinMiner, pwallet));
975 }
976 
977 // ppcoin: stake minter thread
978 void ThreadStakeMinter()
979 {
980  boost::this_thread::interruption_point();
981  LogPrintf("ThreadStakeMinter started\n");
982  CWallet* pwallet = pwalletMain;
983  try {
984  BitcoinMiner(pwallet, true);
985  boost::this_thread::interruption_point();
986  } catch (const std::exception& e) {
987  LogPrintf("ThreadStakeMinter() exception: %s \n", e.what());
988  } catch (...) {
989  LogPrintf("ThreadStakeMinter() error \n");
990  }
991  LogPrintf("ThreadStakeMinter exiting,\n");
992 }
993 
994 #endif // ENABLE_WALLET
CTxIn
An input of a transaction.
Definition: transaction.h:83
block.h
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:183
CBlockHeader::hashPoAMerkleRoot
uint256 hashPoAMerkleRoot
Definition: block.h:75
CMutableTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:387
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
OP_0
@ OP_0
Definition: script.h:41
vNodes
std::vector< CNode * > vNodes
Definition: net.cpp:85
CWallet::GenerateAddress
bool GenerateAddress(CPubKey &pub, CPubKey &txPub, CKey &txPriv) const
Definition: wallet.cpp:6623
g_best_block_mutex
Mutex g_best_block_mutex
Definition: main.cpp:75
CWallet::MintableCoins
bool MintableCoins()
Definition: wallet.cpp:2674
CBigNum
C++ wrapper for BIGNUM (OpenSSL bignum)
Definition: bignum.h:54
CWallet::MakeShnorrSignature
bool MakeShnorrSignature(CTransaction &)
Definition: wallet.cpp:3993
GetTime
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:19
CBlockHeader::hashMerkleRoot
uint256 hashMerkleRoot
Definition: block.h:62
transaction.h
CBlockHeader::nBits
uint32_t nBits
Definition: block.h:65
b
void const uint64_t * b
Definition: field_5x52_asm_impl.h:10
CBlock::IsProofOfWork
bool IsProofOfWork() const
Definition: block.h:218
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:52
PoSBlockSummary::nTime
uint32_t nTime
Definition: block.h:20
SignBlock
bool SignBlock(CBlock &block, const CKeyStore &keystore)
Definition: blocksignature.cpp:32
CTxUndo
Undo information for a CTransaction.
Definition: undo.h:63
CBlock::ComputePoAMerkleTree
uint256 ComputePoAMerkleTree(bool *mutated=NULL) const
Definition: block.cpp:122
AllowFree
bool AllowFree(double dPriority)
Definition: txmempool.h:26
CBlockHeader::nVersion
int32_t nVersion
Definition: block.h:59
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
timedata.h
THREAD_PRIORITY_NORMAL
#define THREAD_PRIORITY_NORMAL
Definition: compat.h:80
CWallet::CreateCoinStake
bool CreateCoinStake(const CKeyStore &keystore, unsigned int nBits, int64_t nSearchInterval, CMutableTransaction &txNew, unsigned int &nTxNewTime)
Definition: wallet.cpp:4302
CheckHaveInputs
bool CheckHaveInputs(const CCoinsViewCache &view, const CTransaction &tx)
Find the best known block, and make it the tip of the block chain.
Definition: main.cpp:1521
CPubKey::Set
void Set(const T pbegin, const T pend)
Initialize a public key using begin/end iterators to byte data.
Definition: pubkey.h:71
CWallet::mapRequestCount
std::map< uint256, int > mapRequestCount
Definition: wallet.h:352
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
CNode
Information about a peer.
Definition: net.h:306
CReserveKey
A key allocated from the key pool.
Definition: wallet.h:679
validationinterface.h
uint256::SetCompact
uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
Definition: uint256.cpp:14
wallet.h
THREAD_PRIORITY_LOWEST
#define THREAD_PRIORITY_LOWEST
Definition: compat.h:78
CheckInputs
bool CheckInputs(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheStore, std::vector< CScriptCheck > *pvChecks)
Check whether all inputs of this transaction are valid (no double spends, scripts & sigs,...
Definition: main.cpp:2766
CBlockHeader::nAccumulatorCheckpoint
uint256 nAccumulatorCheckpoint
Definition: block.h:67
MSG_BLOCK
@ MSG_BLOCK
Definition: protocol.h:389
ToByteVector
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:32
masternode-sync.h
invalid_out::ContainsOutPoint
bool ContainsOutPoint(const COutPoint &out)
Definition: invalid.cpp:54
TxPriorityCompare::TxPriorityCompare
TxPriorityCompare(bool _byFee)
Definition: miner.cpp:78
UpdateCoins
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
Definition: main.cpp:2706
COrphan
Definition: miner.cpp:52
UpdateTime
void UpdateTime(CBlockHeader *pblock, const CBlockIndex *pindexPrev)
Check mined block.
Definition: miner.cpp:94
AnnotatedMixin< std::recursive_mutex >
COrphan::dPriority
double dPriority
Definition: miner.cpp:58
SetThreadPriority
void SetThreadPriority(int nPriority)
Definition: util.cpp:648
GetSerializeSize
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:194
nLastCoinStakeSearchTime
int64_t nLastCoinStakeSearchTime
GetLegacySigOpCount
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Count ECDSA signature operations the old-fashioned (pre-0.6) way.
Definition: tx_verify.cpp:30
CInv
inv message data
Definition: protocol.h:358
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:159
CTxMemPool::GetTransactionsUpdated
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:389
IsFinalTx
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time.
Definition: tx_verify.cpp:12
GetNextWorkRequired
unsigned int GetNextWorkRequired(const CBlockIndex *pindexLast, const CBlockHeader *pblock, bool fProofOfStake)
GetListOfPoSInfo
uint32_t GetListOfPoSInfo(uint32_t currentHeight, std::vector< PoSBlockSummary > &audits)
Definition: miner.cpp:103
CFeeRate
Fee rate in PRCY per kilobyte: CAmount / kB.
Definition: amount.h:39
CBlockHeader::GetHash
uint256 GetHash() const
Definition: block.cpp:80
CPubKey::GetHex
std::string GetHex() const
Definition: pubkey.h:193
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
CKey::end
const unsigned char * end() const
Definition: key.h:101
GetMainSignals
CMainSignals & GetMainSignals()
Definition: validationinterface.cpp:10
masternodeSync
CMasternodeSync masternodeSync
Definition: masternode-sync.cpp:19
g_best_block
uint256 g_best_block
Definition: main.cpp:77
dHashesPerSec
double dHashesPerSec
CScriptNum
Definition: script.h:190
CPubKey::begin
const unsigned char * begin() const
Definition: pubkey.h:95
CWallet::AddComputedPrivateKey
void AddComputedPrivateKey(const CTxOut &out)
Definition: wallet.cpp:4264
CBlockHeader::nNonce
uint32_t nNonce
Definition: block.h:66
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
CKey::begin
const unsigned char * begin() const
Definition: key.h:100
nLastBlockTx
uint64_t nLastBlockTx
Definition: miner.cpp:65
CTransaction::IsCoinBase
bool IsCoinBase() const
Definition: transaction.h:359
ReVerifyPoSBlock
bool ReVerifyPoSBlock(CBlockIndex *pindex)
Definition: main.cpp:621
CTxMemPool::cs
RecursiveMutex cs
sum of all mempool tx' byte sizes
Definition: txmempool.h:135
TxPriorityCompare::operator()
bool operator()(const TxPriority &a, const TxPriority &b)
Definition: miner.cpp:80
COrphan::COrphan
COrphan(const CTransaction *ptxIn)
Definition: miner.cpp:60
tx_verify.h
nReserveBalance
int64_t nReserveBalance
Definition: wallet.cpp:59
CBlockIndex::GetMedianTimePast
int64_t GetMedianTimePast() const
Definition: chain.h:371
nDefaultMinerSleep
int64_t nDefaultMinerSleep
Definition: miner.cpp:68
VerifyShnorrKeyImageTx
bool VerifyShnorrKeyImageTx(const CTransaction &tx)
Definition: main.cpp:1454
CPubKey::end
const unsigned char * end() const
Definition: pubkey.h:96
util::ThreadRename
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
Definition: threadnames.cpp:57
miner.h
CChainParams::LAST_POW_BLOCK
int LAST_POW_BLOCK() const
Definition: chainparams.h:111
GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:255
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
blocksignature.h
pcoinsTip
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:1130
CTransaction::nTxFee
CAmount nTxFee
Definition: transaction.h:298
mempool
CTxMemPool mempool(::minRelayTxFee)
COINBASE_FLAGS
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: main.cpp:117
CBlockHeader::minedHash
uint256 minedHash
Definition: block.h:79
CBlockHeader::nTime
uint32_t nTime
Definition: block.h:64
mapHashedBlocks
std::map< unsigned int, unsigned int > mapHashedBlocks
Definition: main.cpp:69
masternode-payments.h
CWallet::GetBalance
CAmount GetBalance()
Definition: wallet.cpp:2243
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CWallet::CreateCommitment
static bool CreateCommitment(const CAmount val, CKey &blind, std::vector< unsigned char > &commitment)
Definition: wallet.cpp:3096
OP_CHECKSIG
@ OP_CHECKSIG
Definition: script.h:155
LogPrint
#define LogPrint(category,...)
Definition: logging.h:162
fGeneratePrcycoins
bool fGeneratePrcycoins
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
CMasternodeSync::IsSynced
bool IsSynced()
Definition: masternode-sync.cpp:27
COrphan::setDependsOn
std::set< uint256 > setDependsOn
Definition: miner.cpp:56
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
GetPriority
double GetPriority(const CTransaction &tx, int nHeight)
Return priority of tx at height nHeight.
Definition: main.cpp:259
nLastCoinStakeSearchInterval
int64_t nLastCoinStakeSearchInterval
Definition: miner.cpp:67
COrphan::feeRate
CFeeRate feeRate
Definition: miner.cpp:57
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
merkle.h
PoSBlockSummary
Definition: block.h:17
poa.h
CBlockHeader::hashPrevBlock
uint256 hashPrevBlock
Definition: block.h:61
base_uint::SetNull
void SetNull()
Definition: arith_uint256.h:308
CBlock::vtx
std::vector< CTransaction > vtx
Definition: block.h:146
GetTimeMillis
int64_t GetTimeMillis()
Definition: utiltime.cpp:31
invalid.h
CBlock
Definition: block.h:142
CMutableTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:388
CreateNewBlock
CBlockTemplate * CreateNewBlock(const CScript &scriptPubKeyIn, const CPubKey &txPub, const CKey &txPriv, CWallet *pwallet, bool fProofOfStake)
Generate a new block, without valid proof-of-work.
Definition: miner.cpp:160
CPubKey
An encapsulated public key.
Definition: pubkey.h:37
GetAdjustedTime
int64_t GetAdjustedTime()
Definition: timedata.cpp:30
PoSBlockSummary::height
uint32_t height
Definition: block.h:21
CWallet::IsTransactionForMe
bool IsTransactionForMe(const CTransaction &tx)
Definition: wallet.cpp:6705
CMainSignals::BlockFound
boost::signals2::signal< void(const uint256 &)> BlockFound
Notifies listeners that a key for mining is required (coinbase)
Definition: validationinterface.h:72
CKey
An encapsulated private key.
Definition: key.h:39
CReserveKey::KeepKey
void KeepKey()
Definition: wallet.cpp:5008
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:414
utilmoneystr.h
CBlockTemplate
Definition: miner.h:50
main.h
CTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:285
CTxMemPool::mapTx
std::map< uint256, CTxMemPoolEntry > mapTx
Definition: txmempool.h:136
LOCK
#define LOCK(cs)
Definition: sync.h:182
ProcessNewBlock
bool ProcessNewBlock(CValidationState &state, CNode *pfrom, CBlock *pblock, CDiskBlockPos *dbp)
Process an incoming block.
Definition: main.cpp:4890
TxPriorityCompare
Definition: miner.cpp:73
CWallet
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:243
BCLog::STAKING
@ STAKING
Definition: logging.h:61
ReadBlockFromDisk
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
Definition: main.cpp:2101
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:86
COrphan::ptx
const CTransaction * ptx
Definition: miner.cpp:55
PoSBlockSummary::hash
uint256 hash
Definition: block.h:19
CBlockHeader::hashPrevPoABlock
uint256 hashPrevPoABlock
Definition: block.h:73
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:463
MilliSleep
void MilliSleep(int64_t n)
Definition: utiltime.cpp:45
CTxMemPool::ApplyDeltas
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta)
Definition: txmempool.cpp:686
hash.h
CWallet::nHashInterval
unsigned int nHashInterval
Definition: wallet.h:316
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
CFeeRate::ToString
std::string ToString() const
Definition: amount.cpp:30
GetBlockValue
CAmount GetBlockValue(int nHeight)
Definition: main.cpp:2158
CBlock::ToString
std::string ToString() const
Definition: block.cpp:150
TxPriorityCompare::byFee
bool byFee
Definition: miner.cpp:75
COutPoint::ToString
std::string ToString() const
Definition: transaction.cpp:21
CBlockHeader::SetVersionPoABlock
void SetVersionPoABlock()
Definition: block.h:109
CTransaction::GetHash
const uint256 & GetHash() const
Definition: transaction.h:342
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
nLastBlockSize
uint64_t nLastBlockSize
Definition: miner.cpp:66
CreateNewPoABlock
CBlockTemplate * CreateNewPoABlock(const CScript &scriptPubKeyIn, const CPubKey &txPub, const CKey &txPriv, CWallet *pwallet)
Definition: miner.cpp:509
CBlock::SetNull
void SetNull()
Definition: block.h:183
CMutableTransaction
A mutable version of CTransaction.
Definition: transaction.h:384
CBlockHeader::ComputeMinedHash
uint256 ComputeMinedHash() const
Definition: block.cpp:66
CTxIn::keyImage
CKeyImage keyImage
Definition: transaction.h:97
net.h
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:241
CChainParams::MAX_NUM_POS_BLOCKS_AUDITED
int MAX_NUM_POS_BLOCKS_AUDITED() const
Definition: chainparams.h:128
TxPriority
boost::tuple< double, CFeeRate, const CTransaction * > TxPriority
Definition: miner.cpp:72
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
nHPSTimerStart
int64_t nHPSTimerStart
amount.h
IncrementExtraNonce
void IncrementExtraNonce(CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Modify the extranonce in a block.
Definition: miner.cpp:609
CBlock::payee
CScript payee
Definition: block.h:155
CWallet::EncodeTxOutAmount
bool EncodeTxOutAmount(CTxOut &out, const CAmount &amount, const unsigned char *sharedSec, bool isCoinstake=false)
Definition: wallet.cpp:7168
CValidationState
Capture information about block/transaction validation.
Definition: validation.h:23
util.h
CChainParams::DefaultMinerThreads
int DefaultMinerThreads() const
Used if GeneratePrcycoins is called with a negative number of threads.
Definition: chainparams.h:67
CBlock::IsProofOfStake
bool IsProofOfStake() const
Definition: block.h:213
WAIT_LOCK
#define WAIT_LOCK(cs, name)
Definition: sync.h:187
IsSpentKeyImage
bool IsSpentKeyImage(const std::string &kiHex, const uint256 &againsHash)
Definition: main.cpp:283
CCryptoKeyStore::IsLocked
bool IsLocked() const
Definition: crypter.h:159
FillBlockPayee
bool FillBlockPayee(CMutableTransaction &txNew, CAmount nFees, bool fProofOfStake)
Definition: masternode-payments.cpp:214
error
bool error(const char *fmt, const Args &... args)
Definition: util.h:61
TX_TYPE_REVEAL_AMOUNT
@ TX_TYPE_REVEAL_AMOUNT
Definition: transaction.h:261
CBlock::posBlocksAudited
std::vector< PoSBlockSummary > posBlocksAudited
Definition: block.h:149
mapBlockIndex
BlockMap mapBlockIndex
Definition: main.cpp:67
BlockMerkleRoot
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
Definition: merkle.cpp:150
CTransaction::IsCoinStake
bool IsCoinStake() const
Definition: transaction.cpp:143
base_uint::ToString
std::string ToString() const
Definition: arith_uint256.cpp:199