Keep external signer discovery and approval responsive #977

Open
opened 2026-10-02 17:35:55 +00:00 by johnny9 · 3 comments
johnny9 commented 2026-10-02 17:35:55 +00:00 (Migrated from github.com)

Parent: #583.

Opening signer settings, creating a signer wallet or approving a transaction can wait for an external subprocess. A GUI timer only postpones that wait. Signing may hold wallet locks, so moving the subprocess call alone is insufficient if GUI getters still query the backend.

Cover listExternalSigners(), discovery during creation and initialization, and device signing through fillPSBT(), imported PSBTs and fee replacement.

Run blocking work outside the GUI thread. Expose pending, available, unavailable and error states; coalesce repeated discovery; prevent duplicate approval; and reject results after settings, wallet or transaction changes. Keep the reviewed transaction bound to its approval and return complete results without GUI-side backend queries.

Define helper lifetime, timeout, cancellation and shutdown behavior explicitly. Discarding a result does not stop a running subprocess. Keep resources valid while it runs and avoid overlapping device commands after navigation or retry.

Acceptance should cover delayed or hung helpers, missing/multiple devices, malformed output, failure/retry, partial signatures, wallet changes and shutdown during discovery or approval.

Parent: #583. Opening signer settings, creating a signer wallet or approving a transaction can wait for an external subprocess. A GUI timer only postpones that wait. Signing may hold wallet locks, so moving the subprocess call alone is insufficient if GUI getters still query the backend. Cover `listExternalSigners()`, discovery during creation and initialization, and device signing through `fillPSBT()`, imported PSBTs and fee replacement. Run blocking work outside the GUI thread. Expose pending, available, unavailable and error states; coalesce repeated discovery; prevent duplicate approval; and reject results after settings, wallet or transaction changes. Keep the reviewed transaction bound to its approval and return complete results without GUI-side backend queries. Define helper lifetime, timeout, cancellation and shutdown behavior explicitly. Discarding a result does not stop a running subprocess. Keep resources valid while it runs and avoid overlapping device commands after navigation or retry. Acceptance should cover delayed or hung helpers, missing/multiple devices, malformed output, failure/retry, partial signatures, wallet changes and shutdown during discovery or approval.
jarolrod commented 2026-10-15 08:04:41 +00:00 (Migrated from github.com)

Found two concrete cases for keeping signer approval tied to the transaction being reviewed. Both happen within the same wallet.

Tested on qt6 at d567e3eb2497, native macOS / Qt 6.9.0, using the repository’s mock signer and disposable regtest wallets. I didn’t test physical hardware.

For the fixture, I used bitcoin/test/functional/mocks/signer.py and the signing-key setup from test/functional/qml_test_external_signer.py. Make two unsigned version-0 PSBTs spending the same confirmed coin, sending 0.02 BTC and 0.03 BTC. Save each as a binary .psbt file. The mock reads mock_psbt and mock_result from the GUI process’s working directory.

  1. Import the 0.02 BTC PSBT through File → Load PSBT from file.
  2. Put its valid signed PSBT in mock_psbt, click Approve on external signer, and leave the review open without sending.
  3. Import the unsigned 0.03 BTC PSBT through the File menu. The amount changes, but the button is still Send and the status still says “Signed on external signer. Ready to send.”
  4. Write 1 {"error":"test signer failure"} to mock_result, then click Send.

The GUI terminates with an uncaught std::runtime_error from RunCommandParseJSON when the mock’s enumerate command exits with status 1. The same helper failure through a fresh Approve action is caught and shows Retry external signer. The replacement does contact the signer again; it’s the error handling in this path that fails.

There’s also a stuck-button case. Start with a fresh review of the first PSBT, remove mock_result, and put that first unsigned PSBT in mock_psbt unchanged to exercise an incomplete signer result. Click Approve, then import the second unsigned PSBT without closing the review. The new transaction is signable, but its button stays disabled as “More signatures required.” This fixture returns an incomplete PSBT; it doesn’t add a partial signature.

Closing and reimporting the second PSBT restores Approve. With the mock returning its signed PSBT, I could then approve and send it, and checked the exact transaction ID in the mempool.

