diff options
author | Andrew Chow <github@achow101.com> | 2022-11-29 18:38:40 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2022-11-29 18:54:57 -0500 |
commit | 5690848dfb60f68f433b992180d5f906ef8a10b0 (patch) | |
tree | cd49dd8c066ca1bbe7f4d9e5eec25bc80b762eeb /src/bench | |
parent | a63192afb832bdd73de8705b2ada882b086a7e2f (diff) | |
parent | 13d97608297bd56ed033d0e754d2e50447b02af0 (diff) |
Merge bitcoin/bitcoin#26532: wallet: bugfix, invalid crypted key "checksum_valid" set
13d97608297bd56ed033d0e754d2e50447b02af0 test: load wallet, coverage for crypted keys (furszy)
373c99633ec7f20557db2734c49116ee4ad15423 refactor: move DuplicateMockDatabase to wallet/test/util.h (furszy)
ee7a984f85015b610be4929b7c35cb501c1fbf7c refactor: unify test/util/wallet.h with wallet/test/util.h (furszy)
cc5a5e81217506ec6f9fff34056290f8f40a7396 wallet: bugfix, invalid crypted key "checksum_valid" set (furszy)
Pull request description:
At wallet load time, the crypted key "checksum_valid" variable is always set to false. Which, on every wallet decryption call, forces the process to re-write all the ckeys to db when it's not needed.
Note:
The first commit fixes the issue, the two commits in the middle are cleanups so `DuplicateMockDatabase`
can be used without duplicating code. And, the last one is pure test coverage for the crypted keys loading
process.
Includes test coverage for the following scenarios:
1) "All ckeys checksums valid" test:
Loads an encrypted wallet with all the crypted keys with a valid checksum and
verifies that 'CWallet::Unlock' doesn't force an entire crypted keys re-write.
(we force a complete ckeys re-write if we find any missing crypted key checksum
during the wallet loading process)
2) "Missing checksum in one ckey" test:
Verifies that loading up a wallet with, at least one, 'ckey' with no checksum
triggers a complete re-write of the crypted keys.
3) "Invalid ckey checksum error" test:
Verifies that loading up a ckey with an invalid checksum stops the wallet loading
process with a corruption error.
4) "Invalid ckey pubkey error" test:
Verifies that loading up a ckey with an invalid pubkey stops the wallet loading
process with a corruption error.
ACKs for top commit:
achow101:
ACK 13d97608297bd56ed033d0e754d2e50447b02af0
aureleoules:
ACK 13d97608297bd56ed033d0e754d2e50447b02af0
Tree-SHA512: 9ea630ee4a355282fbeee61ca04737294382577bb4b2631f50e732568fdab8f72491930807fbda58206446c4f26200cdc34d8afa14dbe1241aec713887d06a0b
Diffstat (limited to 'src/bench')
-rw-r--r-- | src/bench/block_assemble.cpp | 1 | ||||
-rw-r--r-- | src/bench/wallet_balance.cpp | 4 | ||||
-rw-r--r-- | src/bench/wallet_create_tx.cpp | 2 | ||||
-rw-r--r-- | src/bench/wallet_loading.cpp | 26 |
4 files changed, 5 insertions, 28 deletions
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 <test/util/mining.h> #include <test/util/script.h> #include <test/util/setup_common.h> -#include <test/util/wallet.h> #include <txmempool.h> #include <validation.h> 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 <node/context.h> #include <test/util/mining.h> #include <test/util/setup_common.h> -#include <test/util/wallet.h> +#include <wallet/test/util.h> #include <validationinterface.h> #include <wallet/receive.h> #include <wallet/wallet.h> @@ -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<const TestingSetup>(); 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 <kernel/chain.h> #include <node/context.h> #include <test/util/setup_common.h> -#include <test/util/wallet.h> #include <validation.h> #include <wallet/spend.h> +#include <wallet/test/util.h> #include <wallet/wallet.h> using wallet::CWallet; diff --git a/src/bench/wallet_loading.cpp b/src/bench/wallet_loading.cpp index 8bfaf3044b..2f7dc53b0c 100644 --- a/src/bench/wallet_loading.cpp +++ b/src/bench/wallet_loading.cpp @@ -7,7 +7,7 @@ #include <node/context.h> #include <test/util/mining.h> #include <test/util/setup_common.h> -#include <test/util/wallet.h> +#include <wallet/test/util.h> #include <util/translation.h> #include <validationinterface.h> #include <wallet/context.h> @@ -52,30 +52,6 @@ static void AddTx(CWallet& wallet) wallet.AddToWallet(MakeTransactionRef(mtx), TxStateInactive{}); } -static std::unique_ptr<WalletDatabase> DuplicateMockDatabase(WalletDatabase& database, DatabaseOptions& options) -{ - auto new_database = CreateMockWalletDatabase(options); - - // Get a cursor to the original database - auto batch = database.MakeBatch(); - batch->StartCursor(); - - // Get a batch for the new database - auto new_batch = new_database->MakeBatch(); - - // Read all records from the original database and write them to the new one - while (true) { - CDataStream key(SER_DISK, CLIENT_VERSION); - CDataStream value(SER_DISK, CLIENT_VERSION); - bool complete; - batch->ReadAtCursor(key, value, complete); - if (complete) break; - new_batch->Write(key, value); - } - - return new_database; -} - static void WalletLoading(benchmark::Bench& bench, bool legacy_wallet) { const auto test_setup = MakeNoLogFileContext<TestingSetup>(); |