Skip to content

pack of small cleanup fixes / optimizations#2334

Merged
UdjinM6 merged 9 commits intodashpay:developfrom
nmarley:cleanup1
Oct 11, 2018
Merged

pack of small cleanup fixes / optimizations#2334
UdjinM6 merged 9 commits intodashpay:developfrom
nmarley:cleanup1

Conversation

@nmarley
Copy link

@nmarley nmarley commented Oct 4, 2018

See individual commits for more info on each one.

This commit removes 2 loops and a vector which I don't believe are necessary in
CMasternode::FlagGovernanceItemsAsDirty. I could be missing something, but
can't think of any good reason why this was implemented this way.
This is the entire purpose of the Get<X>String methods on MNP class.
@UdjinM6 UdjinM6 added this to the 12.4 milestone Oct 4, 2018
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments

NetMsgType::MNBUDGETPROPOSAL, // deprecated since 12.1
NetMsgType::MNBUDGETFINAL, // deprecated since 12.1
NetMsgType::MNBUDGETFINALVOTE, // deprecated since 12.1
NetMsgType::MNQUORUM, // not implemented
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't do this, read the NOTE (line 83) ;)

NOTE: include non-implmented here, we must keep this list in sync with enum in protocol.h

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I see your point (and commented more below), but the fact that we must keep this list in sync with enum in protocol.h seems like a code smell to me. I'm also not convinced that an enum is actually the right data type, since we're just directly assigning values and they're part of the protocol. Really I think that's a poor case for an enum, since the values have to be maintained.

strHTML += "<b>" + tr("Version") + ": </b>" + (mn.lastPing.nDaemonVersion > DEFAULT_DAEMON_VERSION ? GUIUtil::HtmlEscape(FormatVersion(mn.lastPing.nDaemonVersion)) : tr("Unknown")) + "<br>";
strHTML += "<b>" + tr("Sentinel") + ": </b>" + (mn.lastPing.nSentinelVersion > DEFAULT_SENTINEL_VERSION ? GUIUtil::HtmlEscape(SafeIntVersionToString(mn.lastPing.nSentinelVersion)) : tr("Unknown")) + "<br>";
strHTML += "<b>" + tr("Version") + ": </b>" + GUIUtil::HtmlEscape(mn.lastPing.GetDaemonString()) + "<br>";
strHTML += "<b>" + tr("Sentinel") + ": </b>" + GUIUtil::HtmlEscape(mn.lastPing.GetSentinelString()) + "<br>";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New code won't produce the same results - unlike RPC, GUI uses tr (i.e. translation) for the "Unknown" string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I see your point. But I'd really like to try and find a solution that doesn't duplicate the logic both here and in the GetString methods. Is there a way of providing translation for "Unknown" in the code for (e.g.) GetDaemonString instead?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that it's common to see translated strings in GUI but not in RPC, that's why it was implemented this way. I don't see how to reuse it cleanly tbh, maybe only smth like

