Skip to content

Commit

Permalink
Merge pull request #2414 from jamescowens/implement_split_cpid_gui_wa…
Browse files Browse the repository at this point in the history
…rning

gui: Implement a warning about split CPID/email mismatch condition
  • Loading branch information
jamescowens authored Dec 18, 2021
2 parents e3ef089 + adef591 commit 0917c91
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
36 changes: 31 additions & 5 deletions src/gridcoin/researcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,24 @@ std::optional<Cpid> FallbackToCpidByEmail(
//! \param projects Map of local projects loaded from BOINC's client_state.xml
//! file.
//!
void DetectSplitCpid(const MiningProjectMap& projects)
bool DetectSplitCpid(const MiningProjectMap& projects)
{
std::unordered_map<Cpid, std::string> eligible_cpids;
bool mismatched_email = false;

for (const auto& project_pair : projects) {
if (project_pair.second.Eligible()) {
eligible_cpids.emplace(
project_pair.second.m_cpid,
project_pair.second.m_name);
}

if (project_pair.second.m_error == MiningProject::Error::MISMATCHED_CPID) {
mismatched_email = true;
}
}

if (eligible_cpids.size() > 1) {
if (mismatched_email || eligible_cpids.size() > 1) {
std::string warning = "WARNING: Detected potential CPID split. ";
warning += "Eligible CPIDs: \n";

Expand All @@ -423,7 +428,11 @@ void DetectSplitCpid(const MiningProjectMap& projects)
}

LogPrintf("%s", warning);

return true;
}

return false;
}

//!
Expand Down Expand Up @@ -1046,10 +1055,13 @@ Researcher::Researcher()
Researcher::Researcher(
MiningId mining_id,
MiningProjectMap projects,
const GRC::BeaconError beacon_error)
const GRC::BeaconError beacon_error,
const bool has_split_cpid
)
: m_mining_id(std::move(mining_id))
, m_projects(std::move(projects))
, m_beacon_error(beacon_error)
, m_has_split_cpid(has_split_cpid)
{
}

Expand Down Expand Up @@ -1205,15 +1217,24 @@ void Researcher::Reload(MiningProjectMap projects, GRC::BeaconError beacon_error
}
}

bool has_split_cpid = false;

// SplitCpid currently can occur if EITHER project have the right email but thed CPID is not converged, OR
// the email is mismatched between them or this client, or BOTH. Right now it is too hard to tease all of that
// out without significant replumbing. So instead if projects not empty run the DetectSplitCpid regardless
// of whether the mining_id has actually been populated.
if (!projects.empty()) {
has_split_cpid = DetectSplitCpid(projects);
}

if (const CpidOption cpid = mining_id.TryCpid()) {
DetectSplitCpid(projects);
LogPrintf("Selected primary CPID: %s", cpid->ToString());
} else if (!projects.empty()) {
LogPrintf("WARNING: no projects eligible for research rewards.");
}

StoreResearcher(
Researcher(std::move(mining_id), std::move(projects), beacon_error));
Researcher(std::move(mining_id), std::move(projects), beacon_error, has_split_cpid));
}

void Researcher::Refresh()
Expand Down Expand Up @@ -1361,6 +1382,11 @@ GRC::BeaconError Researcher::BeaconError() const
return m_beacon_error;
}

bool Researcher::hasSplitCpid() const
{
return m_has_split_cpid;
}

bool Researcher::ChangeMode(const ResearcherMode mode, std::string email)
{
email = ToLower(email);
Expand Down
12 changes: 11 additions & 1 deletion src/gridcoin/researcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,13 @@ class Researcher
//! \param mining_id Represents a CPID or an investor.
//! \param projects A set of local projects loaded from BOINC.
//! \param beacon_error Last beacon advertisement error, if any.
//! \param has_split_cpid Existence of split cpid.
//!
Researcher(
MiningId mining_id,
MiningProjectMap projects,
const BeaconError beacon_error = GRC::BeaconError::NONE);
const BeaconError beacon_error = GRC::BeaconError::NONE,
bool has_split_cpid = false);

//!
//! \brief Set up the local researcher context.
Expand Down Expand Up @@ -577,6 +579,13 @@ class Researcher
//!
GRC::BeaconError BeaconError() const;

//!
//! \brief Returns true if a split CPID situation exists (i.e. project list
//! refers to more than one CPID).
//! \return boolean of split cpid existence
//!
bool hasSplitCpid() const;

