wallet: RPC coin locking leaves coin status and available balance stale #995

Open
opened 2026-10-12 00:21:29 +00:00 by jarolrod · 1 comment
jarolrod commented 2026-10-12 00:21:29 +00:00 (Migrated from github.com)

Locking a coin through RPC leaves the GUI showing its previous lock state and available balance. I reproduced both on qt6: Core reports the only spendable coin as locked, but the open coin row still shows it unlocked and Send still shows 50 BTC available.

These are two views of the same refresh gap, so I'm tracking them together.

Environment

  • macOS 26.6.2, Qt 6.9.0, Release build.
  • Tested qt6 at a91f4b4774f25de061fe1a7c132a91ddde117fca.
  • Current qt6 is 09c6de77d7f36bf7fa07c354ebeea51105c447a3; the relevant wallet and coin model code is unchanged.
  • Real disposable regtest wallets. The test-automation build was used to navigate the QML views and read their displayed values; Core's RPC results were checked independently.

Setup

Start the GUI with a fresh regtest datadir and RPC enabled. Below, cli means bitcoin-cli -regtest -datadir=/absolute/path/to/test-datadir, plus any RPC options for that node.

Create a wallet with exactly one mature 50 BTC output. Mine the following 100 blocks to an address outside this wallet so they do not create more wallet transactions:

cli -named createwallet wallet_name=rpc_lock
RECEIVE_ADDR=$(cli -rpcwallet=rpc_lock getnewaddress)
OUTSIDE_ADDR=bcrt1qdavt4j2sd7dlhqsavtnfxvzppw6k7qy97tmnu9
cli generatetoaddress 1 "$RECEIVE_ADDR"
cli generatetoaddress 100 "$OUTSIDE_ADDR"
cli -rpcwallet=rpc_lock listunspent

Select rpc_lock in the GUI. Copy the sole output's txid and vout from listunspent for the commands below.

Reproduce the stale coin row

  1. Open Settings → Wallet settings → View coins while the output is unlocked.

  2. Leave the view open and lock that output from a terminal:

    cli -rpcwallet=rpc_lock lockunspent false '[{"txid":"<txid>","vout":<vout>}]'
    cli -rpcwallet=rpc_lock listlockunspent
    
  3. Core lists the locked output, but the existing GUI row retains its unlocked state.

Reproduce the stale available balance

  1. Unlock the same output through RPC:

    cli -rpcwallet=rpc_lock lockunspent true '[{"txid":"<txid>","vout":<vout>}]'
    
  2. Open Send with no manually selected inputs and confirm that available balance is 50 BTC.

  3. Run the same lockunspent false command again while Send remains open. Check listlockunspent and listunspent without generating an address, changing a label, or sending another transaction.

The recorded results were:

Coin view:
  Core locked: true
  GUI locked:  false

Send:
  Before RPC lock:          50.00000000 BTC
  Core listunspent after:   []
  GUI available after:      50.00000000 BTC

The Send check still showed the old value after a two-second wait. getbalances.mine.trusted is not the comparison for this check: locking a coin does not remove it from the wallet's trusted balance.

Expected result

RPC lock/unlock changes should refresh both the coin list and the available balance without requiring another wallet event or reopening the wallet.

This gives users conflicting information about which coins are available. The reproduction establishes stale GUI state; it does not establish an unintended spend.

The coin model refreshes on transaction, address-book and balance signals, but external coin-lock changes do not produce the wallet notifications it relies on. Refreshing only after a GUI lock command won't cover this path.

Related to #974. This behavior already exists on qt6; it is not introduced by #990. A regression test should keep each view open, lock and unlock through RPC without another wallet notification, and compare both displayed states with Core.

Locking a coin through RPC leaves the GUI showing its previous lock state and available balance. I reproduced both on `qt6`: Core reports the only spendable coin as locked, but the open coin row still shows it unlocked and Send still shows 50 BTC available. These are two views of the same refresh gap, so I'm tracking them together. ### Environment - macOS 26.6.2, Qt 6.9.0, Release build. - Tested `qt6` at `a91f4b4774f25de061fe1a7c132a91ddde117fca`. - Current `qt6` is `09c6de77d7f36bf7fa07c354ebeea51105c447a3`; the relevant wallet and coin model code is unchanged. - Real disposable regtest wallets. The test-automation build was used to navigate the QML views and read their displayed values; Core's RPC results were checked independently. ### Setup Start the GUI with a fresh regtest datadir and RPC enabled. Below, `cli` means `bitcoin-cli -regtest -datadir=/absolute/path/to/test-datadir`, plus any RPC options for that node. Create a wallet with exactly one mature 50 BTC output. Mine the following 100 blocks to an address outside this wallet so they do not create more wallet transactions: ```sh cli -named createwallet wallet_name=rpc_lock RECEIVE_ADDR=$(cli -rpcwallet=rpc_lock getnewaddress) OUTSIDE_ADDR=bcrt1qdavt4j2sd7dlhqsavtnfxvzppw6k7qy97tmnu9 cli generatetoaddress 1 "$RECEIVE_ADDR" cli generatetoaddress 100 "$OUTSIDE_ADDR" cli -rpcwallet=rpc_lock listunspent ``` Select `rpc_lock` in the GUI. Copy the sole output's `txid` and `vout` from `listunspent` for the commands below. ### Reproduce the stale coin row 1. Open **Settings → Wallet settings → View coins** while the output is unlocked. 2. Leave the view open and lock that output from a terminal: ```sh cli -rpcwallet=rpc_lock lockunspent false '[{"txid":"<txid>","vout":<vout>}]' cli -rpcwallet=rpc_lock listlockunspent ``` 3. Core lists the locked output, but the existing GUI row retains its unlocked state. ### Reproduce the stale available balance 1. Unlock the same output through RPC: ```sh cli -rpcwallet=rpc_lock lockunspent true '[{"txid":"<txid>","vout":<vout>}]' ``` 2. Open **Send** with no manually selected inputs and confirm that available balance is 50 BTC. 3. Run the same `lockunspent false` command again while Send remains open. Check `listlockunspent` and `listunspent` without generating an address, changing a label, or sending another transaction. The recorded results were: ```text Coin view: Core locked: true GUI locked: false Send: Before RPC lock: 50.00000000 BTC Core listunspent after: [] GUI available after: 50.00000000 BTC ``` The Send check still showed the old value after a two-second wait. `getbalances.mine.trusted` is not the comparison for this check: locking a coin does not remove it from the wallet's trusted balance. ### Expected result RPC lock/unlock changes should refresh both the coin list and the available balance without requiring another wallet event or reopening the wallet. This gives users conflicting information about which coins are available. The reproduction establishes stale GUI state; it does not establish an unintended spend. The [coin model](https://github.com/bitcoin-core/gui-qml/blob/a91f4b4774f25de061fe1a7c132a91ddde117fca/qml/models/coinslistmodel.cpp#L12) refreshes on transaction, address-book and balance signals, but external coin-lock changes do not produce the wallet notifications it relies on. Refreshing only after a GUI lock command won't cover this path. Related to #974. This behavior already exists on `qt6`; it is not introduced by #990. A regression test should keep each view open, lock and unlock through RPC without another wallet notification, and compare both displayed states with Core.
jarolrod commented 2026-11-11 21:29:19 +00:00 (Migrated from github.com)

