From cc5a5e81217506ec6f9fff34056290f8f40a7396 Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 18 Nov 2022 11:38:56 -0300 Subject: [PATCH 1/4] wallet: bugfix, invalid crypted key "checksum_valid" set At wallet load time, we set the crypted key "checksum_valid" variable always to false. Which, on every wallet decryption call, forces the process to re-write the entire ckeys to db when it's not needed. --- src/wallet/walletdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 6a8f0d2481..9d72323f46 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -482,7 +482,7 @@ ReadKeyValue(CWallet* pwallet, CDataStream& ssKey, CDataStream& ssValue, if (!ssValue.eof()) { uint256 checksum; ssValue >> checksum; - if ((checksum_valid = Hash(vchPrivKey) != checksum)) { + if (!(checksum_valid = Hash(vchPrivKey) == checksum)) { strErr = "Error reading wallet database: Encrypted key corrupt"; return false; } From ee7a984f85015b610be4929b7c35cb501c1fbf7c Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 19 Aug 2022 11:13:41 -0300 Subject: [PATCH 2/4] refactor: unify test/util/wallet.h with wallet/test/util.h files share the same purpose, and we shouldn't have wallet code inside the test directory. This later is needed to use wallet util functions in the bench and test binaries without be forced to duplicate them. --- src/Makefile.test.include | 2 -- src/Makefile.test_util.include | 17 ++++++++++++----- src/bench/block_assemble.cpp | 1 - src/bench/wallet_balance.cpp | 4 +++- src/bench/wallet_create_tx.cpp | 2 +- src/bench/wallet_loading.cpp | 2 +- src/test/util/wallet.cpp | 32 -------------------------------- src/test/util/wallet.h | 29 ----------------------------- src/wallet/test/util.cpp | 22 ++++++++++++++++------ src/wallet/test/util.h | 8 ++++++++ 10 files changed, 41 insertions(+), 78 deletions(-) delete mode 100644 src/test/util/wallet.cpp delete mode 100644 src/test/util/wallet.h diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 9a9424e84c..74c30f1caf 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -199,8 +199,6 @@ FUZZ_WALLET_SRC += \ endif # USE_SQLITE BITCOIN_TEST_SUITE += \ - wallet/test/util.cpp \ - wallet/test/util.h \ wallet/test/wallet_test_fixture.cpp \ wallet/test/wallet_test_fixture.h \ wallet/test/init_test_fixture.cpp \ diff --git a/src/Makefile.test_util.include b/src/Makefile.test_util.include index d142572b27..a4e8b3f842 100644 --- a/src/Makefile.test_util.include +++ b/src/Makefile.test_util.include @@ -18,8 +18,11 @@ TEST_UTIL_H = \ test/util/str.h \ test/util/transaction_utils.h \ test/util/txmempool.h \ - test/util/validation.h \ - test/util/wallet.h + test/util/validation.h + +if ENABLE_WALLET +TEST_UTIL_H += wallet/test/util.h +endif # ENABLE_WALLET libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BOOST_CPPFLAGS) libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -33,6 +36,10 @@ libtest_util_a_SOURCES = \ test/util/str.cpp \ test/util/transaction_utils.cpp \ test/util/txmempool.cpp \ - test/util/validation.cpp \ - test/util/wallet.cpp \ - $(TEST_UTIL_H) + test/util/validation.cpp + +if ENABLE_WALLET +libtest_util_a_SOURCES += wallet/test/util.cpp +endif # ENABLE_WALLET + +libtest_util_a_SOURCES += $(TEST_UTIL_H) diff --git a/src/bench/block_assemble.cpp b/src/bench/block_assemble.cpp index 09be011fda..69258377d5 100644 --- a/src/bench/block_assemble.cpp +++ b/src/bench/block_assemble.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/src/bench/wallet_balance.cpp b/src/bench/wallet_balance.cpp index 22d99c0e29..5a52774a8e 100644 --- a/src/bench/wallet_balance.cpp +++ b/src/bench/wallet_balance.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -20,6 +20,8 @@ using wallet::DBErrors; using wallet::GetBalance; using wallet::WALLET_FLAG_DESCRIPTORS; +const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj"; + static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const bool add_mine) { const auto test_setup = MakeNoLogFileContext(); diff --git a/src/bench/wallet_create_tx.cpp b/src/bench/wallet_create_tx.cpp index 8f5c50872b..3cbf2c9008 100644 --- a/src/bench/wallet_create_tx.cpp +++ b/src/bench/wallet_create_tx.cpp @@ -9,9 +9,9 @@ #include #include #include -#include #include #include +#include #include using wallet::CWallet; diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp index 8bfaf3044b..6c9936ccd9 100644 --- a/src/bench/wallet_loading.cpp +++ b/src/bench/wallet_loading.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/test/util/wallet.cpp b/src/test/util/wallet.cpp deleted file mode 100644 index 2dadffafb4..0000000000 --- a/src/test/util/wallet.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2019-2021 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include - -#include -#include -#include