ExternalSignerReviewActions keeps its old state when the transaction changes, and the stale Send action reaches a signing path without the exception handling used by normal approval. We should reset that state for a new PSBT and handle helper failures in the Send path too. These are worth fixing before release, independently of moving the work off the GUI thread.

Related to #763 and #1037; the latter covers the old password prompt surviving another PSBT import.

Found two concrete cases for keeping signer approval tied to the transaction being reviewed. Both happen within the same wallet. Tested on `qt6` at `d567e3eb2497`, native macOS / Qt 6.9.0, using the repository’s mock signer and disposable regtest wallets. I didn’t test physical hardware. For the fixture, I used `bitcoin/test/functional/mocks/signer.py` and the signing-key setup from `test/functional/qml_test_external_signer.py`. Make two unsigned version-0 PSBTs spending the same confirmed coin, sending 0.02 BTC and 0.03 BTC. Save each as a binary `.psbt` file. The mock reads `mock_psbt` and `mock_result` from the GUI process’s working directory. 1. Import the 0.02 BTC PSBT through File → Load PSBT from file. 2. Put its valid signed PSBT in `mock_psbt`, click Approve on external signer, and leave the review open without sending. 3. Import the unsigned 0.03 BTC PSBT through the File menu. The amount changes, but the button is still Send and the status still says “Signed on external signer. Ready to send.” 4. Write `1 {"error":"test signer failure"}` to `mock_result`, then click Send. The GUI terminates with an uncaught `std::runtime_error` from `RunCommandParseJSON` when the mock’s `enumerate` command exits with status 1. The same helper failure through a fresh Approve action is caught and shows Retry external signer. The replacement does contact the signer again; it’s the error handling in this path that fails. There’s also a stuck-button case. Start with a fresh review of the first PSBT, remove `mock_result`, and put that first unsigned PSBT in `mock_psbt` unchanged to exercise an incomplete signer result. Click Approve, then import the second unsigned PSBT without closing the review. The new transaction is signable, but its button stays disabled as “More signatures required.” This fixture returns an incomplete PSBT; it doesn’t add a partial signature. Closing and reimporting the second PSBT restores Approve. With the mock returning its signed PSBT, I could then approve and send it, and checked the exact transaction ID in the mempool. `ExternalSignerReviewActions` keeps its old state when the transaction changes, and the stale Send action reaches a signing path without the exception handling used by normal approval. We should reset that state for a new PSBT and handle helper failures in the Send path too. These are worth fixing before release, independently of moving the work off the GUI thread. Related to #763 and #1037; the latter covers the old password prompt surviving another PSBT import.
jarolrod commented 2026-10-16 02:49:09 +00:00 (Migrated from github.com)

I can hit the helper-error crash through Activity → Speed up too, without replacing a PSBT.

Tested on qt6 at d567e3eb2497, native macOS / Qt 6.9.0, using the repository’s mock signer and disposable regtest wallets. I didn’t test physical hardware.

To reproduce:

  1. Set up a funded external-signer regtest wallet with bitcoin/test/functional/mocks/signer.py. The signing-key fixture in test/functional/qml_test_external_signer.py works for this.
  2. Broadcast a replaceable payment and leave it unconfirmed. I used 0.01 BTC at 1 sat/vB.
  3. Open that payment in Activity and click Speed up.
  4. In the GUI process’s working directory, create mock_result containing 1 signer transport unavailable. This makes the mock’s next enumerate call exit with status 1.
  5. Click Update transaction.

The whole GUI terminates with an uncaught std::runtime_error from RunCommandParseJSON. The call to signBumpTransaction() has no exception handling.

Returning 0 [] from the mock instead shows “Failed to sign transaction” and keeps the app running, so this is specifically the helper-error path. Also checked that mining the original while the dialog is open correctly prevents the bump.

We need to catch the helper failure and show an error in the dialog. Moving this to a worker alone won’t fix the uncaught exception. Related to #976 and #642.

