wallet: set keypool_size instead of access global args manager
This commit is contained in:
7 files changed
+38
-26
No files matched your search
@@ -13,11 +13,11 @@ namespace wallet {
|
|||||||
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
|
class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
ExternalSignerScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size)
|
||||||
: DescriptorScriptPubKeyMan(storage, descriptor)
|
: DescriptorScriptPubKeyMan(storage, descriptor, keypool_size)
|
||||||
{}
|
{}
|
||||||
ExternalSignerScriptPubKeyMan(WalletStorage& storage)
|
ExternalSignerScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
|
||||||
: DescriptorScriptPubKeyMan(storage)
|
: DescriptorScriptPubKeyMan(storage, keypool_size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/** Provide a descriptor at setup time
|
/** Provide a descriptor at setup time
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/bip32.h>
|
#include <util/bip32.h>
|
||||||
#include <util/system.h>
|
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/rpc/util.h>
|
#include <wallet/rpc/util.h>
|
||||||
@@ -1478,7 +1477,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
|
|||||||
} else {
|
} else {
|
||||||
warnings.push_back("Range not given, using default keypool range");
|
warnings.push_back("Range not given, using default keypool range");
|
||||||
range_start = 0;
|
range_start = 0;
|
||||||
range_end = gArgs.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE);
|
range_end = wallet.m_keypool_size;
|
||||||
}
|
}
|
||||||
next_index = range_start;
|
next_index = range_start;
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <util/bip32.h>
|
#include <util/bip32.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/system.h>
|
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <wallet/scriptpubkeyman.h>
|
#include <wallet/scriptpubkeyman.h>
|
||||||
@@ -1294,7 +1293,7 @@ bool LegacyScriptPubKeyMan::TopUpChain(CHDChain& chain, unsigned int kpSize)
|
|||||||
if (kpSize > 0) {
|
if (kpSize > 0) {
|
||||||
nTargetSize = kpSize;
|
nTargetSize = kpSize;
|
||||||
} else {
|
} else {
|
||||||
nTargetSize = std::max(gArgs.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{0});
|
nTargetSize = m_keypool_size;
|
||||||
}
|
}
|
||||||
int64_t target = std::max((int64_t) nTargetSize, int64_t{1});
|
int64_t target = std::max((int64_t) nTargetSize, int64_t{1});
|
||||||
|
|
||||||
@@ -1784,7 +1783,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
|
|||||||
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
|
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
|
||||||
|
|
||||||
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
|
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
|
||||||
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc));
|
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size));
|
||||||
desc_spk_man->AddDescriptorKey(key, key.GetPubKey());
|
desc_spk_man->AddDescriptorKey(key, key.GetPubKey());
|
||||||
desc_spk_man->TopUp();
|
desc_spk_man->TopUp();
|
||||||
auto desc_spks = desc_spk_man->GetScriptPubKeys();
|
auto desc_spks = desc_spk_man->GetScriptPubKeys();
|
||||||
@@ -1829,7 +1828,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
|
|||||||
WalletDescriptor w_desc(std::move(desc), 0, 0, chain_counter, 0);
|
WalletDescriptor w_desc(std::move(desc), 0, 0, chain_counter, 0);
|
||||||
|
|
||||||
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
|
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
|
||||||
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc));
|
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size));
|
||||||
desc_spk_man->AddDescriptorKey(master_key.key, master_key.key.GetPubKey());
|
desc_spk_man->AddDescriptorKey(master_key.key, master_key.key.GetPubKey());
|
||||||
desc_spk_man->TopUp();
|
desc_spk_man->TopUp();
|
||||||
auto desc_spks = desc_spk_man->GetScriptPubKeys();
|
auto desc_spks = desc_spk_man->GetScriptPubKeys();
|
||||||
@@ -1891,7 +1890,7 @@ std::optional<MigrationData> LegacyScriptPubKeyMan::MigrateToDescriptor()
|
|||||||
} else {
|
} else {
|
||||||
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
|
// Make the DescriptorScriptPubKeyMan and get the scriptPubKeys
|
||||||
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
|
WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0);
|
||||||
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc));
|
auto desc_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(m_storage, w_desc, m_keypool_size));
|
||||||
for (const auto& keyid : privkeyids) {
|
for (const auto& keyid : privkeyids) {
|
||||||
CKey key;
|
CKey key;
|
||||||
if (!GetKey(keyid, key)) {
|
if (!GetKey(keyid, key)) {
|
||||||
@@ -2122,7 +2121,7 @@ bool DescriptorScriptPubKeyMan::TopUp(unsigned int size)
|
|||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
target_size = size;
|
target_size = size;
|
||||||
} else {
|
} else {
|
||||||
target_size = std::max(gArgs.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1});
|
target_size = m_keypool_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the new range_end
|
// Calculate the new range_end
|
||||||
|
|||||||
@@ -286,6 +286,9 @@ private:
|
|||||||
|
|
||||||
int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = 0;
|
int64_t nTimeFirstKey GUARDED_BY(cs_KeyStore) = 0;
|
||||||
|
|
||||||
|
//! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments)
|
||||||
|
int64_t m_keypool_size GUARDED_BY(cs_KeyStore){DEFAULT_KEYPOOL_SIZE};
|
||||||
|
|
||||||
bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey);
|
bool AddKeyPubKeyInner(const CKey& key, const CPubKey &pubkey);
|
||||||
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
bool AddCryptedKeyInner(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret);
|
||||||
|
|
||||||
@@ -363,7 +366,7 @@ private:
|
|||||||
|
|
||||||
bool TopUpChain(CHDChain& chain, unsigned int size);
|
bool TopUpChain(CHDChain& chain, unsigned int size);
|
||||||
public:
|
public:
|
||||||
using ScriptPubKeyMan::ScriptPubKeyMan;
|
LegacyScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size) : ScriptPubKeyMan(storage), m_keypool_size(keypool_size) {}
|
||||||
|
|
||||||
util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
|
util::Result<CTxDestination> GetNewDestination(const OutputType type) override;
|
||||||
isminetype IsMine(const CScript& script) const override;
|
isminetype IsMine(const CScript& script) const override;
|
||||||
@@ -555,6 +558,9 @@ private:
|
|||||||
//! keeps track of whether Unlock has run a thorough check before
|
//! keeps track of whether Unlock has run a thorough check before
|
||||||
bool m_decryption_thoroughly_checked = false;
|
bool m_decryption_thoroughly_checked = false;
|
||||||
|
|
||||||
|
//! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments)
|
||||||
|
int64_t m_keypool_size GUARDED_BY(cs_desc_man){DEFAULT_KEYPOOL_SIZE};
|
||||||
|
|
||||||
bool AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
bool AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||||
|
|
||||||
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
|
||||||
@@ -572,12 +578,14 @@ protected:
|
|||||||
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
|
WalletDescriptor m_wallet_descriptor GUARDED_BY(cs_desc_man);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor)
|
DescriptorScriptPubKeyMan(WalletStorage& storage, WalletDescriptor& descriptor, int64_t keypool_size)
|
||||||
: ScriptPubKeyMan(storage),
|
: ScriptPubKeyMan(storage),
|
||||||
|
m_keypool_size(keypool_size),
|
||||||
m_wallet_descriptor(descriptor)
|
m_wallet_descriptor(descriptor)
|
||||||
{}
|
{}
|
||||||
DescriptorScriptPubKeyMan(WalletStorage& storage)
|
DescriptorScriptPubKeyMan(WalletStorage& storage, int64_t keypool_size)
|
||||||
: ScriptPubKeyMan(storage)
|
: ScriptPubKeyMan(storage),
|
||||||
|
m_keypool_size(keypool_size)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
mutable RecursiveMutex cs_desc_man;
|
mutable RecursiveMutex cs_desc_man;
|
||||||
|
|||||||
@@ -932,7 +932,7 @@ BOOST_AUTO_TEST_CASE(effective_value_test)
|
|||||||
BOOST_CHECK_EQUAL(output5.GetEffectiveValue(), nValue); // The effective value should be equal to the absolute value if input_bytes is -1
|
BOOST_CHECK_EQUAL(output5.GetEffectiveValue(), nValue); // The effective value should be equal to the absolute value if input_bytes is -1
|
||||||
}
|
}
|
||||||
|
|
||||||
static util::Result<SelectionResult> select_coins(const CAmount& target, const CoinSelectionParams& cs_params, const CCoinControl& cc, std::function<CoinsResult(CWallet&)> coin_setup, interfaces::Chain* chain, const ArgsManager& args)
|
static util::Result<SelectionResult> select_coins(const CAmount& target, const CoinSelectionParams& cs_params, const CCoinControl& cc, std::function<CoinsResult(CWallet&)> coin_setup, interfaces::Chain* chain)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(chain, "", args, CreateMockWalletDatabase());
|
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(chain, "", args, CreateMockWalletDatabase());
|
||||||
wallet->LoadWallet();
|
wallet->LoadWallet();
|
||||||
@@ -995,7 +995,7 @@ BOOST_AUTO_TEST_CASE(check_max_weight)
|
|||||||
add_coin(available_coins, wallet, CAmount(50 * COIN), CFeeRate(0), 144, false, 0, true);
|
add_coin(available_coins, wallet, CAmount(50 * COIN), CFeeRate(0), 144, false, 0, true);
|
||||||
return available_coins;
|
return available_coins;
|
||||||
},
|
},
|
||||||
chain, m_args);
|
chain);
|
||||||
|
|
||||||
BOOST_CHECK(result);
|
BOOST_CHECK(result);
|
||||||
BOOST_CHECK(has_coin(result->GetInputSet(), CAmount(50 * COIN)));
|
BOOST_CHECK(has_coin(result->GetInputSet(), CAmount(50 * COIN)));
|
||||||
@@ -1020,7 +1020,7 @@ BOOST_AUTO_TEST_CASE(check_max_weight)
|
|||||||
}
|
}
|
||||||
return available_coins;
|
return available_coins;
|
||||||
},
|
},
|
||||||
chain, m_args);
|
chain);
|
||||||
|
|
||||||
BOOST_CHECK(has_coin(result->GetInputSet(), CAmount(0.0625 * COIN)));
|
BOOST_CHECK(has_coin(result->GetInputSet(), CAmount(0.0625 * COIN)));
|
||||||
BOOST_CHECK(has_coin(result->GetInputSet(), CAmount(0.025 * COIN)));
|
BOOST_CHECK(has_coin(result->GetInputSet(), CAmount(0.025 * COIN)));
|
||||||
@@ -1041,7 +1041,7 @@ BOOST_AUTO_TEST_CASE(check_max_weight)
|
|||||||
}
|
}
|
||||||
return available_coins;
|
return available_coins;
|
||||||
},
|
},
|
||||||
chain, m_args);
|
chain);
|
||||||
|
|
||||||
// No results
|
// No results
|
||||||
// 1515 inputs * 68 bytes = 103,020 bytes
|
// 1515 inputs * 68 bytes = 103,020 bytes
|
||||||
|
|||||||
@@ -2914,6 +2914,9 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
|
|||||||
// TODO: Can't use std::make_shared because we need a custom deleter but
|
// TODO: Can't use std::make_shared because we need a custom deleter but
|
||||||
// should be possible to use std::allocate_shared.
|
// should be possible to use std::allocate_shared.
|
||||||
std::shared_ptr<CWallet> walletInstance(new CWallet(chain, name, args, std::move(database)), ReleaseWallet);
|
std::shared_ptr<CWallet> walletInstance(new CWallet(chain, name, args, std::move(database)), ReleaseWallet);
|
||||||
|
walletInstance->m_keypool_size = std::max(args.GetIntArg("-keypool", DEFAULT_KEYPOOL_SIZE), int64_t{1});
|
||||||
|
|
||||||
|
// Load wallet
|
||||||
bool rescan_required = false;
|
bool rescan_required = false;
|
||||||
DBErrors nLoadWalletRet = walletInstance->LoadWallet();
|
DBErrors nLoadWalletRet = walletInstance->LoadWallet();
|
||||||
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
||||||
@@ -3534,7 +3537,7 @@ void CWallet::SetupLegacyScriptPubKeyMan()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new LegacyScriptPubKeyMan(*this));
|
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new LegacyScriptPubKeyMan(*this, m_keypool_size));
|
||||||
for (const auto& type : LEGACY_OUTPUT_TYPES) {
|
for (const auto& type : LEGACY_OUTPUT_TYPES) {
|
||||||
m_internal_spk_managers[type] = spk_manager.get();
|
m_internal_spk_managers[type] = spk_manager.get();
|
||||||
m_external_spk_managers[type] = spk_manager.get();
|
m_external_spk_managers[type] = spk_manager.get();
|
||||||
@@ -3563,10 +3566,10 @@ void CWallet::ConnectScriptPubKeyManNotifiers()
|
|||||||
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
void CWallet::LoadDescriptorScriptPubKeyMan(uint256 id, WalletDescriptor& desc)
|
||||||
{
|
{
|
||||||
if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
|
if (IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
|
||||||
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, desc));
|
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, desc, m_keypool_size));
|
||||||
m_spk_managers[id] = std::move(spk_manager);
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
} else {
|
} else {
|
||||||
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc));
|
auto spk_manager = std::unique_ptr<ScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size));
|
||||||
m_spk_managers[id] = std::move(spk_manager);
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3577,7 +3580,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans(const CExtKey& master_key)
|
|||||||
|
|
||||||
for (bool internal : {false, true}) {
|
for (bool internal : {false, true}) {
|
||||||
for (OutputType t : OUTPUT_TYPES) {
|
for (OutputType t : OUTPUT_TYPES) {
|
||||||
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this));
|
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, m_keypool_size));
|
||||||
if (IsCrypted()) {
|
if (IsCrypted()) {
|
||||||
if (IsLocked()) {
|
if (IsLocked()) {
|
||||||
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
|
||||||
@@ -3633,7 +3636,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
OutputType t = *desc->GetOutputType();
|
OutputType t = *desc->GetOutputType();
|
||||||
auto spk_manager = std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this));
|
auto spk_manager = std::unique_ptr<ExternalSignerScriptPubKeyMan>(new ExternalSignerScriptPubKeyMan(*this, m_keypool_size));
|
||||||
spk_manager->SetupDescriptor(std::move(desc));
|
spk_manager->SetupDescriptor(std::move(desc));
|
||||||
uint256 id = spk_manager->GetID();
|
uint256 id = spk_manager->GetID();
|
||||||
m_spk_managers[id] = std::move(spk_manager);
|
m_spk_managers[id] = std::move(spk_manager);
|
||||||
@@ -3749,7 +3752,7 @@ ScriptPubKeyMan* CWallet::AddWalletDescriptor(WalletDescriptor& desc, const Flat
|
|||||||
WalletLogPrintf("Update existing descriptor: %s\n", desc.descriptor->ToString());
|
WalletLogPrintf("Update existing descriptor: %s\n", desc.descriptor->ToString());
|
||||||
spk_man->UpdateWalletDescriptor(desc);
|
spk_man->UpdateWalletDescriptor(desc);
|
||||||
} else {
|
} else {
|
||||||
auto new_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc));
|
auto new_spk_man = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, desc, m_keypool_size));
|
||||||
spk_man = new_spk_man.get();
|
spk_man = new_spk_man.get();
|
||||||
|
|
||||||
// Save the descriptor to memory
|
// Save the descriptor to memory
|
||||||
|
|||||||
@@ -642,6 +642,9 @@ public:
|
|||||||
/** Absolute maximum transaction fee (in satoshis) used by default for the wallet */
|
/** Absolute maximum transaction fee (in satoshis) used by default for the wallet */
|
||||||
CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE};
|
CAmount m_default_max_tx_fee{DEFAULT_TRANSACTION_MAXFEE};
|
||||||
|
|
||||||
|
/** Number of pre-generated keys/scripts by each spkm (part of the look-ahead process, used to detect payments) */
|
||||||
|
int64_t m_keypool_size{DEFAULT_KEYPOOL_SIZE};
|
||||||
|
|
||||||
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
size_t KeypoolCountExternalKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
|
||||||
bool TopUpKeyPool(unsigned int kpSize = 0);
|
bool TopUpKeyPool(unsigned int kpSize = 0);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user