Skip to content

Commit

Permalink
Bugfix: Wallet: Don't initialise "used" flag for wallet tool "info" c…
Browse files Browse the repository at this point in the history
…ommand

Initialising "used" would otherwise incorrectly inflate the address book count beyond what was actually in the file
  • Loading branch information
luke-jr committed Apr 13, 2022
1 parent 6cf672e commit 290a27b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,7 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
}
}

DBErrors CWallet::LoadWallet()
DBErrors CWallet::LoadWallet(const do_init_used_flag do_init_used_flag_val)
{
LOCK(cs_wallet);

Expand All @@ -2210,7 +2210,7 @@ DBErrors CWallet::LoadWallet()
if (nLoadWalletRet != DBErrors::LOAD_OK)
return nLoadWalletRet;

InitialiseAddressBookUsed();
if (do_init_used_flag_val == do_init_used_flag::Init) InitialiseAddressBookUsed();

return DBErrors::LOAD_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const;
void chainStateFlushed(const CBlockLocator& loc) override;

DBErrors LoadWallet();
enum class do_init_used_flag { Init, Skip };
DBErrors LoadWallet(const do_init_used_flag do_init_used_flag_val = do_init_used_flag::Init);
DBErrors ZapSelectTx(std::vector<uint256>& vHashIn, std::vector<uint256>& vHashOut) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);

bool SetAddressBook(const CTxDestination& address, const std::string& strName, const std::string& purpose);
Expand Down
7 changes: 4 additions & 3 deletions src/wallet/wallettool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
wallet_instance->TopUpKeyPool();
}

static const std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::path& path, const ArgsManager& args, DatabaseOptions options)
static const std::shared_ptr<CWallet> MakeWallet(const std::string& name, const fs::path& path, const ArgsManager& args, DatabaseOptions options, CWallet::do_init_used_flag do_init_used_flag_val = CWallet::do_init_used_flag::Init)
{
DatabaseStatus status;
bilingual_str error;
Expand All @@ -61,7 +61,7 @@ static const std::shared_ptr<CWallet> MakeWallet(const std::string& name, const
std::shared_ptr<CWallet> wallet_instance{new CWallet(nullptr /* chain */, name, args, std::move(database)), WalletToolReleaseWallet};
DBErrors load_wallet_ret;
try {
load_wallet_ret = wallet_instance->LoadWallet();
load_wallet_ret = wallet_instance->LoadWallet(do_init_used_flag_val);
} catch (const std::runtime_error&) {
tfm::format(std::cerr, "Error loading %s. Is wallet being used by another process?\n", name);
return nullptr;
Expand Down Expand Up @@ -168,7 +168,8 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
DatabaseOptions options;
ReadDatabaseArgs(args, options);
options.require_existing = true;
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options);
// NOTE: We need to skip initialisation of the m_used flag, or else the address book count might be wrong
const std::shared_ptr<CWallet> wallet_instance = MakeWallet(name, path, args, options, CWallet::do_init_used_flag::Skip);
if (!wallet_instance) return false;
WalletShowInfo(wallet_instance.get());
wallet_instance->Close();
Expand Down

0 comments on commit 290a27b

Please sign in to comment.