One consequence of the stale available balance, at eed1f426fcb6: with Use maximum, the "Use all available funds?" prompt quotes one amount and the review then prepares another.

Regtest wallet with a 2 BTC coin and a 0.4 BTC coin, Automatic coin selection, 1 sat/vB.

After an outside unlock

  1. Lock the 0.4 BTC coin in View coins. In Send, enter an address and click Use maximum: the amount is 1.99999890, Available 2.00000000 BTC.
  2. Unlock the coin with lockunspent true, from bitcoin-cli or from the app's own RPC console.
  3. Back on Send the form is unchanged, 20 and 60 seconds later. Click Review Transaction.

The prompt reads "You're preparing to send all available funds (1.99999890 BTC) from this wallet." After Use maximum, the review shows 2.39999823 BTC to the recipient, a total of 2.40000000 BTC and 2 inputs, with Ready to send and Send transaction enabled. That is 0.4 BTC more than the amount on the form and in the prompt just accepted.

After an outside lock

The other direction: with both coins unlocked the form shows 2.39999823, and the 0.4 BTC coin is then locked with lockunspent false. Thirty seconds later the prompt still quotes 2.39999823 BTC, and the review shows 1.99999890 BTC from one input. After closing the review the form shows 1.99999890 with Available 2.40000000 BTC, Amount plus fee exceeds available balance and a disabled Review button, until View coins is opened.

The prompt uses the form's total (SendCreate.qml#L1199-L1205), and preparing the transaction then reads the wallet afresh. The review page shows the true amount and inputs, and I sent nothing. A lock or unlock made with the app's own Lock coins updates Send at once.

Tested on macOS / Qt 6.9, isolated regtest, offscreen only. The unlock case was run twice, once from the app's console and once from bitcoin-cli; the lock case once. The console command was set into its field and submitted through the console's Enter handler; every other step was a click or typing through the test bridge. I have not run this on #990.

One consequence of the stale available balance, at `eed1f426fcb6`: with **Use maximum**, the "Use all available funds?" prompt quotes one amount and the review then prepares another. Regtest wallet with a 2 BTC coin and a 0.4 BTC coin, Automatic coin selection, 1 sat/vB. **After an outside unlock** 1. Lock the 0.4 BTC coin in View coins. In Send, enter an address and click **Use maximum**: the amount is 1.99999890, Available 2.00000000 BTC. 2. Unlock the coin with `lockunspent true`, from `bitcoin-cli` or from the app's own RPC console. 3. Back on Send the form is unchanged, 20 and 60 seconds later. Click **Review Transaction**. The prompt reads "You're preparing to send all available funds (1.99999890 BTC) from this wallet." After **Use maximum**, the review shows 2.39999823 BTC to the recipient, a total of 2.40000000 BTC and 2 inputs, with **Ready to send** and **Send transaction** enabled. That is 0.4 BTC more than the amount on the form and in the prompt just accepted. **After an outside lock** The other direction: with both coins unlocked the form shows 2.39999823, and the 0.4 BTC coin is then locked with `lockunspent false`. Thirty seconds later the prompt still quotes 2.39999823 BTC, and the review shows 1.99999890 BTC from one input. After closing the review the form shows 1.99999890 with Available 2.40000000 BTC, **Amount plus fee exceeds available balance** and a disabled Review button, until View coins is opened. The prompt uses the form's total ([SendCreate.qml#L1199-L1205](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/pages/wallet/SendCreate.qml#L1199-L1205)), and preparing the transaction then reads the wallet afresh. The review page shows the true amount and inputs, and I sent nothing. A lock or unlock made with the app's own Lock coins updates Send at once. Tested on macOS / Qt 6.9, isolated regtest, offscreen only. The unlock case was run twice, once from the app's console and once from `bitcoin-cli`; the lock case once. The console command was set into its field and submitted through the console's Enter handler; every other step was a click or typing through the test bridge. I have not run this on #990.
Sign in to join this conversation.
No description provided.