2011-05-14 10:31:46 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2023-04-25 13:51:26 +02:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2022-06-08 01:36:46 +02:00
|
|
|
// Copyright (c) 2014-2022 The Dash Core developers
|
2014-11-17 04:04:01 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-04-13 07:13:08 +02:00
|
|
|
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
|
|
|
/**
|
|
|
|
* Server/client environment: argument handling, config file parsing,
|
2018-04-20 07:02:12 +02:00
|
|
|
* thread wrappers, startup time
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
|
|
|
*/
|
2021-06-27 08:33:13 +02:00
|
|
|
#ifndef BITCOIN_UTIL_SYSTEM_H
|
|
|
|
#define BITCOIN_UTIL_SYSTEM_H
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2022-08-02 18:34:58 +02:00
|
|
|
#include <config/bitcoin-config.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
#endif
|
|
|
|
|
2021-03-22 18:10:27 +01:00
|
|
|
#include <attributes.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <compat.h>
|
2019-02-15 15:57:07 +01:00
|
|
|
#include <compat/assumptions.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <fs.h>
|
2018-04-20 07:02:12 +02:00
|
|
|
#include <logging.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <sync.h>
|
2022-06-02 22:25:16 +02:00
|
|
|
#include <util/settings.h>
|
2018-08-25 20:20:30 +02:00
|
|
|
#include <util/time.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <amount.h>
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <exception>
|
|
|
|
#include <map>
|
2022-10-15 22:11:49 +02:00
|
|
|
#include <optional>
|
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
|
|
|
#include <set>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
2018-10-08 03:47:03 +02:00
|
|
|
#include <utility>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <vector>
|
2013-05-24 15:45:08 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// Debugging macros
|
|
|
|
|
|
|
|
// Uncomment the following line to enable debugging messages
|
|
|
|
// or enable on a per file basis prior to inclusion of util.h
|
|
|
|
//#define ENABLE_DASH_DEBUG
|
|
|
|
#ifdef ENABLE_DASH_DEBUG
|
|
|
|
#define DBG( x ) x
|
|
|
|
#else
|
2017-03-17 10:28:50 +01:00
|
|
|
#define DBG( x )
|
2016-08-17 09:08:25 +02:00
|
|
|
#endif
|
|
|
|
|
2015-03-18 00:06:58 +01:00
|
|
|
//Dash only features
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-01-26 02:11:01 +01:00
|
|
|
extern bool fMasternodeMode;
|
2020-06-28 23:00:00 +02:00
|
|
|
extern bool fDisableGovernance;
|
2016-06-15 21:13:04 +02:00
|
|
|
extern int nWalletBackups;
|
2021-07-11 11:28:50 +02:00
|
|
|
extern const std::string gCoinJoinName;
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2017-06-27 11:33:32 +02:00
|
|
|
// Application startup time (used for uptime calculation)
|
|
|
|
int64_t GetStartupTime();
|
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
extern const char * const BITCOIN_CONF_FILENAME;
|
2020-07-23 18:39:18 +02:00
|
|
|
extern const char * const BITCOIN_SETTINGS_FILENAME;
|
2015-06-27 21:21:41 +02:00
|
|
|
|
2014-05-13 12:15:00 +02:00
|
|
|
void SetupEnvironment();
|
2015-09-02 16:18:16 +02:00
|
|
|
bool SetupNetworking();
|
2013-09-18 10:03:21 +02:00
|
|
|
|
2016-07-29 12:32:38 +02:00
|
|
|
template<typename... Args>
|
|
|
|
bool error(const char* fmt, const Args&... args)
|
2016-05-05 08:19:35 +02:00
|
|
|
{
|
2018-05-01 04:13:30 +02:00
|
|
|
LogPrintf("ERROR: %s\n", SafeStringFormat(fmt, args...));
|
2014-01-16 15:52:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-09 14:43:06 +02:00
|
|
|
|
2020-08-14 13:43:22 +02:00
|
|
|
void PrintExceptionContinue(const std::exception_ptr pex, const char* pszExceptionOrigin);
|
2021-01-07 21:56:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure file contents are fully committed to disk, using a platform-specific
|
|
|
|
* feature analogous to fsync().
|
|
|
|
*/
|
2018-04-23 14:29:15 +02:00
|
|
|
bool FileCommit(FILE *file);
|
2021-01-07 21:56:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync directory contents. This is required on some environments to ensure that
|
|
|
|
* newly created files are committed to disk.
|
|
|
|
*/
|
|
|
|
void DirectoryCommit(const fs::path &dirname);
|
|
|
|
|
2013-01-30 04:17:33 +01:00
|
|
|
bool TruncateFile(FILE *file, unsigned int length);
|
2013-04-26 00:46:47 +02:00
|
|
|
int RaiseFileDescriptorLimit(int nMinFD);
|
2012-08-16 02:21:28 +02:00
|
|
|
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
|
2020-12-01 08:28:29 +01:00
|
|
|
[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
|
2018-01-16 10:54:13 +01:00
|
|
|
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
|
2019-02-05 22:09:24 +01:00
|
|
|
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
2018-03-22 14:57:46 +01:00
|
|
|
bool DirIsWritable(const fs::path& directory);
|
2021-08-12 09:02:29 +02:00
|
|
|
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
|
2018-02-15 22:02:39 +01:00
|
|
|
|
2020-04-23 00:38:35 +02:00
|
|
|
/** Get the size of a file by scanning it.
|
|
|
|
*
|
|
|
|
* @param[in] path The file path
|
|
|
|
* @param[in] max Stop seeking beyond this limit
|
|
|
|
* @return The file size or max
|
|
|
|
*/
|
|
|
|
std::streampos GetFileSize(const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
|
|
|
|
|
2018-02-15 22:02:39 +01:00
|
|
|
/** Release all directory locks. This is used for unit testing only, at runtime
|
|
|
|
* the global destructor will take care of the locks.
|
|
|
|
*/
|
|
|
|
void ReleaseDirectoryLocks();
|
|
|
|
|
2017-06-14 16:00:39 +02:00
|
|
|
bool TryCreateDirectories(const fs::path& p);
|
2017-04-06 20:19:21 +02:00
|
|
|
fs::path GetDefaultDataDir();
|
2019-01-16 13:28:54 +01:00
|
|
|
// The blocks directory is always net specific.
|
|
|
|
const fs::path &GetBlocksDir();
|
2017-04-06 20:19:21 +02:00
|
|
|
const fs::path &GetDataDir(bool fNetSpecific = true);
|
2019-05-24 14:53:24 +02:00
|
|
|
fs::path GetBackupsDir();
|
2019-04-29 21:46:34 +02:00
|
|
|
// Return true if -datadir option points to a valid directory or is not specified.
|
|
|
|
bool CheckDataDirOption();
|
2019-06-28 13:41:10 +02:00
|
|
|
/** Tests only */
|
2015-03-03 16:49:12 +01:00
|
|
|
void ClearDatadirCache();
|
2017-04-06 20:19:21 +02:00
|
|
|
fs::path GetConfigFile(const std::string& confPath);
|
2012-04-22 16:22:45 +02:00
|
|
|
#ifdef WIN32
|
2017-04-06 20:19:21 +02:00
|
|
|
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
2012-04-22 16:22:45 +02:00
|
|
|
#endif
|
2018-05-29 15:37:53 +02:00
|
|
|
#ifndef WIN32
|
|
|
|
std::string ShellEscape(const std::string& arg);
|
|
|
|
#endif
|
2022-05-21 09:57:28 +02:00
|
|
|
#if HAVE_SYSTEM
|
2015-05-31 15:36:44 +02:00
|
|
|
void runCommand(const std::string& strCommand);
|
2022-05-21 09:33:04 +02:00
|
|
|
#endif
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2018-02-06 16:00:41 +01:00
|
|
|
/**
|
|
|
|
* Most paths passed as configuration arguments are treated as relative to
|
|
|
|
* the datadir if they are not absolute.
|
|
|
|
*
|
|
|
|
* @param path The path to be conditionally prefixed with datadir.
|
|
|
|
* @param net_specific Forwarded to GetDataDir().
|
|
|
|
* @return The normalized path.
|
|
|
|
*/
|
|
|
|
fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true);
|
|
|
|
|
2011-05-14 10:31:46 +02:00
|
|
|
inline bool IsSwitchChar(char c)
|
|
|
|
{
|
2011-10-07 17:02:21 +02:00
|
|
|
#ifdef WIN32
|
2011-05-14 10:31:46 +02:00
|
|
|
return c == '-' || c == '/';
|
|
|
|
#else
|
|
|
|
return c == '-';
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-30 19:42:58 +02:00
|
|
|
enum class OptionsCategory {
|
2021-03-19 16:00:24 +01:00
|
|
|
OPTIONS,
|
|
|
|
CONNECTION,
|
|
|
|
INDEXING,
|
|
|
|
MASTERNODE,
|
|
|
|
STATSD,
|
|
|
|
WALLET,
|
|
|
|
WALLET_FEE,
|
|
|
|
WALLET_HD,
|
|
|
|
WALLET_COINJOIN,
|
|
|
|
WALLET_DEBUG_TEST,
|
|
|
|
ZMQ,
|
|
|
|
DEBUG_TEST,
|
|
|
|
CHAINPARAMS,
|
|
|
|
NODE_RELAY,
|
|
|
|
BLOCK_CREATION,
|
|
|
|
RPC,
|
|
|
|
GUI,
|
|
|
|
COMMANDS,
|
2018-05-30 19:42:58 +02:00
|
|
|
REGISTER_COMMANDS,
|
|
|
|
|
|
|
|
HIDDEN // Always the last option to avoid printing these in the help
|
2021-03-19 16:00:24 +01:00
|
|
|
};
|
|
|
|
|
2019-03-02 15:59:09 +01:00
|
|
|
struct SectionInfo
|
|
|
|
{
|
|
|
|
std::string m_name;
|
|
|
|
std::string m_file;
|
|
|
|
int m_line;
|
|
|
|
};
|
|
|
|
|
2017-05-15 07:30:09 +02:00
|
|
|
class ArgsManager
|
|
|
|
{
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
public:
|
2021-02-05 09:54:40 +01:00
|
|
|
enum Flags : uint32_t {
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
// Boolean options can accept negation syntax -noOPTION or -noOPTION=1
|
|
|
|
ALLOW_BOOL = 0x01,
|
|
|
|
ALLOW_INT = 0x02,
|
|
|
|
ALLOW_STRING = 0x04,
|
|
|
|
ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING,
|
|
|
|
DEBUG_ONLY = 0x100,
|
|
|
|
/* Some options would cause cross-contamination if values for
|
|
|
|
* mainnet were used while running on regtest/testnet (or vice-versa).
|
|
|
|
* Setting them as NETWORK_ONLY ensures that sharing a config file
|
|
|
|
* between mainnet and regtest/testnet won't cause problems due to these
|
|
|
|
* parameters by accident. */
|
|
|
|
NETWORK_ONLY = 0x200,
|
2020-01-30 23:10:50 +01:00
|
|
|
// This argument's value is sensitive (such as a password).
|
|
|
|
SENSITIVE = 0x400,
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
};
|
|
|
|
|
2017-05-15 07:30:09 +02:00
|
|
|
protected:
|
2018-05-30 19:42:58 +02:00
|
|
|
struct Arg
|
|
|
|
{
|
|
|
|
std::string m_help_param;
|
|
|
|
std::string m_help_text;
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
unsigned int m_flags;
|
2018-05-30 19:42:58 +02:00
|
|
|
};
|
|
|
|
|
2023-04-25 13:51:26 +02:00
|
|
|
mutable RecursiveMutex cs_args;
|
2022-06-02 22:25:16 +02:00
|
|
|
util::Settings m_settings GUARDED_BY(cs_args);
|
2018-08-30 13:52:44 +02:00
|
|
|
std::string m_network GUARDED_BY(cs_args);
|
|
|
|
std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
|
|
|
|
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
|
2019-03-02 15:59:09 +01:00
|
|
|
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args);
|
2018-03-30 17:43:38 +02:00
|
|
|
|
2019-03-02 15:59:09 +01:00
|
|
|
[[nodiscard]] bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false);
|
2020-04-29 12:16:37 +02:00
|
|
|
|
2019-12-19 21:05:19 +01:00
|
|
|
/**
|
|
|
|
* Returns true if settings values from the default section should be used,
|
|
|
|
* depending on the current network and whether the setting is
|
|
|
|
* network-specific.
|
|
|
|
*/
|
|
|
|
bool UseDefaultSection(const std::string& arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get setting value.
|
|
|
|
*
|
|
|
|
* Result will be null if setting was unset, true if "-setting" argument was passed
|
|
|
|
* false if "-nosetting" argument was passed, and a string if a "-setting=value"
|
|
|
|
* argument was passed.
|
|
|
|
*/
|
|
|
|
util::SettingsValue GetSetting(const std::string& arg) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of setting values.
|
|
|
|
*/
|
|
|
|
std::vector<util::SettingsValue> GetSettingsList(const std::string& arg) const;
|
|
|
|
|
2017-05-15 07:30:09 +02:00
|
|
|
public:
|
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
|
|
|
ArgsManager();
|
2022-05-21 10:00:37 +02:00
|
|
|
~ArgsManager();
|
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Select the network in use
|
|
|
|
*/
|
|
|
|
void SelectConfigNetwork(const std::string& network);
|
|
|
|
|
2023-01-31 11:03:42 +01:00
|
|
|
[[nodiscard]] bool ParseParameters(int argc, const char* const argv[], std::string& error);
|
2021-07-29 07:53:44 +02:00
|
|
|
[[nodiscard]] bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);
|
2017-08-16 15:59:26 +02:00
|
|
|
|
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
|
|
|
/**
|
|
|
|
* Log warnings for options in m_section_only_args when
|
|
|
|
* they are specified in the default section but not overridden
|
|
|
|
* on the command line or in a network-specific section in the
|
|
|
|
* config file.
|
|
|
|
*/
|
Merge #14708: Warn unrecognised sections in the config file
3fb09b9889665a24b34f25e9d1385a05058a28b7 Warn unrecognized sections in the config file (Akio Nakamura)
Pull request description:
This PR intends to resolve #14702.
In the config file, sections are specified by square bracket pair "[]"$,
or included in the option name itself which separated by a period"(.)".
Typicaly, [testnet] is not a correct section name and specified options
in that section are ignored but user cannot recognize what is happen.
So, add some log-warning messages if unrecognized section names are
present in the config file after checking section only args.
note: Currentry, followings are out of scope of this PR.
1) Empty section name or option name can describe.
e.g. [] , .a=b, =c
2) Multiple period characters can exist in the section name and option name.
e.g. [c.d.e], [..], f.g.h.i=j, ..=k
Tree-SHA512: 2cea02a0525feb40320613989a75cd7b7b1bd12158d5e6f3174ca77e6a25bb84425dd8812f62483df9fc482045c7b5402d69bc714430518b1847d055a2dc304b
2018-11-21 16:43:46 +01:00
|
|
|
const std::set<std::string> GetUnsuitableSectionOnlyArgs() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log warnings for unrecognized section names in the config file.
|
|
|
|
*/
|
2019-03-02 15:59:09 +01:00
|
|
|
const std::list<SectionInfo> GetUnrecognizedSections() const;
|
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns)
5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)
005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns)
608415d [tests] Unit tests for network-specific config entries (Anthony Towns)
68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)
d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns)
8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns)
30f9407 [tests] Unit tests for config file sections (Anthony Towns)
95eb66d ArgsManager: support config file sections (Anthony Towns)
4d34fcc ArgsManager: drop m_negated_args (Anthony Towns)
3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns)
Pull request description:
The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file:
<cfields> an alternative to that would be sections in a config file. and on the
cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5.
This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line.
The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys.
I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf:
wallet=/secret/wallet.dat
upnp=1
and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified:
upnp=1
[main]
wallet=/secret/wallet.dat
For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance.
I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have:
maxmempool=200
[regtest]
maxmempool=100
your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect...
The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected.
Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos
Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
2020-04-29 14:50:51 +02:00
|
|
|
|
2022-06-02 22:25:16 +02:00
|
|
|
/**
|
|
|
|
* Return the map of all the args passed via the command line
|
|
|
|
*/
|
|
|
|
const std::map<std::string, std::vector<util::SettingsValue>> GetCommandLineArgs() const;
|
|
|
|
|
2017-08-16 15:59:26 +02:00
|
|
|
/**
|
|
|
|
* Return a vector of strings of the given argument
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @return command-line arguments
|
|
|
|
*/
|
|
|
|
std::vector<std::string> GetArgs(const std::string& strArg) const;
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2017-06-18 14:07:29 +02:00
|
|
|
/**
|
|
|
|
* Return true if the given argument has been manually set
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @return true if the argument has been set
|
|
|
|
*/
|
2017-08-16 15:59:26 +02:00
|
|
|
bool IsArgSet(const std::string& strArg) const;
|
2017-06-18 14:07:29 +02:00
|
|
|
|
2018-03-30 17:43:38 +02:00
|
|
|
/**
|
|
|
|
* Return true if the argument was originally passed as a negated option,
|
|
|
|
* i.e. -nofoo.
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @return true if the argument was passed negated
|
|
|
|
*/
|
|
|
|
bool IsArgNegated(const std::string& strArg) const;
|
|
|
|
|
2017-06-18 14:07:29 +02:00
|
|
|
/**
|
|
|
|
* Return string argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
2017-07-16 23:41:24 +02:00
|
|
|
* @param strDefault (e.g. "1")
|
2017-06-18 14:07:29 +02:00
|
|
|
* @return command-line argument or default value
|
|
|
|
*/
|
2017-08-16 15:59:26 +02:00
|
|
|
std::string GetArg(const std::string& strArg, const std::string& strDefault) const;
|
2017-06-18 14:07:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return integer argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
2017-07-16 23:41:24 +02:00
|
|
|
* @param nDefault (e.g. 1)
|
2017-06-18 14:07:29 +02:00
|
|
|
* @return command-line argument (0 if invalid number) or default value
|
|
|
|
*/
|
2017-08-16 15:59:26 +02:00
|
|
|
int64_t GetArg(const std::string& strArg, int64_t nDefault) const;
|
2017-06-18 14:07:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return boolean argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
2017-07-16 23:41:24 +02:00
|
|
|
* @param fDefault (true or false)
|
2017-06-18 14:07:29 +02:00
|
|
|
* @return command-line argument or default value
|
|
|
|
*/
|
2017-08-16 15:59:26 +02:00
|
|
|
bool GetBoolArg(const std::string& strArg, bool fDefault) const;
|
2017-06-18 14:07:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an argument if it doesn't already have a value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to set (e.g. "-foo")
|
|
|
|
* @param strValue Value (e.g. "1")
|
|
|
|
* @return true if argument gets set, false if it already had a value
|
|
|
|
*/
|
|
|
|
bool SoftSetArg(const std::string& strArg, const std::string& strValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a boolean argument if it doesn't already have a value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to set (e.g. "-foo")
|
|
|
|
* @param fValue Value (e.g. false)
|
|
|
|
* @return true if argument gets set, false if it already had a value
|
|
|
|
*/
|
|
|
|
bool SoftSetBoolArg(const std::string& strArg, bool fValue);
|
|
|
|
|
|
|
|
// Forces an arg setting. Called by SoftSetArg() if the arg hasn't already
|
|
|
|
// been set. Also called directly in testing.
|
|
|
|
void ForceSetArg(const std::string& strArg, const std::string& strValue);
|
2019-07-10 16:42:53 +02:00
|
|
|
void ForceRemoveArg(const std::string& strArg);
|
2018-03-30 17:43:38 +02:00
|
|
|
|
2020-04-29 12:16:37 +02:00
|
|
|
/**
|
2019-11-02 14:47:34 +01:00
|
|
|
* Returns the appropriate chain name from the program arguments.
|
2020-04-29 12:16:37 +02:00
|
|
|
* @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.
|
|
|
|
*/
|
|
|
|
std::string GetChainName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Looks for -devnet and returns either "devnet-<name>" or simply "devnet" if no name was specified.
|
|
|
|
* This function should never be called for non-devnets.
|
|
|
|
* @return either "devnet-<name>" or "devnet"; raises runtime error if no -devent was specified.
|
|
|
|
*/
|
|
|
|
std::string GetDevNetName() const;
|
2021-03-19 16:00:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add argument
|
|
|
|
*/
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
void AddArg(const std::string& name, const std::string& help, unsigned int flags, const OptionsCategory& cat);
|
2021-03-19 16:00:24 +01:00
|
|
|
|
2021-06-19 16:34:39 +02:00
|
|
|
/**
|
|
|
|
* Add many hidden arguments
|
|
|
|
*/
|
|
|
|
void AddHiddenArgs(const std::vector<std::string>& args);
|
|
|
|
|
2018-05-30 19:42:58 +02:00
|
|
|
/**
|
|
|
|
* Clear available arguments
|
|
|
|
*/
|
2018-08-30 13:52:44 +02:00
|
|
|
void ClearArgs() {
|
|
|
|
LOCK(cs_args);
|
|
|
|
m_available_args.clear();
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
m_network_only_args.clear();
|
2018-08-30 13:52:44 +02:00
|
|
|
}
|
2018-05-30 19:42:58 +02:00
|
|
|
|
2021-03-19 16:00:24 +01:00
|
|
|
/**
|
|
|
|
* Get the help string
|
|
|
|
*/
|
2018-07-22 16:05:10 +02:00
|
|
|
std::string GetHelpMessage() const;
|
2018-05-30 19:42:58 +02:00
|
|
|
|
|
|
|
/**
|
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
|
|
|
* Return Flags for known arg.
|
2019-11-12 01:05:12 +01:00
|
|
|
* Return nullopt for unknown arg.
|
2018-05-30 19:42:58 +02:00
|
|
|
*/
|
2022-10-15 22:11:49 +02:00
|
|
|
std::optional<unsigned int> GetArgFlags(const std::string& name) const;
|
2020-01-30 23:10:50 +01:00
|
|
|
|
2020-07-23 18:39:18 +02:00
|
|
|
/**
|
|
|
|
* Read and update settings file with saved settings. This needs to be
|
|
|
|
* called after SelectParams() because the settings file location is
|
|
|
|
* network-specific.
|
|
|
|
*/
|
|
|
|
bool InitSettings(std::string& error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get settings file path, or return false if read-write settings were
|
|
|
|
* disabled with -nosettings.
|
|
|
|
*/
|
|
|
|
bool GetSettingsPath(fs::path* filepath = nullptr, bool temp = false) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read settings file. Push errors to vector, or log them if null.
|
|
|
|
*/
|
|
|
|
bool ReadSettingsFile(std::vector<std::string>* errors = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write settings file. Push errors to vector, or log them if null.
|
|
|
|
*/
|
|
|
|
bool WriteSettingsFile(std::vector<std::string>* errors = nullptr) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access settings with lock held.
|
|
|
|
*/
|
|
|
|
template <typename Fn>
|
|
|
|
void LockSettings(Fn&& fn)
|
|
|
|
{
|
|
|
|
LOCK(cs_args);
|
|
|
|
fn(m_settings);
|
|
|
|
}
|
|
|
|
|
2020-01-30 23:10:50 +01:00
|
|
|
/**
|
|
|
|
* Log the config file options and the command line arguments,
|
|
|
|
* useful for troubleshooting.
|
|
|
|
*/
|
|
|
|
void LogArgs() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helper function for LogArgs().
|
|
|
|
void logArgsPrefix(
|
|
|
|
const std::string& prefix,
|
|
|
|
const std::string& section,
|
|
|
|
const std::map<std::string, std::vector<util::SettingsValue>>& args) const;
|
2017-05-15 07:30:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern ArgsManager gArgs;
|
|
|
|
|
2018-04-03 17:51:48 +02:00
|
|
|
/**
|
|
|
|
* @return true if help has been requested via a command-line arg
|
|
|
|
*/
|
|
|
|
bool HelpRequested(const ArgsManager& args);
|
|
|
|
|
2022-05-21 10:12:13 +02:00
|
|
|
/** Add help options to the args manager */
|
|
|
|
void SetupHelpOptions(ArgsManager& args);
|
|
|
|
|
2015-02-04 09:11:49 +01:00
|
|
|
/**
|
|
|
|
* Format a string to be used as group of options in help messages
|
|
|
|
*
|
|
|
|
* @param message Group name (e.g. "RPC server options:")
|
|
|
|
* @return the formatted string
|
|
|
|
*/
|
|
|
|
std::string HelpMessageGroup(const std::string& message);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2013-08-08 11:58:57 +02:00
|
|
|
/**
|
2015-02-04 09:11:49 +01:00
|
|
|
* Format a string to be used as option description in help messages
|
|
|
|
*
|
|
|
|
* @param option Option message (e.g. "-rpcuser=<user>")
|
|
|
|
* @param message Option description (e.g. "Username for JSON-RPC connections")
|
|
|
|
* @return the formatted string
|
2013-08-08 11:58:57 +02:00
|
|
|
*/
|
2015-02-04 09:11:49 +01:00
|
|
|
std::string HelpMessageOpt(const std::string& option, const std::string& message);
|
|
|
|
|
2015-07-01 17:38:15 +02:00
|
|
|
/**
|
Merge #10271: Use std::thread::hardware_concurrency, instead of Boost, to determine available cores
937bf4335 Use std::thread::hardware_concurrency, instead of Boost, to determine available cores (fanquake)
Pull request description:
Following discussion on IRC about replacing Boost usage for detecting available system cores, I've opened this to collect some benchmarks + further discussion.
The current method for detecting available cores was introduced in #6361.
Recap of the IRC chat:
```
21:14:08 fanquake: Since we seem to be giving Boost removal a good shot for 0.15, does anyone have suggestions for replacing GetNumCores?
21:14:26 fanquake: There is std::thread::hardware_concurrency(), but that seems to count virtual cores, which I don't think we want.
21:14:51 BlueMatt: fanquake: I doubt we'll do boost removal for 0.15
21:14:58 BlueMatt: shit like BOOST_FOREACH, sure
21:15:07 BlueMatt: but all of boost? doubtful, there are still things we need
21:16:36 fanquake: Yea sorry, not the whole lot, but we can remove a decent chunk. Just looking into what else needs to be done to replace some of the less involved Boost usage.
21:16:43 BlueMatt: fair
21:17:14 wumpus: yes, it makes sense to plan ahead a bit, without immediately doing it
21:18:12 wumpus: right, don't count virtual cores, that used to be the case but it makes no sense for our usage
21:19:15 wumpus: it'd create a swarm of threads overwhelming any machine with hyperthreading (+accompanying thread stack overhead), for script validation, and there was no gain at all for that
21:20:03 sipa: BlueMatt: don't worry, there is no hurry
21:59:10 morcos: wumpus: i don't think that is correct
21:59:24 morcos: suppose you have 4 cores (8 virtual cores)
21:59:24 wumpus: fanquake: indeed seems that std has no equivalent to physical_concurrency, on any standard. That's annoying as it is non-trivial to implement
21:59:35 morcos: i think running par=8 (if it let you) would be notably faster
21:59:59 morcos: jeremyrubin and i discussed this at length a while back... i think i commented about it on irc at the time
22:00:21 wumpus: morcos: I think the conclusion at the time was that it made no difference, but sure would make sense to benchmark
22:00:39 morcos: perhaps historical testing on the virtual vs actual cores was polluted by concurrency issues that have now improved
22:00:47 wumpus: I think there are not more ALUs, so there is not really a point in having more threads
22:01:40 wumpus: hyperthreads are basically just a stored register state right?
22:02:23 sipa: wumpus: yes but it helps the scheduler
22:02:27 wumpus: in which case the only speedup using "number of cores" threads would give you is, possibly, excluding other software from running on the cores on the same time
22:02:37 morcos: well this is where i get out of my depth
22:02:50 sipa: if one of the threads is waiting on a read from ram, the other can use the arithmetic unit for example
22:02:54 morcos: wumpus: i'm pretty sure though that the speed up is considerably more than what you might expect from that
22:02:59 wumpus: sipa: ok, I back down, I didn't want to argue this at all
22:03:35 morcos: the reason i haven't tested it myself, is the machine i usually use has 16 cores... so not easy due to remaining concurrency issues to get much more speedup
22:03:36 wumpus: I'm fine with restoring it to number of virtual threads if that's faster
22:03:54 morcos: we should have somene with 4 cores (and  actually test it though, i agree
22:03:58 sipa: i would expect (but we should benchmark...) that if 8 scriot validation threads instead of 4 on a quadcore hyperthreading is not faster, it's due to lock contention
22:04:20 morcos: sipa: yeah thats my point, i think lock contention isn't that bad with 8 now
22:04:22 wumpus: on 64-bit systems the additional thread overhead wouldn't be important at least
22:04:23 gmaxwell: I previously benchmarked, a long time ago, it was faster.
22:04:33 gmaxwell: (to use the HT core count)
22:04:44 wumpus: why was this changed at all then?
22:04:47 wumpus: I'm confused
22:05:04 sipa: good question!
22:05:06 gmaxwell: I had no idea we changed it.
22:05:25 wumpus: sigh 
22:05:54 gmaxwell: What PR changed it?
22:06:51 gmaxwell: In any case, on 32-bit it's probably a good tradeoff... the extra ram overhead is worth avoiding.
22:07:22 wumpus: https://github.com/bitcoin/bitcoin/pull/6361
22:07:28 gmaxwell: PR 6461 btw.
22:07:37 gmaxwell: er lol at least you got it right.
22:07:45 wumpus: the complaint was that systems became unsuably slow when using that many thread
22:07:51 wumpus: so at least I got one thing right, woohoo
22:07:55 sipa: seems i even acked it!
22:07:57 BlueMatt: wumpus: there are more alus
22:08:38 BlueMatt: but we need to improve lock contention first
22:08:40 morcos: anywya, i think in the past the lock contention made 8 threads regardless of cores a bit dicey.. now that is much better (although more still to be done)
22:09:01 BlueMatt: or we can just merge #10192, thats fee
22:09:04 gribble: https://github.com/bitcoin/bitcoin/issues/10192 | Cache full script execution results in addition to signatures by TheBlueMatt · Pull Request #10192 · bitcoin/bitcoin · GitHub
22:09:11 BlueMatt: s/fee/free/
22:09:21 morcos: no, we do not need to improve lock contention first. but we should probably do that before we increase the max beyond 16
22:09:26 BlueMatt: then we can toss concurrency issues out the window and get more speedup anyway
22:09:35 gmaxwell: wumpus: yea, well in QT I thought we also diminished the count by 1 or something? but yes, if the motivation was to reduce how heavily the machine was used, thats fair.
22:09:56 sipa: the benefit of using HT cores is certainly not a factor 2
22:09:58 wumpus: gmaxwell: for the default I think this makes a lot of sense, yes
22:10:10 gmaxwell: morcos: right now on my 24/28 physical core hosts going beyond 16 still reduces performance.
22:10:11 wumpus: gmaxwell: do we also restrict the maximum par using this? that'd make less sense
22:10:51 wumpus: if someone *wants* to use the virtual cores they should be able to by setting -par=
22:10:51 sipa: *flies to US*
22:10:52 BlueMatt: sipa: sure, but the shared cache helps us get more out of it than some others, as morcos points out
22:11:30 BlueMatt: (because it means our thread contention issues are less)
22:12:05 morcos: gmaxwell: yeah i've been bogged down in fee estimation as well (and the rest of life) for a while now.. otherwise i would have put more effort into jeremy's checkqueue
22:12:36 BlueMatt: morcos: heh, well now you can do other stuff while the rest of us get bogged down in understanding fee estimation enough to review it 
22:12:37 wumpus: [to answer my own question: no, the limit for par is MAX_SCRIPTCHECK_THREADS, or 16]
22:12:54 morcos: but to me optimizing for more than 16 cores is pretty valuable as miners could use beefy machines and be less concerned by block validation time
22:14:38 BlueMatt: morcos: i think you may be surprised by the number of mining pools that are on VPSes that do not have 16 cores 
22:15:34 gmaxwell: I assume right now most of the time block validation is bogged in the parts that are not as concurrent. simple because caching makes the concurrent parts so fast. (and soon to hopefully increase with bluematt's patch)
22:17:55 gmaxwell: improving sha2 speed, or transaction malloc overhead are probably bigger wins now for connection at the tip than parallelism beyond 16 (though I'd like that too).
22:18:21 BlueMatt: sha2 speed is big
22:18:27 morcos: yeah lots of things to do actually...
22:18:57 gmaxwell: BlueMatt: might be a tiny bit less big if we didn't hash the block header 8 times for every block. 
22:21:27 BlueMatt: ehh, probably, but I'm less rushed there
22:21:43 BlueMatt: my new cache thing is about to add a bunch of hashing
22:21:50 BlueMatt: 1 sha round per tx
22:22:25 BlueMatt: and sigcache is obviously a ton
```
Tree-SHA512: a594430e2a77d8cc741ea8c664a2867b1e1693e5050a4bbc8511e8d66a2bffe241a9965f6dff1e7fbb99f21dd1fdeb95b826365da8bd8f9fab2d0ffd80d5059c
2018-03-06 19:21:31 +01:00
|
|
|
* Return the number of cores available on the current system.
|
|
|
|
* @note This does count virtual cores, such as those provided by HyperThreading.
|
2015-07-01 17:38:15 +02:00
|
|
|
*/
|
|
|
|
int GetNumCores();
|
|
|
|
|
2018-05-24 13:57:36 +02:00
|
|
|
namespace ctpl {
|
|
|
|
class thread_pool;
|
|
|
|
}
|
|
|
|
void RenameThreadPool(ctpl::thread_pool& tp, const char* baseName);
|
|
|
|
|
2017-12-11 15:20:11 +01:00
|
|
|
std::string CopyrightHolders(const std::string& strPrefix, unsigned int nStartYear, unsigned int nEndYear);
|
2017-07-04 19:31:57 +02:00
|
|
|
|
2018-04-07 19:24:47 +02:00
|
|
|
/**
|
|
|
|
* On platforms that support it, tell the kernel the calling thread is
|
|
|
|
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.
|
|
|
|
*
|
|
|
|
*/
|
2019-11-28 12:49:19 +01:00
|
|
|
void ScheduleBatchPriority();
|
2018-04-07 19:24:47 +02:00
|
|
|
|
Merge #12257: [wallet] Use destination groups instead of coins in coin select
232f96f5c8a3920c09db92f4dbac2ad7d10ce8cf doc: Add release notes for -avoidpartialspends (Karl-Johan Alm)
e00b4699cc6d2ee5697d38dd6607eb2631c9b77a clean-up: Remove no longer used ivars from CInputCoin (Karl-Johan Alm)
43e04d13b1ffc02b1082176e87f420198b40c7b1 wallet: Remove deprecated OutputEligibleForSpending (Karl-Johan Alm)
0128121101fb3ee82f3abd3973a967a4226ffe0e test: Add basic testing for wallet groups (Karl-Johan Alm)
59d6f7b4e2f847ec1f2ff46c84e6157655984f85 wallet: Switch to using output groups instead of coins in coin selection (Karl-Johan Alm)
87ebce25d66952f5ce565bb5130dcf5e24049872 wallet: Add output grouping (Karl-Johan Alm)
bb629cb9dc567cc819724d9f4852652926e60cbf Add -avoidpartialspends and m_avoid_partial_spends (Karl-Johan Alm)
65b3eda458221644616d0fdd6ba0fe01bdbce893 wallet: Add input bytes to CInputCoin (Karl-Johan Alm)
a443d7a0ca333b0bae63e04b5d476f9ad9c7aeac moveonly: CoinElegibilityFilter into coinselection.h (Karl-Johan Alm)
173e18a289088c6087ba6fac708e322aa63b7a94 utils: Add insert() convenience templates (Karl-Johan Alm)
Pull request description:
This PR adds an optional (off by default) `-avoidpartialspends` flag, which changes coin select to use output groups rather than outputs, where each output group corresponds to all outputs with the same destination.
It is a privacy improvement, as each time you spend some output, any other output that is publicly associated with the destination (address) will also be spent at the same time, at the cost of fee increase for cases where coin select without group restriction would find a more optimal set of coins (see example below).
For regular use without address reuse, this PR should have no effect on the user experience whatsoever; it only affects users who, for some reason, have multiple outputs with the same destination (i.e. address reuse).
Nodes with this turned off will still try to avoid partial spending, if the fee of the resulting transaction is not greater than the fee of the original transaction.
Example: a node has four outputs linked to two addresses `A` and `B`:
* 1.0 btc to `A`
* 0.5 btc to `A`
* 1.0 btc to `B`
* 0.5 btc to `B`
The node sends 0.2 btc to `C`. Without `-avoidpartialspends`, the following coin selection will occur:
* 0.5 btc to `A` or `B` is picked
* 0.2 btc is output to `C`
* 0.3 - fee is output to (unique change address)
With `-avoidpartialspends`, the following will instead happen:
* Both of (0.5, 1.0) btc to `A` or `B` is picked (one or the other pair)
* 0.2 btc is output to `C`
* 1.3 - fee is output to (unique change address)
As noted, the pro here is that, assuming nobody sends to the address after you spend from it, you will only ever use one address once. The con is that the transaction becomes slightly larger in this case, because it is overpicking outputs to adhere to the no partial spending rule.
This complements #10386, in particular it addresses @luke-jr and @gmaxwell's concerns in https://github.com/bitcoin/bitcoin/pull/10386#issuecomment-300667926 and https://github.com/bitcoin/bitcoin/pull/10386#issuecomment-302361381.
Together with `-avoidreuse`, this fully addresses the concerns in #10065 I believe.
Tree-SHA512: 24687a4490ba59cf4198ed90052944ff4996653a4257833bb52ed24d058b3e924800c9b3790aeb6be6385b653b49e304453e5d7ff960e64c682fc23bfc447621
# Conflicts:
# src/Makefile.am
# src/bench/coin_selection.cpp
# src/wallet/coincontrol.h
# src/wallet/coinselection.cpp
# src/wallet/coinselection.h
# src/wallet/init.cpp
# src/wallet/test/coinselector_tests.cpp
# src/wallet/wallet.cpp
# src/wallet/wallet.h
# test/functional/test_runner.py
2018-07-24 15:06:21 +02:00
|
|
|
namespace util {
|
|
|
|
|
|
|
|
//! Simplification of std insertion
|
|
|
|
template <typename Tdst, typename Tsrc>
|
|
|
|
inline void insert(Tdst& dst, const Tsrc& src) {
|
|
|
|
dst.insert(dst.begin(), src.begin(), src.end());
|
|
|
|
}
|
|
|
|
template <typename TsetT, typename Tsrc>
|
|
|
|
inline void insert(std::set<TsetT>& dst, const Tsrc& src) {
|
|
|
|
dst.insert(src.begin(), src.end());
|
|
|
|
}
|
|
|
|
|
2018-10-08 03:47:03 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
class WinCmdLineArgs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WinCmdLineArgs();
|
|
|
|
~WinCmdLineArgs();
|
|
|
|
std::pair<int, char**> get();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int argc;
|
|
|
|
char** argv;
|
|
|
|
std::vector<std::string> args;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
Merge #12257: [wallet] Use destination groups instead of coins in coin select
232f96f5c8a3920c09db92f4dbac2ad7d10ce8cf doc: Add release notes for -avoidpartialspends (Karl-Johan Alm)
e00b4699cc6d2ee5697d38dd6607eb2631c9b77a clean-up: Remove no longer used ivars from CInputCoin (Karl-Johan Alm)
43e04d13b1ffc02b1082176e87f420198b40c7b1 wallet: Remove deprecated OutputEligibleForSpending (Karl-Johan Alm)
0128121101fb3ee82f3abd3973a967a4226ffe0e test: Add basic testing for wallet groups (Karl-Johan Alm)
59d6f7b4e2f847ec1f2ff46c84e6157655984f85 wallet: Switch to using output groups instead of coins in coin selection (Karl-Johan Alm)
87ebce25d66952f5ce565bb5130dcf5e24049872 wallet: Add output grouping (Karl-Johan Alm)
bb629cb9dc567cc819724d9f4852652926e60cbf Add -avoidpartialspends and m_avoid_partial_spends (Karl-Johan Alm)
65b3eda458221644616d0fdd6ba0fe01bdbce893 wallet: Add input bytes to CInputCoin (Karl-Johan Alm)
a443d7a0ca333b0bae63e04b5d476f9ad9c7aeac moveonly: CoinElegibilityFilter into coinselection.h (Karl-Johan Alm)
173e18a289088c6087ba6fac708e322aa63b7a94 utils: Add insert() convenience templates (Karl-Johan Alm)
Pull request description:
This PR adds an optional (off by default) `-avoidpartialspends` flag, which changes coin select to use output groups rather than outputs, where each output group corresponds to all outputs with the same destination.
It is a privacy improvement, as each time you spend some output, any other output that is publicly associated with the destination (address) will also be spent at the same time, at the cost of fee increase for cases where coin select without group restriction would find a more optimal set of coins (see example below).
For regular use without address reuse, this PR should have no effect on the user experience whatsoever; it only affects users who, for some reason, have multiple outputs with the same destination (i.e. address reuse).
Nodes with this turned off will still try to avoid partial spending, if the fee of the resulting transaction is not greater than the fee of the original transaction.
Example: a node has four outputs linked to two addresses `A` and `B`:
* 1.0 btc to `A`
* 0.5 btc to `A`
* 1.0 btc to `B`
* 0.5 btc to `B`
The node sends 0.2 btc to `C`. Without `-avoidpartialspends`, the following coin selection will occur:
* 0.5 btc to `A` or `B` is picked
* 0.2 btc is output to `C`
* 0.3 - fee is output to (unique change address)
With `-avoidpartialspends`, the following will instead happen:
* Both of (0.5, 1.0) btc to `A` or `B` is picked (one or the other pair)
* 0.2 btc is output to `C`
* 1.3 - fee is output to (unique change address)
As noted, the pro here is that, assuming nobody sends to the address after you spend from it, you will only ever use one address once. The con is that the transaction becomes slightly larger in this case, because it is overpicking outputs to adhere to the no partial spending rule.
This complements #10386, in particular it addresses @luke-jr and @gmaxwell's concerns in https://github.com/bitcoin/bitcoin/pull/10386#issuecomment-300667926 and https://github.com/bitcoin/bitcoin/pull/10386#issuecomment-302361381.
Together with `-avoidreuse`, this fully addresses the concerns in #10065 I believe.
Tree-SHA512: 24687a4490ba59cf4198ed90052944ff4996653a4257833bb52ed24d058b3e924800c9b3790aeb6be6385b653b49e304453e5d7ff960e64c682fc23bfc447621
# Conflicts:
# src/Makefile.am
# src/bench/coin_selection.cpp
# src/wallet/coincontrol.h
# src/wallet/coinselection.cpp
# src/wallet/coinselection.h
# src/wallet/init.cpp
# src/wallet/test/coinselector_tests.cpp
# src/wallet/wallet.cpp
# src/wallet/wallet.h
# test/functional/test_runner.py
2018-07-24 15:06:21 +02:00
|
|
|
} // namespace util
|
|
|
|
|
2021-06-27 08:33:13 +02:00
|
|
|
#endif // BITCOIN_UTIL_SYSTEM_H
|