Merge bitcoin/bitcoin#34582: rpc: Properly parse -rpcworkqueue/-rpcthreads

fa5672dcaf refactor: [gui] Use SettingTo<int64_t> over deprecated SettingToInt (MarcoFalke)
fac3ecaf69 rpc: Properly parse -rpcworkqueue/-rpcthreads (MarcoFalke)
faee36f63b util: Add SettingTo<Int>() and GetArg<Int>() (MarcoFalke)

Pull request description:

  The integral arg parsing has many issues:

  * There is no way to parse an unsigned integral type at all
  * There is no way to parse an integral type of less width than int64_t
  * As a result, calling code splatters confusing c-style casts just to let the code compile. However, usually there are no range checks and proper range handling.

  For example, when someone (maybe for testing) wants to set the rpc work queue to the maximum possible number, there is no easy way to do so without reading the source code and manually crafting the exact integer value. Using the "9999 hack" will silently set it to `-1` (!)

  To test:

  `/bld-cmake/bin/bitcoin-qt -datadir=/tmp -regtest -rpcworkqueue=99999999999999999999999999 -printtoconsole=1 -server=1 -debug=http | grep 'set work queue of depth'`

  Before:

  ```
  [http] set work queue of depth -1
  ```

  After:

  ```
  [http] set work queue of depth 2147483647

ACKs for top commit:
  stickies-v:
    ACK fa5672dcaf
  pinheadmz:
    ACK fa5672dcaf
  sedited:
    ACK fa5672dcaf

Tree-SHA512: e5060453a0aa1c4e27080e928b0ae2d1015fe487246e4059866eef415f301bc7712ce306d95076ce5b66a5e57c620715b33998192c0ff06b0384085a0390c714
This commit is contained in:
merge-script
2026-02-19 17:44:52 +01:00
5 changed files with 70 additions and 24 deletions

View File

@@ -247,26 +247,41 @@ BOOST_AUTO_TEST_CASE(intarg)
const auto foo = std::make_pair("-foo", ArgsManager::ALLOW_ANY);
const auto bar = std::make_pair("-bar", ArgsManager::ALLOW_ANY);
SetupArgs(local_args, {foo, bar});
ResetArgs(local_args, "");
BOOST_CHECK(!local_args.GetArg<int64_t>("-foo").has_value());
BOOST_CHECK(!local_args.GetArg<uint8_t>("-bar").has_value());
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 11);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 0);
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{222}), 222);
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{0}), 0);
ResetArgs(local_args, "-foo -bar");
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), 0);
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), 0);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 11), 0);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{222}), 0);
// Check under-/overflow behavior.
ResetArgs(local_args, "-foo=-9223372036854775809 -bar=9223372036854775808");
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), std::numeric_limits<int64_t>::min());
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), std::numeric_limits<uint8_t>::max());
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), std::numeric_limits<int64_t>::min());
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 0), std::numeric_limits<int64_t>::max());
BOOST_CHECK_EQUAL(local_args.GetArg("-foo", uint8_t{0}), std::numeric_limits<uint8_t>::min());
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{0}), std::numeric_limits<uint8_t>::max());
ResetArgs(local_args, "-foo=11 -bar=12");
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), 11);
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), 12);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 0), 11);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 12);
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{11}), 12);
ResetArgs(local_args, "-foo=NaN -bar=NotANumber");
BOOST_CHECK_EQUAL(local_args.GetArg<int64_t>("-foo"), 0);
BOOST_CHECK_EQUAL(local_args.GetArg<uint8_t>("-bar"), 0);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-foo", 1), 0);
BOOST_CHECK_EQUAL(local_args.GetIntArg("-bar", 11), 0);
BOOST_CHECK_EQUAL(local_args.GetArg("-bar", uint8_t{11}), 0);
}
BOOST_AUTO_TEST_CASE(patharg)