mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-09 06:09:48 +02:00
Merge bitcoin/bitcoin#34582: rpc: Properly parse -rpcworkqueue/-rpcthreads
fa5672dcafrefactor: [gui] Use SettingTo<int64_t> over deprecated SettingToInt (MarcoFalke)fac3ecaf69rpc: Properly parse -rpcworkqueue/-rpcthreads (MarcoFalke)faee36f63butil: 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: ACKfa5672dcafpinheadmz: ACKfa5672dcafsedited: ACKfa5672dcafTree-SHA512: e5060453a0aa1c4e27080e928b0ae2d1015fe487246e4059866eef415f301bc7712ce306d95076ce5b66a5e57c620715b33998192c0ff06b0384085a0390c714
This commit is contained in:
@@ -88,14 +88,14 @@ static common::SettingsValue PruneSetting(bool prune_enabled, int prune_size_gb)
|
||||
static bool PruneEnabled(const common::SettingsValue& prune_setting)
|
||||
{
|
||||
// -prune=1 setting is manual pruning mode, so disabled for purposes of the gui
|
||||
return SettingToInt(prune_setting, 0) > 1;
|
||||
return SettingTo<int64_t>(prune_setting, 0) > 1;
|
||||
}
|
||||
|
||||
//! Get pruning size value to show in GUI from bitcoin -prune setting. If
|
||||
//! pruning is not enabled, just show default recommended pruning size (2GB).
|
||||
static int PruneSizeGB(const common::SettingsValue& prune_setting)
|
||||
{
|
||||
int value = SettingToInt(prune_setting, 0);
|
||||
int value = SettingTo<int64_t>(prune_setting, 0);
|
||||
return value > 1 ? PruneMiBtoGB(value) : DEFAULT_PRUNE_TARGET_GB;
|
||||
}
|
||||
|
||||
@@ -469,9 +469,9 @@ QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) con
|
||||
suffix.empty() ? getOption(option, "-prev") :
|
||||
DEFAULT_PRUNE_TARGET_GB;
|
||||
case DatabaseCache:
|
||||
return qlonglong(SettingToInt(setting(), DEFAULT_DB_CACHE >> 20));
|
||||
return qlonglong(SettingTo<int64_t>(setting(), DEFAULT_DB_CACHE >> 20));
|
||||
case ThreadsScriptVerif:
|
||||
return qlonglong(SettingToInt(setting(), DEFAULT_SCRIPTCHECK_THREADS));
|
||||
return qlonglong(SettingTo<int64_t>(setting(), DEFAULT_SCRIPTCHECK_THREADS));
|
||||
case Listen:
|
||||
return SettingToBool(setting(), DEFAULT_LISTEN);
|
||||
case Server:
|
||||
|
||||
Reference in New Issue
Block a user