Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI][Bug] Don't set a proposal's status to PASSING_NOT_FUNDED prematurely #2717

Merged
merged 5 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,19 @@ int ClientModel::getNumConnections(unsigned int flags) const
return 0;
}

QString ClientModel::getMasternodeCountString() const
QString ClientModel::getMasternodeCountString()
{
const auto& info = mnodeman.getMNsInfo();
int unknown = std::max(0, info.total - info.ipv4 - info.ipv6 - info.onion);
m_cached_masternodes_count = info.total;
return tr("Total: %1 (IPv4: %2 / IPv6: %3 / Tor: %4 / Unknown: %5)").arg(QString::number(info.total))
.arg(QString::number(info.ipv4))
.arg(QString::number(info.ipv6))
.arg(QString::number(info.onion))
.arg(QString::number(unknown));
}

QString ClientModel::getMasternodesCount()
QString ClientModel::getMasternodesCountString()
{
if (!cachedMasternodeCountString.isEmpty()) {
return cachedMasternodeCountString;
Expand Down
8 changes: 6 additions & 2 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QObject>
#include <QDateTime>

#include <atomic>
#include <memory>

class AddressTableModel;
Expand Down Expand Up @@ -106,7 +107,8 @@ class ClientModel : public QObject
void stopMasternodesTimer();
// Force a MN count update calling mnmanager directly locking its internal mutex.
// Future todo: implement an event based update and remove the lock requirement.
QString getMasternodesCount();
QString getMasternodesCountString();
int getMasternodesCount() const { return m_cached_masternodes_count; }

// Return the specific chain amount value for the MN collateral output.
CAmount getMNCollateralRequiredAmount();
Expand All @@ -120,7 +122,7 @@ class ClientModel : public QObject
std::unique_ptr<interfaces::Handler> m_handler_banned_list_changed;
std::unique_ptr<interfaces::Handler> m_handler_notify_block_tip;

QString getMasternodeCountString() const;
QString getMasternodeCountString();
OptionsModel* optionsModel;
PeerTableModel* peerTableModel;
BanTableModel *banTableModel;
Expand All @@ -136,6 +138,8 @@ class ClientModel : public QObject
QTimer* pollTimer;
QTimer* pollMnTimer;

std::atomic_int m_cached_masternodes_count{0};

void subscribeToCoreSignals();
void unsubscribeFromCoreSignals();

Expand Down
6 changes: 3 additions & 3 deletions src/qt/pivx/governancemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "budget/budgetutil.h"
#include "destination_io.h"
#include "guiconstants.h"
#include "script/standard.h"
#include "qt/transactiontablemodel.h"
#include "qt/transactionrecord.h"
#include "qt/pivx/mnmodel.h"
Expand Down Expand Up @@ -54,6 +53,7 @@ ProposalInfo GovernanceModel::buildProposalInfo(const CBudgetProposal* prop, boo
// Calculate status
int votesYes = prop->GetYeas();
int votesNo = prop->GetNays();
int mnCount = clientModel->getMasternodesCount();
int remainingPayments = prop->GetRemainingPaymentCount(clientModel->getLastBlockProcessedHeight());
ProposalInfo::Status status;

Expand All @@ -65,7 +65,7 @@ ProposalInfo GovernanceModel::buildProposalInfo(const CBudgetProposal* prop, boo
status = ProposalInfo::FINISHED;
} else if (isPassing) {
status = ProposalInfo::PASSING;
} else if (votesYes > votesNo) {
} else if (votesYes - votesNo > mnCount / 10) {
status = ProposalInfo::PASSING_NOT_FUNDED;
} else {
status = ProposalInfo::NOT_PASSING;
Expand Down Expand Up @@ -182,7 +182,7 @@ std::vector<VoteInfo> GovernanceModel::getLocalMNsVotesForProposal(const Proposa

OperationResult GovernanceModel::validatePropName(const QString& name) const
{
if ((int) name.toUtf8().size() > PROP_NAME_MAX_SIZE) { // limit
if (name.toUtf8().size() > (int)PROP_NAME_MAX_SIZE) { // limit
return {false, _("Invalid name, maximum size exceeded")};
}
return {true};
Expand Down
26 changes: 13 additions & 13 deletions src/qt/pivx/governancemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ struct ProposalInfo {
uint256 id;
std::string name;
std::string url;
int votesYes;
int votesNo;
int votesYes{0};
int votesNo{0};
/** Payment script destination */
std::string recipientAdd;
/** Amount of PIV paid per month */
CAmount amount;
CAmount amount{0};
/** Amount of times that the proposal will be paid */
int totalPayments;
int totalPayments{0};
/** Amount of times that the proposal was paid already */
int remainingPayments;
int remainingPayments{0};
/** Proposal state */
Status status;
Status status{WAITING_FOR_APPROVAL};
/** Start superblock height */
int startBlock;
int startBlock{0};
/** End superblock height */
int endBlock;
int endBlock{0};

ProposalInfo() {}
explicit ProposalInfo(const uint256& _id, std::string _name, std::string _url,
Expand All @@ -58,19 +58,19 @@ struct ProposalInfo {
endBlock(_endBlock) {}

bool operator==(const ProposalInfo& prop2) const { return id == prop2.id; }
bool isFinished() { return status == Status::FINISHED; }
bool isFinished() const { return status == Status::FINISHED; }
std::string statusToStr() const;
};

struct VoteInfo {
enum VoteDirection {
ABSTAIN=0,
YES=1,
NO=2
ABSTAIN = 0,
YES = 1,
NO = 2
};

explicit VoteInfo(const COutPoint _mnId, VoteDirection _vote, std::string _mnAlias, int64_t _time) :
mnVoter(_mnId), vote(_vote), mnAlias(_mnAlias), time(_time) {}
mnVoter(_mnId), vote(_vote), mnAlias(std::move(_mnAlias)), time(_time) {}
COutPoint mnVoter;
VoteDirection vote;
std::string mnAlias;
Expand Down
8 changes: 5 additions & 3 deletions src/qt/pivx/proposalcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void ProposalCard::setProposal(const ProposalInfo& _proposalInfo)
ui->labelYes->setText(tr("Yes") + " " + QString::number(percentageYes) + "%");

QString cssClassStatus;
if (proposalInfo.status == ProposalInfo::WAITING_FOR_APPROVAL){
if (proposalInfo.status == ProposalInfo::WAITING_FOR_APPROVAL) {
cssClassStatus = "card-status-no-votes";
setStatusAndVotes(tr("Waiting"), 50);
} else if (proposalInfo.status == ProposalInfo::FINISHED) {
Expand All @@ -59,10 +59,12 @@ void ProposalCard::setProposal(const ProposalInfo& _proposalInfo)
} else if (totalVotes == 0) {
cssClassStatus = "card-status-no-votes";
setStatusAndVotes(tr("No Votes"), 50);
} else if (proposalInfo.status == ProposalInfo::NOT_PASSING ||
proposalInfo.status == ProposalInfo::PASSING_NOT_FUNDED) {
} else if (proposalInfo.status == ProposalInfo::NOT_PASSING) {
cssClassStatus = "card-status-not-passing";
setStatusAndVotes(tr("Not Passing"), (int)percentageNo);
} else if (proposalInfo.status == ProposalInfo::PASSING_NOT_FUNDED) {
cssClassStatus = "card-status-not-passing";
setStatusAndVotes(tr("Over Budget"), (int)percentageNo);
} else if (proposalInfo.status == ProposalInfo::PASSING) {
cssClassStatus = "card-status-passing";
setStatusAndVotes(tr("Passing"), (int)percentageNo);
Expand Down
5 changes: 2 additions & 3 deletions src/qt/pivx/proposalcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "qt/pivx/governancemodel.h"

#include <QGridLayout>
#include <QProgressBar>
#include <QWidget>

namespace Ui {
Expand All @@ -21,14 +20,14 @@ class ProposalCard : public QWidget

public:
explicit ProposalCard(QWidget *parent = nullptr);
~ProposalCard();
~ProposalCard() override;

void setProposal(const ProposalInfo& _proposalInfo);
ProposalInfo getProposal() { return proposalInfo; }

// Update-only functions
void setNeedsUpdate(bool _update) { needsUpdate = _update; }
bool isUpdateNeeded() { return needsUpdate; }
bool isUpdateNeeded() const { return needsUpdate; }

public Q_SLOTS:
void onCopyUrlClicked();
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/settings/settingsinformationwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void SettingsInformationWidget::run(int type)
{
if (type == REQUEST_UPDATE_COUNTS) {
QMetaObject::invokeMethod(this, "setMasternodeCount",
Qt::QueuedConnection, Q_ARG(QString, clientModel->getMasternodesCount()));
Qt::QueuedConnection, Q_ARG(QString, clientModel->getMasternodesCountString()));
QMetaObject::invokeMethod(this, "setNumBlocks",
Qt::QueuedConnection, Q_ARG(int, clientModel->getLastBlockProcessedHeight()));
}
Expand Down