Previously, the ThreadSafeQuestion signal was using btcsignals::optional_last_value<bool>.
However, this only worked by accident:
- Calling
CClientUIInterface::ThreadSafeQuestiondid not return anstd::optional<bool>, butvalue_or(false). This makes it hard for callers to differentiate betweennulloptandfalse. - The return value was further 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 --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index https://github.com/bitcoin/bitcoin/commit/0b89c605b9ce69abcce88ac5a88699c353418078..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.
So fix that by properly returning from the signal.
Also, remove the then-unused btcsignals::optional_last_value<T> combiner.
Also, other follow-ups from #34495 (comment)