diff --git a/src/qt/masternodelist.cpp b/src/qt/masternodelist.cpp
index 266a14335..e2a42df4a 100644
--- a/src/qt/masternodelist.cpp
+++ b/src/qt/masternodelist.cpp
@@ -492,6 +492,9 @@ void MasternodeList::ShowQRCode(std::string strAlias) {
     // Title above QR-Code
     QString strQRCodeTitle = tr("Masternode Private Key");
 
+    std::string strDaemon = mn.lastPing.GetDaemonString();
+    std::string strSentinel = mn.lastPing.GetSentinelString();
+
     // Create dialog text as HTML
     QString strHTML = "<html><font face='verdana, arial, helvetica, sans-serif'>";
     strHTML += "<b>" + tr("Alias") +            ": </b>" + GUIUtil::HtmlEscape(strAlias) + "<br>";
@@ -500,8 +503,8 @@ void MasternodeList::ShowQRCode(std::string strAlias) {
     strHTML += "<b>" + tr("IP") +               ": </b>" + GUIUtil::HtmlEscape(strIP) + "<br>";
     if (fFound) {
         strHTML += "<b>" + tr("Protocol") +     ": </b>" + QString::number(mn.nProtocolVersion) + "<br>";
-        strHTML += "<b>" + tr("Version") +      ": </b>" + (mn.lastPing.nDaemonVersion > DEFAULT_DAEMON_VERSION ? GUIUtil::HtmlEscape(FormatVersion(mn.lastPing.nDaemonVersion)) : tr("Unknown")) + "<br>";
-        strHTML += "<b>" + tr("Sentinel") +     ": </b>" + (mn.lastPing.nSentinelVersion > DEFAULT_SENTINEL_VERSION ? GUIUtil::HtmlEscape(SafeIntVersionToString(mn.lastPing.nSentinelVersion)) : tr("Unknown")) + "<br>";
+        strHTML += "<b>" + tr("Version") +      ": </b>" + (strDaemon == "Unknown" ? tr("Unknown") : strDaemon.c_str()) + "<br>";
+        strHTML += "<b>" + tr("Sentinel") +     ": </b>" + (strDaemon == "Unknown" ? tr("Unknown") : strSentinel.c_str()) + "<br>";
         strHTML += "<b>" + tr("Status") +       ": </b>" + GUIUtil::HtmlEscape(CMasternode::StateToString(mn.nActiveState)) + "<br>";
         strHTML += "<b>" + tr("Payee") +        ": </b>" + GUIUtil::HtmlEscape(CBitcoinAddress(mn.pubKeyCollateralAddress.GetID()).ToString()) + "<br>";
         strHTML += "<b>" + tr("Active") +       ": </b>" + GUIUtil::HtmlEscape(DurationToDHMS(mn.lastPing.sigTime - mn.sigTime)) + "<br>";

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UdjinM6 I've been thinking a bit more on this... is "Unknown" really necessary at all? Can we use a "0" version string, or an empty string instead? Just seems weird that we have these special processing rules based on the string content.

That said, I fully understand the tr() for Qt only, but if we're putting in a either version or "Unknown", then it's obviously for human consumption, so why not make it more consistent and remove these conditionals?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, maybe we should get rid of "Unknown" (less strings to translate, yay! :) ) but not in this (refactoring) PR imo.

const char *MNBUDGETPROPOSAL="mprop"; // deprecated since 12.1
const char *MNBUDGETFINAL="fbs"; // deprecated since 12.1
const char *MNBUDGETFINALVOTE="fbvote"; // deprecated since 12.1
const char *MNQUORUM="mn quorum"; // not implemented
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't drop this, see below

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't realize they needed to be in-sync (esp these NsgMsgType constants here, since those aren't an enum and just directly assigned values). I mean, in theory we could replace these with a single const char *NOTIMPLEMENTED = "notimplemented";, right?

But for the sake of not making any functional changes I'll revert this commit.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, NOTIMPLEMENTED would work I guess.

@nmarley
Copy link
Author

nmarley commented Oct 9, 2018

Reverted Qt version handling change, should be ready for re-review for small refactoring / cleanup.

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@UdjinM6 UdjinM6 merged commit 89f744d into dashpay:develop Oct 11, 2018
@nmarley nmarley deleted the cleanup1 branch October 12, 2018 23:07
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request May 21, 2019
* remove vector, extra loop in cleanup function

This commit removes 2 loops and a vector which I don't believe are necessary in
CMasternode::FlagGovernanceItemsAsDirty. I could be missing something, but
can't think of any good reason why this was implemented this way.

* use range operator to range over vectors

* remove deprecated wire message types

* mn: simplify govobj map mgmt a bit

* remove extra semicolons

* invert if/else condition and drop else

* remove if/else logic from Qt

This is the entire purpose of the Get<X>String methods on MNP class.

* Revert "remove deprecated wire message types"

This reverts commit 9de88a3.

* Revert "remove if/else logic from Qt"

This reverts commit c0f43c9.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants