Skip to content

GUI: Sync RPC console wallet selector with main window selector#331

Open
kwsantiago wants to merge 1 commit into
bitcoinknots:29.x-knotsfrom
privkeyio:fix-rpcconsole-wallet-selector-sync
Open

GUI: Sync RPC console wallet selector with main window selector#331
kwsantiago wants to merge 1 commit into
bitcoinknots:29.x-knotsfrom
privkeyio:fix-rpcconsole-wallet-selector-sync

Conversation

@kwsantiago

Copy link
Copy Markdown

Switching wallets with the main window's toolbar selector does not update the RPC console's wallet selector. Commands typed into the console keep executing against the previously selected wallet, so a user who selects a wallet in the toolbar and then runs sendtoaddress or getbalance in the console silently operates on a different wallet than the one displayed.

This is the exact failure mode 99c0eb9 ("Fix RPCConsole wallet selection") set out to prevent:

If a user opens multiple wallets in the GUI from the menu bar, the last one opened is the active one in the main window. However, for the RPC Console window, the first one opened is active. This can be confusing, as wallet RPC commands may be sent to a wallet the user didn't intend.

That commit connected the console to the open, restore and create wallet activities, but not to the toolbar selector, which is the most common way users switch wallets. The wallet migration path was never connected either.

Rather than adding a fourth per-callsite connect(), this calls RPCConsole::setCurrentWallet() from BitcoinGUI::setCurrentWallet(), alongside the existing walletFrame->setCurrentWallet() call. Every path that changes the active wallet, including the toolbar selector and wallet migration, now keeps the console in sync. rpcConsole is constructed in the BitcoinGUI constructor, well before any wallet can be added, and the console's combo box has no signal connected back to BitcoinGUI, so there is no ordering hazard or signal loop.

Testing

Built with the GUI and wallet enabled and exercised bitcoin-qt on regtest with two wallets loaded, "" and "coin".

Before, after selecting coin in the toolbar:

Executing command using "" wallet
getwalletinfo()[walletname]
                                  <- empty: still the default wallet

After:

Executing command using "coin" wallet
getwalletinfo()[walletname]
coin

The console's wallet selector also visibly follows the toolbar selection.

Additionally verified:

  • Running unloadwallet while the console pointed at that wallet: no crash, both selectors correctly hide with one wallet remaining, and the console falls back to the default wallet. BitcoinGUI::removeWallet() removes from the toolbar selector before rpcConsole->removeWallet(), so the intermediate setCurrentWallet() triggered by currentIndexChanged still resolves a wallet the console knows about.
  • With a single wallet loaded, behavior is unchanged.
  • test_bitcoin-qt passes all suites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant