Skip to content

Conversation

@luke-jr
Copy link
Member

@luke-jr luke-jr commented Mar 3, 2021

Right now, if a GUI user leaves a wallet loaded and something happens to make it error at startup, they're stuck.

This turns the error dialog into a question about starting without the wallet instead.

@luke-jr
Copy link
Member Author

luke-jr commented Mar 3, 2021

Not sure why GitHub thinks this has conflicts - it doesn't.

Mainly this is a WIP because it uses a hacky global to avoid trying to load the wallets the user has chosen to skip... Suggestions for a good way to deal with that?

@hebasto hebasto added UX All about "how to get things done" Wallet labels May 9, 2021
@luke-jr luke-jr force-pushed the gui_init_walleterror_cont branch from 3c8f9fc to 053bd2e Compare July 30, 2021 19:57
@luke-jr luke-jr force-pushed the gui_init_walleterror_cont branch from 053bd2e to fb3ea0a Compare January 10, 2022 01:51
@luke-jr luke-jr marked this pull request as ready for review January 10, 2022 01:51
@luke-jr
Copy link
Member Author

luke-jr commented Jan 10, 2022

Rebased, which made it practical to drop the global hack. This seems ready for review now.

@kristapsk
Copy link
Contributor

Concept ACK, will review / test.

@kristapsk
Copy link
Contributor

Still gives me error message without ability to continue, not question.

$ ./src/qt/bitcoin-qt -version
Bitcoin Core versija v22.99.0-fb3ea0ad3a87
Copyright (C) 2009-2021 The Bitcoin Core developers

Please contribute if you find Bitcoin Core useful. Visit
<https://bitcoincore.org/> for further information about the software.
The source code is available from <https://github.com/bitcoin/bitcoin>.

This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING
or <https://opensource.org/licenses/MIT>

$ git log | head -n 1
commit fb3ea0ad3a8788e023b9ba7237c26fc8ef0dba79
$ ./src/qt/bitcoin-qt -signet
Error: Error loading /fast_home/neonz/.bitcoin/signet/wallets/jmw/wallet.dat: Wallet requires newer version of Bitcoin Core

image

@luke-jr
Copy link
Member Author

luke-jr commented Mar 8, 2022

Ah, it only caught some errors. Pushed a revision that should catch the rest.

@luke-jr luke-jr force-pushed the gui_init_walleterror_cont branch from fb3ea0a to e40c6da Compare March 8, 2022 22:53
@luke-jr luke-jr force-pushed the gui_init_walleterror_cont branch from e40c6da to 243dc11 Compare March 8, 2022 23:32
@kristapsk
Copy link
Contributor

Apart from review comment above, ACK, working for me (tested scenario with trying to load external signer wallet without external signer support compiled into Bitcoin Core).

@luke-jr luke-jr force-pushed the gui_init_walleterror_cont branch from 243dc11 to cc85951 Compare March 9, 2022 03:35
Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK cc85951

@hebasto hebasto requested a review from ryanofsky April 4, 2022 18:44
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! I think there is a minor problem in the implementation, where if a user chooses not to load any wallet, none of the bitcoin.conf or command line wallets will be loaded even if they were present and could be verified. I suggested a fix for this below.


