mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
Merge bitcoin/bitcoin#25471: rpc: Disallow gettxoutsetinfo queries for a specific block with use_index=false
27c8056885
rpc: Disallow gettxoutsetinfo queries for a specific block with use_index=false (Martin Zumsande) Pull request description: In the `gettxoutsetinfo` RPC, if we set `use_index` to false but specify `hash_or_height`, we currently hit a nonfatal error, e.g. `gettxoutsetinfo "muhash" "1" "false"` results in: ``` Internal bug detected: "!pindex || pindex->GetBlockHash() == view->GetBestBlock()" rpc/blockchain.cpp:836 (GetUTXOStats) ``` The failing check was added in [#24410](664a14ba7c
), but the previous behavior, returning the specified height together with data corresponding to the tip's height, was very confusing too in my opinion. Fix this by disallowing the interaction of `use_index=false` and `hash_or_height` and add a RPC help example with `-named` because users might ask themselves how to use the `use_index` flag witout hitting an error. An alternative way would be to allow the interaction if the specified `hash_or_height` happens to correspond to the tip (which should then also be applied to the `HASH_SERIALIZED` check before). If reviewers would prefer that, please say so. ACKs for top commit: fjahr: utACK27c8056885
shaavan: ACK27c8056885
Tree-SHA512: 1d81c34eaa48c86134a2cf7193246d5de6bfd819d413c3b3fae9cb9290e0297a336111eeaecede2f0f020b0f9a181d240de0da4493e1b387fe63b8189154442b
This commit is contained in:
commit
53b1a2426c
1 changed files with 5 additions and 1 deletions
|
@ -845,7 +845,7 @@ static RPCHelpMan gettxoutsetinfo()
|
|||
"Note this call may take some time if you are not using coinstatsindex.\n",
|
||||
{
|
||||
{"hash_type", RPCArg::Type::STR, RPCArg::Default{"hash_serialized_2"}, "Which UTXO set hash should be calculated. Options: 'hash_serialized_2' (the legacy algorithm), 'muhash', 'none'."},
|
||||
{"hash_or_height", RPCArg::Type::NUM, RPCArg::Optional::OMITTED_NAMED_ARG, "The block hash or height of the target height (only available with coinstatsindex).", "", {"", "string or numeric"}},
|
||||
{"hash_or_height", RPCArg::Type::NUM, RPCArg::DefaultHint{"the current best block"}, "The block hash or height of the target height (only available with coinstatsindex).", "", {"", "string or numeric"}},
|
||||
{"use_index", RPCArg::Type::BOOL, RPCArg::Default{true}, "Use coinstatsindex, if available."},
|
||||
},
|
||||
RPCResult{
|
||||
|
@ -881,6 +881,7 @@ static RPCHelpMan gettxoutsetinfo()
|
|||
HelpExampleCli("gettxoutsetinfo", R"("none")") +
|
||||
HelpExampleCli("gettxoutsetinfo", R"("none" 1000)") +
|
||||
HelpExampleCli("gettxoutsetinfo", R"("none" '"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09"')") +
|
||||
HelpExampleCli("-named gettxoutsetinfo", R"(hash_type='muhash' use_index='false')") +
|
||||
HelpExampleRpc("gettxoutsetinfo", "") +
|
||||
HelpExampleRpc("gettxoutsetinfo", R"("none")") +
|
||||
HelpExampleRpc("gettxoutsetinfo", R"("none", 1000)") +
|
||||
|
@ -917,6 +918,9 @@ static RPCHelpMan gettxoutsetinfo()
|
|||
throw JSONRPCError(RPC_INVALID_PARAMETER, "hash_serialized_2 hash type cannot be queried for a specific block");
|
||||
}
|
||||
|
||||
if (!index_requested) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot set use_index to false when querying for a specific block");
|
||||
}
|
||||
pindex = ParseHashOrHeight(request.params[1], chainman);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue