mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge #19328: Add gettxoutsetinfo hash_type option
40506bf93ftest: Test gettxouttsetinfo hash_type option (Fabian Jahr)f17a4d1c4drpc: Add hash_type NONE to gettxoutsetinfo (Fabian Jahr)a712cf6f68rpc: gettxoutsetinfo can specify hash_type (only legacy option for now) (Fabian Jahr)605884ef21refactor: Extract GetBogoSize function (Fabian Jahr) Pull request description: This is another intermediate part of the Coinstats Index (tracked in #18000). Sjors suggested [here](https://github.com/bitcoin/bitcoin/pull/18000#issuecomment-641423019) that the part of the changes in #19145 that don't rely on the new `hash_type` muhash, i.e. that are for `hash_type=none`, could be merged separately from everything involving muhash. So these changes are extracted from #19145 here and can be merged without any other requirements. Building the index with no UTXO set hash is still valuable because `gettxoutsetinfo` can still be used to audit the `total_amount` for example. By itself this PR is not a huge improvement, `hash_type=none` is speeding up `gettxoutsetinfo` by about 10%, but it enables the implementation of an index on top of it in a follow-up and that means large parts of the index code of Coinstats Index can be merged while reviews for the hashing algorithm might take longer. ACKs for top commit: MarcoFalke: ACK40506bf93f🖨 Sjors: tACK40506bf93fTree-SHA512: 3964c2b8eed427511b1aa9b2ef285dff27dc4d1537d72c3911e435b6e6b40912232da4acb3a09bd19a0372ddffa44103388d8a650169d95a4a727b970d210add
This commit is contained in:
@@ -975,7 +975,9 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
||||
RPCHelpMan{"gettxoutsetinfo",
|
||||
"\nReturns statistics about the unspent transaction output set.\n"
|
||||
"Note this call may take some time.\n",
|
||||
{},
|
||||
{
|
||||
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'none'."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
@@ -984,7 +986,7 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
||||
{RPCResult::Type::NUM, "transactions", "The number of transactions with unspent outputs"},
|
||||
{RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs"},
|
||||
{RPCResult::Type::NUM, "bogosize", "A meaningless metric for UTXO set size"},
|
||||
{RPCResult::Type::STR_HEX, "hash_serialized_2", "The serialized hash"},
|
||||
{RPCResult::Type::STR_HEX, "hash_serialized_2", "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"},
|
||||
{RPCResult::Type::NUM, "disk_size", "The estimated size of the chainstate on disk"},
|
||||
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount"},
|
||||
}},
|
||||
@@ -999,14 +1001,18 @@ static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
|
||||
CCoinsStats stats;
|
||||
::ChainstateActive().ForceFlushStateToDisk();
|
||||
|
||||
const CoinStatsHashType hash_type = ParseHashType(request.params[0], CoinStatsHashType::HASH_SERIALIZED);
|
||||
|
||||
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
|
||||
if (GetUTXOStats(coins_view, stats, RpcInterruptionPoint)) {
|
||||
if (GetUTXOStats(coins_view, stats, hash_type, RpcInterruptionPoint)) {
|
||||
ret.pushKV("height", (int64_t)stats.nHeight);
|
||||
ret.pushKV("bestblock", stats.hashBlock.GetHex());
|
||||
ret.pushKV("transactions", (int64_t)stats.nTransactions);
|
||||
ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs);
|
||||
ret.pushKV("bogosize", (int64_t)stats.nBogoSize);
|
||||
ret.pushKV("hash_serialized_2", stats.hashSerialized.GetHex());
|
||||
if (hash_type == CoinStatsHashType::HASH_SERIALIZED) {
|
||||
ret.pushKV("hash_serialized_2", stats.hashSerialized.GetHex());
|
||||
}
|
||||
ret.pushKV("disk_size", stats.nDiskSize);
|
||||
ret.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount));
|
||||
} else {
|
||||
@@ -2317,7 +2323,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
|
||||
|
||||
::ChainstateActive().ForceFlushStateToDisk();
|
||||
|
||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, RpcInterruptionPoint)) {
|
||||
if (!GetUTXOStats(&::ChainstateActive().CoinsDB(), stats, CoinStatsHashType::NONE, RpcInterruptionPoint)) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
|
||||
}
|
||||
|
||||
@@ -2378,7 +2384,7 @@ static const CRPCCommand commands[] =
|
||||
{ "blockchain", "getmempoolinfo", &getmempoolinfo, {} },
|
||||
{ "blockchain", "getrawmempool", &getrawmempool, {"verbose"} },
|
||||
{ "blockchain", "gettxout", &gettxout, {"txid","n","include_mempool"} },
|
||||
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, {} },
|
||||
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, {"hash_type"} },
|
||||
{ "blockchain", "pruneblockchain", &pruneblockchain, {"height"} },
|
||||
{ "blockchain", "savemempool", &savemempool, {} },
|
||||
{ "blockchain", "verifychain", &verifychain, {"checklevel","nblocks"} },
|
||||
|
||||
Reference in New Issue
Block a user