if (modified_wallet_list) {
// Ensure new wallet list overrides commandline options
args.ForceSetArgV("wallet", chain.getRwSetting("wallet"));
Copy link
Contributor

@ryanofsky ryanofsky Apr 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Bugfix: GUI: Allow the user to start anyway when loading a wallet errors" (cc85951)

Two issues this line:

  1. This prevents all bitcoin.conf or command line wallets from being loaded if modified_wallet_list is true, because getRwSetting() doesn't return these wallets (it only returns settings.json wallets).
  2. This line has no effect if wallet code is running in a separate process, because ForceSet call is changing wallet process args, but code that runs later in LoadWallet is calling chain.getSettingsList which reads the node process args instead of wallet process args. The code was confused even before this PR, but this change would make it actually not work correctly.

Would suggest a change like the following as a fix:

diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index 6f900a64375..5c7c66a62ba 100644
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -270,6 +270,10 @@ public:
     //! Get list of settings values.
     virtual std::vector<util::SettingsValue> getSettingsList(const std::string& arg) = 0;
 
+    //! Override setting in memory, so future getSetting / GetArg calls return
+    //! specified value. If value is null, will unset any previously forced value.
+    virtual void forceSetting(const std::string& name, const util::SettingsValue& value) = 0;
+
     //! Return <datadir>/settings.json setting value.
     virtual util::SettingsValue getRwSetting(const std::string& name) = 0;
 
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 364a8406af7..0f2f90c11e5 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -692,6 +692,16 @@ public:
     {
         return gArgs.GetSettingsList(name);
     }
+    void forceSetting(const std::string& name, const util::SettingsValue& value) override
+    {
+        gArgs.LockSettings([&](util::Settings& settings) {
+            if (value.isNull()) {
+                settings.forced_settings.erase(name);
+            } else {
+                settings.forced_settings[name] = value;
+            }
+        });
+    }
     util::SettingsValue getRwSetting(const std::string& name) override
     {
         util::SettingsValue result;
diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp
index ecd832d6224..8a1164ae71d 100644
--- a/src/wallet/load.cpp
+++ b/src/wallet/load.cpp
@@ -66,7 +66,7 @@ bool VerifyWallets(WalletContext& context)
 
     // For backwards compatibility if an unnamed top level wallet exists in the
     // wallets directory, include it in the default list of wallets to load.
-    if (!args.IsArgSet("wallet")) {
+    if (chain.getSetting("wallet").isNull()) {
         DatabaseOptions options;
         DatabaseStatus status;
         bilingual_str error_string;
@@ -86,6 +86,7 @@ bool VerifyWallets(WalletContext& context)
     std::set<fs::path> wallet_paths;
 
     bool modified_wallet_list = false;
+    util::SettingsValue verified_wallets{UniValue::VARR};
     for (const auto& wallet : chain.getSettingsList("wallet")) {
         const auto& wallet_file = wallet.get_str();
         const fs::path path = fsbridge::AbsPathJoin(GetWalletDir(), fs::PathFromString(wallet_file));
@@ -110,12 +111,14 @@ bool VerifyWallets(WalletContext& context)
                     return false;
                 }
             }
+        } else {
+            verified_wallets.push_back(wallet_file);
         }
     }
 
     if (modified_wallet_list) {
-        // Ensure new wallet list overrides commandline options
-        args.ForceSetArgV("wallet", chain.getRwSetting("wallet"));
+        // Prevent loading any command-line or bitcoin.conf wallets that failed to verify.
+        chain.forceSetting("wallet", verified_wallets);
     }
 
     return true;

@hebasto hebasto changed the title Bugfix: GUI: Allow the user to start anyway when loading a wallet errors Bugfix: Allow the user to start anyway when loading a wallet errors Apr 15, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 12, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@luke-jr luke-jr force-pushed the gui_init_walleterror_cont branch from cc85951 to 6cbea59 Compare September 5, 2022 23:48
@ryanofsky
Copy link
Contributor

ryanofsky commented Oct 6, 2022

@luke-jr do you want to respond to suggestions here? Or would you be open to a someone making a new PR?

Status of the PR seems to be that it is up to date, but has a bug that could cause command line and bitcoin.conf wallets to be ignored. I suggested a fix for the bug and some cleanups in #236 (comment).

I think there is also a usability problem with this PR in the case of temporary errors where a wallet can't be loaded due to a temporary issue like: background assumeutxo download bitcoin/bitcoin#23997, pruning, a missing external signer bitcoin/bitcoin#22173, an encrypted drive not being mounted, a removable drive not being plugged in, or a version incompatibility that will be resolved by upgrading or downgrading. In these cases it would be useful to have the option to continue starting the GUI and letting the node sync, while temporarily not loading individual wallets that are unavailable, and the current dialog doesn't provide an option to temporarily not load a wallet. The only options are quit or continue without loading the wallet next time. I think it would be a improvement to change the dialog to "Wallet could not be loaded because of , do you want to try to load it next time Bitcoin Core is started?" with "Yes" "No" buttons (and maybe "Details" and "Abort" buttons off to the side like #379). This was one of four alternatives suggested in #95, and there is more discussion about this issue there.

@hebasto
Copy link
Member

hebasto commented Dec 6, 2022

@luke-jr do you want to respond to suggestions here? Or would you be open to a someone making a new PR?

I'm going to close this, and mark "Up for grabs".

@hebasto hebasto closed this Dec 6, 2022
@bitcoin-core bitcoin-core locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Up for grabs UX All about "how to get things done" Wallet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants