Wallet close, settings, and mempool information #551

Manually merged
johnny9 merged 18 commits from wallet-settings into qt6 2026-05-18 13:45:25 +00:00 AGit
johnny9 commented 2026-04-20 00:49:07 +00:00 (Migrated from github.com)
05-wallet-settings-opened image image image image

Closes #509
Closes #515
Closes #698

<img width="813" height="665" alt="05-wallet-settings-opened" src="https://git.fish.foo/attachments/39422dc8-1d95-4cd3-a566-2a2605aa45f8" /> <img width="833" height="755" alt="image" src="https://git.fish.foo/attachments/f8a3bf15-cc18-4ed6-a153-5b0d99d338f1" /> <img width="833" height="755" alt="image" src="https://git.fish.foo/attachments/5d76093a-221e-4bb8-9e61-fe3e8c04c962" /> <img width="833" height="755" alt="image" src="https://git.fish.foo/attachments/8ca6bf4c-5bbf-4e6a-8c3e-a33a3156786e" /> <img width="833" height="755" alt="image" src="https://git.fish.foo/attachments/8898fb59-7807-42e3-a3b7-4cdc57d251a5" /> Closes #509 Closes #515 Closes #698
johnny9 commented 2026-04-21 15:37:40 +00:00 (Migrated from github.com)

Related to #509 and #515

Related to #509 and #515
pseudoramdom (Migrated from github.com) reviewed 2026-05-11 21:53:09 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-11 21:42:11 +00:00

This will not work in other languages, right?

This will not work in other languages, right?
pseudoramdom (Migrated from github.com) commented 2026-05-11 21:47:45 +00:00

Can we subscribe to changes? Do we not get notified if a tx was added to mempool, similar to blockTipHeightChanged?

Can we subscribe to changes? Do we not get notified if a tx was added to mempool, similar to blockTipHeightChanged?
pseudoramdom (Migrated from github.com) commented 2026-05-11 21:36:39 +00:00

Should have guards to check if the file is inside walletDir? Just so that we don't end up deleting other files if walletStoragePath() returns path outside of walletDir.

Should have guards to check if the file is inside walletDir? Just so that we don't end up deleting other files if ` walletStoragePath()` returns path outside of walletDir.
pseudoramdom (Migrated from github.com) commented 2026-05-11 21:40:12 +00:00

(Apologies for the LLM suggested code)


const QString wallet_dir_canonical = QFileInfo(
      QString::fromStdString(m_node.walletLoader().getWalletDir())).canonicalFilePath();
const QString storage_canonical = QFileInfo(storage_path).canonicalFilePath();
const QString prefix = wallet_dir_canonical.endsWith('/')
      ? wallet_dir_canonical : wallet_dir_canonical + '/';

