PIVX Core  5.6.99
P2P Digital Currency
mining.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2022 The PIVX Core developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
7 
8 #include "amount.h"
9 #include "blockassembler.h"
10 #include "chainparams.h"
11 #include "core_io.h"
12 #include "key_io.h"
13 #include "miner.h"
14 #include "net.h"
15 #include "rpc/server.h"
16 #include "shutdown.h"
17 #include "util/blockstatecatcher.h"
18 #include "validationinterface.h"
19 #ifdef ENABLE_WALLET
20 #include "wallet/rpcwallet.h"
21 #include "wallet/db.h"
22 #include "wallet/wallet.h"
23 #endif
24 #include "warnings.h"
25 
26 #include <univalue.h>
27 
28 #ifdef ENABLE_WALLET
29 UniValue generateBlocks(const Consensus::Params& consensus,
30  CWallet* const pwallet,
31  bool fPoS,
32  const int nGenerate,
33  int nHeight,
34  int nHeightEnd,
35  CScript* coinbaseScript)
36 {
37  UniValue blockHashes(UniValue::VARR);
38 
40  sc.registerEvent();
41  while (nHeight < nHeightEnd && !ShutdownRequested()) {
42 
43  // Get available coins
44  std::vector<CStakeableOutput> availableCoins;
45  if (fPoS && !pwallet->StakeableCoins(&availableCoins)) {
46  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "No available coins to stake");
47  }
48 
49  std::unique_ptr<CBlockTemplate> pblocktemplate(fPoS ?
50  BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(CScript(), pwallet, true, &availableCoins) :
51  CreateNewBlockWithScript(*coinbaseScript, pwallet));
52  if (!pblocktemplate.get()) break;
53  std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(pblocktemplate->block);
54 
55  if(!fPoS) {
56  if (ShutdownRequested()) break;
57  if (!SolveBlock(pblock, nHeight + 1)) continue;
58  }
59 
60  sc.get().setBlockHash(pblock->GetHash());
61  bool res = ProcessNewBlock(pblock, nullptr);
62  if (!res || sc.get().stateErrorFound())
63  throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
64 
65  ++nHeight;
66  blockHashes.push_back(pblock->GetHash().GetHex());
67 
68  // Check PoS if needed.
69  if (!fPoS)
70  fPoS = consensus.NetworkUpgradeActive(nHeight + 1, Consensus::UPGRADE_POS);
71  }
72 
73  const int nGenerated = blockHashes.size();
74  if (nGenerated == 0 || (!fPoS && nGenerated < nGenerate))
75  throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new blocks");
76 
77  return blockHashes;
78 }
79 
80 UniValue generate(const JSONRPCRequest& request)
81 {
82  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
83 
84  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
85  return NullUniValue;
86 
87  if (request.fHelp || request.params.size() < 1 || request.params.size() > 1)
88  throw std::runtime_error(
89  "generate nblocks\n"
90  "\nMine blocks immediately (before the RPC call returns)\n"
91  "\nNote: this function can only be used on the regtest network\n"
92 
93  "\nArguments:\n"
94  "1. nblocks (numeric, required) How many blocks to generate.\n"
95 
96  "\nResult\n"
97  "[ blockhashes ] (array) hashes of blocks generated\n"
98 
99  "\nExamples:\n"
100  "\nGenerate 11 blocks\n"
101  + HelpExampleCli("generate", "11")
102  );
103 
104  if (!Params().IsRegTestNet())
105  throw JSONRPCError(RPC_METHOD_NOT_FOUND, "This method can only be used on regtest");
106 
107  const int nGenerate = request.params[0].get_int();
108  int nHeightEnd = 0;
109  int nHeight = 0;
110 
111  { // Don't keep cs_main locked
112  LOCK(cs_main);
113  nHeight = chainActive.Height();
114  nHeightEnd = nHeight + nGenerate;
115  }
116 
117  const Consensus::Params& consensus = Params().GetConsensus();
118  bool fPoS = consensus.NetworkUpgradeActive(nHeight + 1, Consensus::UPGRADE_POS);
119  std::unique_ptr<CReserveKey> reservekey;
120  CScript coinbaseScript;
121 
122  if (fPoS) {
123  // If we are in PoS, wallet must be unlocked.
124  EnsureWalletIsUnlocked(pwallet);
125  } else {
126  // Coinbase key
127  reservekey = std::make_unique<CReserveKey>(pwallet);
128  CPubKey pubkey;
129  if (!reservekey->GetReservedKey(pubkey)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Error: Cannot get key from keypool");
130  coinbaseScript = GetScriptForDestination(pubkey.GetID());
131  }
132 
133  // Create the blocks
134  UniValue blockHashes = generateBlocks(consensus,
135  pwallet,
136  fPoS,
137  nGenerate,
138  nHeight,
139  nHeightEnd,
140  &coinbaseScript);
141 
142  // mark key as used, only for PoW coinbases
143  if (reservekey) {
144  // Remove key from key pool
145  reservekey->KeepKey();
146  }
147 
148  return blockHashes;
149 }
150 
151 UniValue generatetoaddress(const JSONRPCRequest& request)
152 {
153  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
154 
155  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
156  return NullUniValue;
157 
158  if (request.fHelp || request.params.size() != 2)
159  throw std::runtime_error(
160  "generatetoaddress nblocks \"address\"\n"
161  "\nMine blocks immediately to a specified address (before the RPC call returns)\n"
162  "\nArguments:\n"
163  "1. nblocks (numeric, required) How many blocks are generated immediately.\n"
164  "2. \"address\" (string, required) The address to send the newly generated bitcoin to.\n"
165  "\nResult\n"
166  "[ blockhashes ] (array) hashes of blocks generated\n"
167  "\nExamples:\n"
168  "\nGenerate 11 blocks to myaddress\n"
169  + HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
170  );
171 
172  int nGenerate = request.params[0].get_int();
173  CTxDestination dest(DecodeDestination(request.params[1].get_str()));
174  if (!IsValidDestination(dest)) {
175  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Error: Invalid address");
176  }
177  CScript coinbaseScript = GetScriptForDestination(dest);
178 
179  const Consensus::Params& consensus = Params().GetConsensus();
180  int nHeightEnd = 0;
181  int nHeight = 0;
182 
183  { // Don't keep cs_main locked
184  LOCK(cs_main);
185  nHeight = chainActive.Height();
186  nHeightEnd = nHeight + nGenerate;
187  }
188 
189  bool fPoS = consensus.NetworkUpgradeActive(nHeight + 1, Consensus::UPGRADE_POS);
190  return generateBlocks(consensus,
191  pwallet,
192  fPoS,
193  nGenerate,
194  nHeight,
195  nHeightEnd,
196  &coinbaseScript);
197 }
198 
199 #endif // ENABLE_WALLET
200 
201 #ifdef ENABLE_MINING_RPC
207 UniValue GetNetworkHashPS(int lookup, int height)
208 {
209  CBlockIndex *pb = chainActive.Tip();
210 
211  if (height >= 0 && height < chainActive.Height())
212  pb = chainActive[height];
213 
214  if (pb == nullptr || !pb->nHeight)
215  return 0;
216 
217  // If lookup is -1, then use blocks since last difficulty change.
218  if (lookup <= 0)
219  lookup = pb->nHeight % 2016 + 1;
220 
221  // If lookup is larger than chain, then set it to chain length.
222  if (lookup > pb->nHeight)
223  lookup = pb->nHeight;
224 
225  CBlockIndex* pb0 = pb;
226  int64_t minTime = pb0->GetBlockTime();
227  int64_t maxTime = minTime;
228  for (int i = 0; i < lookup; i++) {
229  pb0 = pb0->pprev;
230  int64_t time = pb0->GetBlockTime();
231  minTime = std::min(time, minTime);
232  maxTime = std::max(time, maxTime);
233  }
234 
235  // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
236  if (minTime == maxTime)
237  return 0;
238 
239  arith_uint256 workDiff = pb->nChainWork - pb0->nChainWork;
240  int64_t timeDiff = maxTime - minTime;
241 
242  return (int64_t)(workDiff.getdouble() / timeDiff);
243 }
244 
245 UniValue getnetworkhashps(const JSONRPCRequest& request)
246 {
247  if (request.fHelp || request.params.size() > 2)
248  throw std::runtime_error(
249  "getnetworkhashps ( nblocks height )\n"
250  "\nReturns the estimated network hashes per second based on the last n blocks.\n"
251  "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
252  "Pass in [height] to estimate the network speed at the time when a certain block was found.\n"
253 
254  "\nArguments:\n"
255  "1. nblocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n"
256  "2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n"
257 
258  "\nResult:\n"
259  "x (numeric) Hashes per second estimated\n"
260  "\nExamples:\n" +
261  HelpExampleCli("getnetworkhashps", "") + HelpExampleRpc("getnetworkhashps", ""));
262 
263  LOCK(cs_main);
264  return GetNetworkHashPS(request.params.size() > 0 ? request.params[0].get_int() : 120, request.params.size() > 1 ? request.params[1].get_int() : -1);
265 }
266 
267 #ifdef ENABLE_WALLET
268 UniValue getgenerate(const JSONRPCRequest& request)
269 {
270  if (request.fHelp || request.params.size() != 0)
271  throw std::runtime_error(
272  "getgenerate\n"
273  "\nReturn if the server is set to generate coins or not. The default is false.\n"
274  "It is set with the command line argument -gen (or pivx.conf setting gen)\n"
275  "It can also be set with the setgenerate call.\n"
276 
277  "\nResult\n"
278  "true|false (boolean) If the server is set to generate coins or not\n"
279 
280  "\nExamples:\n" +
281  HelpExampleCli("getgenerate", "") + HelpExampleRpc("getgenerate", ""));
282 
283  LOCK(cs_main);
284  return gArgs.GetBoolArg("-gen", false);
285 }
286 
287 UniValue setgenerate(const JSONRPCRequest& request)
288 {
289  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
290 
291  if (!EnsureWalletIsAvailable(pwallet, request.fHelp))
292  return NullUniValue;
293 
294  if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
295  throw std::runtime_error(
296  "setgenerate generate ( genproclimit )\n"
297  "\nSet 'generate' true or false to turn generation on or off.\n"
298  "Generation is limited to 'genproclimit' processors, -1 is unlimited.\n"
299  "See the getgenerate call for the current setting.\n"
300 
301  "\nArguments:\n"
302  "1. generate (boolean, required) Set to true to turn on generation, false to turn off.\n"
303  "2. genproclimit (numeric, optional) Set the processor limit for when generation is on. Can be -1 for unlimited.\n"
304 
305  "\nExamples:\n"
306  "\nSet the generation on with a limit of one processor\n" +
307  HelpExampleCli("setgenerate", "true 1") +
308  "\nCheck the setting\n" + HelpExampleCli("getgenerate", "") +
309  "\nTurn off generation\n" + HelpExampleCli("setgenerate", "false") +
310  "\nUsing json rpc\n" + HelpExampleRpc("setgenerate", "true, 1"));
311 
312  if (Params().IsRegTestNet())
313  throw JSONRPCError(RPC_INVALID_REQUEST, "Use the generate method instead of setgenerate on regtest");
314 
315  bool fGenerate = true;
316  if (request.params.size() > 0)
317  fGenerate = request.params[0].get_bool();
318 
319  const int nHeight = WITH_LOCK(cs_main, return chainActive.Height() + 1);
320  if (fGenerate && Params().GetConsensus().NetworkUpgradeActive(nHeight, Consensus::UPGRADE_POS))
321  throw JSONRPCError(RPC_INVALID_REQUEST, "Proof of Work phase has already ended");
322 
323  int nGenProcLimit = -1;
324  if (request.params.size() > 1) {
325  nGenProcLimit = request.params[1].get_int();
326  if (nGenProcLimit == 0)
327  fGenerate = false;
328  }
329 
330  gArgs.GetArg("-gen", "") = (fGenerate ? "1" : "0");
331  gArgs.GetArg("-genproclimit", "") = itostr(nGenProcLimit);
332  GenerateBitcoins(fGenerate, pwallet, nGenProcLimit);
333 
334  return NullUniValue;
335 }
336 
337 UniValue gethashespersec(const JSONRPCRequest& request)
338 {
339  if (request.fHelp || request.params.size() != 0)
340  throw std::runtime_error(
341  "gethashespersec\n"
342  "\nReturns a recent hashes per second performance measurement while generating.\n"
343  "See the getgenerate and setgenerate calls to turn generation on and off.\n"
344 
345  "\nResult:\n"
346  "n (numeric) The recent hashes per second when generation is on (will return 0 if generation is off)\n"
347 
348  "\nExamples:\n" +
349  HelpExampleCli("gethashespersec", "") + HelpExampleRpc("gethashespersec", ""));
350 
351  if (GetTimeMillis() - nHPSTimerStart > 8000)
352  return (int64_t)0;
353  return (int64_t)dHashesPerSec;
354 }
355 #endif
356 
357 
358 UniValue getmininginfo(const JSONRPCRequest& request)
359 {
360  if (request.fHelp || request.params.size() != 0)
361  throw std::runtime_error(
362  "getmininginfo\n"
363  "\nReturns a json object containing mining-related information."
364 
365  "\nResult:\n"
366  "{\n"
367  " \"blocks\": nnn, (numeric) The current block\n"
368  " \"currentblocksize\": nnn, (numeric) The last block size\n"
369  " \"currentblocktx\": nnn, (numeric) The last block transaction\n"
370  " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n"
371  " \"generate\": true|false (boolean) If the generation is on or off (see getgenerate or setgenerate calls)\n"
372  " \"genproclimit\": n (numeric) The processor limit for generation. -1 if no generation. (see getgenerate or setgenerate calls)\n"
373  " \"hashespersec\": n (numeric) The hashes per second of the generation, or 0 if no generation.\n"
374  " \"pooledtx\": n (numeric) The size of the mem pool\n"
375  " \"testnet\": true|false (boolean) If using testnet or not\n"
376  " \"chain\": \"xxxx\", (string) current network name (main, test, regtest)\n"
377  " \"warnings\": \"...\" (string) any network and blockchain warnings\n"
378  " \"errors\": \"...\" (string) DEPRECATED. Same as warnings. Only shown when bitcoind is started with -deprecatedrpc=getmininginfo\n"
379  "}\n"
380 
381  "\nExamples:\n" +
382  HelpExampleCli("getmininginfo", "") + HelpExampleRpc("getmininginfo", ""));
383 
384  LOCK(cs_main);
385 
387  obj.pushKV("blocks", (int)chainActive.Height());
388  obj.pushKV("currentblocksize", (uint64_t)nLastBlockSize);
389  obj.pushKV("currentblocktx", (uint64_t)nLastBlockTx);
390  obj.pushKV("difficulty", (double)GetDifficulty());
391  obj.pushKV("genproclimit", (int)gArgs.GetArg("-genproclimit", -1));
392  obj.pushKV("networkhashps", getnetworkhashps(request));
393  obj.pushKV("pooledtx", (uint64_t)mempool.size());
394  obj.pushKV("testnet", Params().IsTestnet());
395  obj.pushKV("chain", Params().NetworkIDString());
396  obj.pushKV("errors", GetWarnings("statusbar"));
397  if (IsDeprecatedRPCEnabled("getmininginfo")) {
398  obj.pushKV("errors", GetWarnings("statusbar"));
399  } else {
400  obj.pushKV("warnings", GetWarnings("statusbar"));
401  }
402 #ifdef ENABLE_WALLET
403  obj.pushKV("generate", getgenerate(request));
404  obj.pushKV("hashespersec", gethashespersec(request));
405 #endif
406  return obj;
407 }
408 #endif // ENABLE_MINING_RPC
409 
410 // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
412 {
413  if (request.fHelp || request.params.size() != 2)
414  throw std::runtime_error(
415  "prioritisetransaction \"txid\" priority_delta fee_delta\n"
416  "Accepts the transaction into mined blocks at a higher (or lower) priority\n"
417 
418  "\nArguments:\n"
419  "1. \"txid\" (string, required) The transaction id.\n"
420  "2. fee_delta (numeric, required) The fee value (in satoshis) to add (or subtract, if negative).\n"
421  " The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
422  " considers the transaction as it would have paid a higher (or lower) fee.\n"
423 
424  "\nResult\n"
425  "true (boolean) Returns true\n"
426 
427  "\nExamples:\n" +
428  HelpExampleCli("prioritisetransaction", "\"txid\" 10000") + HelpExampleRpc("prioritisetransaction", "\"txid\", 10000"));
429 
430  LOCK(cs_main);
431 
432  uint256 hash = ParseHashStr(request.params[0].get_str(), "txid");
433  CAmount nAmount = request.params[1].get_int64();
434 
435  mempool.PrioritiseTransaction(hash, nAmount);
436  return true;
437 }
438 
439 // NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
440 static UniValue BIP22ValidationResult(const CValidationState& state)
441 {
442  if (state.IsValid())
443  return NullUniValue;
444 
445  std::string strRejectReason = state.GetRejectReason();
446  if (state.IsError())
447  throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
448  if (state.IsInvalid()) {
449  if (strRejectReason.empty())
450  return "rejected";
451  return strRejectReason;
452  }
453  // Should be impossible
454  return "valid?";
455 }
456 
457 #ifdef ENABLE_MINING_RPC
458 UniValue getblocktemplate(const JSONRPCRequest& request)
459 {
460  CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
461 
462  if (request.fHelp || request.params.size() > 1)
463  throw std::runtime_error(
464  "getblocktemplate ( \"template_request\" )\n"
465  "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
466  "It returns data needed to construct a block to work on.\n"
467  "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
468 
469  "\nArguments:\n"
470  "1. template_request (json object, optional) A json object in the following spec\n"
471  " {\n"
472  " \"mode\":\"template\" (string, optional) This must be set to \"template\" or omitted\n"
473  " \"capabilities\":[ (array, optional) A list of strings\n"
474  " \"support\" (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'\n"
475  " ,...\n"
476  " ]\n"
477  " }\n"
478  "\n"
479 
480  "\nResult:\n"
481  "{\n"
482  " \"version\" : n, (numeric) The block version\n"
483  " \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n"
484  " \"transactions\" : [ (array) contents of non-coinbase transactions that should be included in the next block\n"
485  " {\n"
486  " \"data\" : \"xxxx\", (string) transaction data encoded in hexadecimal (byte-for-byte)\n"
487  " \"hash\" : \"xxxx\", (string) hash/id encoded in little-endian hexadecimal\n"
488  " \"depends\" : [ (array) array of numbers \n"
489  " 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"
490  " ,...\n"
491  " ],\n"
492  " \"fee\": n, (numeric) difference in value between transaction inputs and outputs (in upiv); 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"
493  " \"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"
494  " \"required\" : true|false (boolean) if provided and true, this transaction must be in the final block\n"
495  " }\n"
496  " ,...\n"
497  " ],\n"
498  " \"coinbaseaux\" : { (json object) data that should be included in the coinbase's scriptSig content\n"
499  " \"flags\" : \"flags\" (string) \n"
500  " },\n"
501  " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in upiv)\n"
502  " \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n"
503  " \"target\" : \"xxxx\", (string) The hash target\n"
504  " \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n"
505  " \"mutable\" : [ (array of string) list of ways the block template may be changed \n"
506  " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n"
507  " ,...\n"
508  " ],\n"
509  " \"noncerange\" : \"00000000ffffffff\", (string) A range of valid nonces\n"
510  " \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n"
511  " \"sizelimit\" : n, (numeric) limit of block size\n"
512  " \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
513  " \"bits\" : \"xxx\", (string) compressed target of next block\n"
514  " \"height\" : n (numeric) The height of the next block\n"
515  " \"payee\" : \"xxx\", (string) required payee for the next block\n"
516  " \"payee_amount\" : n, (numeric) required amount to pay\n"
517  " \"votes\" : [\n (array) show vote candidates\n"
518  " { ... } (json object) vote candidate\n"
519  " ,...\n"
520  " ],\n"
521  " \"enforce_masternode_payments\" : true|false (boolean) true, if masternode payments are enforced\n"
522  "}\n"
523 
524  "\nExamples:\n" +
525  HelpExampleCli("getblocktemplate", "") + HelpExampleRpc("getblocktemplate", ""));
526 
527  LOCK(cs_main);
528 
529  std::string strMode = "template";
530  UniValue lpval = NullUniValue;
531  if (request.params.size() > 0) {
532  const UniValue& oparam = request.params[0].get_obj();
533  const UniValue& modeval = find_value(oparam, "mode");
534  if (modeval.isStr())
535  strMode = modeval.get_str();
536  else if (modeval.isNull()) {
537  /* Do nothing */
538  } else
539  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
540  lpval = find_value(oparam, "longpollid");
541 
542  if (strMode == "proposal") {
543  const UniValue& dataval = find_value(oparam, "data");
544  if (!dataval.isStr())
545  throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");
546 
547  CBlock block;
548  if (!DecodeHexBlk(block, dataval.get_str()))
549  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
550 
551  uint256 hash = block.GetHash();
552  CBlockIndex* pindex = LookupBlockIndex(hash);
553  if (pindex) {
554  if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
555  return "duplicate";
556  if (pindex->nStatus & BLOCK_FAILED_MASK)
557  return "duplicate-invalid";
558  return "duplicate-inconclusive";
559  }
560 
561  CBlockIndex* const pindexPrev = chainActive.Tip();
562  // TestBlockValidity only supports blocks built on the current Tip
563  if (block.hashPrevBlock != pindexPrev->GetBlockHash())
564  return "inconclusive-not-best-prevblk";
565  CValidationState state;
566  TestBlockValidity(state, block, pindexPrev, false, true);
567  return BIP22ValidationResult(state);
568  }
569  }
570 
571  if (strMode != "template")
572  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
573 
574  if(!g_connman)
575  throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
576 
577  if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
578  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "PIVX is not connected!");
579 
581  throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "PIVX is downloading blocks...");
582 
583  static unsigned int nTransactionsUpdatedLast;
584 
585  if (!lpval.isNull()) {
586  // Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
587  uint256 hashWatchedChain;
589  unsigned int nTransactionsUpdatedLastLP;
590 
591  if (lpval.isStr()) {
592  // Format: <hashBestChain><nTransactionsUpdatedLast>
593  std::string lpstr = lpval.get_str();
594 
595  hashWatchedChain = ParseHashV(lpstr.substr(0, 64), "longpollid");
596  nTransactionsUpdatedLastLP = atoi64(lpstr.substr(64));
597  } else {
598  // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
599  hashWatchedChain = chainActive.Tip()->GetBlockHash();
600  nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
601  }
602 
603  // Release the wallet and main lock while waiting
605  {
606  checktxtime = std::chrono::steady_clock::now() + std::chrono::minutes(1);
607 
609  while (g_best_block == hashWatchedChain && IsRPCRunning()) {
610  if (g_best_block_cv.wait_until(lock, checktxtime) == std::cv_status::timeout)
611  {
612  // Timeout: Check transactions for update
613  if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
614  break;
615  checktxtime += std::chrono::seconds(10);
616  }
617  }
618  }
620 
621  if (!IsRPCRunning())
622  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
623  // TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
624  }
625 
626  // Update block
627  static CBlockIndex* pindexPrev;
628  static int64_t nStart;
629  static std::unique_ptr<CBlockTemplate> pblocktemplate;
630  if (pindexPrev != chainActive.Tip() ||
631  (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) {
632  // Clear pindexPrev so future calls make a new block, despite any failures from here on
633  pindexPrev = nullptr;
634 
635  // Store the chainActive.Tip() used before CreateNewBlock, to avoid races
636  nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
637  CBlockIndex* pindexPrevNew = chainActive.Tip();
638  nStart = GetTime();
639 
640  // Create new block
641  if (pblocktemplate) {
642  pblocktemplate.release();
643  pblocktemplate = nullptr;
644  }
645  CScript scriptDummy = CScript() << OP_TRUE;
646  pblocktemplate = BlockAssembler(Params(), DEFAULT_PRINTPRIORITY).CreateNewBlock(scriptDummy, pwallet, false);
647  if (!pblocktemplate)
648  throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
649 
650  // Need to update only after we know CreateNewBlock succeeded
651  pindexPrev = pindexPrevNew;
652  }
653  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
654 
655  // Update nTime
656  UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
657  pblock->nNonce = 0;
658 
659  UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
660 
661  UniValue transactions(UniValue::VARR);
662  std::map<uint256, int64_t> setTxIndex;
663  int i = 0;
664  for (const auto& txIn : pblock->vtx) {
665  const CTransaction& tx = *txIn;
666  const uint256& txHash = tx.GetHash();
667  setTxIndex[txHash] = i++;
668 
669  if (tx.IsCoinBase())
670  continue;
671 
672  UniValue entry(UniValue::VOBJ);
673 
674  entry.pushKV("data", EncodeHexTx(tx));
675 
676  entry.pushKV("hash", txHash.GetHex());
677 
678  UniValue deps(UniValue::VARR);
679  for (const CTxIn& in : tx.vin) {
680  if (setTxIndex.count(in.prevout.hash))
681  deps.push_back(setTxIndex[in.prevout.hash]);
682  }
683  entry.pushKV("depends", deps);
684 
685  int index_in_template = i - 1;
686  entry.pushKV("fee", pblocktemplate->vTxFees[index_in_template]);
687  entry.pushKV("sigops", pblocktemplate->vTxSigOps[index_in_template]);
688 
689  transactions.push_back(entry);
690  }
691 
693  aux.pushKV("flags", HexStr(COINBASE_FLAGS));
694 
695  arith_uint256& hashTarget = arith_uint256().SetCompact(pblock->nBits);
696 
697  static UniValue aMutable(UniValue::VARR);
698  if (aMutable.empty()) {
699  aMutable.push_back("time");
700  aMutable.push_back("transactions");
701  aMutable.push_back("prevblock");
702  }
703 
704  UniValue aVotes(UniValue::VARR);
705 
706  UniValue result(UniValue::VOBJ);
707  result.pushKV("capabilities", aCaps);
708  result.pushKV("version", pblock->nVersion);
709  result.pushKV("previousblockhash", pblock->hashPrevBlock.GetHex());
710  result.pushKV("transactions", transactions);
711  result.pushKV("coinbaseaux", aux);
712  result.pushKV("coinbasevalue", (int64_t)pblock->vtx[0]->GetValueOut());
713  result.pushKV("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast));
714  result.pushKV("target", hashTarget.GetHex());
715  result.pushKV("mintime", (int64_t)pindexPrev->GetMedianTimePast() + 1);
716  result.pushKV("mutable", aMutable);
717  result.pushKV("noncerange", "00000000ffffffff");
718 // result.pushKV("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS);
719 // result.pushKV("sizelimit", (int64_t)MAX_BLOCK_SIZE);
720  result.pushKV("curtime", pblock->GetBlockTime());
721  result.pushKV("bits", strprintf("%08x", pblock->nBits));
722  result.pushKV("height", (int64_t)(pindexPrev->nHeight + 1));
723  result.pushKV("votes", aVotes);
724  result.pushKV("enforce_masternode_payments", true);
725 
726  return result;
727 }
728 #endif // ENABLE_MINING_RPC
729 
731 {
732  if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
733  throw std::runtime_error(
734  "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n"
735  "\nAttempts to submit new block to network.\n"
736  "The 'jsonparametersobject' parameter is currently ignored.\n"
737  "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
738 
739  "\nArguments\n"
740  "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n"
741  "2. \"parameters\" (string, optional) object of optional parameters\n"
742  " {\n"
743  " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n"
744  " }\n"
745 
746  "\nResult:\n"
747 
748  "\nExamples:\n" +
749  HelpExampleCli("submitblock", "\"mydata\"") + HelpExampleRpc("submitblock", "\"mydata\""));
750 
751  std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
752  CBlock& block = *blockptr;
753  if (!DecodeHexBlk(block, request.params[0].get_str()))
754  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
755 
756  if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
757  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a coinbase");
758  }
759 
760  uint256 hash = block.GetHash();
761  bool fBlockPresent = false;
762  {
763  LOCK(cs_main);
764  CBlockIndex* pindex = LookupBlockIndex(hash);
765  if (pindex) {
766  if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
767  return "duplicate";
768  if (pindex->nStatus & BLOCK_FAILED_MASK)
769  return "duplicate-invalid";
770  // Otherwise, we might only have the header - process the block before returning
771  fBlockPresent = true;
772  }
773  }
774 
775  BlockStateCatcherWrapper sc(block.GetHash());
776  sc.registerEvent();
777  bool fAccepted = ProcessNewBlock(blockptr, nullptr);
778  if (fBlockPresent) {
779  if (fAccepted && !sc.get().found)
780  return "duplicate-inconclusive";
781  return "duplicate";
782  }
783  if (fAccepted) {
784  if (!sc.get().found)
785  return "inconclusive";
786  }
787  return BIP22ValidationResult(sc.get().state);
788 }
789 
791 {
792  if (request.fHelp || request.params.size() != 1)
793  throw std::runtime_error(
794  "estimatefee nblocks\n"
795  "\nEstimates the approximate fee per kilobyte\n"
796  "needed for a transaction to begin confirmation\n"
797  "within nblocks blocks.\n"
798 
799  "\nArguments:\n"
800  "1. nblocks (numeric)\n"
801 
802  "\nResult:\n"
803  "n : (numeric) estimated fee-per-kilobyte\n"
804  "\n"
805  "-1.0 is returned if not enough transactions and\n"
806  "blocks have been observed to make an estimate.\n"
807 
808  "\nExample:\n" +
809  HelpExampleCli("estimatefee", "6"));
810 
811  RPCTypeCheck(request.params, {UniValue::VNUM});
812 
813  int nBlocks = request.params[0].get_int();
814  if (nBlocks < 1)
815  nBlocks = 1;
816 
817  CFeeRate feeRate = mempool.estimateFee(nBlocks);
818  if (feeRate == CFeeRate(0))
819  return -1.0;
820 
821  return ValueFromAmount(feeRate.GetFeePerK());
822 }
823 
825 {
826  if (request.fHelp || request.params.size() != 1)
827  throw std::runtime_error(
828  "estimatesmartfee nblocks\n"
829  "\nDEPRECATED. WARNING: This interface is unstable and may disappear or change!\n"
830  "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
831  "confirmation within nblocks blocks if possible and return the number of blocks\n"
832  "for which the estimate is valid.\n"
833  "\nArguments:\n"
834  "1. nblocks (numeric)\n"
835  "\nResult:\n"
836  "{\n"
837  " \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n"
838  " \"blocks\" : n (numeric) block number where estimate was found\n"
839  "}\n"
840  "\n"
841  "A negative value is returned if not enough transactions and blocks\n"
842  "have been observed to make an estimate for any number of blocks.\n"
843  "However it will not return a value below the mempool reject fee.\n"
844  "\nExample:\n"
845  + HelpExampleCli("estimatesmartfee", "6")
846  );
847 
848  RPCTypeCheck(request.params, {UniValue::VNUM});
849 
850  int nBlocks = request.params[0].get_int();
851 
852  UniValue result(UniValue::VOBJ);
853  int answerFound;
854  CFeeRate feeRate = mempool.estimateSmartFee(nBlocks, &answerFound);
855  result.pushKV("feerate", feeRate == CFeeRate(0) ? -1.0 : ValueFromAmount(feeRate.GetFeePerK()));
856  result.pushKV("blocks", answerFound);
857  return result;
858 }
859 
860 // clang-format off
861 static const CRPCCommand commands[] =
862 { // category name actor (function) okSafe argNames
863  // --------------------- ------------------------ ----------------------- ------ --------
864  { "util", "estimatefee", &estimatefee, true, {"nblocks"} },
865  { "util", "estimatesmartfee", &estimatesmartfee, true, {"nblocks"} },
866  { "mining", "prioritisetransaction", &prioritisetransaction, true, {"txid","priority_delta","fee_delta"} },
867 
869 #ifdef ENABLE_WALLET
870  { "hidden", "generate", &generate, true, {"nblocks"} },
871  { "hidden", "generatetoaddress", &generatetoaddress, true, {"nblocks","address"} },
872 #endif
873  { "hidden", "submitblock", &submitblock, true, {"hexdata","parameters"} },
874 #ifdef ENABLE_MINING_RPC
875  { "hidden", "getblocktemplate", &getblocktemplate, true, {"template_request"} },
876  { "hidden", "getnetworkhashps", &getnetworkhashps, true, {"nblocks","height"} },
877  { "hidden", "getmininginfo", &getmininginfo, true, {} },
878 #ifdef ENABLE_WALLET
879  { "hidden", "getgenerate", &getgenerate, true, {} },
880  { "hidden", "gethashespersec", &gethashespersec, true, {} },
881  { "hidden", "setgenerate", &setgenerate, true, {"generate","genproclimit"} },
882 #endif // ENABLE_WALLET
883 #endif // ENABLE_MINING_RPC
884 
885 };
886 // clang-format on
887 
889 {
890  for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
891  tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
892 }
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
uint64_t nLastBlockTx
bool SolveBlock(std::shared_ptr< CBlock > &pblock, int nHeight)
Modify the nonce/extranonce in a block.
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev)
uint64_t nLastBlockSize
double GetDifficulty(const CBlockIndex *blockindex)
Definition: blockchain.cpp:67
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:110
@ BLOCK_FAILED_MASK
descends from failed block
Definition: chain.h:123
const CChainParams & Params()
Return the currently selected parameters.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:449
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:465
uint256 hash
Definition: transaction.h:35
Generate a new block.
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn, CWallet *pwallet=nullptr, bool fProofOfStake=false, std::vector< CStakeableOutput > *availableCoins=nullptr, bool fNoMempoolTx=false, bool fTestValidity=true, CBlockIndex *prevBlock=nullptr, bool stopPoSOnNewBlock=true, bool fIncludeQfc=true)
Construct a new block template with coinbase to scriptPubKeyIn.
CValidationState state
BlockStateCatcher & get() const
uint32_t nNonce
Definition: block.h:32
uint32_t nBits
Definition: block.h:31
int64_t GetBlockTime() const
Definition: block.h:72
int32_t nVersion
Definition: block.h:27
uint256 hashPrevBlock
Definition: block.h:28
uint256 GetHash() const
Definition: block.cpp:15
Definition: block.h:80
std::vector< CTransactionRef > vtx
Definition: block.h:83
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:145
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: chain.h:163
uint256 GetBlockHash() const
Definition: chain.h:215
int64_t GetBlockTime() const
Definition: chain.h:216
int64_t GetMedianTimePast() const
Definition: chain.cpp:204
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.cpp:313
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:151
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:175
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:405
int Height() const
Return the maximal height in the chain.
Definition: chain.h:450
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:72
@ CONNECTIONS_ALL
Definition: net.h:152
Fee rate in PIV per kilobyte: CAmount / kB.
Definition: feerate.h:20
CAmount GetFeePerK() const
Definition: feerate.h:29
An encapsulated public key.
Definition: pubkey.h:44
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Definition: pubkey.h:167
std::string name
Definition: server.h:137
PIVX RPC command dispatcher.
Definition: server.h:147
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:314
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:244
std::vector< CTxIn > vin
Definition: transaction.h:270
const uint256 & GetHash() const
Definition: transaction.h:301
bool IsCoinBase() const
Definition: transaction.h:376
An input of a transaction.
Definition: transaction.h:94
COutPoint prevout
Definition: transaction.h:96
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:1243
CFeeRate estimateFee(int nBlocks) const
Estimate fee rate needed to get into the next nBlocks.
Definition: txmempool.cpp:1200
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=nullptr) const
Estimate fee rate needed to get into the next nBlocks If no answer can be given at nBlocks,...
Definition: txmempool.cpp:1206
unsigned long size() const
Definition: txmempool.h:629
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:351
Capture information about block/transaction validation.
Definition: validation.h:24
bool IsValid() const
Definition: validation.h:69
std::string GetRejectReason() const
Definition: validation.h:94
bool IsInvalid() const
Definition: validation.h:73
bool IsError() const
Definition: validation.h:77
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
UniValue params
Definition: server.h:47
bool fHelp
Definition: server.h:48
const std::string & get_str() const
@ VOBJ
Definition: univalue.h:21
@ VARR
Definition: univalue.h:21
int64_t get_int64() const
bool isNull() const
Definition: univalue.h:77
const UniValue & get_obj() const
size_t size() const
Definition: univalue.h:68
bool isStr() const
Definition: univalue.h:81
bool push_back(const UniValue &val)
Definition: univalue.cpp:108
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
bool get_bool() const
int get_int() const
256-bit unsigned big integer.
arith_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...
std::string GetHex() const
Definition: uint256.cpp:21
double getdouble() const
std::string GetHex() const
256-bit opaque blob.
Definition: uint256.h:138
std::string EncodeHexTx(const CTransaction &tx)
Definition: core_write.cpp:116
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
Definition: core_read.cpp:93
uint256 ParseHashStr(const std::string &, const std::string &strName)
Definition: core_read.cpp:117
bool StakeableCoins(std::vector< CStakeableOutput > *pCoins=nullptr)
Available coins (staking)
Definition: wallet.cpp:2709
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:90
@ LOCK
Definition: lockunlock.h:16
double dHashesPerSec
int64_t nHPSTimerStart
void RegisterMiningRPCCommands(CRPCTable &tableRPC)
Register mining RPC commands.
Definition: mining.cpp:888
UniValue estimatesmartfee(const JSONRPCRequest &request)
Definition: mining.cpp:824
UniValue prioritisetransaction(const JSONRPCRequest &request)
Definition: mining.cpp:411
UniValue estimatefee(const JSONRPCRequest &request)
Definition: mining.cpp:790
UniValue submitblock(const JSONRPCRequest &request)
Definition: mining.cpp:730
@ UPGRADE_POS
Definition: params.h:28
bool IsValidDestination(const CWDestination &address)
CWDestination DecodeDestination(const std::string &strAddress)
clock::time_point time_point
Definition: bench.h:48
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:80
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:53
@ RPC_OUT_OF_MEMORY
Invalid address or key.
Definition: protocol.h:45
@ RPC_WALLET_INSUFFICIENT_FUNDS
Unspecified problem with wallet (key not found etc.)
Definition: protocol.h:71
@ RPC_METHOD_NOT_FOUND
Definition: protocol.h:35
@ RPC_TYPE_ERROR
Server is in safe mode, and command is not allowed in safe mode.
Definition: protocol.h:43
@ RPC_CLIENT_NOT_CONNECTED
P2P client errors.
Definition: protocol.h:61
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
Definition: protocol.h:46
@ RPC_VERIFY_ERROR
Error parsing or validating structure in raw format.
Definition: protocol.h:49
@ RPC_INTERNAL_ERROR
Definition: protocol.h:37
@ RPC_CLIENT_IN_INITIAL_DOWNLOAD
PIVX is not connected.
Definition: protocol.h:62
@ RPC_DESERIALIZATION_ERROR
Database error.
Definition: protocol.h:48
@ RPC_INVALID_REQUEST
Standard JSON-RPC 2.0 errors.
Definition: protocol.h:34
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
Definition: protocol.h:44
@ RPC_CLIENT_P2P_DISABLED
Invalid IP/Subnet.
Definition: protocol.h:67
CWallet * GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
Definition: rpcwallet.cpp:39
void EnsureWalletIsUnlocked(CWallet *const pwallet, bool fAllowAnonOnly)
Definition: rpcwallet.cpp:71
bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException)
Definition: rpcwallet.cpp:59
@ OP_TRUE
Definition: script.h:60
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:407
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:128
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:351
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:527
void RPCTypeCheck(const UniValue &params, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:63
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:138
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:532
CRPCTable tableRPC
Definition: server.cpp:565
bool ShutdownRequested()
Definition: shutdown.cpp:22
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
Definition: standard.cpp:278
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:72
Parameters that influence chain consensus.
Definition: params.h:171
bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const
Returns true if the given network upgrade is active as of the given block height.
Definition: params.cpp:12
#define WAIT_LOCK(cs, name)
Definition: sync.h:225
#define ENTER_CRITICAL_SECTION(cs)
Definition: sync.h:227
#define LEAVE_CRITICAL_SECTION(cs)
Definition: sync.h:233
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:247
ArgsManager gArgs
Definition: system.cpp:89
#define strprintf
Definition: tinyformat.h:1056
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:234
const UniValue NullUniValue
Definition: univalue.cpp:13
bool NetworkUpgradeActive(int nHeight, const Consensus::Params &params, Consensus::UpgradeIndex idx)
Returns true if the given network upgrade is active as of the given block height.
Definition: upgrades.cpp:107
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
int64_t atoi64(const char *psz)
std::string itostr(int n)
std::string i64tostr(int64_t n)
#define ARRAYLEN(array)
int64_t GetTimeMillis()
Returns the system time (not mockable)
Definition: utiltime.cpp:61
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
Definition: utiltime.cpp:27
std::condition_variable g_best_block_cv
Definition: validation.cpp:89
CTxMemPool mempool(::minRelayTxFee)
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: validation.cpp:119
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network)
Definition: validation.cpp:862
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
Process an incoming block.
Mutex g_best_block_mutex
Definition: validation.cpp:88
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:84
bool TestBlockValidity(CValidationState &state, const CBlock &block, CBlockIndex *const pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckBlockSig)
Check a block is completely valid from start to finish (only works on top of our current best block,...
uint256 g_best_block
Definition: validation.cpp:90
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:345
std::string GetWarnings(const std::string &strFor)
Definition: warnings.cpp:47