mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-19 12:10:19 +01:00
Merge #19145: Add hash_type MUHASH for gettxoutsetinfo
e987ae5a55test: Add test for deterministic UTXO set hash results (Fabian Jahr)6ccc8fc067test: Add test for gettxoutsetinfo RPC with MuHash (Fabian Jahr)0d3b2f643drpc: Add hash_type MUHASH to gettxoutsetinfo (Fabian Jahr)2474645f3brefactor: Separate hash and stats calculation in coinstats (Fabian Jahr)a1fcceac69refactor: Improve encapsulation between MuHash3072 and Num3072 (Fabian Jahr) Pull request description: This is another Pr in the series PRs for Coinstatsindex (see overview in #18000). This PR adds the `hash_type` option `muhash` to `gettxoutsetinfo` through which the user can calculate the serialized muhash of the utxo set. This PR does not use the index yet. ACKs for top commit: Sjors: tACKe987ae5achow101: ACKe987ae5a55jonatack: Tested re-ACKe987ae5a55per `git diff 3506d90 e987ae5`, reviewed diff, debug built, ran gettxoutsetinfo -signet and help on this branch vs master, at height 23127 both returned `hash_serialized_2` of `2b72d65f3b6efb2311f58374ea2b939abf49684d44f4bafda45faa3b5452a454` and this branch returned `muhash` of `c9f1ff12d345ccf9939c6bbf087e6f7399b6115adee1569287e9c5c43dbb475c` ryanofsky: Code review ACKe987ae5a55. Looks very good. I left one suggestion to simplify code, but feel free to ignore it here and maybe consider it for later since PR has already had a lot of review. Tree-SHA512: 9a739ce375e73749fa69a467262b60d3e5314ef384e2d7150b3bbc8e4125cd9fd1db95306623bb9a632fcbaf5d9d2bf2f5cc43bf717d4ff5e2c9c4b52dd9296c
This commit is contained in:
@@ -1026,13 +1026,26 @@ static RPCHelpMan pruneblockchain()
|
||||
};
|
||||
}
|
||||
|
||||
CoinStatsHashType ParseHashType(const std::string& hash_type_input)
|
||||
{
|
||||
if (hash_type_input == "hash_serialized_2") {
|
||||
return CoinStatsHashType::HASH_SERIALIZED;
|
||||
} else if (hash_type_input == "muhash") {
|
||||
return CoinStatsHashType::MUHASH;
|
||||
} else if (hash_type_input == "none") {
|
||||
return CoinStatsHashType::NONE;
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%s is not a valid hash_type", hash_type_input));
|
||||
}
|
||||
}
|
||||
|
||||
static RPCHelpMan gettxoutsetinfo()
|
||||
{
|
||||
return 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'."},
|
||||
{"hash_type", RPCArg::Type::STR, /* default */ "hash_serialized_2", "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
@@ -1042,7 +1055,8 @@ static RPCHelpMan gettxoutsetinfo()
|
||||
{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 (only present if 'hash_serialized_2' hash_type is chosen)"},
|
||||
{RPCResult::Type::STR_HEX, "hash_serialized_2", /* optional */ true, "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"},
|
||||
{RPCResult::Type::STR_HEX, "muhash", /* optional */ true, "The serialized hash (only present if 'muhash' 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"},
|
||||
}},
|
||||
@@ -1057,7 +1071,7 @@ static RPCHelpMan gettxoutsetinfo()
|
||||
CCoinsStats stats;
|
||||
::ChainstateActive().ForceFlushStateToDisk();
|
||||
|
||||
const CoinStatsHashType hash_type = ParseHashType(request.params[0], CoinStatsHashType::HASH_SERIALIZED);
|
||||
const CoinStatsHashType hash_type{request.params[0].isNull() ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType(request.params[0].get_str())};
|
||||
|
||||
CCoinsView* coins_view = WITH_LOCK(cs_main, return &ChainstateActive().CoinsDB());
|
||||
NodeContext& node = EnsureNodeContext(request.context);
|
||||
@@ -1070,6 +1084,9 @@ static RPCHelpMan gettxoutsetinfo()
|
||||
if (hash_type == CoinStatsHashType::HASH_SERIALIZED) {
|
||||
ret.pushKV("hash_serialized_2", stats.hashSerialized.GetHex());
|
||||
}
|
||||
if (hash_type == CoinStatsHashType::MUHASH) {
|
||||
ret.pushKV("muhash", stats.hashSerialized.GetHex());
|
||||
}
|
||||
ret.pushKV("disk_size", stats.nDiskSize);
|
||||
ret.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount));
|
||||
} else {
|
||||
|
||||
@@ -113,23 +113,6 @@ std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey)
|
||||
return ParseHexV(find_value(o, strKey), strKey);
|
||||
}
|
||||
|
||||
CoinStatsHashType ParseHashType(const UniValue& param, const CoinStatsHashType default_type)
|
||||
{
|
||||
if (param.isNull()) {
|
||||
return default_type;
|
||||
} else {
|
||||
std::string hash_type_input = param.get_str();
|
||||
|
||||
if (hash_type_input == "hash_serialized_2") {
|
||||
return CoinStatsHashType::HASH_SERIALIZED;
|
||||
} else if (hash_type_input == "none") {
|
||||
return CoinStatsHashType::NONE;
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("%d is not a valid hash_type", hash_type_input));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string HelpExampleCli(const std::string& methodname, const std::string& args)
|
||||
{
|
||||
return "> bitcoin-cli " + methodname + " " + args + "\n";
|
||||
|
||||
@@ -77,8 +77,6 @@ extern uint256 ParseHashO(const UniValue& o, std::string strKey);
|
||||
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
|
||||
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
|
||||
|
||||
CoinStatsHashType ParseHashType(const UniValue& param, const CoinStatsHashType default_type);
|
||||
|
||||
extern CAmount AmountFromValue(const UniValue& value);
|
||||
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
|
||||
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
|
||||
|
||||
Reference in New Issue
Block a user