if (wallet_dir_canonical.isEmpty() || storage_canonical.isEmpty() ||
      storage_canonical == wallet_dir_canonical ||
      !storage_canonical.startsWith(prefix)) {
    setWalletLoadError(tr("..."));
    return false;
}
(Apologies for the LLM suggested code) ```cpp const QString wallet_dir_canonical = QFileInfo( QString::fromStdString(m_node.walletLoader().getWalletDir())).canonicalFilePath(); const QString storage_canonical = QFileInfo(storage_path).canonicalFilePath(); const QString prefix = wallet_dir_canonical.endsWith('/') ? wallet_dir_canonical : wallet_dir_canonical + '/'; if (wallet_dir_canonical.isEmpty() || storage_canonical.isEmpty() || storage_canonical == wallet_dir_canonical || !storage_canonical.startsWith(prefix)) { setWalletLoadError(tr("...")); return false; }
pseudoramdom (Migrated from github.com) commented 2026-05-11 21:52:46 +00:00

Is this okay to fire when when we're locking the lock in line 681? Do we need to release the lock?

Is this okay to fire when when we're locking the lock in line 681? Do we need to release the lock?
johnny9 (Migrated from github.com) reviewed 2026-05-11 22:33:10 +00:00
johnny9 (Migrated from github.com) commented 2026-05-11 22:33:10 +00:00

The bilingual error string should have the untranslated error. Ideally we have error codes, though.

The bilingual error string should have the untranslated error. Ideally we have error codes, though.
johnny9 (Migrated from github.com) reviewed 2026-05-11 22:48:26 +00:00
johnny9 (Migrated from github.com) commented 2026-05-11 22:48:26 +00:00

This is fragile. I will double check if there is an alternative or if we just need to always unlock for transaction prep

This is fragile. I will double check if there is an alternative or if we just need to always unlock for transaction prep
johnny9 (Migrated from github.com) reviewed 2026-05-11 23:13:51 +00:00
johnny9 (Migrated from github.com) commented 2026-05-11 23:13:51 +00:00

Ill look at changing this signal to be sure anyway. There's no reason we need to read all of the names again in this path

Ill look at changing this signal to be sure anyway. There's no reason we need to read all of the names again in this path
johnny9 (Migrated from github.com) reviewed 2026-05-12 16:03:56 +00:00
johnny9 (Migrated from github.com) commented 2026-05-12 16:03:56 +00:00

Decided to do away with this logic and the changes are in #548 I will rebase this PR on that

Decided to do away with this logic and the changes are in #548 I will rebase this PR on that
johnny9 (Migrated from github.com) reviewed 2026-05-15 08:43:55 +00:00
johnny9 (Migrated from github.com) commented 2026-05-15 08:43:55 +00:00

I have decided to just remove this feature for now

I have decided to just remove this feature for now
johnny9 (Migrated from github.com) reviewed 2026-05-15 08:45:09 +00:00
johnny9 (Migrated from github.com) commented 2026-05-15 08:45:09 +00:00

updated this logic to avoid locking and make updates to the loaded wallets to use signals for adding/removing

updated this logic to avoid locking and make updates to the loaded wallets to use signals for adding/removing
pseudoramdom (Migrated from github.com) reviewed 2026-05-15 19:31:17 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-15 19:31:18 +00:00
        header: qsTr("Mempool Information")

or just

        header: qsTr("Mempool")
```suggestion header: qsTr("Mempool Information") ``` or just ```suggestion header: qsTr("Mempool") ```
pseudoramdom (Migrated from github.com) reviewed 2026-05-15 19:54:21 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-15 19:54:21 +00:00

This should probably go to Theme.text.button / Theme.text.buttonStrong. This way OutlineButton NavButton can all use it.
We should also limit specifying on-off text styles. Using Theme will pay us dividends when we need to focus on DynamicText

This should probably go to `Theme.text.button` / `Theme.text.buttonStrong`. This way `OutlineButton` `NavButton` can all use it. We should also limit specifying on-off text styles. Using Theme will pay us dividends when we need to focus on DynamicText
pseudoramdom (Migrated from github.com) reviewed 2026-05-15 19:54:53 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-15 19:54:53 +00:00
Ditto - https://github.com/bitcoin-core/gui-qml/pull/551/changes/ed41f5b91ecbeb9a37f96fe9d1a4e89623e19bb6..12aeb67e448eac7781c16bb17879859e2e1ba889#r3250649381
pseudoramdom (Migrated from github.com) reviewed 2026-05-15 21:00:02 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-15 21:00:02 +00:00

The UX for editing row seems to be inconsistent

Image Image
The UX for editing row seems to be inconsistent <img width="528" height="79" alt="Image" src="https://git.fish.foo/attachments/045666d5-e830-44e7-91ba-628116a491a7" /> <img width="510" height="84" alt="Image" src="https://git.fish.foo/attachments/8cc02118-16cb-4523-8778-7cfb88baae87" />
pseudoramdom (Migrated from github.com) reviewed 2026-05-15 21:36:36 +00:00
pseudoramdom (Migrated from github.com) commented 2026-05-15 21:36:36 +00:00

Should we clear passwords or at least currentPassword.text even in the else case?

Should we clear passwords or at least `currentPassword.text` even in the `else` case?
pseudoramdom commented 2026-05-15 21:43:14 +00:00 (Migrated from github.com)

We have a UX to resolve here - You can select wallet A, go to change password, select wallet B and update the password. I don't know for which wallet it applied the password to.

https://github.com/user-attachments/assets/0d54537e-4da6-4959-800f-03ff82ab0883

We have a UX to resolve here - You can select wallet A, go to change password, select wallet B and update the password. I don't know for which wallet it applied the password to. https://github.com/user-attachments/assets/0d54537e-4da6-4959-800f-03ff82ab0883
johnny9 commented 2026-05-16 01:01:31 +00:00 (Migrated from github.com)

We have a UX to resolve here - You can select wallet A, go to change password, select wallet B and update the password. I don't know for which wallet it applied the password to.
wallet-settings.mp4

selecting a different wallet should pop the password page from the stack. will add this.

> We have a UX to resolve here - You can select wallet A, go to change password, select wallet B and update the password. I don't know for which wallet it applied the password to. > wallet-settings.mp4 selecting a different wallet should pop the password page from the stack. will add this.
johnny9 (Migrated from github.com) reviewed 2026-05-16 01:02:57 +00:00
johnny9 (Migrated from github.com) commented 2026-05-16 01:02:57 +00:00

I think its best to stick with the timer until we need this kind of precision. Current qt gui uses a timer

I think its best to stick with the timer until we need this kind of precision. Current qt gui uses a timer
johnny9 (Migrated from github.com) reviewed 2026-05-16 01:05:23 +00:00
johnny9 (Migrated from github.com) commented 2026-05-16 01:05:23 +00:00

Rename requires something more than our settings config ux so i will stick with what it is for now but expect it to be redesigned and moved but ill double check mempool input matches our other settings

Rename requires something more than our settings config ux so i will stick with what it is for now but expect it to be redesigned and moved but ill double check mempool input matches our other settings
johnny9 (Migrated from github.com) reviewed 2026-05-16 01:06:02 +00:00
johnny9 (Migrated from github.com) commented 2026-05-16 01:06:02 +00:00

yes

yes
jarolrod (Migrated from github.com) reviewed 2026-05-18 01:09:16 +00:00
jarolrod (Migrated from github.com) commented 2026-05-18 01:09:16 +00:00

this probably shouldn't show on a watch only wallet, so we prob need a few changes to make introducing the settings feature correct.

If we can set a context property from the cpp side on this then we can make a gate on something like the following

 readonly property bool passwordActionVisible: root.wallet && root.wallet.canManagePassphrase
this probably shouldn't show on a watch only wallet, so we prob need a few changes to make introducing the settings feature correct. If we can set a context property from the cpp side on this then we can make a gate on something like the following ``` readonly property bool passwordActionVisible: root.wallet && root.wallet.canManagePassphrase ```
jarolrod (Migrated from github.com) reviewed 2026-05-18 01:17:26 +00:00
jarolrod (Migrated from github.com) commented 2026-05-18 01:17:26 +00:00

When someone encrypts in qt widgets there's the reminder to update the backups or make new backups, if we have a design for that we should at that page here, if not let's make an issue to track adding this

When someone encrypts in qt widgets there's the reminder to update the backups or make new backups, if we have a design for that we should at that page here, if not let's make an issue to track adding this
jarolrod (Migrated from github.com) reviewed 2026-05-18 01:28:40 +00:00
jarolrod (Migrated from github.com) commented 2026-05-18 01:28:40 +00:00

this is probably fine for now because it's low frequency, but it would still be best to do this outside of the UI thread, either now or later, not a blocker for me.

The following should get it done, can be included or done as a follow-up

commit cc08adb6efd545b23f7e9d76616c51b6ea52af17
Author: jarolrod <[email protected]>
Date:   Sun May 17 21:27:35 2026 -0400

    qml: keep mempool information grab outside of UI thread

diff --git a/qml/models/nodemodel.cpp b/qml/models/nodemodel.cpp
index 7392e10ec..5e73d97eb 100644
--- a/qml/models/nodemodel.cpp
+++ b/qml/models/nodemodel.cpp
@@ -9,6 +9,7 @@
 #include <net_processing.h>
 #include <netbase.h>
 #include <node/interface_ui.h>
+#include <util/threadnames.h>
 #include <validation.h>
 
 #include <cassert>
@@ -16,17 +17,33 @@
 
 #include <QDateTime>
 #include <QMetaObject>
+#include <QThread>
+#include <QTimer>
 #include <QTimerEvent>
 
+using namespace std::chrono_literals;
+
+static constexpr int MEMPOOL_INFO_POLLING_INTERVAL_MS{3000};
+
 NodeModel::NodeModel(interfaces::Node& node)
     : m_node{node}
 {
+    initializeMempoolInfoPolling();
     ConnectToBlockTipSignal();
     ConnectToNumConnectionsChangedSignal();
     ConnectToBannedListChangedSignal();
     refreshMempoolInfo();
 }
 
+NodeModel::~NodeModel()
+{
+    setMempoolInfoPollingActive(false);
+    if (m_mempool_info_thread) {
+        m_mempool_info_thread->quit();
+        m_mempool_info_thread->wait();
+    }
+}
+
 void NodeModel::setBlockTipHeight(int new_height)
 {
     if (new_height != m_block_tip_height) {
@@ -43,20 +60,34 @@ void NodeModel::setNumOutboundPeers(int new_num)
     }
 }
 
-void NodeModel::refreshMempoolInfo()
+void NodeModel::setMempoolInfoPollingActive(bool active)
 {
-    const int mempool_transaction_count = static_cast<int>(m_node.getMempoolSize());
-    const double mempool_usage_mb = m_node.getMempoolDynamicUsage() / 1'000'000.0;
-    const double mempool_max_usage_mb = m_node.getMempoolMaxUsage() / 1'000'000.0;
+    if (m_mempool_info_polling_active == active) {
+        return;
+    }
+    m_mempool_info_polling_active = active;
+    Q_EMIT mempoolInfoPollingActiveChanged(active);
 
-    if (mempool_transaction_count != m_mempool_transaction_count ||
-        mempool_usage_mb != m_mempool_usage_mb ||
-        mempool_max_usage_mb != m_mempool_max_usage_mb) {
-        m_mempool_transaction_count = mempool_transaction_count;
-        m_mempool_usage_mb = mempool_usage_mb;
-        m_mempool_max_usage_mb = mempool_max_usage_mb;
-        Q_EMIT mempoolInfoChanged();
+    QTimer* timer = m_mempool_info_timer;
+    if (!timer) {
+        return;
     }
+    QMetaObject::invokeMethod(timer, [timer, active] {
+        if (active) {
+            timer->start();
+        } else {
+            timer->stop();
+        }
+    }, Qt::QueuedConnection);
+
+    if (active) {
+        refreshMempoolInfo();
+    }
+}
+
+void NodeModel::refreshMempoolInfo()
+{
+    requestMempoolInfoRefresh();
 }
 
 void NodeModel::setRemainingSyncTime(double new_progress)
@@ -182,6 +213,63 @@ void NodeModel::ConnectToBlockTipSignal()
         });
 }
 
+void NodeModel::initializeMempoolInfoPolling()
+{
+    m_mempool_info_worker = new QObject;
+    m_mempool_info_thread = new QThread(this);
+    m_mempool_info_timer = new QTimer;
+    m_mempool_info_timer->setInterval(MEMPOOL_INFO_POLLING_INTERVAL_MS);
+
+    m_mempool_info_worker->moveToThread(m_mempool_info_thread);
+    m_mempool_info_timer->moveToThread(m_mempool_info_thread);
+
+    connect(m_mempool_info_timer, &QTimer::timeout, m_mempool_info_worker, [this] {
+        fetchMempoolInfo();
+    });
+    connect(m_mempool_info_thread, &QThread::finished, m_mempool_info_timer, &QObject::deleteLater);
+    connect(m_mempool_info_thread, &QThread::finished, m_mempool_info_worker, &QObject::deleteLater);
+
+    m_mempool_info_thread->start();
+    QTimer::singleShot(0, m_mempool_info_worker, [] {
+        util::ThreadRename("qml-mempool");
+    });
+}
+
+void NodeModel::requestMempoolInfoRefresh()
+{
+    if (!m_mempool_info_worker) {
+        return;
+    }
+    QTimer::singleShot(0, m_mempool_info_worker, [this] {
+        fetchMempoolInfo();
+    });
+}
+
+void NodeModel::fetchMempoolInfo()
+{
+    const MempoolInfo info{
+        static_cast<int>(m_node.getMempoolSize()),
+        m_node.getMempoolDynamicUsage() / 1'000'000.0,
+        m_node.getMempoolMaxUsage() / 1'000'000.0,
+    };
+
+    QMetaObject::invokeMethod(this, [this, info] {
+        applyMempoolInfo(info);
+    }, Qt::QueuedConnection);
+}
+
+void NodeModel::applyMempoolInfo(const MempoolInfo& info)
+{
+    if (info.transaction_count != m_mempool_transaction_count ||
+        info.usage_mb != m_mempool_usage_mb ||
+        info.max_usage_mb != m_mempool_max_usage_mb) {
+        m_mempool_transaction_count = info.transaction_count;
+        m_mempool_usage_mb = info.usage_mb;
+        m_mempool_max_usage_mb = info.max_usage_mb;
+        Q_EMIT mempoolInfoChanged();
+    }
+}
+
 void NodeModel::ConnectToNumConnectionsChangedSignal()
 {
     assert(!m_handler_notify_num_peers_changed);
diff --git a/qml/models/nodemodel.h b/qml/models/nodemodel.h
index ac8613657..77ff274e5 100644
--- a/qml/models/nodemodel.h
+++ b/qml/models/nodemodel.h
@@ -18,6 +18,8 @@ const char DEFAULT_PROXY_HOST[] = "127.0.0.1";
 constexpr uint16_t DEFAULT_PROXY_PORT = 9050;
 
 QT_BEGIN_NAMESPACE
+class QThread;
+class QTimer;
 class QTimerEvent;
 QT_END_NAMESPACE
 
@@ -36,6 +38,7 @@ class NodeModel : public QObject
     Q_PROPERTY(int mempoolTransactionCount READ mempoolTransactionCount NOTIFY mempoolInfoChanged)
     Q_PROPERTY(double mempoolUsageMB READ mempoolUsageMB NOTIFY mempoolInfoChanged)
     Q_PROPERTY(double mempoolMaxUsageMB READ mempoolMaxUsageMB NOTIFY mempoolInfoChanged)
+    Q_PROPERTY(bool mempoolInfoPollingActive READ mempoolInfoPollingActive WRITE setMempoolInfoPollingActive NOTIFY mempoolInfoPollingActiveChanged)
     Q_PROPERTY(int remainingSyncTime READ remainingSyncTime NOTIFY remainingSyncTimeChanged)
     Q_PROPERTY(double verificationProgress READ verificationProgress NOTIFY verificationProgressChanged)
     Q_PROPERTY(bool pause READ pause WRITE setPause NOTIFY pauseChanged)
@@ -43,6 +46,7 @@ class NodeModel : public QObject
 
 public:
     explicit NodeModel(interfaces::Node& node);
+    ~NodeModel();
 
     int blockTipHeight() const { return m_block_tip_height; }
     void setBlockTipHeight(int new_height);
@@ -53,6 +57,8 @@ public:
     int mempoolTransactionCount() const { return m_mempool_transaction_count; }
     double mempoolUsageMB() const { return m_mempool_usage_mb; }
     double mempoolMaxUsageMB() const { return m_mempool_max_usage_mb; }
+    bool mempoolInfoPollingActive() const { return m_mempool_info_polling_active; }
+    void setMempoolInfoPollingActive(bool active);
     int remainingSyncTime() const { return m_remaining_sync_time; }
     void setRemainingSyncTime(double new_progress);
     double verificationProgress() const { return m_verification_progress; }
@@ -83,6 +89,7 @@ public Q_SLOTS:
 Q_SIGNALS:
     void blockTipHeightChanged();
     void mempoolInfoChanged();
+    void mempoolInfoPollingActiveChanged(bool active);
     void numOutboundPeersChanged();
     void remainingSyncTimeChanged();
     void requestedInitialize();
@@ -100,6 +107,12 @@ protected:
     void timerEvent(QTimerEvent* event) override;
 
 private:
+    struct MempoolInfo {
+        int transaction_count{0};
+        double usage_mb{0.0};
+        double max_usage_mb{0.0};
+    };
+
     // Properties that are exposed to QML.
     int m_block_tip_height{0};
     int m_num_outbound_peers{0};
@@ -107,6 +120,7 @@ private:
     int m_mempool_transaction_count{0};
     double m_mempool_usage_mb{0.0};
     double m_mempool_max_usage_mb{0.0};
+    bool m_mempool_info_polling_active{false};
     int m_remaining_sync_time{0};
     double m_verification_progress{0.0};
     bool m_pause{false};
@@ -118,6 +132,9 @@ private:
     QVector<QPair<int, double>> m_block_process_time;
 
     interfaces::Node& m_node;
+    QObject* m_mempool_info_worker{nullptr};
+    QThread* m_mempool_info_thread{nullptr};
+    QTimer* m_mempool_info_timer{nullptr};
     std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;
     std::unique_ptr<interfaces::Handler> m_handler_notify_num_peers_changed;
     std::unique_ptr<interfaces::Handler> m_handler_notify_banned_list_changed;
@@ -125,6 +142,10 @@ private:
     void ConnectToBlockTipSignal();
     void ConnectToNumConnectionsChangedSignal();
     void ConnectToBannedListChangedSignal();
+    void initializeMempoolInfoPolling();
+    void requestMempoolInfoRefresh();
+    void fetchMempoolInfo();
+    void applyMempoolInfo(const MempoolInfo& info);
 };
 
 #endif // BITCOIN_QML_MODELS_NODEMODEL_H
diff --git a/qml/pages/node/MempoolInformationSettings.qml b/qml/pages/node/MempoolInformationSettings.qml
index ebe03296b..e93b0269e 100644
--- a/qml/pages/node/MempoolInformationSettings.qml
+++ b/qml/pages/node/MempoolInformationSettings.qml
@@ -40,17 +40,9 @@ InformationPage {
         id: mempoolInformationRows
     }
 
-    Component.onCompleted: nodeModel.refreshMempoolInfo()
+    Component.onCompleted: nodeModel.mempoolInfoPollingActive = visible
+    Component.onDestruction: nodeModel.mempoolInfoPollingActive = false
     onVisibleChanged: {
-        if (visible) {
-            nodeModel.refreshMempoolInfo()
-        }
-    }
-
-    Timer {
-        interval: 3000
-        repeat: true
-        running: root.visible
-        onTriggered: nodeModel.refreshMempoolInfo()
+        nodeModel.mempoolInfoPollingActive = visible
     }
 }
diff --git a/test/qml/qml_tests_main.cpp b/test/qml/qml_tests_main.cpp
index 22d298e89..ecb435c46 100644
--- a/test/qml/qml_tests_main.cpp
+++ b/test/qml/qml_tests_main.cpp
@@ -964,6 +964,7 @@ class MockNodeModel : public QObject
     Q_PROPERTY(int mempoolTransactionCount MEMBER m_mempool_transaction_count NOTIFY mempoolInfoChanged)
     Q_PROPERTY(double mempoolUsageMB MEMBER m_mempool_usage_mb NOTIFY mempoolInfoChanged)
     Q_PROPERTY(double mempoolMaxUsageMB MEMBER m_mempool_max_usage_mb NOTIFY mempoolInfoChanged)
+    Q_PROPERTY(bool mempoolInfoPollingActive MEMBER m_mempool_info_polling_active NOTIFY mempoolInfoPollingActiveChanged)
 
 public:
     bool m_pause{false};
@@ -976,6 +977,7 @@ public:
     int m_mempool_transaction_count{0};
     double m_mempool_usage_mb{0.0};
     double m_mempool_max_usage_mb{300.0};
+    bool m_mempool_info_polling_active{false};
 
     Q_INVOKABLE void startNodeInitializionThread() {}
     Q_INVOKABLE void requestShutdown() { Q_EMIT requestedShutdown(); }
@@ -999,6 +1001,7 @@ Q_SIGNALS:
     void faultedChanged();
     void blockTipHeightChanged();
     void mempoolInfoChanged();
+    void mempoolInfoPollingActiveChanged(bool active);
 };
 
 class MockPeerTableModel : public QObject
this is probably fine for now because it's low frequency, but it would still be best to do this outside of the UI thread, either now or later, not a blocker for me. The following should get it done, can be included or done as a follow-up <details> ```diff commit cc08adb6efd545b23f7e9d76616c51b6ea52af17 Author: jarolrod <[email protected]> Date: Sun May 17 21:27:35 2026 -0400 qml: keep mempool information grab outside of UI thread diff --git a/qml/models/nodemodel.cpp b/qml/models/nodemodel.cpp index 7392e10ec..5e73d97eb 100644 --- a/qml/models/nodemodel.cpp +++ b/qml/models/nodemodel.cpp @@ -9,6 +9,7 @@ #include <net_processing.h> #include <netbase.h> #include <node/interface_ui.h> +#include <util/threadnames.h> #include <validation.h> #include <cassert> @@ -16,17 +17,33 @@ #include <QDateTime> #include <QMetaObject> +#include <QThread> +#include <QTimer> #include <QTimerEvent> +using namespace std::chrono_literals; + +static constexpr int MEMPOOL_INFO_POLLING_INTERVAL_MS{3000}; + NodeModel::NodeModel(interfaces::Node& node) : m_node{node} { + initializeMempoolInfoPolling(); ConnectToBlockTipSignal(); ConnectToNumConnectionsChangedSignal(); ConnectToBannedListChangedSignal(); refreshMempoolInfo(); } +NodeModel::~NodeModel() +{ + setMempoolInfoPollingActive(false); + if (m_mempool_info_thread) { + m_mempool_info_thread->quit(); + m_mempool_info_thread->wait(); + } +} + void NodeModel::setBlockTipHeight(int new_height) { if (new_height != m_block_tip_height) { @@ -43,20 +60,34 @@ void NodeModel::setNumOutboundPeers(int new_num) } } -void NodeModel::refreshMempoolInfo() +void NodeModel::setMempoolInfoPollingActive(bool active) { - const int mempool_transaction_count = static_cast<int>(m_node.getMempoolSize()); - const double mempool_usage_mb = m_node.getMempoolDynamicUsage() / 1'000'000.0; - const double mempool_max_usage_mb = m_node.getMempoolMaxUsage() / 1'000'000.0; + if (m_mempool_info_polling_active == active) { + return; + } + m_mempool_info_polling_active = active; + Q_EMIT mempoolInfoPollingActiveChanged(active); - if (mempool_transaction_count != m_mempool_transaction_count || - mempool_usage_mb != m_mempool_usage_mb || - mempool_max_usage_mb != m_mempool_max_usage_mb) { - m_mempool_transaction_count = mempool_transaction_count; - m_mempool_usage_mb = mempool_usage_mb; - m_mempool_max_usage_mb = mempool_max_usage_mb; - Q_EMIT mempoolInfoChanged(); + QTimer* timer = m_mempool_info_timer; + if (!timer) { + return; } + QMetaObject::invokeMethod(timer, [timer, active] { + if (active) { + timer->start(); + } else { + timer->stop(); + } + }, Qt::QueuedConnection); + + if (active) { + refreshMempoolInfo(); + } +} + +void NodeModel::refreshMempoolInfo() +{ + requestMempoolInfoRefresh(); } void NodeModel::setRemainingSyncTime(double new_progress) @@ -182,6 +213,63 @@ void NodeModel::ConnectToBlockTipSignal() }); } +void NodeModel::initializeMempoolInfoPolling() +{ + m_mempool_info_worker = new QObject; + m_mempool_info_thread = new QThread(this); + m_mempool_info_timer = new QTimer; + m_mempool_info_timer->setInterval(MEMPOOL_INFO_POLLING_INTERVAL_MS); + + m_mempool_info_worker->moveToThread(m_mempool_info_thread); + m_mempool_info_timer->moveToThread(m_mempool_info_thread); + + connect(m_mempool_info_timer, &QTimer::timeout, m_mempool_info_worker, [this] { + fetchMempoolInfo(); + }); + connect(m_mempool_info_thread, &QThread::finished, m_mempool_info_timer, &QObject::deleteLater); + connect(m_mempool_info_thread, &QThread::finished, m_mempool_info_worker, &QObject::deleteLater); + + m_mempool_info_thread->start(); + QTimer::singleShot(0, m_mempool_info_worker, [] { + util::ThreadRename("qml-mempool"); + }); +} + +void NodeModel::requestMempoolInfoRefresh() +{ + if (!m_mempool_info_worker) { + return; + } + QTimer::singleShot(0, m_mempool_info_worker, [this] { + fetchMempoolInfo(); + }); +} + +void NodeModel::fetchMempoolInfo() +{ + const MempoolInfo info{ + static_cast<int>(m_node.getMempoolSize()), + m_node.getMempoolDynamicUsage() / 1'000'000.0, + m_node.getMempoolMaxUsage() / 1'000'000.0, + }; + + QMetaObject::invokeMethod(this, [this, info] { + applyMempoolInfo(info); + }, Qt::QueuedConnection); +} + +void NodeModel::applyMempoolInfo(const MempoolInfo& info) +{ + if (info.transaction_count != m_mempool_transaction_count || + info.usage_mb != m_mempool_usage_mb || + info.max_usage_mb != m_mempool_max_usage_mb) { + m_mempool_transaction_count = info.transaction_count; + m_mempool_usage_mb = info.usage_mb; + m_mempool_max_usage_mb = info.max_usage_mb; + Q_EMIT mempoolInfoChanged(); + } +} + void NodeModel::ConnectToNumConnectionsChangedSignal() { assert(!m_handler_notify_num_peers_changed); diff --git a/qml/models/nodemodel.h b/qml/models/nodemodel.h index ac8613657..77ff274e5 100644 --- a/qml/models/nodemodel.h +++ b/qml/models/nodemodel.h @@ -18,6 +18,8 @@ const char DEFAULT_PROXY_HOST[] = "127.0.0.1"; constexpr uint16_t DEFAULT_PROXY_PORT = 9050; QT_BEGIN_NAMESPACE +class QThread; +class QTimer; class QTimerEvent; QT_END_NAMESPACE @@ -36,6 +38,7 @@ class NodeModel : public QObject Q_PROPERTY(int mempoolTransactionCount READ mempoolTransactionCount NOTIFY mempoolInfoChanged) Q_PROPERTY(double mempoolUsageMB READ mempoolUsageMB NOTIFY mempoolInfoChanged) Q_PROPERTY(double mempoolMaxUsageMB READ mempoolMaxUsageMB NOTIFY mempoolInfoChanged) + Q_PROPERTY(bool mempoolInfoPollingActive READ mempoolInfoPollingActive WRITE setMempoolInfoPollingActive NOTIFY mempoolInfoPollingActiveChanged) Q_PROPERTY(int remainingSyncTime READ remainingSyncTime NOTIFY remainingSyncTimeChanged) Q_PROPERTY(double verificationProgress READ verificationProgress NOTIFY verificationProgressChanged) Q_PROPERTY(bool pause READ pause WRITE setPause NOTIFY pauseChanged) @@ -43,6 +46,7 @@ class NodeModel : public QObject public: explicit NodeModel(interfaces::Node& node); + ~NodeModel(); int blockTipHeight() const { return m_block_tip_height; } void setBlockTipHeight(int new_height); @@ -53,6 +57,8 @@ public: int mempoolTransactionCount() const { return m_mempool_transaction_count; } double mempoolUsageMB() const { return m_mempool_usage_mb; } double mempoolMaxUsageMB() const { return m_mempool_max_usage_mb; } + bool mempoolInfoPollingActive() const { return m_mempool_info_polling_active; } + void setMempoolInfoPollingActive(bool active); int remainingSyncTime() const { return m_remaining_sync_time; } void setRemainingSyncTime(double new_progress); double verificationProgress() const { return m_verification_progress; } @@ -83,6 +89,7 @@ public Q_SLOTS: Q_SIGNALS: void blockTipHeightChanged(); void mempoolInfoChanged(); + void mempoolInfoPollingActiveChanged(bool active); void numOutboundPeersChanged(); void remainingSyncTimeChanged(); void requestedInitialize(); @@ -100,6 +107,12 @@ protected: void timerEvent(QTimerEvent* event) override; private: + struct MempoolInfo { + int transaction_count{0}; + double usage_mb{0.0}; + double max_usage_mb{0.0}; + }; + // Properties that are exposed to QML. int m_block_tip_height{0}; int m_num_outbound_peers{0}; @@ -107,6 +120,7 @@ private: int m_mempool_transaction_count{0}; double m_mempool_usage_mb{0.0}; double m_mempool_max_usage_mb{0.0}; + bool m_mempool_info_polling_active{false}; int m_remaining_sync_time{0}; double m_verification_progress{0.0}; bool m_pause{false}; @@ -118,6 +132,9 @@ private: QVector<QPair<int, double>> m_block_process_time; interfaces::Node& m_node; + QObject* m_mempool_info_worker{nullptr}; + QThread* m_mempool_info_thread{nullptr}; + QTimer* m_mempool_info_timer{nullptr}; std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip; std::unique_ptr<interfaces::Handler> m_handler_notify_num_peers_changed; std::unique_ptr<interfaces::Handler> m_handler_notify_banned_list_changed; @@ -125,6 +142,10 @@ private: void ConnectToBlockTipSignal(); void ConnectToNumConnectionsChangedSignal(); void ConnectToBannedListChangedSignal(); + void initializeMempoolInfoPolling(); + void requestMempoolInfoRefresh(); + void fetchMempoolInfo(); + void applyMempoolInfo(const MempoolInfo& info); }; #endif // BITCOIN_QML_MODELS_NODEMODEL_H diff --git a/qml/pages/node/MempoolInformationSettings.qml b/qml/pages/node/MempoolInformationSettings.qml index ebe03296b..e93b0269e 100644 --- a/qml/pages/node/MempoolInformationSettings.qml +++ b/qml/pages/node/MempoolInformationSettings.qml @@ -40,17 +40,9 @@ InformationPage { id: mempoolInformationRows } - Component.onCompleted: nodeModel.refreshMempoolInfo() + Component.onCompleted: nodeModel.mempoolInfoPollingActive = visible + Component.onDestruction: nodeModel.mempoolInfoPollingActive = false onVisibleChanged: { - if (visible) { - nodeModel.refreshMempoolInfo() - } - } - - Timer { - interval: 3000 - repeat: true - running: root.visible - onTriggered: nodeModel.refreshMempoolInfo() + nodeModel.mempoolInfoPollingActive = visible } } diff --git a/test/qml/qml_tests_main.cpp b/test/qml/qml_tests_main.cpp index 22d298e89..ecb435c46 100644 --- a/test/qml/qml_tests_main.cpp +++ b/test/qml/qml_tests_main.cpp @@ -964,6 +964,7 @@ class MockNodeModel : public QObject Q_PROPERTY(int mempoolTransactionCount MEMBER m_mempool_transaction_count NOTIFY mempoolInfoChanged) Q_PROPERTY(double mempoolUsageMB MEMBER m_mempool_usage_mb NOTIFY mempoolInfoChanged) Q_PROPERTY(double mempoolMaxUsageMB MEMBER m_mempool_max_usage_mb NOTIFY mempoolInfoChanged) + Q_PROPERTY(bool mempoolInfoPollingActive MEMBER m_mempool_info_polling_active NOTIFY mempoolInfoPollingActiveChanged) public: bool m_pause{false}; @@ -976,6 +977,7 @@ public: int m_mempool_transaction_count{0}; double m_mempool_usage_mb{0.0}; double m_mempool_max_usage_mb{300.0}; + bool m_mempool_info_polling_active{false}; Q_INVOKABLE void startNodeInitializionThread() {} Q_INVOKABLE void requestShutdown() { Q_EMIT requestedShutdown(); } @@ -999,6 +1001,7 @@ Q_SIGNALS: void faultedChanged(); void blockTipHeightChanged(); void mempoolInfoChanged(); + void mempoolInfoPollingActiveChanged(bool active); }; class MockPeerTableModel : public QObject ``` </details>
johnny9 (Migrated from github.com) reviewed 2026-05-18 03:07:26 +00:00
johnny9 (Migrated from github.com) commented 2026-05-18 03:07:26 +00:00

