Skip to content

Sign multi-input P2MR PSBTs outside the qbit-qt GUI thread #140

Closed

Description

@kiwidream

Issues, reports or feature requests related to the qbit GUI should be opened here only when they apply to this repository

  • I still think this issue should be opened here

Report

Summary

qbit-qt signs PSBT inputs synchronously and sequentially on the GUI thread. A PSBT containing many P2MR inputs can therefore make the application appear hung, with no progress indication or cancellation path.

This is independent of the unlock-time deadlock in #138. It remains after wallet unlock successfully returns.

Current behaviour

PSBTOperationsDialog::signTransaction() directly calls:

m_wallet_model->wallet().fillPSBT(
    std::nullopt,
    /*sign=*/true,
    /*bip32derivs=*/true,
    &n_signed,
    m_transaction_data,
    complete);

This call runs on the Qt GUI thread.

CWallet::FillPSBT() subsequently loops over PSBT input indexes and calls SignPSBTInput() sequentially. Unlike normal Send Coins transaction preparation, this path has:

  • no background worker;
  • no signing progress callback;
  • no parallel P2MR input-signing path;
  • no cancellation state; and
  • no explicit shutdown or wallet-unload handling for in-progress PSBT signing.

The checked-in bounded SLH-DSA benchmark reports approximately 149 ms per signature on Apple M3 Max. Ignoring wallet database overhead, this suggests approximately:

  • 10 P2MR inputs: 1.5 seconds;
  • 50 P2MR inputs: 7.4 seconds;
  • 100 P2MR inputs: 14.9 seconds.

Counter persistence and PSBT processing add further latency.

Steps to reproduce

  1. Create and fund an encrypted P2MR wallet with many spendable outputs.
  2. Construct a PSBT spending at least 20–50 P2MR inputs.
  3. Open the PSBT in qbit-qt.
  4. Click Sign Transaction.
  5. Enter the correct wallet passphrase if prompted.
  6. Observe that the GUI stops processing input and repaint events until every input has been signed.

For deterministic testing, replace the signer with a latch-controlled or delayed synthetic wallet.

Expected behaviour

PSBT signing should run outside the GUI thread and display bounded progress. The dialog should remain responsive, and cancellation and shutdown should follow explicit stateful-PQC safety rules.

Scope boundary

This issue is limited to PSBT signing initiated by PSBTOperationsDialog.

No existing issue covers synchronous multi-input FillPSBT() signing in PSBTOperationsDialog.

Suggested direction

Use the background-worker pattern already implemented for normal Send Coins preparation:

  1. Move or copy the PSBT into a worker-owned object.
  2. Clone or obtain a background wallet interface.
  3. Perform provider collection, counter reservation, signing, and finalization off the GUI thread.
  4. Queue progress and completion back to the dialog.
  5. Replace m_transaction_data only after successful worker completion.

Extend the PSBT signing interface with progress phases such as:

  • preparing;
  • reserving PQC counters;
  • signing inputs;
  • finalizing; and
  • verifying.

Cancellation may be allowed before durable PQC counter reservation. Once counters have been reserved, disable cancellation and finish deterministically, matching the normal send flow.

Parallel P2MR signing should be considered, but moving work off the GUI thread is required even if signing remains sequential.

Suggested tests

Add latch-controlled Qt tests covering:

  • signing a many-input PSBT without blocking the event loop;
  • incremental progress updates;
  • cancellation before PQC counter reservation;
  • attempted cancellation after reservation;
  • dialog closure during signing;
  • wallet unload and application shutdown during signing; and
  • failed signing after some counters were consumed.

Acceptance criteria

  • No P2MR PSBT signature is generated on the GUI thread.
  • The GUI remains responsive throughout signing.
  • Progress identifies completed and total input counts.
  • Cancellation cannot abandon work after durable counter reservation.
  • Worker completion cannot access a destroyed dialog or WalletModel.
  • Successful signing updates the displayed PSBT exactly once.
  • Failure leaves the original PSBT in a defined state and reports any consumed PQC capacity.
  • Existing non-P2MR and external-signer PSBT behaviour remains supported.

Relevant code

  • src/qt/psbtoperationsdialog.cpp: PSBTOperationsDialog::signTransaction
  • src/wallet/wallet.cpp: CWallet::FillPSBT
  • src/wallet/scriptpubkeyman.cpp: DescriptorScriptPubKeyMan::FillPSBT
  • src/libbitcoinpqc/benches/REPORT.md: bounded SLH-DSA signing benchmark

Version and platform

Source-inspected on qbit v1.0.0. Applies to all Qt-supported platforms.

Activity

  1. added
    bug
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions