-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toggle chain from menu (using Settings) #414
Conversation
I think you could just use QSettings for this, the same way the GUI datadir preference and all other other GUI-only settings are stored in QSettings. Even bitcoin/bitcoin#15936 which consolidates bitcoin-qt and bitcoind settings in settings.json still stores GUI-only settings in QSettings. |
I guess thinking more generally, for example if we did want to add a I guess my preference would be to take this general approach and store the network preference in the No matter which location is chosen, it could in theory be migrated somewhere else later, but migrating would be at least a little messy and could create edge cases when downgrading, so it is good to put a little effort into choosing the best location now. |
If we're keeping some QSettings around anyway, I might as well use that. With |
13bbc6d
to
0391893
Compare
I switched to using QSettings. Similar to This PR uses the same trick in reverse: it changes the application name back to mainnet right before updating the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
This PR adds the functionality to select a network chain directly from the GUI, making it easier to toggle between the chains. This is achieved by adding a context menu option to set the -chain suboption to the selected chain type and closing the GUI. So that when next time GUI will start, the value of -chain suboption will by default be set to the last selected network by the user. This value, as I observed, can always be overridden while opening the bitcoin GUI through the command line.
Tested the PR on Ubuntu 20.04. The PR works as described by OP. I am adding the screenshot of the added context menu options.
This PR also has a byproduct benefit that is not discussed till now. For a person like me who mainly works on a signet network, I do not have to explicitly create an alias or select the signet chain each time I want to open GUI. So that’s great!
I have a few suggestions I want to put forward that might further improve the PR:
- Before line 459:
QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm chain"),
Add translator’s comment for text in the StandardButton.
- Add mnemonic shortcuts for the added context menu options.
- It would be great if the GUI could automatically start after toggling the chain instead of simply closing the app.
@ShaMan239 thanks for the review! I added a translator hint and keyboard shortcuts (I can't test those on macOS, new screenshot is welcome). Unfortunately afaik Bitcoin Core can't restart itself. This is a problem with some settings changes too. |
0391893
to
79af0d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Translator’s comments look good.
Regarding the mnemonics shortcuts, there are some collisions between them.
Load PSBT from &clipboard
<-> Switch &chain
&Backup wallet
<-> &Bitcoin
Unfortunately, afaik Bitcoin Core can't restart itself.
Well, that’s a bummer. I was just wondering if this feature could be added and would that even be worth adding.
Maybe I misunderstand how these shortcuts work... Wouldn't "c" take you to the chain submenu and then "b" to Bitcoin inside that menu? Or all the shortcuts global? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK, makes sense to have this separate from other options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK 79af0d6.
Also added the check on the current chain to better indicate why the current is disabled.
with the following
+ const bool is_current = gArgs.GetChainName() == chain.first.toStdString();
QAction* action = m_chain_selection_menu->addAction(chain.second);
-
- if (gArgs.GetChainName() == chain.first.toStdString()) {
- action->setEnabled(false);
- }
+ action->setCheckable(true);
+ action->setChecked(is_current);
+ action->setEnabled(!is_current);
Now I can't pick a different chain from the command line, for instance |
79af0d6
to
246d065
Compare
@promag thanks, addressed comments and added the checkmark. Though on my machine I can't see the checkmark (QT 6.1.2 via homebrew). Once you use the GUI to select a chain, there's no way back :-) Actually you can still use The chain is a special case with so many weird rules, I'd rather not mess with: Lines 129 to 143 in f4e12fd
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 246d065.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
- Still having this error on Linux:
Now I can't pick a different chain from the command line, for instance
src/qt/bitcoin-qt -regtest
givesError: Invalid combination of -regtest, -signet, -testnet and -chain. Can use at most one.
.
UPDATE:
Once you use the GUI to select a chain, there's no way back :-)
Maybe always add the chain
value to settings at the first run the new code, and notify users about new behavior?
END OF UPDATE
-
It seems possible to move all new code from
BitcoinGUI::createActions()
toBitcoinGUI::createMenuBar()
and use the local variablechain_selection_action
instead of the data memberm_chain_selection_action
. -
Why not add translator comments to all of the added
tr()
arguments?
src/qt/bitcoingui.cpp
Outdated
connect(action, &QAction::triggered, [this, chain] { | ||
//: Switch to the mainnet, testnet, signet or regtest chain. | ||
QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Switch chain"), | ||
tr("Client restart required to switch chain.") + "<br><br>" + tr("Client will be shut down. Do you want to proceed?"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translators will much appreciate if both strings belong to the same context:
tr("Client restart required to switch chain.") + "<br><br>" + tr("Client will be shut down. Do you want to proceed?"), | |
tr("Client restart required to switch chain.\n\nClient will be shut down. Do you want to proceed?"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/qt/bitcoingui.cpp
Outdated
} | ||
|
||
connect(action, &QAction::triggered, [this, chain] { | ||
//: Switch to the mainnet, testnet, signet or regtest chain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hebasto: "Why not add translator comments to all of the added tr() arguments?"
Noting down some guidance for translator comments here and for the future:
Translator comments should attempt to provide a translator with the appropriate context to aid them with translating a certain string.
Proper context is:
- Where is this string shown?
- e.g; Shown in the Create Wallet dialog, Shown in file menu options ...
- What action is associated with this string?
- If the string is associated with a button, what is the outcome of pressing the button
Optional context is:
- Explain what the string is meant to convey
- This is an explanatory text shown after X that aims to inform the user that ...
- Provide alternatives to complicated/technical words
- Some words may not have a direct one-to-one translation in certain languages. It is nice to provide a replacement for such a word. For example, some languages may not have a 1-1 translation for the word
subnet
, an appropriate replacement for this word can beIP address
.
- Some words may not have a direct one-to-one translation in certain languages. It is nice to provide a replacement for such a word. For example, some languages may not have a 1-1 translation for the word
This context makes the job of translators easier and allows for more effective translations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes since my last review:
- The checkmark is added along with the options to emphasize which chain is currently selected. I think it makes sense to add a checkmark, so I agree with this change
Adding screenshots of the visual change before and after updating PR.
Before Update | After Update |
---|---|
![]() |
![]() |
Maybe I misunderstand how these shortcuts work... Wouldn't "c" take you to the chain submenu and then "b" to Bitcoin inside that menu? Or all the shortcuts global?
I just checked if the shortcuts are global. They are not, and so I have updated my comment accordingly.
But there is still the collision of mnemonics between Load PSBT from &clipboard
and Switch &chain
as they are part of the same menu. So I would recommend updating the mnemonics shortcut to &S
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 39a58f4d1..5aedbbf43 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -441,7 +441,7 @@ void BitcoinGUI::createActions()
}
#endif // ENABLE_WALLET
- m_chain_selection_action = new QAction(tr("Switch &chain"), this);
+ m_chain_selection_action = new QAction(tr("&Switch chain"), this);
m_chain_selection_action->setStatusTip(tr("Restart application using a different (test) network"));
m_chain_selection_menu = new QMenu(this);
Done, and added a release note. I moved the menu stuff to
Done (I think). I switched the shortcut to |
b1447d8
to
bc72b19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK bc72b19
Tested on Ubuntu 20.04 (Using Qt version 5.12.8)
Updates since my last review:
- Release notes are added to inform users about the change in behavior in the way of using chain variables.
- GUI will open on the mainnet when the user specifies no specific chain, either through Command-Line or GUI.
- The scope of the
chain_selction_menu
variable has been changed from global to local.
btnRetVal
renamed tobtn_ret_val
according to the naming convention. - The mnemonic shortcut of the switch chain option has been changed from
&c
to&S
, removing shortcut collision.
I tested the updated PR on Ubuntu 20.04. The PR works perfectly. Also, I followed the release notes word by word while testing. They are correct too. The collision between mnemonic shortcuts has been resolved, and the new mnemonic shortcut is working perfectly.
I am adding the screenshot of the latest commit.
Thanks for this amazing work, @Sjors!
@kallewoof @ajtowns you might enjoy this PR |
That sounds like it could potentially be a really confusing eventual .5 TB loss of disk space for users who think "regtest" means "regtest" and not "regtest with a slice of main net syncing in the background".. The "document" approach seems sensible, i.e. where you "open" instances (main/test/sig/reg/custom) from within the application. Could be potentially really useful if you are doing multiple regtests and like doing things in the GUI. |
@Sjors thx for PR. Please add support of custom private rpc for regtest. |
Receiving this alert on MacOS
|
Running Cirrus on PR: Running Cirrus on the rebased branch: |
It seems that Switch chain belongs in the Settings menu: |
12431e0
to
f3ddafa
Compare
@RandyMcMillan thanks for testing! That crash is worrying. I'm getting this too now some of the time. Inspired by #336 I changed I also moved the menu to Settings. And rebased.
I'm not sure what you mean by this. |
I will retest shortly - this sounds like a much friendlier method of shutdown... |
The selected chain is stored in the QSettings for mainnet.
f3ddafa
to
df3ad9a
Compare
Thanks! I fixed the duplicate "ClientClient" string. |
reACK Approach df3ad9a Tested on MacOS Arm64 - shutting down cleanly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reservations about this feature, and also think the implementation could be improved, but code review ACK 12431e0 since I don't think there are problems with the code.
Code review comments below suggest ways to improve the implementation, and I also agree with luke-jr (#414 (comment)) and kalle and achow and jarolrod that in general this change could result in confusion and be a net negative. I mostly just don't think it makes sense from a user perspective that you are forced to shut down your connection and wallets for one network to connect to a different network, instead of just opening different networks in different windows. There's no problem doing this on Linux or Windows (IIUC from #78 (comment)) because Linux and Windows packages can provide separate icons for launching testnet and signet instances. Ideally the mac package would just provide separate icons as well so we wouldn't need this less flexible and potentially confusing toggle.
I don't see a technical reason why providing separate icons shouldn't be possible on mac. This guide about creating DMGs https://intmaker.com/deploy-to-macos/ has a section "Level 3: additional applications" about adding helper applications alongside the main application. In this case, helper applications could be Bitcoin-Qt (testnet)
and Bitcoin-Qt (signet)
scripts that call the main Bitcoin-Qt
application with appropriate command line arguments. https://superuser.com/a/16777 shows how to write applescripts that invoke applications with command lines and https://apple.stackexchange.com/a/407885 shows how to package scripts as applications with icons.
Another approach would be to replace the "Switch Chain" toggle menu with an "Open Chain" menu, which would just open new windows connecting to other networks, instead of closing down the whole application and restarting. The implementation could still use QSettings to remember what windows are open so relaunching bitcoin will reopen the same windows (Or if every window was manually closed by the user, reopen the last closed window).
//: Switch to the mainnet, testnet, signet or regtest chain. | ||
QMessageBox::StandardButton btn_ret_val = QMessageBox::question(this, tr("Switch chain"), | ||
//: Switching between mainnet, testnet, signet or regtest chain requires a restart. | ||
tr("Client restart required to switch chain.\n\nClient will be shut down. Do you want to proceed?"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "gui: toggle chain via menu" (12431e0)
I think it would be good for the dialog to describe what the option actually does. I'm concerned that someone could click this without really understanding it, and then next time they start bitcoin they find their wallets are missing and bitcoin is doing a new sync to a different network.
I think ideally dialog would say something like. "Are you sure you want to switch networks from main to test? Testnet coins are separate from actual bitcoins, and are not supposed to have any value. Switching networks
requires restarting Bitcoin Core, and any existing wallets from the current network will be hidden while using the other network. It will be possible to switch back to the current network by using the "Switch chain" menu again and restarting." It could also be good to change the affirmative button text from "Yes" to something more explicit like "Switch to {network name} network and exit."
@@ -564,6 +564,10 @@ int GuiMain(int argc, char* argv[]) | |||
// - QSettings() will use the new application name after this, resulting in network-specific settings | |||
// - Needs to be done before createOptionsModel | |||
|
|||
QSettings settings; | |||
std::string chain = settings.value("chain", "main").toString().toStdString(); | |||
gArgs.SoftSetArg("-chain", chain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "gui: toggle chain via menu" (12431e0)
It might be good to show a message on startup the first time bitcoin is started after switching networks.
The toggle chain menu could set a boolean "switched_chain" QSetting, and this code could check for the "switched_chain" setting, clear it, and show a message like "Bitcoin Core is connecting to new network {network}. Use the "Switch chain" menu to switch networks again." (It could be a dialog with a "Do not show this message in the future checkbox" if users switch network repeatedly.) But I think this would provide a useful alert and a good second chance to recover if someone clicked through the first dialog not expecting bitcoin to be starting from scratch again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #414 (comment)
It might be good to show a message on startup the first time bitcoin is started after switching networks. [...]
Replying to myself, maybe a better startup message would be: "Bitcoin-Qt configuration has changed and will now connect to the {Testnet} network instead of the {Mainnet} network. {Mainnet} wallets will not be loaded while connected to the {Testnet} network. Also {Testnet} coins are separate from actual bitcoins, and are not supposed to have any value." Dialog could include a checkbox "Do not show this message again," and buttons "Continue connecting to {Testnet} network" / "Exit and switch back to {Mainnet network}" for a safe escape.
(And again I really think ideally none of these dialogs would be necessary and new networks would just open in new windows without closing existing ones. But showing clear messages could at least avoid pitfalls if only one window can be open at a time)
- Toggle chain from mainnet to testnet, signet or regtest. The GUI now always sets `-chain`, | ||
so any occurrences of `-testnet`, `-signet` or `-regtest` in `bitcoin.conf` should | ||
be replace with `chain=test`, `chain=signet` or `chain=regtest` respectively. (bitcoin-core/gui#414) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "gui: toggle chain via menu" (12431e0)
I think it would be better if these notes were clearer about what behavior is. What happens if you don't follow the advice? Is this saying if you run use -testnet the parameter will be silently ignored because the GUI overrides it internally?
If so, I think this might rise to the level of a bug because command line arguments by design are supposed to override GUI settings and other configuration sources. If not, and there is an explicit error about conflicting settings, that is probably ok. But I think ideally GUI setting would still be overridden if -chain or -testnet or -signet or -regtest were specified. It seems like it should be trivial to implement that instead of requiring users to read this and change their setups.
|
||
connect(chain_selection_menu, &QMenu::aboutToShow, [this, chain_selection_menu] { | ||
chain_selection_menu->clear(); | ||
const std::vector<std::pair<QString, QString>> chains = {{"main", "&Bitcoin"}, {"test", "&Testnet"}, {"regtest", "&Regtest"}, {"signet", "&Signet"}}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "gui: toggle chain via menu" (12431e0)
Interesting the text is is "Bitcoin" instead of "Mainnet". I think that it is good because it implies the other networks are not the Bitcoin network. Another way to do this while being a little more consistent could be to make the choices "Mainnet (Bitcoin)" / "Testnet" / "Regtest" / "Signet"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted this as well - IMO "Bitcoin" is a better way to go - "Mainnet" may actually confuse new users at this point.
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
@ryanofsky thanks for all the comments, I'm a bit behind on things, but will get to them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #414 (comment)
@ryanofsky thanks for all the comments, I'm a bit behind on things, but will get to them.
👍
Even though I suggested a lot of changes, I think this PR is ok in its current form. The other reviewers who objected to this PR previously should speak up if they still have issues with it, or if they think any changes would make it better. Sjors has already put a good amount of work into this, and some of the changes I suggested would require even more effort. So it'd be good to sync up and make sure effort is not wasted.
@@ -564,6 +564,10 @@ int GuiMain(int argc, char* argv[]) | |||
// - QSettings() will use the new application name after this, resulting in network-specific settings | |||
// - Needs to be done before createOptionsModel | |||
|
|||
QSettings settings; | |||
std::string chain = settings.value("chain", "main").toString().toStdString(); | |||
gArgs.SoftSetArg("-chain", chain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #414 (comment)
It might be good to show a message on startup the first time bitcoin is started after switching networks. [...]
Replying to myself, maybe a better startup message would be: "Bitcoin-Qt configuration has changed and will now connect to the {Testnet} network instead of the {Mainnet} network. {Mainnet} wallets will not be loaded while connected to the {Testnet} network. Also {Testnet} coins are separate from actual bitcoins, and are not supposed to have any value." Dialog could include a checkbox "Do not show this message again," and buttons "Continue connecting to {Testnet} network" / "Exit and switch back to {Mainnet network}" for a safe escape.
(And again I really think ideally none of these dialogs would be necessary and new networks would just open in new windows without closing existing ones. But showing clear messages could at least avoid pitfalls if only one window can be open at a time)
Concept reACK If a custom signet is detected - It would be great to add a truncated "finger print" of the active signet_challenge - I have experimented with adding a signet challenge to the window title and menu and the string is simply too long - but a "finger print" will work in the window title. Maybe use a finger print with 8 chars? examples:
Just an idea...but if this was added - option 3 seems best IMO. |
Concept re-NACK. How about for macOS only, a menu item that simply launches a separate instance on a test network? |
What is the status of this PR? |
@hebasto still on my list to look into some of the other approaches suggested above. But if anyone else wants to do it sooner, don't hesitate!
That would be fine by me, not sure if it requires adding dependencies to launch an application. |
Closing this as it has not had any activity in a while. If you are interested in continuing work on this, please leave a comment so that it can be reopened.
Will be labeled "Up for grabs". |
Implements #78
It's currently not easy for GUI users to switch to a test chain like signet. E.g on macOS this requires using the command line, since Spotlight doesn't let you add an argument like
-signet
.This PR makes it easier by adding a menu option to restart with a different chain.
It does this by adding aIt does this by adding.chain_gui
file. Unfortunately we can't usesettings.json
, because this file is network specific. This file is ignored bybitcoind
.chain
to the mainnet QSettings.
(it's now under Settings, not File)