Added a check for this as well as a functional test in the external signer tests.

Added a check for this as well as a functional test in the external signer tests.
johnny9 (Migrated from github.com) reviewed 2026-05-18 03:08:06 +00:00
johnny9 (Migrated from github.com) commented 2026-05-18 03:08:06 +00:00

Ill add an issue to track this

Ill add an issue to track this
johnny9 (Migrated from github.com) reviewed 2026-05-18 03:08:19 +00:00
johnny9 (Migrated from github.com) commented 2026-05-18 03:08:19 +00:00

Will include this. I agree

Will include this. I agree
johnny9 (Migrated from github.com) reviewed 2026-05-18 03:26:15 +00:00
johnny9 (Migrated from github.com) commented 2026-05-18 03:26:15 +00:00

Moved the timer off the gui thread and added unittests and qml tests for coverage

Moved the timer off the gui thread and added unittests and qml tests for coverage
johnny9 (Migrated from github.com) reviewed 2026-05-18 03:28:20 +00:00
jarolrod commented 2026-05-18 05:02:51 +00:00 (Migrated from github.com)

ACK 008bcb7860

This is good to merge. There are some follow-ups to do that have been opened as independent issues.

ACK 008bcb78603f27b3d468775d8aa0a69a98c8eb47 This is good to merge. There are some follow-ups to do that have been opened as independent issues.
MarnixCroes (Migrated from github.com) reviewed 2026-05-18 13:49:11 +00:00
MarnixCroes (Migrated from github.com) left a comment

