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.

@pdath

pdath commented Jul 15, 2026

Copy link
Copy Markdown

ACK accba6a

I reviewed the change and the fix seems elegant and simple.

I reviewed the change with Code Rabbit and it found no issues.

I built the system using Ubuntu 24.04 running on ARMv8-A (64-bit) with gcc and used guix to create a Windows binary.

git clone https://github.com/bitcoinknots/bitcoin.git pr331
cd pr331
git fetch origin pull/331/head:pr331
git switch pr331
cmake -B build -DCMAKE_BUILD_TYPE=Release -DRDTS_CONSENT=IMPLICIT
nice cmake --build build -j$(nproc)

I then built using guix.

env HOSTS='x86_64-w64-mingw32' ./contrib/guix/guix-build

And tested with:

bitcoin-qt.exe -regtest

I repeated the test of creating two wallets, and the fix works for me. The console follows the selected wallet.

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.

2 participants