Dash Core  0.12.2.1
P2P Digital Currency
mining.cpp
Go to the documentation of this file.
1 // Copyright (c) 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 "base58.h"
8 #include "amount.h"
9 #include "chain.h"
10 #include "chainparams.h"
11 #include "consensus/consensus.h"
12 #include "consensus/params.h"
13 #include "consensus/validation.h"
14 #include "core_io.h"
15 #include "init.h"
16 #include "validation.h"
17 #include "miner.h"
18 #include "net.h"
19 #include "pow.h"
20 #include "rpc/server.h"
21 #include "spork.h"
22 #include "txmempool.h"
23 #include "util.h"
24 #ifdef ENABLE_WALLET
25 #include "masternode-sync.h"
26 #endif
27 #include "utilstrencodings.h"
28 #include "validationinterface.h"
29 
30 #include <stdint.h>
31 
32 #include <boost/assign/list_of.hpp>
33 #include <boost/shared_ptr.hpp>
34 
35 #include <univalue.h>
36 
37 using namespace std;
38 
44 UniValue GetNetworkHashPS(int lookup, int height) {
45  CBlockIndex *pb = chainActive.Tip();
46 
47  if (height >= 0 && height < chainActive.Height())
48  pb = chainActive[height];
49 
50  if (pb == NULL || !pb->nHeight)
51  return 0;
52 
53  // If lookup is -1, then use blocks since last difficulty change.
54  if (lookup <= 0)
56 
57  // If lookup is larger than chain, then set it to chain length.
58  if (lookup > pb->nHeight)
59  lookup = pb->nHeight;
60 
61  CBlockIndex *pb0 = pb;
62  int64_t minTime = pb0->GetBlockTime();
63  int64_t maxTime = minTime;
64  for (int i = 0; i < lookup; i++) {
65  pb0 = pb0->pprev;
66  int64_t time = pb0->GetBlockTime();
67  minTime = std::min(time, minTime);
68  maxTime = std::max(time, maxTime);
69  }
70 
71  // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
72  if (minTime == maxTime)
73  return 0;
74 
75  arith_uint256 workDiff = pb->nChainWork - pb0->nChainWork;
76  int64_t timeDiff = maxTime - minTime;
77 
78  return workDiff.getdouble() / timeDiff;
79 }
80 
81 UniValue getnetworkhashps(const UniValue& params, bool fHelp)
82 {
83  if (fHelp || params.size() > 2)
84  throw runtime_error(
85  "getnetworkhashps ( blocks height )\n"
86  "\nReturns the estimated network hashes per second based on the last n blocks.\n"
87  "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
88  "Pass in [height] to estimate the network speed at the time when a certain block was found.\n"
89  "\nArguments:\n"
90  "1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n"
91  "2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n"
92  "\nResult:\n"
93  "x (numeric) Hashes per second estimated\n"
94  "\nExamples:\n"
95  + HelpExampleCli("getnetworkhashps", "")
96  + HelpExampleRpc("getnetworkhashps", "")
97  );
98 
99  LOCK(cs_main);
100  return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
101 }
102 
103 UniValue getgenerate(const UniValue& params, bool fHelp)
104 {
105  if (fHelp || params.size() != 0)
106  throw runtime_error(
107  "getgenerate\n"
108  "\nReturn if the server is set to generate coins or not. The default is false.\n"
109  "It is set with the command line argument -gen (or " + std::string(BITCOIN_CONF_FILENAME) + " setting gen)\n"
110  "It can also be set with the setgenerate call.\n"
111  "\nResult\n"
112  "true|false (boolean) If the server is set to generate coins or not\n"
113  "\nExamples:\n"
114  + HelpExampleCli("getgenerate", "")
115  + HelpExampleRpc("getgenerate", "")
116  );
117 
118  LOCK(cs_main);
119  return GetBoolArg("-gen", DEFAULT_GENERATE);
120 }
121 
122 UniValue generate(const UniValue& params, bool fHelp)
123 {
124  if (fHelp || params.size() < 1 || params.size() > 1)
125  throw runtime_error(
126  "generate numblocks\n"
127  "\nMine blocks immediately (before the RPC call returns)\n"
128  "\nNote: this function can only be used on the regtest network\n"
129  "\nArguments:\n"
130  "1. numblocks (numeric, required) How many blocks are generated immediately.\n"
131  "\nResult\n"
132  "[ blockhashes ] (array) hashes of blocks generated\n"
133  "\nExamples:\n"
134  "\nGenerate 11 blocks\n"
135  + HelpExampleCli("generate", "11")
136  );
137 
138  if (!Params().MineBlocksOnDemand())
139  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "This method can only be used on regtest");
140 
141  int nHeightStart = 0;
142  int nHeightEnd = 0;
143  int nHeight = 0;
144  int nGenerate = params[0].get_int();
145 
146  boost::shared_ptr<CReserveScript> coinbaseScript;
147  GetMainSignals().ScriptForMining(coinbaseScript);
148 
149  // If the keypool is exhausted, no script is returned at all. Catch this.
150  if (!coinbaseScript)
151  throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
152 
153  //throw an error if no script was provided
154  if (coinbaseScript->reserveScript.empty())
155  throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available (mining requires a wallet)");
156 
157  { // Don't keep cs_main locked
158  LOCK(cs_main);
159  nHeightStart = chainActive.Height();
160  nHeight = nHeightStart;
161  nHeightEnd = nHeightStart+nGenerate;
162  }
163  unsigned int nExtraNonce = 0;
164  UniValue blockHashes(UniValue::VARR);
165  while (nHeight < nHeightEnd)
166  {
167  std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(Params(), coinbaseScript->reserveScript));
168  if (!pblocktemplate.get())
169  throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
170  CBlock *pblock = &pblocktemplate->block;
171  {
172  LOCK(cs_main);
173  IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
174  }
175  while (!CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
176  // Yes, there is a chance every nonce could fail to satisfy the -regtest
177  // target -- 1 in 2^(2^32). That ain't gonna happen.
178  ++pblock->nNonce;
179  }
180  if (!ProcessNewBlock(Params(), pblock, true, NULL, NULL))
181  throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
182  ++nHeight;
183  blockHashes.push_back(pblock->GetHash().GetHex());
184 
185  //mark script as important because it was used at least for one coinbase output
186  coinbaseScript->KeepScript();
187  }
188  return blockHashes;
189 }
190 
191 UniValue setgenerate(const UniValue& params, bool fHelp)
192 {
193  if (fHelp || params.size() < 1 || params.size() > 2)
194  throw runtime_error(
195  "setgenerate generate ( genproclimit )\n"
196  "\nSet 'generate' true or false to turn generation on or off.\n"
197  "Generation is limited to 'genproclimit' processors, -1 is unlimited.\n"
198  "See the getgenerate call for the current setting.\n"
199  "\nArguments:\n"
200  "1. generate (boolean, required) Set to true to turn on generation, false to turn off.\n"
201  "2. genproclimit (numeric, optional) Set the processor limit for when generation is on. Can be -1 for unlimited.\n"
202  "\nExamples:\n"
203  "\nSet the generation on with a limit of one processor\n"
204  + HelpExampleCli("setgenerate", "true 1") +
205  "\nCheck the setting\n"
206  + HelpExampleCli("getgenerate", "") +
207  "\nTurn off generation\n"
208  + HelpExampleCli("setgenerate", "false") +
209  "\nUsing json rpc\n"
210  + HelpExampleRpc("setgenerate", "true, 1")
211  );
212 
213  if (Params().MineBlocksOnDemand())
214  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Use the generate method instead of setgenerate on this network");
215 
216  bool fGenerate = true;
217  if (params.size() > 0)
218  fGenerate = params[0].get_bool();
219 
220  int nGenProcLimit = GetArg("-genproclimit", DEFAULT_GENERATE_THREADS);
221  if (params.size() > 1)
222  {
223  nGenProcLimit = params[1].get_int();
224  if (nGenProcLimit == 0)
225  fGenerate = false;
226  }
227 
228  mapArgs["-gen"] = (fGenerate ? "1" : "0");
229  mapArgs ["-genproclimit"] = itostr(nGenProcLimit);
230  GenerateBitcoins(fGenerate, nGenProcLimit, Params(), *g_connman);
231 
232  return NullUniValue;
233 }
234 
235 UniValue getmininginfo(const UniValue& params, bool fHelp)
236 {
237  if (fHelp || params.size() != 0)
238  throw runtime_error(
239  "getmininginfo\n"
240  "\nReturns a json object containing mining-related information."
241  "\nResult:\n"
242  "{\n"
243  " \"blocks\": nnn, (numeric) The current block\n"
244  " \"currentblocksize\": nnn, (numeric) The last block size\n"
245  " \"currentblocktx\": nnn, (numeric) The last block transaction\n"
246  " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n"
247  " \"errors\": \"...\" (string) Current errors\n"
248  " \"generate\": true|false (boolean) If the generation is on or off (see getgenerate or setgenerate calls)\n"
249  " \"genproclimit\": n (numeric) The processor limit for generation. -1 if no generation. (see getgenerate or setgenerate calls)\n"
250  " \"pooledtx\": n (numeric) The size of the mem pool\n"
251  " \"testnet\": true|false (boolean) If using testnet or not\n"
252  " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
253  "}\n"
254  "\nExamples:\n"
255  + HelpExampleCli("getmininginfo", "")
256  + HelpExampleRpc("getmininginfo", "")
257  );
258 
259 
260  LOCK(cs_main);
261 
263  obj.push_back(Pair("blocks", (int)chainActive.Height()));
264  obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
265  obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
266  obj.push_back(Pair("difficulty", (double)GetDifficulty()));
267  obj.push_back(Pair("errors", GetWarnings("statusbar")));
268  obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", DEFAULT_GENERATE_THREADS)));
269  obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
270  obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
271  obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
272  obj.push_back(Pair("chain", Params().NetworkIDString()));
273  obj.push_back(Pair("generate", getgenerate(params, false)));
274  return obj;
275 }
276 
277 
278 // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
279 UniValue prioritisetransaction(const UniValue& params, bool fHelp)
280 {
281  if (fHelp || params.size() != 3)
282  throw runtime_error(
283  "prioritisetransaction <txid> <priority delta> <fee delta>\n"
284  "Accepts the transaction into mined blocks at a higher (or lower) priority\n"
285  "\nArguments:\n"
286  "1. \"txid\" (string, required) The transaction id.\n"
287  "2. priority delta (numeric, required) The priority to add or subtract.\n"
288  " The transaction selection algorithm considers the tx as it would have a higher priority.\n"
289  " (priority of a transaction is calculated: coinage * value_in_duffs / txsize) \n"
290  "3. fee delta (numeric, required) The fee value (in duffs) to add (or subtract, if negative).\n"
291  " The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
292  " considers the transaction as it would have paid a higher (or lower) fee.\n"
293  "\nResult\n"
294  "true (boolean) Returns true\n"
295  "\nExamples:\n"
296  + HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
297  + HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")
298  );
299 
300  LOCK(cs_main);
301  uint256 hash = ParseHashStr(params[0].get_str(), "txid");
302  CAmount nAmount = params[2].get_int64();
303 
304  mempool.PrioritiseTransaction(hash, params[0].get_str(), params[1].get_real(), nAmount);
305  return true;
306 }
307 
308 
309 // NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
311 {
312  if (state.IsValid())
313  return NullUniValue;
314 
315  std::string strRejectReason = state.GetRejectReason();
316  if (state.IsError())
317  throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
318  if (state.IsInvalid())
319  {
320  if (strRejectReason.empty())
321  return "rejected";
322  return strRejectReason;
323  }
324  // Should be impossible
325  return "valid?";
326 }
327 
328 std::string gbt_vb_name(const Consensus::DeploymentPos pos) {
329  const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
330  std::string s = vbinfo.name;
331  if (!vbinfo.gbt_force) {
332  s.insert(s.begin(), '!');
333  }
334  return s;
335 }
336 
337 UniValue getblocktemplate(const UniValue& params, bool fHelp)
338 {
339  if (fHelp || params.size() > 1)
340  throw runtime_error(
341  "getblocktemplate ( \"jsonrequestobject\" )\n"
342  "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
343  "It returns data needed to construct a block to work on.\n"
344  "For full specification, see BIPs 22 and 9:\n"
345  " https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n"
346  " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n"
347 
348  "\nArguments:\n"
349  "1. \"jsonrequestobject\" (string, optional) A json object in the following spec\n"
350  " {\n"
351  " \"mode\":\"template\" (string, optional) This must be set to \"template\" or omitted\n"
352  " \"capabilities\":[ (array, optional) A list of strings\n"
353  " \"support\" (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'\n"
354  " ,...\n"
355  " ]\n"
356  " }\n"
357  "\n"
358 
359  "\nResult:\n"
360  "{\n"
361  " \"version\" : n, (numeric) The block version\n"
362  " \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n"
363  " \"vbavailable\" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments\n"
364  " \"rulename\" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule\n"
365  " ,...\n"
366  " },\n"
367  " \"vbrequired\" : n, (numeric) bit mask of versionbits the server requires set in submissions\n"
368  " \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n"
369  " \"transactions\" : [ (array) contents of non-coinbase transactions that should be included in the next block\n"
370  " {\n"
371  " \"data\" : \"xxxx\", (string) transaction data encoded in hexadecimal (byte-for-byte)\n"
372  " \"hash\" : \"xxxx\", (string) hash/id encoded in little-endian hexadecimal\n"
373  " \"depends\" : [ (array) array of numbers \n"
374  " n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is\n"
375  " ,...\n"
376  " ],\n"
377  " \"fee\": n, (numeric) difference in value between transaction inputs and outputs (in duffs); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one\n"
378  " \"sigops\" : n, (numeric) total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any\n"
379  " \"required\" : true|false (boolean) if provided and true, this transaction must be in the final block\n"
380  " }\n"
381  " ,...\n"
382  " ],\n"
383  " \"coinbaseaux\" : { (json object) data that should be included in the coinbase's scriptSig content\n"
384  " \"flags\" : \"flags\" (string) \n"
385  " },\n"
386  " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in duffs)\n"
387  " \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n"
388  " \"target\" : \"xxxx\", (string) The hash target\n"
389  " \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n"
390  " \"mutable\" : [ (array of string) list of ways the block template may be changed \n"
391  " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n"
392  " ,...\n"
393  " ],\n"
394  " \"noncerange\" : \"00000000ffffffff\", (string) A range of valid nonces\n"
395  " \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n"
396  " \"sizelimit\" : n, (numeric) limit of block size\n"
397  " \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
398  " \"bits\" : \"xxx\", (string) compressed target of next block\n"
399  " \"height\" : n (numeric) The height of the next block\n"
400  " \"masternode\" : { (json object) required masternode payee that must be included in the next block\n"
401  " \"payee\" : \"xxxx\", (string) payee address\n"
402  " \"script\" : \"xxxx\", (string) payee scriptPubKey\n"
403  " \"amount\": n (numeric) required amount to pay\n"
404  " },\n"
405  " \"masternode_payments_started\" : true|false, (boolean) true, if masternode payments started\n"
406  " \"masternode_payments_enforced\" : true|false, (boolean) true, if masternode payments are enforced\n"
407  " \"superblock\" : [ (array) required superblock payees that must be included in the next block\n"
408  " {\n"
409  " \"payee\" : \"xxxx\", (string) payee address\n"
410  " \"script\" : \"xxxx\", (string) payee scriptPubKey\n"
411  " \"amount\": n (numeric) required amount to pay\n"
412  " }\n"
413  " ,...\n"
414  " ],\n"
415  " \"superblocks_started\" : true|false, (boolean) true, if superblock payments started\n"
416  " \"superblocks_enabled\" : true|false (boolean) true, if superblock payments are enabled\n"
417  "}\n"
418 
419  "\nExamples:\n"
420  + HelpExampleCli("getblocktemplate", "")
421  + HelpExampleRpc("getblocktemplate", "")
422  );
423 
424  LOCK(cs_main);
425 
426  std::string strMode = "template";
427  UniValue lpval = NullUniValue;
428  std::set<std::string> setClientRules;
429  int64_t nMaxVersionPreVB = -1;
430  if (params.size() > 0)
431  {
432  const UniValue& oparam = params[0].get_obj();
433  const UniValue& modeval = find_value(oparam, "mode");
434  if (modeval.isStr())
435  strMode = modeval.get_str();
436  else if (modeval.isNull())
437  {
438  /* Do nothing */
439  }
440  else
441  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
442  lpval = find_value(oparam, "longpollid");
443 
444  if (strMode == "proposal")
445  {
446  const UniValue& dataval = find_value(oparam, "data");
447  if (!dataval.isStr())
448  throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");
449 
450  CBlock block;
451  if (!DecodeHexBlk(block, dataval.get_str()))
452  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
453 
454  uint256 hash = block.GetHash();
455  BlockMap::iterator mi = mapBlockIndex.find(hash);
456  if (mi != mapBlockIndex.end()) {
457  CBlockIndex *pindex = mi->second;
458  if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
459  return "duplicate";
460  if (pindex->nStatus & BLOCK_FAILED_MASK)
461  return "duplicate-invalid";
462  return "duplicate-inconclusive";
463  }
464 
465  CBlockIndex* const pindexPrev = chainActive.Tip();
466  // TestBlockValidity only supports blocks built on the current Tip
467  if (block.hashPrevBlock != pindexPrev->GetBlockHash())
468  return "inconclusive-not-best-prevblk";
469  CValidationState state;
470  TestBlockValidity(state, Params(), block, pindexPrev, false, true);
471  return BIP22ValidationResult(state);
472  }
473 
474  const UniValue& aClientRules = find_value(oparam, "rules");
475  if (aClientRules.isArray()) {
476  for (unsigned int i = 0; i < aClientRules.size(); ++i) {
477  const UniValue& v = aClientRules[i];
478  setClientRules.insert(v.get_str());
479  }
480  } else {
481  // NOTE: It is important that this NOT be read if versionbits is supported
482  const UniValue& uvMaxVersion = find_value(oparam, "maxversion");
483  if (uvMaxVersion.isNum()) {
484  nMaxVersionPreVB = uvMaxVersion.get_int64();
485  }
486  }
487  }
488 
489  if (strMode != "template")
490  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
491 
492  if(!g_connman)
493  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
494 
495  if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
496  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Dash Core is not connected!");
497 
499  throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Dash Core is downloading blocks...");
500 
501  if (!masternodeSync.IsSynced())
502  throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Dash Core is syncing with network...");
503 
504  static unsigned int nTransactionsUpdatedLast;
505 
506  if (!lpval.isNull())
507  {
508  // Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
509  uint256 hashWatchedChain;
510  boost::system_time checktxtime;
511  unsigned int nTransactionsUpdatedLastLP;
512 
513  if (lpval.isStr())
514  {
515  // Format: <hashBestChain><nTransactionsUpdatedLast>
516  std::string lpstr = lpval.get_str();
517 
518  hashWatchedChain.SetHex(lpstr.substr(0, 64));
519  nTransactionsUpdatedLastLP = atoi64(lpstr.substr(64));
520  }
521  else
522  {
523  // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
524  hashWatchedChain = chainActive.Tip()->GetBlockHash();
525  nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
526  }
527 
528  // Release the wallet and main lock while waiting
530  {
531  checktxtime = boost::get_system_time() + boost::posix_time::minutes(1);
532 
533  boost::unique_lock<boost::mutex> lock(csBestBlock);
534  while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning())
535  {
536  if (!cvBlockChange.timed_wait(lock, checktxtime))
537  {
538  // Timeout: Check transactions for update
539  if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
540  break;
541  checktxtime += boost::posix_time::seconds(10);
542  }
543  }
544  }
546 
547  if (!IsRPCRunning())
548  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
549  // TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
550  }
551 
552  // Update block
553  static CBlockIndex* pindexPrev;
554  static int64_t nStart;
555  static CBlockTemplate* pblocktemplate;
556  if (pindexPrev != chainActive.Tip() ||
557  (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5))
558  {
559  // Clear pindexPrev so future calls make a new block, despite any failures from here on
560  pindexPrev = NULL;
561 
562  // Store the chainActive.Tip() used before CreateNewBlock, to avoid races
563  nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
564  CBlockIndex* pindexPrevNew = chainActive.Tip();
565  nStart = GetTime();
566 
567  // Create new block
568  if(pblocktemplate)
569  {
570  delete pblocktemplate;
571  pblocktemplate = NULL;
572  }
573  CScript scriptDummy = CScript() << OP_TRUE;
574  pblocktemplate = CreateNewBlock(Params(), scriptDummy);
575  if (!pblocktemplate)
576  throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
577 
578  // Need to update only after we know CreateNewBlock succeeded
579  pindexPrev = pindexPrevNew;
580  }
581  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
582  const Consensus::Params& consensusParams = Params().GetConsensus();
583 
584  // Update nTime
585  UpdateTime(pblock, consensusParams, pindexPrev);
586  pblock->nNonce = 0;
587 
588  UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
589 
590  UniValue transactions(UniValue::VARR);
591  map<uint256, int64_t> setTxIndex;
592  int i = 0;
593  BOOST_FOREACH (const CTransaction& tx, pblock->vtx) {
594  uint256 txHash = tx.GetHash();
595  setTxIndex[txHash] = i++;
596 
597  if (tx.IsCoinBase())
598  continue;
599 
600  UniValue entry(UniValue::VOBJ);
601 
602  entry.push_back(Pair("data", EncodeHexTx(tx)));
603 
604  entry.push_back(Pair("hash", txHash.GetHex()));
605 
606  UniValue deps(UniValue::VARR);
607  BOOST_FOREACH (const CTxIn &in, tx.vin)
608  {
609  if (setTxIndex.count(in.prevout.hash))
610  deps.push_back(setTxIndex[in.prevout.hash]);
611  }
612  entry.push_back(Pair("depends", deps));
613 
614  int index_in_template = i - 1;
615  entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template]));
616  entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template]));
617 
618  transactions.push_back(entry);
619  }
620 
623 
624  arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
625 
626  UniValue aMutable(UniValue::VARR);
627  aMutable.push_back("time");
628  aMutable.push_back("transactions");
629  aMutable.push_back("prevblock");
630 
632  result.push_back(Pair("capabilities", aCaps));
633 
634  UniValue aRules(UniValue::VARR);
635  UniValue vbavailable(UniValue::VOBJ);
636  for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) {
638  ThresholdState state = VersionBitsState(pindexPrev, consensusParams, pos, versionbitscache);
639  switch (state) {
640  case THRESHOLD_DEFINED:
641  case THRESHOLD_FAILED:
642  // Not exposed to GBT at all
643  break;
644  case THRESHOLD_LOCKED_IN:
645  // Ensure bit is set in block version
646  pblock->nVersion |= VersionBitsMask(consensusParams, pos);
647  // FALL THROUGH to get vbavailable set...
648  case THRESHOLD_STARTED:
649  {
650  const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
651  vbavailable.push_back(Pair(gbt_vb_name(pos), consensusParams.vDeployments[pos].bit));
652  if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
653  if (!vbinfo.gbt_force) {
654  // If the client doesn't support this, don't indicate it in the [default] version
655  pblock->nVersion &= ~VersionBitsMask(consensusParams, pos);
656  }
657  }
658  break;
659  }
660  case THRESHOLD_ACTIVE:
661  {
662  // Add to rules only
663  const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
664  aRules.push_back(gbt_vb_name(pos));
665  if (setClientRules.find(vbinfo.name) == setClientRules.end()) {
666  // Not supported by the client; make sure it's safe to proceed
667  if (!vbinfo.gbt_force) {
668  // If we do anything other than throw an exception here, be sure version/force isn't sent to old clients
669  throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
670  }
671  }
672  break;
673  }
674  }
675  }
676  result.push_back(Pair("version", pblock->nVersion));
677  result.push_back(Pair("rules", aRules));
678  result.push_back(Pair("vbavailable", vbavailable));
679  result.push_back(Pair("vbrequired", int(0)));
680 
681  if (nMaxVersionPreVB >= 2) {
682  // If VB is supported by the client, nMaxVersionPreVB is -1, so we won't get here
683  // Because BIP 34 changed how the generation transaction is serialised, we can only use version/force back to v2 blocks
684  // This is safe to do [otherwise-]unconditionally only because we are throwing an exception above if a non-force deployment gets activated
685  // Note that this can probably also be removed entirely after the first BIP9 non-force deployment (ie, probably segwit) gets activated
686  aMutable.push_back("version/force");
687  }
688 
689  result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
690  result.push_back(Pair("transactions", transactions));
691  result.push_back(Pair("coinbaseaux", aux));
692  result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].GetValueOut()));
693  result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
694  result.push_back(Pair("target", hashTarget.GetHex()));
695  result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
696  result.push_back(Pair("mutable", aMutable));
697  result.push_back(Pair("noncerange", "00000000ffffffff"));
698  result.push_back(Pair("sigoplimit", (int64_t)MaxBlockSigOps(fDIP0001ActiveAtTip)));
699  result.push_back(Pair("sizelimit", (int64_t)MaxBlockSize(fDIP0001ActiveAtTip)));
700  result.push_back(Pair("curtime", pblock->GetBlockTime()));
701  result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
702  result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
703 
704  UniValue masternodeObj(UniValue::VOBJ);
705  if(pblock->txoutMasternode != CTxOut()) {
706  CTxDestination address1;
708  CBitcoinAddress address2(address1);
709  masternodeObj.push_back(Pair("payee", address2.ToString().c_str()));
710  masternodeObj.push_back(Pair("script", HexStr(pblock->txoutMasternode.scriptPubKey.begin(), pblock->txoutMasternode.scriptPubKey.end())));
711  masternodeObj.push_back(Pair("amount", pblock->txoutMasternode.nValue));
712  }
713  result.push_back(Pair("masternode", masternodeObj));
714  result.push_back(Pair("masternode_payments_started", pindexPrev->nHeight + 1 > Params().GetConsensus().nMasternodePaymentsStartBlock));
715  result.push_back(Pair("masternode_payments_enforced", sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)));
716 
717  UniValue superblockObjArray(UniValue::VARR);
718  if(pblock->voutSuperblock.size()) {
719  BOOST_FOREACH (const CTxOut& txout, pblock->voutSuperblock) {
720  UniValue entry(UniValue::VOBJ);
721  CTxDestination address1;
722  ExtractDestination(txout.scriptPubKey, address1);
723  CBitcoinAddress address2(address1);
724  entry.push_back(Pair("payee", address2.ToString().c_str()));
725  entry.push_back(Pair("script", HexStr(txout.scriptPubKey.begin(), txout.scriptPubKey.end())));
726  entry.push_back(Pair("amount", txout.nValue));
727  superblockObjArray.push_back(entry);
728  }
729  }
730  result.push_back(Pair("superblock", superblockObjArray));
731  result.push_back(Pair("superblocks_started", pindexPrev->nHeight + 1 > Params().GetConsensus().nSuperblockStartBlock));
732  result.push_back(Pair("superblocks_enabled", sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)));
733 
734  return result;
735 }
736 
738 {
739 public:
741  bool found;
743 
744  submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {};
745 
746 protected:
747  virtual void BlockChecked(const CBlock& block, const CValidationState& stateIn) {
748  if (block.GetHash() != hash)
749  return;
750  found = true;
751  state = stateIn;
752  };
753 };
754 
755 UniValue submitblock(const UniValue& params, bool fHelp)
756 {
757  if (fHelp || params.size() < 1 || params.size() > 2)
758  throw runtime_error(
759  "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n"
760  "\nAttempts to submit new block to network.\n"
761  "The 'jsonparametersobject' parameter is currently ignored.\n"
762  "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
763 
764  "\nArguments\n"
765  "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n"
766  "2. \"jsonparametersobject\" (string, optional) object of optional parameters\n"
767  " {\n"
768  " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n"
769  " }\n"
770  "\nResult:\n"
771  "\nExamples:\n"
772  + HelpExampleCli("submitblock", "\"mydata\"")
773  + HelpExampleRpc("submitblock", "\"mydata\"")
774  );
775 
776  CBlock block;
777  if (!DecodeHexBlk(block, params[0].get_str()))
778  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
779 
780  uint256 hash = block.GetHash();
781  bool fBlockPresent = false;
782  {
783  LOCK(cs_main);
784  BlockMap::iterator mi = mapBlockIndex.find(hash);
785  if (mi != mapBlockIndex.end()) {
786  CBlockIndex *pindex = mi->second;
787  if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
788  return "duplicate";
789  if (pindex->nStatus & BLOCK_FAILED_MASK)
790  return "duplicate-invalid";
791  // Otherwise, we might only have the header - process the block before returning
792  fBlockPresent = true;
793  }
794  }
795 
796  submitblock_StateCatcher sc(block.GetHash());
798  bool fAccepted = ProcessNewBlock(Params(), &block, true, NULL, NULL);
800  if (fBlockPresent)
801  {
802  if (fAccepted && !sc.found)
803  return "duplicate-inconclusive";
804  return "duplicate";
805  }
806  if (!sc.found)
807  return "inconclusive";
808  return BIP22ValidationResult(sc.state);
809 }
810 
811 UniValue estimatefee(const UniValue& params, bool fHelp)
812 {
813  if (fHelp || params.size() != 1)
814  throw runtime_error(
815  "estimatefee nblocks\n"
816  "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
817  "confirmation within nblocks blocks.\n"
818  "\nArguments:\n"
819  "1. nblocks (numeric)\n"
820  "\nResult:\n"
821  "n (numeric) estimated fee-per-kilobyte\n"
822  "\n"
823  "A negative value is returned if not enough transactions and blocks\n"
824  "have been observed to make an estimate.\n"
825  "\nExample:\n"
826  + HelpExampleCli("estimatefee", "6")
827  );
828 
829  RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
830 
831  int nBlocks = params[0].get_int();
832  if (nBlocks < 1)
833  nBlocks = 1;
834 
835  CFeeRate feeRate = mempool.estimateFee(nBlocks);
836  if (feeRate == CFeeRate(0))
837  return -1.0;
838 
839  return ValueFromAmount(feeRate.GetFeePerK());
840 }
841 
842 UniValue estimatepriority(const UniValue& params, bool fHelp)
843 {
844  if (fHelp || params.size() != 1)
845  throw runtime_error(
846  "estimatepriority nblocks\n"
847  "\nEstimates the approximate priority a zero-fee transaction needs to begin\n"
848  "confirmation within nblocks blocks.\n"
849  "\nArguments:\n"
850  "1. nblocks (numeric)\n"
851  "\nResult:\n"
852  "n (numeric) estimated priority\n"
853  "\n"
854  "A negative value is returned if not enough transactions and blocks\n"
855  "have been observed to make an estimate.\n"
856  "\nExample:\n"
857  + HelpExampleCli("estimatepriority", "6")
858  );
859 
860  RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
861 
862  int nBlocks = params[0].get_int();
863  if (nBlocks < 1)
864  nBlocks = 1;
865 
866  return mempool.estimatePriority(nBlocks);
867 }
868 
869 UniValue estimatesmartfee(const UniValue& params, bool fHelp)
870 {
871  if (fHelp || params.size() != 1)
872  throw runtime_error(
873  "estimatesmartfee nblocks\n"
874  "\nWARNING: This interface is unstable and may disappear or change!\n"
875  "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
876  "confirmation within nblocks blocks if possible and return the number of blocks\n"
877  "for which the estimate is valid.\n"
878  "\nArguments:\n"
879  "1. nblocks (numeric)\n"
880  "\nResult:\n"
881  "{\n"
882  " \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n"
883  " \"blocks\" : n (numeric) block number where estimate was found\n"
884  "}\n"
885  "\n"
886  "A negative value is returned if not enough transactions and blocks\n"
887  "have been observed to make an estimate for any number of blocks.\n"
888  "However it will not return a value below the mempool reject fee.\n"
889  "\nExample:\n"
890  + HelpExampleCli("estimatesmartfee", "6")
891  );
892 
893  RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
894 
895  int nBlocks = params[0].get_int();
896 
898  int answerFound;
899  CFeeRate feeRate = mempool.estimateSmartFee(nBlocks, &answerFound);
900  result.push_back(Pair("feerate", feeRate == CFeeRate(0) ? -1.0 : ValueFromAmount(feeRate.GetFeePerK())));
901  result.push_back(Pair("blocks", answerFound));
902  return result;
903 }
904 
905 UniValue estimatesmartpriority(const UniValue& params, bool fHelp)
906 {
907  if (fHelp || params.size() != 1)
908  throw runtime_error(
909  "estimatesmartpriority nblocks\n"
910  "\nWARNING: This interface is unstable and may disappear or change!\n"
911  "\nEstimates the approximate priority a zero-fee transaction needs to begin\n"
912  "confirmation within nblocks blocks if possible and return the number of blocks\n"
913  "for which the estimate is valid.\n"
914  "\nArguments:\n"
915  "1. nblocks (numeric)\n"
916  "\nResult:\n"
917  "{\n"
918  " \"priority\" : x.x, (numeric) estimated priority\n"
919  " \"blocks\" : n (numeric) block number where estimate was found\n"
920  "}\n"
921  "\n"
922  "A negative value is returned if not enough transactions and blocks\n"
923  "have been observed to make an estimate for any number of blocks.\n"
924  "However if the mempool reject fee is set it will return 1e9 * MAX_MONEY.\n"
925  "\nExample:\n"
926  + HelpExampleCli("estimatesmartpriority", "6")
927  );
928 
929  RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
930 
931  int nBlocks = params[0].get_int();
932 
934  int answerFound;
935  double priority = mempool.estimateSmartPriority(nBlocks, &answerFound);
936  result.push_back(Pair("priority", priority));
937  result.push_back(Pair("blocks", answerFound));
938  return result;
939 }
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: chain.h:125
boost::signals2::signal< void(boost::shared_ptr< CReserveScript > &)> ScriptForMining
UniValue prioritisetransaction(const UniValue &params, bool fHelp)
Definition: mining.cpp:279
UniValue getnetworkhashps(const UniValue &params, bool fHelp)
Definition: mining.cpp:81
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
Definition: standard.h:69
CMasternodeSync masternodeSync
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
Definition: core_read.cpp:110
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: standard.cpp:164
Invalid account name.
Definition: protocol.h:72
unsigned long size()
Definition: txmempool.h:551
Invalid address or key.
Definition: protocol.h:45
const char *const BITCOIN_CONF_FILENAME
Definition: util.cpp:119
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev)
Definition: miner.cpp:62
bool IsRPCRunning()
Definition: server.cpp:452
std::string GetRejectReason() const
Definition: validation.h:81
uint64_t nLastBlockSize
Definition: miner.cpp:49
CTxOut txoutMasternode
Definition: block.h:80
unsigned int MaxBlockSize(bool fDIP0001Active)
Definition: consensus.h:12
#define strprintf
Definition: tinyformat.h:1011
descends from failed block
Definition: chain.h:92
CWaitableCriticalSection csBestBlock
Definition: validation.cpp:67
submitblock_StateCatcher(const uint256 &hashIn)
Definition: mining.cpp:744
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:55
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=NULL) const
Definition: txmempool.cpp:883
static const int DEFAULT_GENERATE_THREADS
Definition: miner.h:22
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
Definition: chain.h:253
UniValue getblocktemplate(const UniValue &params, bool fHelp)
Definition: mining.cpp:337
UniValue GetNetworkHashPS(int lookup, int height)
Definition: mining.cpp:44
bool isStr() const
Definition: univalue.h:81
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=NULL, bool *pfOverflow=NULL)
double estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks=NULL) const
Definition: txmempool.cpp:893
CCriticalSection cs_main
Definition: validation.cpp:62
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
CAmount nValue
Definition: transaction.h:136
static const int SPORK_9_SUPERBLOCKS_ENABLED
Definition: spork.h:26
int64_t GetBlockTime() const
Definition: block.h:66
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:586
double GetDifficulty(const CBlockIndex *blockindex)
Definition: blockchain.cpp:32
ThresholdState
Definition: versionbits.h:20
uint32_t VersionBitsMask(const Consensus::Params &params, Consensus::DeploymentPos pos)
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
UniValue estimatepriority(const UniValue &params, bool fHelp)
Definition: mining.cpp:842
std::vector< CTxOut > voutSuperblock
Definition: block.h:81
bool push_back(const UniValue &val)
Definition: univalue.cpp:176
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:122
Ran out of memory during operation.
Definition: protocol.h:46
std::vector< CAmount > vTxFees
Definition: miner.h:29
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:280
std::vector< CTransaction > vtx
Definition: block.h:77
UniValue submitblock(const UniValue &params, bool fHelp)
Definition: mining.cpp:755
std::string ToString() const
Definition: base58.cpp:193
int64_t get_int64() const
Definition: univalue.cpp:327
DeploymentPos
Definition: params.h:15
bool ProcessNewBlock(const CChainParams &chainparams, const CBlock *pblock, bool fForceProcessing, const CDiskBlockPos *dbp, bool *fNewBlock)
int64_t CAmount
Definition: amount.h:14
Error parsing or validating structure in raw format.
Definition: protocol.h:49
uint256 hashPrevBlock
Definition: block.h:25
iterator end()
Definition: prevector.h:272
const UniValue & get_obj() const
Definition: univalue.cpp:347
bool GetBoolArg(const std::string &strArg, bool fDefault)
Definition: util.cpp:455
virtual void BlockChecked(const CBlock &block, const CValidationState &stateIn)
Definition: mining.cpp:747
COutPoint prevout
Definition: transaction.h:61
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:178
#define LOCK(cs)
Definition: sync.h:168
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
Definition: params.h:75
uint64_t nLastBlockTx
Definition: miner.cpp:48
unsigned int MaxBlockSigOps(bool fDIP0001Active)
Definition: consensus.h:18
UniValue setgenerate(const UniValue &params, bool fHelp)
Definition: mining.cpp:191
CAmount GetFeePerK() const
Definition: amount.h:47
static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT
Definition: spork.h:25
bool isNull() const
Definition: univalue.h:77
void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams &chainparams, CConnman &connman)
Definition: miner.cpp:524
Server is in safe mode, and command is not allowed in safe mode.
Definition: protocol.h:43
int Height() const
Definition: chain.h:397
static UniValue BIP22ValidationResult(const CValidationState &state)
Definition: mining.cpp:310
bool IsInitialBlockDownload()
uint32_t nBits
Definition: block.h:28
std::atomic< bool > fDIP0001ActiveAtTip
Definition: validation.cpp:89
bool isArray() const
Definition: univalue.h:83
CMainSignals & GetMainSignals()
CChain chainActive
Definition: validation.cpp:65
CValidationState state
Definition: mining.cpp:742
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:581
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:166
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params &params)
Definition: pow.cpp:238
CScript COINBASE_FLAGS
Definition: validation.cpp:107
int64_t DifficultyAdjustmentInterval() const
Definition: params.h:82
CBlock block
Definition: miner.h:28
CScript scriptPubKey
Definition: transaction.h:137
VersionBitsCache versionbitscache
std::vector< int64_t > vTxSigOps
Definition: miner.h:30
const char * name
Definition: versionbits.h:35
void RegisterValidationInterface(CValidationInterface *pwalletIn)
bool IsValid() const
Definition: validation.h:61
CSporkManager sporkManager
Definition: spork.cpp:14
void IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Definition: miner.cpp:322
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:172
UniValue generate(const UniValue &params, bool fHelp)
Definition: mining.cpp:122
const std::vector< CTxIn > vin
Definition: transaction.h:233
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_write.cpp:119
void RPCTypeCheck(const UniValue &params, const list< UniValue::VType > &typesExpected, bool fAllowNull)
Definition: server.cpp:70
CTxMemPool mempool
static const bool DEFAULT_GENERATE
Definition: miner.h:21
uint256 ParseHashStr(const std::string &, const std::string &strName)
Definition: core_read.cpp:135
uint32_t nNonce
Definition: block.h:29
std::string GetWarnings(const std::string &strFor)
const CChainParams & Params()
const uint256 & GetHash() const
Definition: transaction.h:262
bool isNum() const
Definition: univalue.h:82
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:137
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
uint256 GetBlockHash() const
Definition: chain.h:218
bool IsCoinBase() const
Definition: transaction.h:284
bool IsInvalid() const
Definition: validation.h:64
std::string GetHex() const
Definition: uint256.cpp:21
int32_t nVersion
Definition: block.h:24
int64_t atoi64(const char *psz)
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:103
const UniValue NullUniValue
Definition: univalue.cpp:78
std::string i64tostr(int64_t n)
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:80
int get_int() const
Definition: univalue.cpp:317
CBlockIndex * Tip() const
Definition: chain.h:366
iterator begin()
Definition: prevector.h:270
std::string gbt_vb_name(const Consensus::DeploymentPos pos)
Definition: mining.cpp:328
int64_t GetMedianTimePast() const
Definition: chain.h:230
int64_t GetBlockTime() const
Definition: chain.h:223
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Definition: util.cpp:441
void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount &nFeeDelta)
Definition: txmempool.cpp:934
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:107
bool IsError() const
Definition: validation.h:67
Invalid IP/Subnet.
Definition: protocol.h:66
std::string GetHex() const
bool IsSporkActive(int nSporkID)
Definition: spork.cpp:120
int64_t GetTime()
For unit testing.
Definition: utiltime.cpp:20
UniValue estimatesmartfee(const UniValue &params, bool fHelp)
Definition: mining.cpp:869
CFeeRate estimateFee(int nBlocks) const
Definition: txmempool.cpp:878
Dash Core is not connected.
Definition: protocol.h:61
CBlockTemplate * CreateNewBlock(const CChainParams &chainparams, const CScript &scriptPubKeyIn)
Definition: miner.cpp:77
Definition: block.h:73
UniValue estimatefee(const UniValue &params, bool fHelp)
Definition: mining.cpp:811
Definition: script.h:52
void SetHex(const char *psz)
Definition: uint256.cpp:30
ThresholdState VersionBitsState(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos, VersionBitsCache &cache)
uint256 GetHash() const
Definition: block.cpp:13
P2P client errors.
Definition: protocol.h:60
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:113
bool MineBlocksOnDemand() const
Definition: chainparams.h:71
double getdouble() const
uint256 hash
Definition: transaction.h:18
UniValue estimatesmartpriority(const UniValue &params, bool fHelp)
Definition: mining.cpp:905
UniValue JSONRPCError(int code, const string &message)
Definition: protocol.cpp:57
double estimatePriority(int nBlocks) const
Definition: txmempool.cpp:888
BlockMap mapBlockIndex
Definition: validation.cpp:64
size_t size() const
Definition: univalue.h:69
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:360
std::string get_str() const
Definition: univalue.cpp:310
UniValue getmininginfo(const UniValue &params, bool fHelp)
Definition: mining.cpp:235
std::string itostr(int n)
const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
Definition: versionbits.cpp:9
map< string, string > mapArgs
Definition: util.cpp:122
Database error.
Definition: protocol.h:48
CConditionVariable cvBlockChange
Definition: validation.cpp:68
result
Definition: rpcuser.py:37
UniValue getgenerate(const UniValue &params, bool fHelp)
Definition: mining.cpp:103