tested ACK 008bcb7860

There are several (minor) issues that can be fixed in follow up.

To name a few:

  • The entering of decimals at max mempool size: enter 5,5 -> it changes automatically to 55. Or enter 55,55 it changes to 5,555
  • Mempool Information being displayed when running blocksonly
  • That there is currently no verification of the wallet name can lead to dislay inaccuracies when renaming a wallet, the names don't update/match:
Image
  • When changing the password ,the old password entry at the top should be the one that is automatically selected.
tested ACK 008bcb78603f27b3d468775d8aa0a69a98c8eb47 There are several (minor) issues that can be fixed in follow up. To name a few: - The entering of decimals at max mempool size: enter 5,5 -> it changes automatically to 55. Or enter 55,55 it changes to 5,555 - Mempool Information being displayed when running blocksonly - That there is currently no verification of the wallet name can lead to dislay inaccuracies when renaming a wallet, the names don't update/match: <img width="1160" height="212" alt="Image" src="https://git.fish.foo/attachments/86a70f77-5ca4-4a11-9d5e-7a81be3689e1" /> - When changing the password ,the old password entry at the top should be the one that is automatically selected.
johnny9 commented 2026-05-18 14:46:53 +00:00 (Migrated from github.com)

tested ACK 008bcb7

There are several (minor) issues that can be fixed in follow up.

