AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 51 Bitcoin

refactor: Properly return from ThreadSafeQuestion signal

Public commit record

What the developer wrote

Authored by MarcoFalke

95/100 · Strong
refactor: Properly return from ThreadSafeQuestion signal

Previously, the signal was using btcsignals::optional_last_value<bool>.
However, this only worked by accident:

The return value was influenced by the order in which the connections
were done. The noui callbacks would always overwrite the return value
with false. This makes the code overall brittle, and confusing.

For example, the following patch that changes the order of connections
would break the only and single place where the return value actually
matters:

```diff
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 0b89c605b9..976549470e 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -488,3 +488,2 @@ int GuiMain(int argc, char* argv[])
btcsignals::scoped_connection handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
- btcsignals::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
btcsignals::scoped_connection handler_init_message = ::uiInterface.InitMessage_connect(noui_InitMessage);
@@ -663,2 +662,3 @@ int GuiMain(int argc, char* argv[])
app.createWindow(networkStyle.data());
+ btcsignals::scoped_connection handler_question = ::uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
// Perform base initialization before spinning up initialization/shutdown thread
```

This can be tested by applying the patch and then calling:

(May have to be started twice to trigger the question)

```
bitcoin-qt -regtest -datadir=/tmp -mocktime=123456789
```

Before the changes in this commit (on current master), pressing `OK`
would not have any effect and would abort the program.

After the changes in this commit, pressing `OK` will correctly trigger a
-reindex and leave the program running.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit fixes a brittle signal-handling bug in Bitcoin Core's user-interface code. Previously, when the program asked the user a yes/no question (for example, whether to rebuild the database), the answer could be ignored depending on the order in which internal callbacks were connected. The commit changes the signal system so that a 'yes' answer from any relevant handler is respected, rather than being overwritten by a later handler. The commit message explicitly notes that, before the fix, clicking 'OK' could abort the program instead of performing the requested recovery.

Recommended action

Treat this as a reliability fix with possible denial-of-service or recovery-failure implications. Users and node operators should upgrade to a release containing this commit, especially those running bitcoin-qt, because the bug can prevent automatic database recovery from proceeding when the GUI is used. Reviewers should verify that no other signals rely on the removed optional_last_value semantics.

Security signals we found

01

Logic bug in signal combiner caused return value to depend on connection order

02

GUI 'OK' response to a recovery question could be discarded, aborting instead of reindexing

03

Non-interactive callback silently overrode interactive callback's return value

04

Fix changes combiner semantics from last-value-wins to any-true-wins

05

Commit message describes a reproducible failure mode (-regtest -mocktime scenario)

Risk score

Why this scored 51/100

Our methodology →
Potential impact 18/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 7/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.