Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
▲ Show 20 Lines • Show All 2,037 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// outpoint (needed for the utxo index) + nHeight + fCoinBase | // outpoint (needed for the utxo index) + nHeight + fCoinBase | ||||
static constexpr size_t PER_UTXO_OVERHEAD = | static constexpr size_t PER_UTXO_OVERHEAD = | ||||
sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool); | sizeof(COutPoint) + sizeof(uint32_t) + sizeof(bool); | ||||
static UniValue getblockstats(const Config &config, | static UniValue getblockstats(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | const RPCHelpMan help{ | ||||
request.params.size() > 4) { | |||||
throw std::runtime_error(RPCHelpMan{ | |||||
"getblockstats", | "getblockstats", | ||||
"\nCompute per block statistics for a given window. All " | "\nCompute per block statistics for a given window. All amounts are " | ||||
"amounts are in " + | "in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
".\n" | ".\n" | ||||
"It won't work for some heights with pruning.\n" | "It won't work for some heights with pruning.\n" | ||||
"It won't work without -txindex for utxo_size_inc, *fee or " | "It won't work without -txindex for utxo_size_inc, *fee or " | ||||
"*feerate stats.\n", | "*feerate stats.\n", | ||||
{ | { | ||||
{"hash_or_height", | {"hash_or_height", | ||||
RPCArg::Type::NUM, | RPCArg::Type::NUM, | ||||
RPCArg::Optional::NO, | RPCArg::Optional::NO, | ||||
"The block hash or height of the target block", | "The block hash or height of the target block", | ||||
"", | "", | ||||
{"", "string or numeric"}}, | {"", "string or numeric"}}, | ||||
{"stats", | {"stats", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* default */ "all values", | /* default */ "all values", | ||||
"Values to plot (see result below)", | "Values to plot (see result below)", | ||||
{ | { | ||||
{"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, | {"height", RPCArg::Type::STR, RPCArg::Optional::OMITTED, | ||||
"Selected statistic"}, | "Selected statistic"}, | ||||
{"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, | {"time", RPCArg::Type::STR, RPCArg::Optional::OMITTED, | ||||
"Selected statistic"}, | "Selected statistic"}, | ||||
}, | }, | ||||
"stats"}, | "stats"}, | ||||
}, | }, | ||||
RPCResult{ | RPCResult{ | ||||
"{ (json object)\n" | "{ (json object)\n" | ||||
" \"avgfee\": x.xxx, (numeric) Average fee in the " | " \"avgfee\": x.xxx, (numeric) Average fee in the block\n" | ||||
"block\n" | |||||
" \"avgfeerate\": x.xxx, (numeric) Average feerate (in " + | " \"avgfeerate\": x.xxx, (numeric) Average feerate (in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" per byte)\n" | " per byte)\n" | ||||
" \"avgtxsize\": xxxxx, (numeric) Average transaction " | " \"avgtxsize\": xxxxx, (numeric) Average transaction size\n" | ||||
"size\n" | " \"blockhash\": xxxxx, (string) The block hash (to check " | ||||
" \"blockhash\": xxxxx, (string) The block hash (to " | "for potential reorgs)\n" | ||||
"check for potential reorgs)\n" | " \"height\": xxxxx, (numeric) The height of the block\n" | ||||
" \"height\": xxxxx, (numeric) The height of the " | |||||
"block\n" | |||||
" \"ins\": xxxxx, (numeric) The number of inputs " | " \"ins\": xxxxx, (numeric) The number of inputs " | ||||
"(excluding coinbase)\n" | "(excluding coinbase)\n" | ||||
" \"maxfee\": xxxxx, (numeric) Maximum fee in the " | " \"maxfee\": xxxxx, (numeric) Maximum fee in the block\n" | ||||
"block\n" | |||||
" \"maxfeerate\": xxxxx, (numeric) Maximum feerate (in " + | " \"maxfeerate\": xxxxx, (numeric) Maximum feerate (in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" per byte)\n" | " per byte)\n" | ||||
" \"maxtxsize\": xxxxx, (numeric) Maximum transaction " | " \"maxtxsize\": xxxxx, (numeric) Maximum transaction size\n" | ||||
"size\n" | " \"medianfee\": x.xxx, (numeric) Truncated median fee in " | ||||
" \"medianfee\": x.xxx, (numeric) Truncated median fee " | "the block\n" | ||||
"in the block\n" | " \"medianfeerate\": x.xxx, (numeric) Truncated median feerate " | ||||
" \"medianfeerate\": x.xxx, (numeric) Truncated median " | "(in " + | ||||
"feerate (in " + | |||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" per byte)\n" | " per byte)\n" | ||||
" \"mediantime\": xxxxx, (numeric) The block median time " | " \"mediantime\": xxxxx, (numeric) The block median time " | ||||
"past\n" | "past\n" | ||||
" \"mediantxsize\": xxxxx, (numeric) Truncated median " | " \"mediantxsize\": xxxxx, (numeric) Truncated median " | ||||
"transaction size\n" | "transaction size\n" | ||||
" \"minfee\": x.xxx, (numeric) Minimum fee in the " | " \"minfee\": x.xxx, (numeric) Minimum fee in the block\n" | ||||
"block\n" | |||||
" \"minfeerate\": xx.xx, (numeric) Minimum feerate (in " + | " \"minfeerate\": xx.xx, (numeric) Minimum feerate (in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
" per byte)\n" | " per byte)\n" | ||||
" \"mintxsize\": xxxxx, (numeric) Minimum transaction " | " \"mintxsize\": xxxxx, (numeric) Minimum transaction size\n" | ||||
"size\n" | " \"outs\": xxxxx, (numeric) The number of outputs\n" | ||||
" \"outs\": xxxxx, (numeric) The number of " | |||||
"outputs\n" | |||||
" \"subsidy\": x.xxx, (numeric) The block subsidy\n" | " \"subsidy\": x.xxx, (numeric) The block subsidy\n" | ||||
" \"time\": xxxxx, (numeric) The block time\n" | " \"time\": xxxxx, (numeric) The block time\n" | ||||
" \"total_out\": x.xxx, (numeric) Total amount in all " | " \"total_out\": x.xxx, (numeric) Total amount in all " | ||||
"outputs (excluding coinbase and thus reward [ie subsidy + " | "outputs (excluding coinbase and thus reward [ie subsidy + " | ||||
"totalfee])\n" | "totalfee])\n" | ||||
" \"total_size\": xxxxx, (numeric) Total size of all " | " \"total_size\": xxxxx, (numeric) Total size of all " | ||||
"non-coinbase transactions\n" | "non-coinbase transactions\n" | ||||
" \"totalfee\": x.xxx, (numeric) The fee total\n" | " \"totalfee\": x.xxx, (numeric) The fee total\n" | ||||
" \"txs\": xxxxx, (numeric) The number of " | " \"txs\": xxxxx, (numeric) The number of " | ||||
"transactions (excluding coinbase)\n" | "transactions (excluding coinbase)\n" | ||||
" \"utxo_increase\": xxxxx, (numeric) The increase/decrease " | " \"utxo_increase\": xxxxx, (numeric) The increase/decrease in " | ||||
"in the number of unspent outputs\n" | "the number of unspent outputs\n" | ||||
" \"utxo_size_inc\": xxxxx, (numeric) The increase/decrease " | " \"utxo_size_inc\": xxxxx, (numeric) The increase/decrease in " | ||||
"in size for the utxo index (not discounting op_return and " | "size for the utxo index (not discounting op_return and similar)\n" | ||||
"similar)\n" | |||||
"}\n"}, | "}\n"}, | ||||
RPCExamples{ | RPCExamples{HelpExampleCli("getblockstats", | ||||
HelpExampleCli("getblockstats", | |||||
"1000 '[\"minfeerate\",\"avgfeerate\"]'") + | "1000 '[\"minfeerate\",\"avgfeerate\"]'") + | ||||
HelpExampleRpc("getblockstats", | HelpExampleRpc("getblockstats", | ||||
"1000 '[\"minfeerate\",\"avgfeerate\"]'")}, | "1000 '[\"minfeerate\",\"avgfeerate\"]'")}, | ||||
} | }; | ||||
.ToString()); | |||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size())) { | |||||
throw std::runtime_error(help.ToString()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *pindex; | CBlockIndex *pindex; | ||||
if (request.params[0].isNum()) { | if (request.params[0].isNum()) { | ||||
const int height = request.params[0].get_int(); | const int height = request.params[0].get_int(); | ||||
const int current_tip = ::ChainActive().Height(); | const int current_tip = ::ChainActive().Height(); | ||||
▲ Show 20 Lines • Show All 574 Lines • Show Last 20 Lines |