mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-02 17:59:45 +02:00
Merge bitcoin/bitcoin#32636: Split CWallet::Create() into CreateNew and LoadExisting
db2effaca4scripted-diff: refactor: CWallet::Create() -> CreateNew() (David Gumberg)27e021ebc0wallet: Correctly log stats for encrypted messages. (David Gumberg)d8bec61be2wallet: remove loading logic from CWallet::Create (David Gumberg)f35acc893frefactor: wallet: Factor out `WriteVersion()` from `PopulateWalletFromDB()` (David Gumberg)e12ff8aca0test: wallet: Split create and load (David Gumberg)70dbc79b09wallet: Use CWallet::LoadExisting() for loading existing wallets. (David Gumberg)ae66e01164wallet: Create separate function for wallet load (David Gumberg)bc69070416refactor: Wallet stats logging in its own function (David Gumberg)a9d64cd49cwallet: Remove redundant birth time update (David Gumberg)b4a49cc727wallet: Move argument parsing to before DB load (David Gumberg)b15a94a618refactor: Split out wallet argument loading (David Gumberg)a02c4a82d8refactor: Move -walletbroadcast setting init (David Gumberg)411caf7281wallet: refactor: PopulateWalletFromDB use switch statement. (David Gumberg)a48e23f566refactor: wallet: move error handling to PopulateWalletFromDB() (David Gumberg)0972785fd7wallet: Delete unnecessary PopulateWalletFromDB() calls (David Gumberg)f0a046094escripted-diff: refactor: CWallet::LoadWallet->PopulateWalletFromDB (David Gumberg) Pull request description: This PR is mostly a refactor which splits out logic used for creating wallets and for loading wallets, both of which are presently contained in `CWallet::Create()` into `CWallet::CreateNew()` and `CWallet::LoadExisting()` The real win of this PR is that `CWallet::Create()` uses a very bad heuristic for trying to guess whether or not it is supposed to be creating a new wallet or loading an existing wallet:370c592612/src/wallet/wallet.cpp (L2882-L2885)This heuristic assumes that wallets with no `ScriptPubKeyMans` are being created, which sounds reasonable, but as demonstrated in #32112 and #32111, this can happen when the user tries to load a wallet file that is corrupted, both issues are fixed by this PR and any other misbehavior for wallet files which succeeded the broken heuristic's sniff test for new wallets. It was already the case that every caller of `CWallet::Create()` knows whether it is creating a wallet or loading one, so we can avoid replacing this bad heuristic with another one, and just shift the burden to the caller. ACKs for top commit: achow101: ACKdb2effaca4polespinasa: approach ACKdb2effaca4w0xlt: reACKdb2effaca4murchandamus: ACKdb2effaca4rkrux: ACKdb2effaca4Tree-SHA512: c28d60e0a3001058da3fd2bdbe0726c7ebe742a4b900a1dee2e5132eccc22e49619cb747a99b4032b000eafd4aa2fdd4ec244c32be2012aba809fdc94b5f6ecd
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <bitcoin-build-config.h> // IWYU pragma: keep
|
||||
|
||||
#include <wallet/wallettool.h>
|
||||
|
||||
#include <common/args.h>
|
||||
@@ -44,6 +42,7 @@ static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::pa
|
||||
{
|
||||
DatabaseStatus status;
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
std::unique_ptr<WalletDatabase> database = MakeDatabase(path, options, status, error);
|
||||
if (!database) {
|
||||
tfm::format(std::cerr, "%s\n", error.original);
|
||||
@@ -54,35 +53,22 @@ static std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::pa
|
||||
std::shared_ptr<CWallet> wallet_instance{new CWallet(/*chain=*/nullptr, name, std::move(database)), WalletToolReleaseWallet};
|
||||
DBErrors load_wallet_ret;
|
||||
try {
|
||||
load_wallet_ret = wallet_instance->LoadWallet();
|
||||
load_wallet_ret = wallet_instance->PopulateWalletFromDB(error, warnings);
|
||||
} catch (const std::runtime_error&) {
|
||||
tfm::format(std::cerr, "Error loading %s. Is wallet being used by another process?\n", name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (load_wallet_ret != DBErrors::LOAD_OK) {
|
||||
if (load_wallet_ret == DBErrors::CORRUPT) {
|
||||
tfm::format(std::cerr, "Error loading %s: Wallet corrupted", name);
|
||||
return nullptr;
|
||||
} else if (load_wallet_ret == DBErrors::NONCRITICAL_ERROR) {
|
||||
tfm::format(std::cerr, "Error reading %s! All keys read correctly, but transaction data"
|
||||
" or address book entries might be missing or incorrect.",
|
||||
name);
|
||||
} else if (load_wallet_ret == DBErrors::TOO_NEW) {
|
||||
tfm::format(std::cerr, "Error loading %s: Wallet requires newer version of %s",
|
||||
name, CLIENT_NAME);
|
||||
return nullptr;
|
||||
} else if (load_wallet_ret == DBErrors::NEED_REWRITE) {
|
||||
tfm::format(std::cerr, "Wallet needed to be rewritten: restart %s to complete", CLIENT_NAME);
|
||||
return nullptr;
|
||||
} else if (load_wallet_ret == DBErrors::NEED_RESCAN) {
|
||||
tfm::format(std::cerr, "Error reading %s! Some transaction data might be missing or"
|
||||
" incorrect. Wallet requires a rescan.",
|
||||
name);
|
||||
} else {
|
||||
tfm::format(std::cerr, "Error loading %s", name);
|
||||
return nullptr;
|
||||
}
|
||||
if (!error.empty()) {
|
||||
tfm::format(std::cerr, "%s", error.original);
|
||||
}
|
||||
|
||||
for (const auto &warning : warnings) {
|
||||
tfm::format(std::cerr, "%s", warning.original);
|
||||
}
|
||||
|
||||
if (load_wallet_ret != DBErrors::LOAD_OK && load_wallet_ret != DBErrors::NONCRITICAL_ERROR && load_wallet_ret != DBErrors::NEED_RESCAN) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (options.require_create) WalletCreate(wallet_instance.get(), options.create_flags);
|
||||
|
||||
Reference in New Issue
Block a user