To name a few:

* The entering of decimals at max mempool size: enter 5,5 -> it changes automatically to 55. Or enter 55,55 it changes to 5,555

I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer

* Mempool Information being displayed when running blocksonly

#710

* That there is currently no verification of the wallet name can lead to dislay inaccuracies when renaming a wallet, the names don't update/match:

#711

When changing the password ,the old password entry at the top should be the one that is automatically selected.

#712

> tested ACK [008bcb7](https://github.com/bitcoin-core/gui-qml/commit/008bcb78603f27b3d468775d8aa0a69a98c8eb47) > > There are several (minor) issues that can be fixed in follow up. > > To name a few: > > * The entering of decimals at max mempool size: enter 5,5 -> it changes automatically to 55. Or enter 55,55 it changes to 5,555 I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer > * Mempool Information being displayed when running blocksonly #710 > * That there is currently no verification of the wallet name can lead to dislay inaccuracies when renaming a wallet, the names don't update/match: > #711 > When changing the password ,the old password entry at the top should be the one that is automatically selected. > #712
MarnixCroes commented 2026-05-18 18:21:24 +00:00 (Migrated from github.com)

I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer

yes it shouldn't, but it is possible to enter decimals (which works buggy).

> I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer yes it shouldn't, but it is possible to enter decimals (which works buggy).
johnny9 commented 2026-05-20 15:14:54 +00:00 (Migrated from github.com)

I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer

yes it shouldn't, but it is possible to enter decimals (which works buggy).

Ok I will investigate this but for clarity you mean you type 5 then "." and then 5 or is it 5 then 5 and then a "." in the middle? I want to know how exactly a decimal gets added.

> > I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer > > yes it shouldn't, but it is possible to enter decimals (which works buggy). Ok I will investigate this but for clarity you mean you type 5 then "." and then 5 or is it 5 then 5 and then a "." in the middle? I want to know how exactly a decimal gets added.
MarnixCroes commented 2026-05-21 13:24:47 +00:00 (Migrated from github.com)

I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer

yes it shouldn't, but it is possible to enter decimals (which works buggy).

Ok I will investigate this but for clarity you mean you type 5 then "." and then 5 or is it 5 then 5 and then a "." in the middle? I want to know how exactly a decimal gets added.

Can only repro with comma ,

Screencast from 2026-05-21 10-22-31.webm

> > > I can't reproduce this or am not fully understanding. The input should not allow decimals values as mempool memory is an integer > > > > > > yes it shouldn't, but it is possible to enter decimals (which works buggy). > > Ok I will investigate this but for clarity you mean you type 5 then "." and then 5 or is it 5 then 5 and then a "." in the middle? I want to know how exactly a decimal gets added. Can only repro with comma , [Screencast from 2026-05-21 10-22-31.webm](https://github.com/user-attachments/assets/9572ea4d-87ef-453d-847c-a47adad13574)
Sign in to join this conversation.
No description provided.