//!
//! \brief Update how a user prefers to participate in the research reward
//! protocol and set the node's BOINC account email address used to detect
Expand Down Expand Up @@ -637,6 +646,7 @@ class Researcher
MiningId m_mining_id; //!< CPID or INVESTOR variant.
MiningProjectMap m_projects; //!< Local projects loaded from BOINC.
GRC::BeaconError m_beacon_error; //!< Last beacon error that occurred, if any.
bool m_has_split_cpid; //!< Flag that indicates project list has more than one CPID
}; // Researcher
}

Expand Down
12 changes: 11 additions & 1 deletion src/qt/researcher/researchermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ void ResearcherModel::showWizard(WalletModel* wallet_model)
wizard->setStartId(ResearcherWizard::PageInvestor);
} else if (detectedPoolMode()) {
wizard->setStartId(ResearcherWizard::PagePoolSummary);
} else if (hasSplitCpid()) {
// If there is a split CPID situation, then the actionNeeded is also set, but
// in the case of a split CPID we want to go to the PageSummary screen, where they
// will see the warning for the split CPID. This is more important than renewing the beacon
wizard->setStartId(ResearcherWizard::PageSummary);
} else if (hasRenewableBeacon()) {
wizard->setStartId(ResearcherWizard::PageBeacon);
} else if (!actionNeeded()) {
Expand Down Expand Up @@ -235,7 +240,7 @@ bool ResearcherModel::actionNeeded() const
}

if (hasEligibleProjects()) {
return !hasActiveBeacon() && !hasPendingBeacon();
return hasSplitCpid() || (!hasActiveBeacon() && !hasPendingBeacon());
}

return !hasPoolProjects();
Expand Down Expand Up @@ -276,6 +281,11 @@ bool ResearcherModel::hasRAC() const
return m_researcher->HasRAC();
}

bool ResearcherModel::hasSplitCpid() const
{
return m_researcher->hasSplitCpid();
}

bool ResearcherModel::needsBeaconAuth() const
{
if (!hasPendingBeacon()) {
Expand Down
2 changes: 2 additions & 0 deletions src/qt/researcher/researchermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class ResearcherModel : public QObject
bool hasRenewableBeacon() const;
bool hasMagnitude() const;
bool hasRAC() const;
bool hasSplitCpid() const;
bool needsBeaconAuth() const;

QString email() const;
Expand Down Expand Up @@ -121,6 +122,7 @@ class ResearcherModel : public QObject
bool m_configured_for_investor_mode;
bool m_wizard_open;
bool m_out_of_sync;
bool m_split_cpid;
bool m_privacy_enabled;
QString m_theme_suffix;

Expand Down
14 changes: 14 additions & 0 deletions src/qt/researcher/researcherwizardsummarypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "logging.h"

#include "qt/bitcoinunits.h"
#include "qt/decoration.h"
#include "qt/forms/ui_researcherwizardsummarypage.h"
Expand Down Expand Up @@ -114,6 +116,7 @@ void ResearcherWizardSummaryPage::refreshOverallStatus()
const int icon_size = ui->overallStatusIconLabel->width();

QString status;
QString status_tooltip;
QIcon icon;

if (m_researcher_model->outOfSync()) {
Expand All @@ -125,6 +128,14 @@ void ResearcherWizardSummaryPage::refreshOverallStatus()
} else if (m_researcher_model->hasRenewableBeacon()) {
status = tr("Beacon renewal available.");
icon = QIcon(":/icons/warning");
} else if (m_researcher_model->hasSplitCpid()) {
status = tr("Split CPID or mismatched email.");
status_tooltip = tr("Your projects either refer to more than one CPID or your projects\' email do not match "
"what you used to configure Gridcoin here. Please ensure all of your projects are attached "
"using the same email address, the email address matches what was configured here, and if "
"you added a project recently, update that project and then all other projects using the "
"update button in the BOINC manager, then restart the client and recheck.");
icon = QIcon(":/icons/warning");
} else if (!m_researcher_model->hasMagnitude()) {
status = tr("Waiting for magnitude.");
icon = QIcon(":/icons/scraper_waiting_light");
Expand All @@ -134,6 +145,9 @@ void ResearcherWizardSummaryPage::refreshOverallStatus()
}

ui->overallStatusLabel->setText(status);

ui->overallStatusLabel->setToolTip(status_tooltip);

ui->overallStatusIconLabel->setPixmap(icon.pixmap(icon_size, icon_size));
}

Expand Down

0 comments on commit 0917c91

Please sign in to comment.