Bitcoin Core  22.99.0
P2P Digital Currency
init.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <init.h>
7 #include <interfaces/chain.h>
8 #include <interfaces/init.h>
9 #include <interfaces/wallet.h>
10 #include <net.h>
11 #include <node/context.h>
12 #include <node/ui_interface.h>
13 #include <outputtype.h>
14 #include <univalue.h>
15 #include <util/check.h>
16 #include <util/moneystr.h>
17 #include <util/system.h>
18 #include <util/translation.h>
19 #ifdef USE_BDB
20 #include <wallet/bdb.h>
21 #endif
22 #include <wallet/coincontrol.h>
23 #include <wallet/wallet.h>
24 #include <walletinitinterface.h>
25 
27 {
28 public:
30  bool HasWalletSupport() const override {return true;}
31 
33  void AddWalletOptions(ArgsManager& argsman) const override;
34 
36  bool ParameterInteraction() const override;
37 
39  void Construct(NodeContext& node) const override;
40 };
41 
43 
45 {
46  argsman.AddArg("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(DEFAULT_ADDRESS_TYPE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
47  argsman.AddArg("-avoidpartialspends", strprintf("Group outputs by address, selecting many (possibly all) or none, instead of selecting on a per-output basis. Privacy is improved as addresses are mostly swept with fewer transactions and outputs are aggregated in clean change addresses. It may result in higher fees due to less optimal coin selection caused by this added limitation and possibly a larger-than-necessary number of inputs being used. Always enabled for wallets with \"avoid_reuse\" enabled, otherwise default: %u.", DEFAULT_AVOIDPARTIALSPENDS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
48  argsman.AddArg("-changetype", "What type of change to use (\"legacy\", \"p2sh-segwit\", or \"bech32\"). Default is same as -addresstype, except when -addresstype=p2sh-segwit a native segwit output is used when sending to a native segwit address)", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
49  argsman.AddArg("-consolidatefeerate=<amt>", strprintf("The maximum feerate (in %s/kvB) at which transaction building may use more inputs than strictly necessary so that the wallet's UTXO pool can be reduced (default: %s).", CURRENCY_UNIT, FormatMoney(DEFAULT_CONSOLIDATE_FEERATE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
50  argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
51  argsman.AddArg("-discardfee=<amt>", strprintf("The fee rate (in %s/kvB) that indicates your tolerance for discarding change by adding it to the fee (default: %s). "
52  "Note: An output is discarded if it is dust at this rate, but we will always discard up to the dust relay fee and a discard fee above that is limited by the fee estimate for the longest target",
54 
55  argsman.AddArg("-fallbackfee=<amt>", strprintf("A fee rate (in %s/kvB) that will be used when fee estimation has insufficient data. 0 to entirely disable the fallbackfee feature. (default: %s)",
57  argsman.AddArg("-keypool=<n>", strprintf("Set key pool size to <n> (default: %u). Warning: Smaller sizes may increase the risk of losing funds when restoring from an old backup, if none of the addresses in the original keypool have been used.", DEFAULT_KEYPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
58  argsman.AddArg("-maxapsfee=<n>", strprintf("Spend up to this amount in additional (absolute) fees (in %s) if it allows the use of partial spend avoidance (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_MAX_AVOIDPARTIALSPEND_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
59  argsman.AddArg("-maxtxfee=<amt>", strprintf("Maximum total fees (in %s) to use in a single wallet transaction; setting this too low may abort large transactions (default: %s)",
61  argsman.AddArg("-mintxfee=<amt>", strprintf("Fee rates (in %s/kvB) smaller than this are considered zero fee for transaction creation (default: %s)",
63  argsman.AddArg("-paytxfee=<amt>", strprintf("Fee rate (in %s/kvB) to add to transactions you send (default: %s)",
65  argsman.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
66 #ifdef ENABLE_EXTERNAL_SIGNER
67  argsman.AddArg("-signer=<cmd>", "External signing tool, see doc/external-signer.md", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
68 #endif
69  argsman.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
70  argsman.AddArg("-txconfirmtarget=<n>", strprintf("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)", DEFAULT_TX_CONFIRM_TARGET), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
71  argsman.AddArg("-wallet=<path>", "Specify wallet path to load at startup. Can be used multiple times to load multiple wallets. Path is to a directory containing wallet data and log files. If the path is not absolute, it is interpreted relative to <walletdir>. This only loads existing wallets and does not create new ones. For backwards compatibility this also accepts names of existing top-level data files in <walletdir>.", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
72  argsman.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
73  argsman.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
74 #if HAVE_SYSTEM
75  argsman.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes. %s in cmd is replaced by TxID, %w is replaced by wallet name, %b is replaced by the hash of the block including the transaction (set to 'unconfirmed' if the transaction is not included) and %h is replaced by the block height (-1 if not included). %w is not currently implemented on windows. On systems where %w is supported, it should NOT be quoted because this would break shell escaping used to invoke the command.", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
76 #endif
77  argsman.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
78 
79 #ifdef USE_BDB
80  argsman.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DEFAULT_WALLET_DBLOGSIZE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
81  argsman.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
82  argsman.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", DEFAULT_WALLET_PRIVDB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
83 #else
84  argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
85 #endif
86 
87 #ifdef USE_SQLITE
88  argsman.AddArg("-unsafesqlitesync", "Set SQLite synchronous=OFF to disable waiting for the database to sync to disk. This is unsafe and can cause data loss and corruption. This option is only used by tests to improve their performance (default: false)", ArgsManager::ALLOW_BOOL | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
89 #else
90  argsman.AddHiddenArgs({"-unsafesqlitesync"});
91 #endif
92 
93  argsman.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
94 
95  argsman.AddHiddenArgs({"-zapwallettxes"});
96 }
97 
99 {
100 #ifdef USE_BDB
102  return InitError(Untranslated("A version conflict was detected between the run-time BerkeleyDB library and the one used during compilation."));
103  }
104 #endif
105  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
106  for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
107  LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
108  }
109 
110  return true;
111  }
112 
113  if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
114  LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
115  }
116 
117  if (gArgs.IsArgSet("-zapwallettxes")) {
118  return InitError(Untranslated("-zapwallettxes has been removed. If you are attempting to remove a stuck transaction from your wallet, please use abandontransaction instead."));
119  }
120 
121  if (gArgs.GetBoolArg("-sysperms", false))
122  return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));
123 
124  return true;
125 }
126 
128 {
129  ArgsManager& args = *Assert(node.args);
130  if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
131  LogPrintf("Wallet disabled!\n");
132  return;
133  }
134  auto wallet_client = node.init->makeWalletClient(*node.chain);
135  node.wallet_client = wallet_client.get();
136  node.chain_clients.emplace_back(std::move(wallet_client));
137 }
g_wallet_init_interface
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:42
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:600
ArgsManager::AddHiddenArgs
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
Definition: system.cpp:661
DEFAULT_KEYPOOL_SIZE
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
Definition: scriptpubkeyman.h:48
check.h
WalletInit::Construct
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition: init.cpp:127
wallet.h
DEFAULT_FLUSHWALLET
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Definition: walletdb.h:31
FormatOutputType
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:38
ArgsManager::SoftSetBoolArg
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: system.cpp:614
moneystr.h
DEFAULT_WALLET_REJECT_LONG_CHAINS
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:91
DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
static const CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:83
outputtype.h
ArgsManager::ALLOW_ANY
@ ALLOW_ANY
Definition: system.h:166
ArgsManager::IsArgSet
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:492
wallet
Definition: interfaces.cpp:50
bdb.h
chain.h
context.h
Assert
#define Assert(val)
Identity function.
Definition: check.h:57
CFeeRate
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
ArgsManager::DEBUG_ONLY
@ DEBUG_ONLY
Definition: system.h:167
DEFAULT_CONSOLIDATE_FEERATE
static const CAmount DEFAULT_CONSOLIDATE_FEERATE
-consolidatefeerate default
Definition: wallet.h:75
WalletInitInterface
Definition: walletinitinterface.h:12
CURRENCY_UNIT
const std::string CURRENCY_UNIT
Definition: feerate.h:14
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:46
InitError
bool InitError(const bilingual_str &str)
Show error message.
Definition: ui_interface.cpp:56
ArgsManager::AddArg
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:640
DEFAULT_TRANSACTION_MAXFEE
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:99
univalue.h
DEFAULT_WALLET_RBF
static const bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:95
LogPrintf
#define LogPrintf(...)
Definition: logging.h:185
init.h
WalletInit::ParameterInteraction
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:98
walletinitinterface.h
DEFAULT_WALLET_PRIVDB
static const bool DEFAULT_WALLET_PRIVDB
Definition: bdb.h:35
gArgs
ArgsManager gArgs
Definition: system.cpp:84
ui_interface.h
system.h
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
DEFAULT_SPEND_ZEROCONF_CHANGE
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:89
WalletInit::HasWalletSupport
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:30
ArgsManager
Definition: system.h:158
translation.h
OptionsCategory::WALLET_DEBUG_TEST
@ WALLET_DEBUG_TEST
DEFAULT_ADDRESS_TYPE
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:116
DEFAULT_PAY_TX_FEE
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:67
OptionsCategory::WALLET
@ WALLET
DEFAULT_WALLETBROADCAST
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:96
OptionsCategory::DEBUG_TEST
@ DEBUG_TEST
node
Definition: interfaces.cpp:68
wallet.h
ArgsManager::ALLOW_BOOL
@ ALLOW_BOOL
Definition: system.h:163
DEFAULT_DISCARD_FEE
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:71
BerkeleyDatabaseSanityCheck
bool BerkeleyDatabaseSanityCheck()
Perform sanity check of runtime BDB version versus linked BDB version.
Definition: bdb.cpp:726
ArgsManager::GetArgs
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:483
NodeContext
NodeContext struct containing references to chain state and connection state.
Definition: context.h:39
coincontrol.h
DEFAULT_BLOCKSONLY
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:75
DEFAULT_FALLBACK_FEE
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:69
DEFAULT_TX_CONFIRM_TARGET
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:93
WalletInit::AddWalletOptions
void AddWalletOptions(ArgsManager &argsman) const override
Return the wallets help message.
Definition: init.cpp:44
DEFAULT_WALLET_DBLOGSIZE
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
Definition: bdb.h:34
DEFAULT_TRANSACTION_MINFEE
static const CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:73
ArgsManager::NETWORK_ONLY
@ NETWORK_ONLY
Definition: system.h:173
WalletInit
Definition: init.cpp:26
DEFAULT_DISABLE_WALLET
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:97
DEFAULT_AVOIDPARTIALSPENDS
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:20
FormatMoney
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:15