41 #include <condition_variable> 66 "Mempool disabled or instance not found");
85 int nShift = (blockindex->
nBits >> 24) & 0xff;
86 double dDiff = double(0x0000ffff) / double(blockindex->
nBits & 0x00ffffff);
104 if (next && next->
pprev == blockindex) {
108 return blockindex == tip ? 1 : -1;
122 result.
pushKV(
"confirmations", confirmations);
133 result.
pushKV(
"nTx", uint64_t(blockindex->
nTx));
135 if (blockindex->
pprev) {
136 result.
pushKV(
"previousblockhash",
156 result.
pushKV(
"confirmations", confirmations);
163 for (
const auto &tx : block.
vtx) {
179 result.
pushKV(
"nTx", uint64_t(blockindex->
nTx));
181 if (blockindex->
pprev) {
182 result.
pushKV(
"previousblockhash",
195 "\nReturns the height of the most-work fully-validated chain.\n" 196 "The genesis block has height 0.\n",
212 "Returns the hash of the best (tip) block in the " 213 "most-work fully-validated chain.\n",
228 "getfinalizedblockhash",
229 "Returns the hash of the currently finalized block\n",
240 if (blockIndexFinalized) {
248 LOCK(cs_blockchange);
250 latestblock.height = pindex->
nHeight;
259 "Waits for a specific new block and returns useful info about it.\n" 260 "\nReturns the current block on timeout or exit.\n",
263 "Time in milliseconds to wait for a response. 0 indicates no " 289 lock, std::chrono::milliseconds(timeout),
291 return latestblock.height != block.
height ||
297 return latestblock.height != block.
height ||
313 "Waits for a specific new block and returns useful info about it.\n" 314 "\nReturns the current block on timeout or exit.\n",
317 "Block hash to wait for."},
319 "Time in milliseconds to wait for a response. 0 indicates no " 330 "\"0000000000079f8ef3d2c688c244eb7a4570b24c9" 331 "ed7b4a8c619eb02596f8862\" 1000") +
333 "\"0000000000079f8ef3d2c688c244eb7a4570b24c9" 334 "ed7b4a8c619eb02596f8862\", 1000")},
351 lock, std::chrono::milliseconds(timeout),
373 "waitforblockheight",
374 "Waits for (at least) block height and returns the height and " 375 "hash\nof the current tip.\n" 376 "\nReturns the current block on timeout or exit.\n",
379 "Block height to wait for."},
381 "Time in milliseconds to wait for a response. 0 indicates no " 409 lock, std::chrono::milliseconds(timeout),
431 "syncwithvalidationinterfacequeue",
432 "Waits for the validation interface queue to catch up on everything " 433 "that was there when we entered this function.\n",
449 "Returns the proof-of-work difficulty as a multiple of the minimum " 453 "the proof-of-work difficulty as a multiple of the minimum " 470 "transaction fee with fee deltas used for mining priority " 473 "local time transaction entered pool in seconds since 1 Jan " 476 "block height when transaction entered pool"},
478 "number of in-mempool descendant transactions (including " 481 "transaction size of in-mempool descendants " 482 "(including this one)"},
484 "modified fees (see above) of in-mempool descendants " 485 "(including this one) (DEPRECATED)"},
488 "number of in-mempool ancestor transactions (including this one)"},
491 "transaction size of in-mempool ancestors (including this one)"},
493 "modified fees (see above) of in-mempool ancestors " 494 "(including this one) (DEPRECATED)"},
500 "transaction fee in " + CURRENCY_UNIT},
502 "transaction fee with fee deltas used for " 503 "mining priority in " +
506 "modified fees (see above) of in-mempool " 507 "ancestors (including this one) in " +
510 "modified fees (see above) of in-mempool " 511 "descendants (including this one) in " +
517 "unconfirmed transactions used as inputs for this transaction",
519 "parent transaction id"}}},
523 "unconfirmed transactions spending outputs from this transaction",
525 "child transaction id"}}},
539 info.pushKV(
"fees", fees);
541 info.pushKV(
"size", (
int)e.GetTxSize());
545 info.pushKV(
"height", (
int)e.GetHeight());
546 info.pushKV(
"descendantcount", e.GetCountWithDescendants());
547 info.pushKV(
"descendantsize", e.GetSizeWithDescendants());
548 info.pushKV(
"descendantfees", e.GetModFeesWithDescendants() /
SATOSHI);
549 info.pushKV(
"ancestorcount", e.GetCountWithAncestors());
550 info.pushKV(
"ancestorsize", e.GetSizeWithAncestors());
551 info.pushKV(
"ancestorfees", e.GetModFeesWithAncestors() /
SATOSHI);
553 std::set<std::string> setDepends;
561 for (
const std::string &dep : setDepends) {
565 info.pushKV(
"depends", depends);
571 spent.
push_back(childiter->GetTx().GetId().ToString());
574 info.pushKV(
"spentby", spent);
592 std::vector<uint256> vtxids;
596 for (
const uint256 &txid : vtxids) {
608 "Returns all transaction ids in memory pool as a json array of " 609 "string transaction ids.\n" 610 "\nHint: use getmempoolentry to fetch a specific transaction from the " 614 "True for a json object, false for array of transaction ids"},
638 bool fVerbose =
false;
649 "getmempoolancestors",
650 "If txid is in the mempool, returns all in-mempool ancestors.\n",
653 "The transaction id (must be in mempool)"},
655 "True for a json object, false for array of transaction ids"},
659 "for verbose = false",
664 "The transaction id of an in-mempool ancestor transaction"}}},
673 bool fVerbose =
false;
684 if (it == mempool.mapTx.end()) {
686 "Transaction not in mempool");
690 uint64_t noLimit = std::numeric_limits<uint64_t>::max();
693 noLimit, noLimit, dummy,
false);
698 o.
push_back(ancestorIt->GetTx().GetId().ToString());
718 "getmempooldescendants",
719 "If txid is in the mempool, returns all in-mempool descendants.\n",
722 "The transaction id (must be in mempool)"},
724 "True for a json object, false for array of transaction ids"},
732 "The transaction id of an in-mempool descendant " 748 bool fVerbose =
false;
759 if (it == mempool.mapTx.end()) {
761 "Transaction not in mempool");
767 setDescendants.erase(it);
772 o.
push_back(descendantIt->GetTx().GetId().ToString());
793 "Returns mempool data for given transaction\n",
796 "The transaction id (must be in mempool)"},
810 if (it == mempool.mapTx.end()) {
812 "Transaction not in mempool");
825 "Returns hash of block in best-block-chain at height provided.\n",
851 "If verbose is false, returns a string that is serialized, hex-encoded " 852 "data for blockheader 'hash'.\n" 853 "If verbose is true, returns an Object with information about " 854 "blockheader <hash>.\n",
859 "true for a json object, false for the hex-encoded data"},
863 "for verbose = true",
869 "the block hash (same as provided)"},
871 "The number of confirmations, or -1 if the block is not " 872 "on the main chain"},
874 "The block height or index"},
877 "The block version formatted in hexadecimal"},
882 "The median block time expressed in " + UNIX_EPOCH_TIME},
887 "Expected number of hashes required to produce the " 890 "The number of transactions in the block"},
892 "The hash of the previous block"},
894 "The hash of the next block"},
897 "A string that is serialized, hex-encoded data for block " 901 "\"00000000c937983704a73af28acdec37b049d214a" 902 "dbda81d7e2a3dd146f6ed09\"") +
904 "\"00000000c937983704a73af28acdec37b049d214a" 905 "dbda81d7e2a3dd146f6ed09\"")},
911 bool fVerbose =
true;
961 "Undo data not available (pruned data)");
974 "If verbosity is 0 or false, returns a string that is serialized, " 975 "hex-encoded data for block 'hash'.\n" 976 "If verbosity is 1 or true, returns an Object with information about " 978 "If verbosity is 2, returns an Object with information about block " 979 "<hash> and information about each transaction.\n",
984 "0 for hex-encoded data, 1 for a json object, and 2 for json " 985 "object with transaction data"},
989 "A string that is serialized, hex-encoded data for block " 998 "the block hash (same as provided)"},
1000 "The number of confirmations, or -1 if the block is not " 1001 "on the main chain"},
1004 "The block height or index"},
1007 "The block version formatted in hexadecimal"},
1011 "The transaction ids",
1016 "The median block time expressed in " + UNIX_EPOCH_TIME},
1021 "Expected number of hashes required to produce the chain " 1022 "up to this block (in hex)"},
1024 "The number of transactions in the block"},
1026 "The hash of the previous block"},
1028 "The hash of the next block"},
1036 "Same output as verbosity = 1"},
1046 "The transactions in the format of the " 1047 "getrawtransaction RPC. Different from " 1048 "verbosity = 1 \"tx\" result"},
1052 "Same output as verbosity = 1"},
1056 HelpExampleCli(
"getblock",
"\"00000000c937983704a73af28acdec37b049d" 1057 "214adbda81d7e2a3dd146f6ed09\"") +
1058 HelpExampleRpc(
"getblock",
"\"00000000c937983704a73af28acdec37b049d" 1059 "214adbda81d7e2a3dd146f6ed09\"")},
1089 if (verbosity <= 0) {
1097 return blockToJSON(block, tip, pblockindex, verbosity >= 2);
1107 "The block height to prune up to. May be set to a discrete " 1108 "height, or to a " +
1111 " to prune blocks whose block time is at " 1112 "least 2 hours older than the provided timestamp."},
1123 "Cannot prune blocks because node is not in prune mode.");
1129 if (heightParam < 0) {
1135 if (heightParam > 1000000000) {
1143 "Could not find block with at least the specified timestamp.");
1145 heightParam = pindex->
nHeight;
1148 unsigned int height = (
unsigned int)heightParam;
1152 "Blockchain is too short for pruning.");
1153 }
else if (height > chainHeight) {
1156 "Blockchain is shorter than the attempted prune height.");
1159 "Retaining the minimum number of blocks.\n");
1167 block = block->
pprev;
1169 return uint64_t(block->
nHeight);
1176 "Returns statistics about the unspent transaction output set.\n" 1177 "Note this call may take some time.\n",
1184 "The current block height (index)"},
1186 "The hash of the block at the tip of the chain"},
1188 "The number of transactions with unspent outputs"},
1190 "The number of unspent transaction outputs"},
1192 "A meaningless metric for UTXO set size"},
1194 "The serialized hash"},
1196 "The estimated size of the chainstate on disk"},
1198 "The total amount"},
1231 "Returns details about an unspent transaction output.\n",
1234 "The transaction id"},
1237 "Whether to include the mempool. Note that an unspent output that " 1238 "is spent in the mempool won't appear."},
1246 "The hash of the block at the tip of the chain"},
1248 "The number of confirmations"},
1258 "Number of required signatures"},
1260 "The type, eg pubkeyhash"},
1263 "array of bitcoin addresses",
1271 "\nAs a JSON-RPC call\n" +
1283 bool fMempool =
true;
1299 if (!coins_view->
GetCoin(out, coin)) {
1307 ret.
pushKV(
"confirmations", 0);
1309 ret.
pushKV(
"confirmations",
1315 ret.
pushKV(
"scriptPubKey", o);
1325 "Verifies blockchain database.\n",
1329 "How thorough the block verification is."},
1332 "The number of blocks to check."},
1350 check_level, check_depth);
1362 if (consensusParams.vDeployments[
id].nTimeout <= 1230768000) {
1369 switch (thresholdState) {
1371 bip9.
pushKV(
"status",
"defined");
1374 bip9.
pushKV(
"status",
"started");
1377 bip9.
pushKV(
"status",
"locked_in");
1380 bip9.
pushKV(
"status",
"active");
1383 bip9.
pushKV(
"status",
"failed");
1387 bip9.
pushKV(
"bit", consensusParams.vDeployments[
id].bit);
1389 bip9.
pushKV(
"start_time", consensusParams.vDeployments[
id].nStartTime);
1390 bip9.
pushKV(
"timeout", consensusParams.vDeployments[
id].nTimeout);
1392 bip9.
pushKV(
"since", since_height);
1401 bip9.
pushKV(
"statistics", statsUV);
1405 rv.
pushKV(
"type",
"bip9");
1408 rv.
pushKV(
"height", since_height);
1418 "getblockchaininfo",
1419 "Returns an object containing various state info regarding blockchain " 1428 "current network name (main, test, regtest)"},
1430 "the height of the most-work fully-validated chain. The " 1431 "genesis block has height 0"},
1433 "the current number of headers we have validated"},
1435 "the hash of the currently best block"},
1438 "median time for the current best block"},
1440 "estimate of verification progress [0..1]"},
1442 "(debug information) estimate of whether this node is in " 1443 "Initial Block Download mode"},
1445 "total amount of work in active chain, in hexadecimal"},
1447 "the estimated size of the block and undo files on disk"},
1449 "if the blocks are subject to pruning"},
1451 "lowest-height complete block stored (only present if pruning " 1454 "whether automatic pruning is enabled (only present if " 1455 "pruning is enabled)"},
1457 "the target size used by pruning (only present if automatic " 1458 "pruning is enabled)"},
1461 "status of softforks",
1465 "name of the softfork",
1468 "one of \"buried\", \"bip9\""},
1471 "status of bip9 softforks (only for \"bip9\" type)",
1474 "one of \"defined\", \"started\", " 1475 "\"locked_in\", \"active\", \"failed\""},
1477 "the bit (0-28) in the block version field " 1478 "used to signal this softfork (only for " 1479 "\"started\" status)"},
1481 "the minimum median time past of a block at " 1482 "which the bit gains its meaning"},
1484 "the median time past of a block at which the " 1485 "deployment is considered failed if not yet " 1488 "height of the first block to which the status " 1492 "numeric statistics about BIP9 signalling for " 1496 "the length in blocks of the BIP9 " 1497 "signalling period"},
1499 "the number of blocks with the version " 1500 "bit set required to activate the " 1503 "the number of blocks elapsed since the " 1504 "beginning of the current period"},
1506 "the number of blocks with the version " 1507 "bit set in the current period"},
1509 "returns false if there are not enough " 1510 "blocks left in this period to pass " 1511 "activation threshold"},
1515 "height of the first block which the rules are or " 1516 "will be enforced (only for \"buried\" type, or " 1517 "\"bip9\" type with \"active\" status)"},
1519 "true if the rules are enforced for the mempool and " 1524 "any network and blockchain warnings"},
1543 obj.
pushKV(
"verificationprogress",
1545 obj.
pushKV(
"initialblockdownload",
1555 block = block->
pprev;
1561 bool automatic_pruning = (
gArgs.
GetArg(
"-prune", 0) != 1);
1562 obj.
pushKV(
"automatic_pruning", automatic_pruning);
1563 if (automatic_pruning) {
1573 obj.
pushKV(
"softforks", softforks);
1596 "Return information about all known tips in the block tree, including " 1597 "the main chain as well as orphaned branches.\n",
1610 "zero for main chain, otherwise length of branch connecting " 1611 "the tip to the main chain"},
1613 "status of the chain, \"active\" for the main chain\n" 1614 "Possible values for status:\n" 1615 "1. \"invalid\" This branch contains at " 1616 "least one invalid block\n" 1617 "2. \"parked\" This branch contains at " 1618 "least one parked block\n" 1619 "3. \"headers-only\" Not all blocks for this " 1620 "branch are available, but the headers are valid\n" 1621 "4. \"valid-headers\" All blocks are available for " 1622 "this branch, but they were never fully validated\n" 1623 "5. \"valid-fork\" This branch is not part of " 1624 "the active chain, but is fully validated\n" 1625 "6. \"active\" This is the tip of the " 1626 "active main chain, which is certainly valid"},
1644 std::set<const CBlockIndex *, CompareBlocksByHeight> setTips;
1645 std::set<const CBlockIndex *> setOrphans;
1646 std::set<const CBlockIndex *> setPrevs;
1648 for (
const std::pair<const BlockHash, CBlockIndex *> &item :
1651 setOrphans.insert(item.second);
1652 setPrevs.insert(item.second->pprev);
1656 for (std::set<const CBlockIndex *>::iterator it = setOrphans.begin();
1657 it != setOrphans.end(); ++it) {
1658 if (setPrevs.erase(*it) == 0) {
1659 setTips.insert(*it);
1670 obj.
pushKV(
"height", block->nHeight);
1671 obj.
pushKV(
"hash", block->phashBlock->GetHex());
1673 const int branchLen =
1675 obj.
pushKV(
"branchlen", branchLen);
1681 }
else if (block->nStatus.isInvalid()) {
1684 }
else if (block->nStatus.isOnParkedChain()) {
1687 }
else if (!block->HaveTxsDownloaded()) {
1690 status =
"headers-only";
1695 status =
"valid-fork";
1699 status =
"valid-headers";
1704 obj.
pushKV(
"status", status);
1722 ret.
pushKV(
"maxmempool", (int64_t)maxmempool);
1736 "Returns details on the active state of the TX memory pool.\n",
1744 "True if the mempool is fully loaded"},
1748 "Total memory usage for the mempool"},
1750 "Maximum memory usage for the mempool"},
1753 "/kB for tx to be accepted. Is the maximum of " 1754 "minrelaytxfee and minimum mempool fee"},
1756 "Current minimum relay fee for transactions"},
1770 "Treats a block as if it were received before others with the same " 1772 "\nA later preciousblock call can override the effect of an earlier " 1774 "\nThe effects of preciousblock are not retained across restarts.\n",
1777 "the hash of the block to mark as precious"},
1809 "Treats a block as final. It cannot be reorged. Any chain\n" 1810 "that does not contain this block is invalid. Used on a less\n" 1811 "work chain, it can effectively PUT YOU OUT OF CONSENSUS.\n" 1812 "USE WITH CAUTION!\n",
1815 "the hash of the block to mark as invalid"},
1853 "Permanently marks a block as invalid, as if it violated a consensus " 1857 "the hash of the block to mark as invalid"},
1892 "Marks a block as parked.\n",
1895 "the hash of the block to park"},
1932 "Removes invalidity status of a block, its ancestors and its" 1933 "descendants, reconsider them for activation.\n" 1934 "This can be used to undo the effects of invalidateblock.\n",
1937 "the hash of the block to reconsider"},
1970 "Removes parked status of a block and its descendants, reconsider " 1971 "them for activation.\n" 1972 "This can be used to undo the effects of parkblock.\n",
1975 "the hash of the block to unpark"},
2011 "Compute statistics about the total number and rate of transactions " 2015 "Size of the window in number of blocks"},
2017 "The hash of the block that ends the window."},
2024 "The timestamp for the final block in the window, " 2028 "The total number of transactions in the chain up to " 2031 "The hash of the final block in the window"},
2033 "The height of the final block in the window."},
2035 "Size of the window in number of blocks"},
2037 "The number of transactions in the window. Only " 2038 "returned if \"window_block_count\" is > 0"},
2040 "The elapsed time in the window in seconds. Only " 2041 "returned if \"window_block_count\" is > 0"},
2043 "The average rate of transactions per second in the " 2044 "window. Only returned if \"window_interval\" is > 0"},
2054 int blockcount = 30 * 24 * 60 * 60 /
2069 "Block is not in main chain");
2076 blockcount = std::max(0, std::min(blockcount, pindex->
nHeight - 1));
2080 if (blockcount < 0 ||
2081 (blockcount > 0 && blockcount >= pindex->
nHeight)) {
2083 "should be between 0 and " 2084 "the block's height - 1");
2099 ret.
pushKV(
"window_block_count", blockcount);
2100 if (blockcount > 0) {
2101 ret.
pushKV(
"window_tx_count", nTxDiff);
2102 ret.
pushKV(
"window_interval", nTimeDiff);
2103 if (nTimeDiff > 0) {
2104 ret.
pushKV(
"txrate",
double(nTxDiff) / nTimeDiff);
2111 template <
typename T>
2113 size_t size = scores.size();
2118 std::sort(scores.begin(), scores.end());
2119 if (size % 2 == 0) {
2120 return (scores[size / 2 - 1] + scores[size / 2]) / 2;
2122 return scores[size / 2];
2126 template <
typename T>
static inline bool SetHasKeys(
const std::set<T> &
set) {
2129 template <
typename T,
typename Tk,
typename... Args>
2130 static inline bool SetHasKeys(
const std::set<T> &
set,
const Tk &key,
2131 const Args &... args) {
2137 sizeof(
COutPoint) +
sizeof(uint32_t) +
sizeof(bool);
2143 "Compute per block statistics for a given window. All amounts are " 2147 "It won't work for some heights with pruning.\n",
2152 "The block hash or height of the target block",
2154 {
"",
"string or numeric"}},
2158 "Values to plot (see result below)",
2161 "Selected statistic"},
2163 "Selected statistic"},
2174 "Average feerate (in satoshis per virtual byte)"},
2177 "The block hash (to check for potential reorgs)"},
2180 "The number of inputs (excluding coinbase)"},
2183 "Maximum feerate (in satoshis per virtual byte)"},
2186 "Truncated median fee in the block"},
2191 "The block median time past"},
2193 "Truncated median transaction size"},
2196 "Minimum feerate (in satoshis per virtual byte)"},
2202 "Total amount in all outputs (excluding coinbase and thus " 2203 "reward [ie subsidy + totalfee])"},
2205 "Total size of all non-coinbase transactions"},
2208 "The number of transactions (excluding coinbase)"},
2210 "The increase/decrease in the number of unspent outputs"},
2212 "The increase/decrease in size for the utxo index (not " 2213 "discounting op_return and similar)"},
2218 R
"('"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"' '["minfeerate","avgfeerate"]')") + 2220 R
"(1000 '["minfeerate","avgfeerate"]')") + 2223 R
"("00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09", ["minfeerate","avgfeerate"])") + 2225 R
"(1000, ["minfeerate","avgfeerate"])")}, 2238 strprintf(
"Target block height %d is negative", height));
2240 if (height > current_tip) {
2243 strprintf(
"Target block height %d after current tip %d", height,
2257 Params().NetworkIDString()));
2263 std::set<std::string> stats;
2266 for (
unsigned int i = 0; i < stats_univalue.
size(); i++) {
2267 const std::string stat = stats_univalue[i].
get_str();
2276 const bool do_all = stats.size() == 0;
2277 const bool do_mediantxsize = do_all || stats.count(
"mediantxsize") != 0;
2278 const bool do_medianfee = do_all || stats.count(
"medianfee") != 0;
2279 const bool do_medianfeerate = do_all || stats.count(
"medianfeerate") != 0;
2280 const bool loop_inputs =
2281 do_all || do_medianfee || do_medianfeerate ||
2282 SetHasKeys(stats,
"utxo_size_inc",
"totalfee",
"avgfee",
"avgfeerate",
2283 "minfee",
"maxfee",
"minfeerate",
"maxfeerate");
2284 const bool loop_outputs = do_all || loop_inputs || stats.count(
"total_out");
2285 const bool do_calculate_size =
2286 do_mediantxsize || loop_inputs ||
2287 SetHasKeys(stats,
"total_size",
"avgtxsize",
"mintxsize",
"maxtxsize");
2297 int64_t maxtxsize = 0;
2298 int64_t mintxsize = blockMaxSize;
2299 int64_t outputs = 0;
2300 int64_t total_size = 0;
2301 int64_t utxo_size_inc = 0;
2302 std::vector<Amount> fee_array;
2303 std::vector<Amount> feerate_array;
2304 std::vector<int64_t> txsize_array;
2306 for (
size_t i = 0; i < block.
vtx.size(); ++i) {
2307 const auto &tx = block.
vtx.at(i);
2308 outputs += tx->vout.size();
2311 for (
const CTxOut &out : tx->vout) {
2312 tx_total_out += out.
nValue;
2318 if (tx->IsCoinBase()) {
2323 inputs += tx->vin.size();
2325 total_out += tx_total_out;
2327 int64_t tx_size = 0;
2328 if (do_calculate_size) {
2329 tx_size = tx->GetTotalSize();
2330 if (do_mediantxsize) {
2331 txsize_array.push_back(tx_size);
2333 maxtxsize = std::max(maxtxsize, tx_size);
2334 mintxsize = std::min(mintxsize, tx_size);
2335 total_size += tx_size;
2340 const auto &txundo = blockUndo.
vtxundo.at(i - 1);
2341 for (
const Coin &coin : txundo.vprevout) {
2344 tx_total_in += prevoutput.
nValue;
2350 Amount txfee = tx_total_in - tx_total_out;
2353 fee_array.push_back(txfee);
2355 maxfee = std::max(maxfee, txfee);
2356 minfee = std::min(minfee, txfee);
2359 Amount feerate = txfee / tx_size;
2360 if (do_medianfeerate) {
2361 feerate_array.push_back(feerate);
2363 maxfeerate = std::max(maxfeerate, feerate);
2364 minfeerate = std::min(minfeerate, feerate);
2371 ? totalfee /
int((block.
vtx.size() - 1))
2373 ret_all.
pushKV(
"avgfeerate",
2376 ret_all.
pushKV(
"avgtxsize", (block.
vtx.size() > 1)
2377 ? total_size / (block.
vtx.size() - 1)
2381 ret_all.
pushKV(
"ins", inputs);
2384 ret_all.
pushKV(
"maxtxsize", maxtxsize);
2385 ret_all.
pushKV(
"medianfee",
2387 ret_all.
pushKV(
"medianfeerate",
2394 ret_all.
pushKV(
"minfeerate",
2397 ret_all.
pushKV(
"mintxsize", mintxsize == blockMaxSize ? 0 : mintxsize);
2398 ret_all.
pushKV(
"outs", outputs);
2403 ret_all.
pushKV(
"total_size", total_size);
2405 ret_all.
pushKV(
"txs", (int64_t)block.
vtx.size());
2406 ret_all.
pushKV(
"utxo_increase", outputs - inputs);
2407 ret_all.
pushKV(
"utxo_size_inc", utxo_size_inc);
2414 for (
const std::string &stat : stats) {
2415 const UniValue &value = ret_all[stat];
2419 strprintf(
"Invalid selected statistic %s", stat));
2430 "Dumps the mempool to disk. It will fail until the previous dump is " 2454 static bool FindScriptPubKey(std::atomic<int> &scan_progress,
2455 const std::atomic<bool> &should_abort,
2457 const std::set<CScript> &needles,
2458 std::map<COutPoint, Coin> &out_results,
2459 std::function<
void()> &interruption_point) {
2462 while (cursor->
Valid()) {
2468 if (++count % 8192 == 0) {
2469 interruption_point();
2475 if (count % 256 == 0) {
2478 uint32_t high = 0x100 * *txid.
begin() + *(txid.
begin() + 1);
2479 scan_progress = int(high * 100.0 / 65536.0 + 0.5);
2482 out_results.emplace(key, coin);
2486 scan_progress = 100;
2504 if (g_scan_in_progress.exchange(
true)) {
2507 m_could_reserve =
true;
2512 if (m_could_reserve) {
2513 g_scan_in_progress =
false;
2522 "EXPERIMENTAL warning: this call may be removed or changed in future " 2524 "\nScans the unspent transaction output set for entries that match " 2525 "certain output descriptors.\n" 2526 "Examples of output descriptors are:\n" 2527 " addr(<address>) Outputs whose scriptPubKey " 2528 "corresponds to the specified address (does not include P2PK)\n" 2529 " raw(<hex script>) Outputs whose scriptPubKey " 2530 "equals the specified hex scripts\n" 2531 " combo(<pubkey>) P2PK and P2PKH outputs for " 2532 "the given pubkey\n" 2533 " pkh(<pubkey>) P2PKH outputs for the given " 2535 " sh(multi(<n>,<pubkey>,<pubkey>,...)) P2SH-multisig outputs for " 2536 "the given threshold and pubkeys\n" 2537 "\nIn the above, <pubkey> either refers to a fixed public key in " 2538 "hexadecimal notation, or to an xpub/xprv optionally followed by one\n" 2539 "or more path elements separated by \"/\", and optionally ending in " 2540 "\"/*\" (unhardened), or \"/*'\" or \"/*h\" (hardened) to specify all\n" 2541 "unhardened or hardened child keys.\n" 2542 "In the latter case, a range needs to be specified by below if " 2543 "different from 1000.\n" 2544 "For more information on output descriptors, see the documentation in " 2545 "the doc/descriptors.md file.\n",
2548 "The action to execute\n" 2549 " \"start\" for starting a " 2551 " \"abort\" for aborting the " 2552 "current scan (returns true when abort was successful)\n" 2554 "progress report (in %) of the current scan"},
2558 "Array of scan objects. Required for \"start\" action\n" 2559 " Every scan object is either a " 2560 "string descriptor or an object:",
2563 "An output descriptor"},
2568 "An object with output descriptor and metadata",
2571 "An output descriptor"},
2573 "The range of HD chain indexes to explore (either " 2574 "end or [begin,end])"},
2578 "[scanobjects,...]"},
2586 "Whether the scan was completed"},
2588 "The number of unspent transaction outputs scanned"},
2590 "The current block height (index)"},
2592 "The hash of the block at the tip of the chain"},
2602 "The transaction id"},
2607 "A specialized descriptor for the matched " 2611 " of the unspent output"},
2613 "Height of the unspent transaction output"},
2617 "The total amount of all found unspent outputs in " +
2633 result.
pushKV(
"progress", g_scan_progress.load());
2642 g_should_abort_scan =
true;
2649 "Scan already in progress, use action \"abort\" or \"status\"");
2655 "scanobjects argument is required for the start action");
2658 std::set<CScript> needles;
2659 std::map<CScript, std::string> descriptors;
2667 for (
const auto &script : scripts) {
2668 std::string inferred =
2670 needles.emplace(script);
2671 descriptors.emplace(std::move(script), std::move(inferred));
2677 std::vector<CTxOut> input_txos;
2678 std::map<COutPoint, Coin> coins;
2679 g_should_abort_scan =
false;
2680 g_scan_progress = 0;
2682 std::unique_ptr<CCoinsViewCursor> pcursor;
2687 pcursor = std::unique_ptr<CCoinsViewCursor>(
2694 bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count,
2695 pcursor.get(), needles, coins,
2697 result.
pushKV(
"success", res);
2698 result.
pushKV(
"txouts", count);
2702 for (
const auto &it : coins) {
2704 const Coin &coin = it.second;
2706 input_txos.push_back(txo);
2711 unspent.
pushKV(
"vout", int32_t(outpoint.
GetN()));
2720 result.
pushKV(
"unspents", unspents);
2732 "Retrieve a BIP 157 content filter for a particular block.\n",
2735 "The hash of the block"},
2737 "The type name of the filter"},
2744 "the hex-encoded filter data"},
2746 "the hex-encoded filter header"},
2750 "\"00000000c937983704a73af28acdec37b049d214a" 2751 "dbda81d7e2a3dd146f6ed09\" \"basic\"") +
2753 "\"00000000c937983704a73af28acdec37b049d214adbda81d7" 2754 "e2a3dd146f6ed09\", \"basic\"")}}
2758 std::string filtertype_name =
"basic";
2771 "Index is not enabled for filtertype " +
2776 bool block_was_connected;
2793 std::string errmsg =
"Filter not found.";
2795 if (!block_was_connected) {
2797 errmsg +=
" Block was not connected to active chain.";
2798 }
else if (!index_ready) {
2801 " Block filters are still in the process of being indexed.";
2805 " This error is unexpected and indicates index corruption.";
2826 "\nWrite the serialized UTXO set to disk.\n" 2827 "Incidentally flushes the latest coinsdb (leveldb) to disk.\n",
2831 "path to the output file. If relative, will be prefixed by " 2839 "the number of coins written in the snapshot"},
2841 "the hash of the base of the snapshot"},
2843 "the height of the base of the snapshot"},
2845 "the absolute path that the snapshot was written to"},
2856 if (fs::exists(path)) {
2860 " already exists. If you are sure this is what you want, " 2861 "move it out of the way first");
2866 std::unique_ptr<CCoinsViewCursor> pcursor;
2893 pcursor = std::unique_ptr<CCoinsViewCursor>(
2906 unsigned int iter{0};
2908 while (pcursor->Valid()) {
2909 if (iter % 5000 == 0) {
2913 if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
2922 fs::rename(temppath, path);
2928 result.
pushKV(
"path", path.string());
2938 {
"blockchain",
"getblock",
getblock, {
"blockhash",
"verbosity|verbose"} },
2941 {
"blockchain",
"getblockhash",
getblockhash, {
"height"} },
2942 {
"blockchain",
"getblockheader",
getblockheader, {
"blockhash",
"verbose"} },
2943 {
"blockchain",
"getblockstats",
getblockstats, {
"hash_or_height",
"stats"} },
2945 {
"blockchain",
"getchaintxstats",
getchaintxstats, {
"nblocks",
"blockhash"} },
2951 {
"blockchain",
"getrawmempool",
getrawmempool, {
"verbose"} },
2952 {
"blockchain",
"gettxout",
gettxout, {
"txid",
"n",
"include_mempool"} },
2956 {
"blockchain",
"verifychain",
verifychain, {
"checklevel",
"nblocks"} },
2957 {
"blockchain",
"preciousblock",
preciousblock, {
"blockhash"} },
2958 {
"blockchain",
"scantxoutset",
scantxoutset, {
"action",
"scanobjects"} },
2959 {
"blockchain",
"getblockfilter",
getblockfilter, {
"blockhash",
"filtertype"} },
2963 {
"hidden",
"finalizeblock",
finalizeblock, {
"blockhash"} },
2965 {
"hidden",
"parkblock",
parkblock, {
"blockhash"} },
2969 {
"hidden",
"unparkblock",
unparkblock, {
"blockhash"} },
2971 {
"hidden",
"waitforblock",
waitforblock, {
"blockhash",
"timeout"} },
2976 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++) {
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats, const std::function< void()> &interruption_point)
Calculate statistics about the unspent transaction output set.
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
static UniValue scantxoutset(const Config &config, const JSONRPCRequest &request)
static UniValue getrawmempool(const Config &config, const JSONRPCRequest &request)
std::string NetworkIDString() const
Return the BIP70 network string (main, test or regtest)
void queryHashes(std::vector< uint256 > &vtxid) const
bool LookupFilter(const CBlockIndex *block_index, BlockFilter &filter_out) const
Get a single filter by block.
Display status of an in-progress BIP9 softfork.
static UniValue getmempooldescendants(const Config &config, const JSONRPCRequest &request)
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
const util::Ref & context
bool InvalidateBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main
Mark a block as invalid.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
uint64_t nTransactionOutputs
const std::string CURRENCY_UNIT
bool fPruneMode
True if we're running in -prune mode.
static constexpr Amount zero()
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params ¶ms)
Functions for disk access for blocks.
const std::vector< UniValue > & getValues() const
Bitcoin RPC command dispatcher.
#define LogPrint(category,...)
static UniValue preciousblock(const Config &config, const JSONRPCRequest &request)
int64_t GetBlockTime() const
indexed_transaction_set::nth_index< 0 >::type::const_iterator txiter
FILE * fopen(const fs::path &p, const char *mode)
bool ActivateBestChain(const Config &config, BlockValidationState &state, std::shared_ptr< const CBlock > pblock)
Find the best known block, and make it the tip of the block chain.
CBlockIndex * pprev
pointer to the index of the predecessor of this block
static UniValue getblockhash(const Config &config, const JSONRPCRequest &request)
bool IsRPCRunning()
Query whether RPC is running.
static UniValue getblockcount(const Config &config, const JSONRPCRequest &request)
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
UniValue parkblock(const Config &config, const JSONRPCRequest &request)
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE
Default for -maxmempool, maximum megabytes of mempool memory usage.
ChainstateManager & EnsureChainman(const util::Ref &context)
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
void CalculateDescendants(txiter it, setEntries &setDescendants) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Populate setDescendants with all in-mempool descendants of hash.
size_t DynamicMemoryUsage() const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
BlockStatus nStatus
Verification status of this block. See enum BlockStatus.
Comparison function for sorting the getchaintips heads.
static const unsigned int MIN_BLOCKS_TO_KEEP
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ChainActive().Tip() will not be pr...
#define ARRAYLEN(array)
Utilities for converting data from/to strings.
CBlockHeader GetBlockHeader() const
#define CHECK_NONFATAL(condition)
Throw a NonFatalCheckError when the condition evaluates to false.
int Height() const
Return the maximal height in the chain.
void ForceFlushStateToDisk()
Unconditionally flush all changes to disk.
static UniValue dumptxoutset(const Config &config, const JSONRPCRequest &request)
Serialize the UTXO set to a file for loading elsewhere.
const CBlockIndex * GetFinalizedBlock() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return the currently finalized block index.
UniValue getfinalizedblockhash(const Config &config, const JSONRPCRequest &request)
UniValue unparkblock(const Config &config, const JSONRPCRequest &request)
unsigned long size() const
UniValue blockheaderToJSON(const CBlockIndex *tip, const CBlockIndex *blockindex)
Block header to JSON.
uint64_t GetTotalTxSize() const
BIP9Stats VersionBitsTipStatistics(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the numerical statistics for the BIP9 state for a given deployment at the current tip...
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
const TxId & GetTxId() const
const std::string & get_str() const
static constexpr Amount SATOSHI
static void entryToJSON(const CTxMemPool &pool, UniValue &info, const CTxMemPoolEntry &e) EXCLUSIVE_LOCKS_REQUIRED(pool.cs)
static UniValue savemempool(const Config &config, const JSONRPCRequest &request)
static const Amount MAX_MONEY
No amount larger than this (in satoshi) is valid.
static UniValue getdifficulty(const Config &config, const JSONRPCRequest &request)
const UniValue & get_array() const
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Double ended buffer combining vector and stream-like interfaces.
double GetDifficulty(const CBlockIndex *blockindex)
Calculate the difficulty for a given block index.
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
CTxMemPool & EnsureMemPool(const util::Ref &context)
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
UniValue finalizeblock(const Config &config, const JSONRPCRequest &request)
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
static std::atomic< int > g_scan_progress
RAII object to prevent concurrency issue when scanning the txout set.
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
static UniValue gettxoutsetinfo(const Config &config, const JSONRPCRequest &request)
bool DumpMempool(const CTxMemPool &pool)
Dump the mempool to disk.
static UniValue getchaintips(const Config &config, const JSONRPCRequest &request)
int threshold
Number of blocks with the version bit set required to activate the softfork.
virtual const CChainParams & GetChainParams() const =0
void RPCNotifyBlockChange(const CBlockIndex *pindex)
Callback for when block tip changed.
static UniValue pruneblockchain(const Config &config, const JSONRPCRequest &request)
static int ComputeNextBlockAndDepth(const CBlockIndex *tip, const CBlockIndex *blockindex, const CBlockIndex *&next)
bool isSpent(const COutPoint &outpoint) const
const std::vector< CTxIn > vin
Invalid, missing or duplicate parameter.
ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
size_t GetSerializeSize(const T &t, int nVersion=0)
CChainState & ChainstateActive()
std::function< void()> rpc_interruption_point
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
const std::vector< uint8_t > & GetEncodedFilter() const
static T CalculateTruncatedMedian(std::vector< T > &scores)
virtual bool GetValue(Coin &coin) const =0
bool MoneyRange(const Amount nValue)
BlockHash GetBlockHash() const
CBlockIndex * FindEarliestAtLeast(int64_t nTime, int height) const
Find the earliest block with timestamp equal or greater than the given time and height equal or great...
static UniValue getblock(const Config &config, const JSONRPCRequest &request)
static const uint32_t MEMPOOL_HEIGHT
Fake height value used in Coins to signify they are only in the memory pool(since 0...
uint64_t PruneAfterHeight() const
Special type that is a STR with only hex chars.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Amount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
static std::atomic< bool > g_scan_in_progress
ChainstateManager * chainman
UniValue JSONRPCError(int code, const std::string &message)
bool push_back(const UniValue &val)
virtual uint64_t GetMaxBlockSize() const =0
bool operator()(const CBlockIndex *a, const CBlockIndex *b) const
void ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
Special string with only hex chars.
NodeContext struct containing references to chain state and connection state.
virtual bool Valid() const =0
int64_t count_seconds(std::chrono::seconds t)
Helper to count the seconds of a duration.
void RegisterBlockchainRPCCommands(CRPCTable &t)
Register block chain RPC commands.
Abstract view on the open txout dataset.
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
static UniValue getblockstats(const Config &config, const JSONRPCRequest &request)
An input of a transaction.
int period
Length of blocks of the BIP9 signalling period.
std::string ToString() const
uint64_t coins_count
The number of coins contained.
bool FinalizeBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main
Finalize a block.
static std::condition_variable cond_blockchange
Complete block filter struct as defined in BIP 157.
bool IsBlockPruned(const CBlockIndex *pblockindex)
Check whether the block associated with this index entry is pruned or not.
static std::vector< RPCResult > MempoolEntryDescription()
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
uint256 uint256S(const char *str)
uint256 from const char *.
int64_t nPowTargetSpacing
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
const fs::path & GetDataDir(bool fNetSpecific)
static UniValue getbestblockhash(const Config &config, const JSONRPCRequest &request)
RecursiveMutex cs_main
Global state.
std::set< txiter, CompareIteratorById > setEntries
bool VerifyDB(const Config &config, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
General application defined errors std::exception thrown in command handling.
int64_t GetChainTxCount() const
Get the number of transaction in the chain so far.
bool pushKV(const std::string &key, const UniValue &val)
int VersionBitsTipStateSinceHeight(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the block height at which the BIP9 deployment switched into the state for the block building on t...
int count
Number of blocks with the version bit set since the beginning of the current period.
#define WAIT_LOCK(cs, name)
An output of a transaction.
std::string ToString() const
Parameters that influence chain consensus.
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Try to calculate all in-mempool ancestors of entry.
An outpoint - a combination of a transaction hash and an index n into its vout.
UniValue gettxout(const Config &config, const JSONRPCRequest &request)
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
Special numeric to denote unix epoch time.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails)
Block description to JSON.
int64_t GetMedianTimePast() const
static UniValue getchaintxstats(const Config &config, const JSONRPCRequest &request)
Type-safe dynamic reference.
virtual bool GetKey(COutPoint &key) const =0
NodeContext & EnsureNodeContext(const util::Ref &context)
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded values (throws error if not hex).
static UniValue getmempoolancestors(const Config &config, const JSONRPCRequest &request)
Special type that is a NUM or [NUM,NUM].
int32_t nVersion
block header
Optional argument with default value omitted because they are implicitly clear.
bool ParkBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main
Park a block.
bool IsValid(enum BlockValidity nUpTo=BlockValidity::TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
static std::atomic< bool > g_should_abort_scan
#define EXCLUSIVE_LOCKS_REQUIRED(...)
std::vector< CTransactionRef > vtx
const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
bool PreciousBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex)
Mark a block as precious and reorganize.
static UniValue getblockfilter(const Config &config, const JSONRPCRequest &request)
const_iterator end() const
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
static constexpr int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
const_iterator begin() const
static bool SetHasKeys(const std::set< T > &set)
std::unique_ptr< Descriptor > InferDescriptor(const CScript &script, const SigningProvider &provider)
Find a descriptor for the specified script, using information from provider where possible...
A BlockHash is a unqiue identifier for a block.
Special string to represent a floating point amount.
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
static UniValue waitforblock(const Config &config, const JSONRPCRequest &request)
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
Undo information for a CBlock.
int RPCSerializationFlags()
Retrieves any serialization flags requested in command line argument.
static const signed int DEFAULT_CHECKBLOCKS
const CTransaction & GetTx() const
A TxId is the identifier of a transaction.
uint32_t GetHeight() const
static const int PROTOCOL_VERSION
network protocol versioning
static UniValue getblockheader(const Config &config, const JSONRPCRequest &request)
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess how far we are in the verification process at the given block index require cs_main if pindex h...
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
void UnparkBlockAndChildren(CBlockIndex *pindex)
Remove parked status from a block and its descendants.
static UniValue verifychain(const Config &config, const JSONRPCRequest &request)
bool LookupFilterHeader(const CBlockIndex *block_index, uint256 &header_out)
Get a single filter header by block.
static Mutex cs_blockchange
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
CBlockIndex * LookupBlockIndex(const BlockHash &hash)
std::string GetHex() const
static constexpr size_t PER_UTXO_OVERHEAD
std::string HexStr(const T itbegin, const T itend)
const UniValue NullUniValue
#define AssertLockNotHeld(cs)
std::string GetWarnings(bool verbose)
Format a string that describes several potential problems detected by the core.
int elapsed
Number of blocks elapsed since the beginning of the current period.
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
bool possible
False if there are not enough blocks left in this period to pass activation threshold.
BlockHash GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static UniValue waitfornewblock(const Config &config, const JSONRPCRequest &request)
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, bool include_hex=true, int serialize_flags=0)
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
static UniValue reconsiderblock(const Config &config, const JSONRPCRequest &request)
std::string GetHex() const
static CBlockUndo GetUndoChecked(const CBlockIndex *pblockindex)
The basic transaction that is broadcasted on the network and contained in blocks. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
UniValue getblockchaininfo(const Config &config, const JSONRPCRequest &request)
const Consensus::Params & GetConsensus() const
Special dictionary with keys that are not literals.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange)
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
std::string GetRejectReason() const
static UniValue invalidateblock(const Config &config, const JSONRPCRequest &request)
static void BIP9SoftForkDescPushBack(UniValue &softforks, const Consensus::Params &consensusParams, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
void __pushKV(const std::string &key, const UniValue &val)
AssertLockHeld(g_cs_orphans)
uint64_t CalculateCurrentUsage()
BLOCK PRUNING CODE.
static CBlock GetBlockChecked(const Config &config, const CBlockIndex *pblockindex)
static UniValue getmempoolinfo(const Config &config, const JSONRPCRequest &request)
std::vector< CTxUndo > vtxundo
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose)
Mempool to JSON.
static UniValue getmempoolentry(const Config &config, const JSONRPCRequest &request)
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
CCoinsView that brings transactions from a mempool into view.
unsigned int nTx
Number of transactions in this block.
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
bool BlockUntilSyncedToCurrentChain() const
Blocks the current thread until the index is caught up to the current state of the block chain...
static const unsigned int DEFAULT_CHECKLEVEL
Non-refcounted RAII wrapper for FILE*.
static UniValue syncwithvalidationinterfacequeue(const Config &config, const JSONRPCRequest &request)
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency...
Special type to denote elision (...)
static UniValue waitforblockheight(const Config &config, const JSONRPCRequest &request)
UniValue ValueFromAmount(const Amount &amount)
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValueType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Cursor for iterating over CoinsView state.