wallet: Postpone wallet loading notification for encrypted wallets #24711

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:220329-taproot changing 4 files +16 −7
  1. hebasto commented at 9:26 pm on March 29, 2022: member

    Fixes bitcoin-core/gui#571.

    CWallet::Create() notifies about wallet loading too early, that results the notification goes before DescriptorScriptPubKeyMans 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.

  2. wallet, refactor: Add wallet::NotifyWalletLoaded() function
    This change is a prerequisite for the following bugfix.
    aeee419c6a
  3. hebasto added the label Bug on Mar 29, 2022
  4. hebasto added the label Wallet on Mar 29, 2022
  5. MarcoFalke added this to the milestone 23.0 on Mar 30, 2022
  6. MarcoFalke added the label Needs backport (23.x) on Mar 30, 2022
  7. fanquake requested review from ryanofsky on Mar 30, 2022
  8. fanquake requested review from achow101 on Mar 30, 2022
  9. in src/wallet/test/wallet_tests.cpp:781 in 471da60a5f outdated
    777@@ -778,34 +778,6 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
    778     BOOST_CHECK_EQUAL(addtx_count, 4);
    779 
    780 
    781-    TestUnloadWallet(std::move(wallet));
    


    Sjors commented at 8:11 am on March 30, 2022:
    471da60a5f16959480be99c77b995165b585c392 Why are you deleting this part of the test?

    hebasto commented at 8:26 am on March 30, 2022:

    It got broken. Cannot point out the reasons though.

    Happy to accept any help with this test.


    Sjors commented at 9:39 am on March 30, 2022:
    It was written and later refactored by @ryanofsky.
  10. Sjors changes_requested
  11. Sjors commented at 8:18 am on March 30, 2022: member
    tACK bf01a515f79d36577bd09986ff002ad6296e431f modulo mysteriously disappearing test
  12. achow101 commented at 3:06 pm on March 30, 2022: member

    The test fails because TestLoadWallet uses CWallet::Create directly. As that function no longer calls the wallet loading functions, the things that are supposed to happen in the test case don’t happen and causes it to fail.

    Since CWallet::Create sets up unencrypted wallets, I think a reasonable alternative approach is to have it also do the same with born encrypted wallets.

    Or the test can use LoadWallet rather than CWallet::Create directly.

  13. hebasto commented at 6:30 pm on March 30, 2022: member

    Or the test can use LoadWallet rather than CWallet::Create directly.

    Have tried the suggested approach for the removed subtest without success – UnloadWallet waits infinitely.

  14. achow101 commented at 6:43 pm on March 30, 2022: member
    Another alternative is to just put NotifyWalletLoaded in TestLoadWallet.
  15. hebasto commented at 6:50 pm on March 30, 2022: member

    Another alternative is to just put NotifyWalletLoaded in TestLoadWallet.

    0error: in "wallet_tests/CreateWallet": check addtx_count == 4 has failed [3 != 4]
    
  16. achow101 commented at 7:15 pm on March 30, 2022: member

    This diff works for me:

     0diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
     1index efb19518d0..683f0eb327 100644
     2--- a/src/wallet/test/wallet_tests.cpp
     3+++ b/src/wallet/test/wallet_tests.cpp
     4@@ -54,6 +54,7 @@ static const std::shared_ptr<CWallet> TestLoadWallet(WalletContext& context)
     5     std::vector<bilingual_str> warnings;
     6     auto database = MakeWalletDatabase("", options, status, error);
     7     auto wallet = CWallet::Create(context, "", std::move(database), options.create_flags, error, warnings);
     8+    NotifyWalletLoaded(context, wallet);
     9     if (context.chain) {
    10         wallet->postInitProcess();
    11     }
    12@@ -778,6 +779,34 @@ BOOST_FIXTURE_TEST_CASE(CreateWallet, TestChain100Setup)
    13     BOOST_CHECK_EQUAL(addtx_count, 4);
    14 
    15 
    16+    TestUnloadWallet(std::move(wallet));
    17+
    18+
    19+    // Load wallet again, this time creating new block and mempool transactions
    20+    // paying to the wallet as the wallet finishes loading and syncing the
    21+    // queue so the events have to be handled immediately. Releasing the wallet
    22+    // lock during the sync is a little artificial but is needed to avoid a
    23+    // deadlock during the sync and simulates a new block notification happening
    24+    // as soon as possible.
    25+    addtx_count = 0;
    26+    auto handler = HandleLoadWallet(context, [&](std::unique_ptr<interfaces::Wallet> wallet) {
    27+            BOOST_CHECK(rescan_completed);
    28+            m_coinbase_txns.push_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
    29+            block_tx = TestSimpleSpend(*m_coinbase_txns[2], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
    30+            m_coinbase_txns.push_back(CreateAndProcessBlock({block_tx}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
    31+            mempool_tx = TestSimpleSpend(*m_coinbase_txns[3], 0, coinbaseKey, GetScriptForRawPubKey(key.GetPubKey()));
    32+            BOOST_CHECK(m_node.chain->broadcastTransaction(MakeTransactionRef(mempool_tx), DEFAULT_TRANSACTION_MAXFEE, false, error));
    33+            SyncWithValidationInterfaceQueue();
    34+        });
    35+    wallet = TestLoadWallet(context);
    36+    BOOST_CHECK_EQUAL(addtx_count, 4);
    37+    {
    38+        LOCK(wallet->cs_wallet);
    39+        BOOST_CHECK_EQUAL(wallet->mapWallet.count(block_tx.GetHash()), 1U);
    40+        BOOST_CHECK_EQUAL(wallet->mapWallet.count(mempool_tx.GetHash()), 1U);
    41+    }
    42+
    43+
    44     TestUnloadWallet(std::move(wallet));
    45 }
    46 
    
  17. wallet: Postpone NotifyWalletLoaded() for encrypted wallets
    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>
    0c12f0116c
  18. hebasto force-pushed on Mar 30, 2022
  19. hebasto commented at 7:29 pm on March 30, 2022: member

    @achow101

    This diff works for me:

    Thanks! Updated.

  20. MarcoFalke commented at 10:38 am on March 31, 2022: member
    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.
  21. hebasto force-pushed on Mar 31, 2022
  22. hebasto commented at 10:52 am on March 31, 2022: member

    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.

  23. Sjors commented at 11:11 am on March 31, 2022: member
    utACK 0c12f0116ca802f55f5ab43e6c4842ac403b9889
  24. achow101 commented at 4:35 pm on March 31, 2022: member
    ACK 0c12f0116ca802f55f5ab43e6c4842ac403b9889
  25. achow101 merged this on Mar 31, 2022
  26. achow101 closed this on Mar 31, 2022

  27. MarcoFalke referenced this in commit 4f3ba8517a on Mar 31, 2022
  28. MarcoFalke referenced this in commit 1448c99380 on Mar 31, 2022
  29. fanquake removed the label Needs backport (23.x) on Mar 31, 2022
  30. fanquake commented at 5:10 pm on March 31, 2022: member
    Backported in #24725.
  31. hebasto deleted the branch on Mar 31, 2022
  32. fujicoin referenced this in commit aa8d5ea8ad on Apr 1, 2022
  33. fujicoin referenced this in commit 019364f585 on Apr 1, 2022
  34. sidhujag referenced this in commit 7d9925aa86 on Apr 3, 2022
  35. dunxen commented at 12:34 pm on April 3, 2022: contributor

    Post-merge tACK 0c12f01

    Got to this when going through v23.0rc3 testing. I’ve checked against this PR and now it works as expected.

  36. backpacker69 referenced this in commit 41d648b6f2 on Jan 18, 2023
  37. backpacker69 referenced this in commit 74427cde08 on Jan 18, 2023
  38. DrahtBot locked this on Apr 3, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-06 16:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me