I can hit the helper-error crash through Activity → Speed up too, without replacing a PSBT. Tested on `qt6` at `d567e3eb2497`, native macOS / Qt 6.9.0, using the repository’s mock signer and disposable regtest wallets. I didn’t test physical hardware. To reproduce: 1. Set up a funded external-signer regtest wallet with `bitcoin/test/functional/mocks/signer.py`. The signing-key fixture in `test/functional/qml_test_external_signer.py` works for this. 2. Broadcast a replaceable payment and leave it unconfirmed. I used 0.01 BTC at 1 sat/vB. 3. Open that payment in Activity and click Speed up. 4. In the GUI process’s working directory, create `mock_result` containing `1 signer transport unavailable`. This makes the mock’s next `enumerate` call exit with status 1. 5. Click Update transaction. The whole GUI terminates with an uncaught `std::runtime_error` from `RunCommandParseJSON`. The call to [`signBumpTransaction()`](https://github.com/bitcoin-core/gui-qml/blob/d567e3eb2497df3be5d63f4dc1f554b3bf51f59f/qml/models/bumptransactionmodel.cpp#L176) has no exception handling. Returning `0 []` from the mock instead shows “Failed to sign transaction” and keeps the app running, so this is specifically the helper-error path. Also checked that mining the original while the dialog is open correctly prevents the bump. We need to catch the helper failure and show an error in the dialog. Moving this to a worker alone won’t fix the uncaught exception. Related to #976 and #642.
jarolrod commented 2026-11-09 20:48:28 +00:00 (Migrated from github.com)

A concrete startup case for the initialization-discovery work here: a saved external-signer command can block interaction with an ordinary software wallet before the user starts any signer operation.

To reproduce:

  1. Load a normal private-key wallet and configure a working signer command through Settings → External signer → Check device.
  2. Restart with that saved configuration, making the signer delay its enumerate response. I used a synthetic signer with a bounded delay.
  3. While enumeration is pending, click the software wallet’s badge to open the wallet picker.
  4. Release the signer response and observe the pending click complete.

On two restarts, the picker click was still blocked after about 2.54 seconds. During each wait, five Core RPC calls completed in 33–34 ms and confirmed that the ordinary wallet was loaded, had private keys enabled and owned its fixture address. Releasing enumeration allowed the picker to open.

With the same saved signer command answering immediately, the healthy restart controls opened the picker in 28–29 ms.

QML’s wallet-controller initialization calls listExternalSigners() synchronously on the GUI thread, and Core waits for the configured subprocess. Initialization discovery should run off that thread so an already-loaded software wallet remains usable while device discovery is pending. PR #1060 at 733018ca9eab retains this synchronous initialization call.

Reproduced on merged qt6 at eed1f426fcb6, macOS / Qt 6.9, using isolated offscreen regtest profiles. The delayed helper was released in both runs; this establishes the startup blocking behavior, not a permanent hang or a physical-device failure.

A concrete startup case for the initialization-discovery work here: a saved external-signer command can block interaction with an ordinary software wallet before the user starts any signer operation. To reproduce: 1. Load a normal private-key wallet and configure a working signer command through Settings → External signer → Check device. 2. Restart with that saved configuration, making the signer delay its `enumerate` response. I used a synthetic signer with a bounded delay. 3. While enumeration is pending, click the software wallet’s badge to open the wallet picker. 4. Release the signer response and observe the pending click complete. On two restarts, the picker click was still blocked after about 2.54 seconds. During each wait, five Core RPC calls completed in 33–34 ms and confirmed that the ordinary wallet was loaded, had private keys enabled and owned its fixture address. Releasing enumeration allowed the picker to open. With the same saved signer command answering immediately, the healthy restart controls opened the picker in 28–29 ms. QML’s wallet-controller initialization calls `listExternalSigners()` synchronously on the GUI thread, and Core waits for the configured subprocess. Initialization discovery should run off that thread so an already-loaded software wallet remains usable while device discovery is pending. PR [#1060](https://github.com/bitcoin-core/gui-qml/pull/1060) at `733018ca9eab` retains this synchronous initialization call. Reproduced on merged `qt6` at `eed1f426fcb6`, macOS / Qt 6.9, using isolated offscreen regtest profiles. The delayed helper was released in both runs; this establishes the startup blocking behavior, not a permanent hang or a physical-device failure.
Sign in to join this conversation.
No description provided.