Skip to content

Commit 1d2d335

Browse files
committed
Merge #2075: [GUI] Settings information, fix missing initial masternodes count value.
164d6aa GUI: settings information, fix missing initial masternodes count value. (furszy) Pull request description: The count isn't updated on every widget show, only via the event (which only happen every 40 minutes as Masternodes updates aren't regular at all). This PR fixes it updating the masternode count every time that the screen is visible, then the event is in charge of update it if the user stays there long enough. ACKs for top commit: random-zebra: Nice. ACK 164d6aa Fuzzbawls: ACK 164d6aa Tree-SHA512: 6624ee2f408601e46853dc2cd57c5c679736aad8798b38b846af28c59a89a01d9fa2b9027486f6195b8265a2d50fabc9013f90940fc2dda349798b564b510dc0
2 parents 6557613 + 164d6aa commit 1d2d335

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

src/qt/clientmodel.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ QString ClientModel::getMasternodeCountString() const
8383
return tr("Total: %1 (IPv4: %2 / IPv6: %3 / Tor: %4 / Unknown: %5)").arg(QString::number(total)).arg(QString::number((int)ipv4)).arg(QString::number((int)ipv6)).arg(QString::number((int)onion)).arg(QString::number((int)nUnknown));
8484
}
8585

86+
QString ClientModel::getMasternodesCount()
87+
{
88+
if (!cachedMasternodeCountString.isEmpty()) {
89+
return cachedMasternodeCountString;
90+
}
91+
92+
// Force an update
93+
cachedMasternodeCountString = getMasternodeCountString();
94+
return cachedMasternodeCountString;
95+
}
96+
8697
int ClientModel::getNumBlocks()
8798
{
8899
if (!cacheTip) {
@@ -139,12 +150,8 @@ void ClientModel::updateTimer()
139150

140151
void ClientModel::updateMnTimer()
141152
{
142-
// Get required lock upfront. This avoids the GUI from getting stuck on
143-
// periodical polls if the core is holding the locks for a longer time -
144-
// for example, during a wallet rescan.
145-
TRY_LOCK(cs_main, lockMain);
146-
if (!lockMain)
147-
return;
153+
// Following method is locking the mnmanager mutex for now,
154+
// future: move to an event based update.
148155
QString newMasternodeCountString = getMasternodeCountString();
149156

150157
if (cachedMasternodeCountString != newMasternodeCountString) {

src/qt/clientmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class ClientModel : public QObject
8989
// Start/Stop the masternode polling timer
9090
void startMasternodesTimer();
9191
void stopMasternodesTimer();
92+
// Force a MN count update calling mnmanager directly locking its internal mutex.
93+
// Future todo: implement an event based update and remove the lock requirement.
94+
QString getMasternodesCount();
9295

9396
private:
9497
QString getMasternodeCountString() const;

src/qt/pivx/settings/settingsinformationwidget.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2019-2020 The PIVX developers
22
// Distributed under the MIT software license, see the accompanying
3-
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
3+
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
44

55
#include "qt/pivx/settings/settingsinformationwidget.h"
66
#include "qt/pivx/settings/forms/ui_settingsinformationwidget.h"
@@ -14,6 +14,8 @@
1414

1515
#include <QDir>
1616

17+
#define REQUEST_UPDATE_MN_COUNT 0
18+
1719
SettingsInformationWidget::SettingsInformationWidget(PIVXGUI* _window,QWidget *parent) :
1820
PWidget(_window,parent),
1921
ui(new Ui::SettingsInformationWidget)
@@ -165,6 +167,8 @@ void SettingsInformationWidget::showEvent(QShowEvent *event)
165167
QWidget::showEvent(event);
166168
if (clientModel) {
167169
clientModel->startMasternodesTimer();
170+
// Initial masternodes count value, running in a worker thread to not lock mnmanager mutex in the main thread.
171+
execute(REQUEST_UPDATE_MN_COUNT);
168172
}
169173
}
170174

@@ -175,6 +179,21 @@ void SettingsInformationWidget::hideEvent(QHideEvent *event) {
175179
}
176180
}
177181

182+
void SettingsInformationWidget::run(int type)
183+
{
184+
if (type == REQUEST_UPDATE_MN_COUNT) {
185+
QMetaObject::invokeMethod(this, "setMasternodeCount",
186+
Qt::QueuedConnection, Q_ARG(QString, clientModel->getMasternodesCount()));
187+
}
188+
}
189+
190+
void SettingsInformationWidget::onError(QString error, int type)
191+
{
192+
if (type == REQUEST_UPDATE_MN_COUNT) {
193+
setMasternodeCount(tr("No available data"));
194+
}
195+
}
196+
178197
SettingsInformationWidget::~SettingsInformationWidget()
179198
{
180199
delete ui;

src/qt/pivx/settings/settingsinformationwidget.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ class SettingsInformationWidget : public PWidget
1919

2020
public:
2121
explicit SettingsInformationWidget(PIVXGUI* _window, QWidget *parent = nullptr);
22-
~SettingsInformationWidget();
22+
~SettingsInformationWidget() override;
2323

2424
void loadClientModel() override;
2525

26+
void run(int type) override;
27+
void onError(QString error, int type) override;
28+
2629
private Q_SLOTS:
2730
void setNumConnections(int count);
2831
void setNumBlocks(int count);
29-
void setMasternodeCount(const QString& strMasternodes);
3032
void showEvent(QShowEvent* event) override;
3133
void hideEvent(QHideEvent* event) override;
3234

3335
public Q_SLOTS:
3436
void openNetworkMonitor();
37+
void setMasternodeCount(const QString& strMasternodes);
3538

3639
private:
3740
Ui::SettingsInformationWidget *ui;

0 commit comments

Comments
 (0)