wallet: Postpone wallet loading notification for encrypted wallets#24711
Conversation
This change is a prerequisite for the following bugfix.
|
The test fails because Since Or the test can use |
Have tried the suggested approach for the removed subtest without success -- |
|
Another alternative is to just put |
|
|
This diff works for me: diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index efb19518d0..683f0eb327 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -54,6 +54,7 @@ static const std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
std::vector<bilingual_str> warnings;
auto database = MakeWalletDatabase("", options, status, error);
auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
+ NotifyWalletLoaded(context, wallet);
if (context.chain) {
wallet->postInitProcess();
}
@@ -778,6 +779,34 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
BOOST_CHECK_EQUAL(addtx_count, 4);
+ TestUnloadWallet(std::move(wallet));
+
+
+ // Load wallet again, this time creating new block and mempool transactions
+ // paying to the wallet as the wallet finishes loading and syncing the
+ // queue so the events have to be handled immediately. Releasing the wallet
+ // lock during the sync is a little artificial but is needed to avoid a
+ // deadlock during the sync and simulates a new block notification happening
+ // as soon as possible.
+ addtx_count = 0;
+ auto handler = HandleLoadWallet(context, [&](std::unique_ptr<interfaces::Wallet> wallet) {
+ BOOST_CHECK(rescan_completed);
+ m_coinbase_txns.push_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
+ block_tx = TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
+ m_coinbase_txns.push_back(CreateAndProcessBlock({block_tx}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
+ mempool_tx = TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
+ BOOST_CHECK(m_node.chain->broadcastTransaction(MakeTransactionRef(mempool_tx), DEFAULT_TRANSACTION_MAXFEE, false, error));
+ SyncWithValidationInterfaceQueue();
+ });
+ wallet = TestLoadWallet(context);
+ BOOST_CHECK_EQUAL(addtx_count, 4);
+ {
+ LOCK(wallet->cs_wallet);
+ BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetHash()), 1U);
+ BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetHash()), 1U);
+ }
+
+
TestUnloadWallet(std::move(wallet));
}
|
Too early NotifyWalletLoaded() call in CWallet::Create() results the notification goes before DescriptorScriptPubKeyMans were created and added to an encrypted wallet. Co-authored-by: Andrew Chow <achow101-github@achow101.com>
Thanks! Updated. |
|
Not sure about the last commit. I think it makes sense to limit the scope of locks. And given that this is a backport bugfix, we might want to minimize the diff. |
The last commit has been dropped. |
|
utACK 0c12f01 |
|
ACK 0c12f01 |
This change is a prerequisite for the following bugfix. Github-Pull: bitcoin#24711 Rebased-From: aeee419
Too early NotifyWalletLoaded() call in CWallet::Create() results the notification goes before DescriptorScriptPubKeyMans were created and added to an encrypted wallet. Co-authored-by: Andrew Chow <achow101-github@achow101.com> Github-Pull: bitcoin#24711 Rebased-From: 0c12f01
|
Backported in #24725. |
This change is a prerequisite for the following bugfix. Github-Pull: bitcoin/bitcoin#24711 Rebased-From: aeee419c6aae085cacd75343c1ce23486b2b8916
Too early NotifyWalletLoaded() call in CWallet::Create() results the notification goes before DescriptorScriptPubKeyMans were created and added to an encrypted wallet. Co-authored-by: Andrew Chow <achow101-github@achow101.com> Github-Pull: bitcoin/bitcoin#24711 Rebased-From: 0c12f0116ca802f55f5ab43e6c4842ac403b9889
… encrypted wallets 0c12f01 wallet: Postpone NotifyWalletLoaded() for encrypted wallets (Hennadii Stepanov) aeee419 wallet, refactor: Add wallet::NotifyWalletLoaded() function (Hennadii Stepanov) Pull request description: Fixes bitcoin-core/gui#571. `CWallet::Create()` notifies about wallet loading too early, that results the notification goes before `DescriptorScriptPubKeyMan`s were created and added to an encrypted wallet. And `interfaces::Wallet::taprootEnabled()` in https://github.com/bitcoin/bitcoin/blob/ecf692b466860f44334a1da967fc2559da913bec/src/qt/receivecoinsdialog.cpp#L100-L102 erroneously returns `false` for just created encrypted descriptor wallets. ACKs for top commit: Sjors: utACK 0c12f01 achow101: ACK 0c12f01 Tree-SHA512: 2694bacd12748cd5f6c95d9d3bf8bcf4502ee67fecd8d057f33236b72069c61401b08f49deb013fc71c3f1e51ae16bdfd827ddcbc2a083d7044589be7a78982e
This change is a prerequisite for the following bugfix. Github-Pull: bitcoin/bitcoin#24711 Rebased-From: aeee419c6aae085cacd75343c1ce23486b2b8916
Too early NotifyWalletLoaded() call in CWallet::Create() results the notification goes before DescriptorScriptPubKeyMans were created and added to an encrypted wallet. Co-authored-by: Andrew Chow <achow101-github@achow101.com> Github-Pull: bitcoin/bitcoin#24711 Rebased-From: 0c12f0116ca802f55f5ab43e6c4842ac403b9889
Fixes bitcoin-core/gui#571.
CWallet::Create()notifies about wallet loading too early, that results the notification goes beforeDescriptorScriptPubKeyMans were created and added to an encrypted wallet.And
interfaces::Wallet::taprootEnabled()inbitcoin/src/qt/receivecoinsdialog.cpp
Lines 100 to 102 in ecf692b
falsefor just created encrypted descriptor wallets.