Skip to content

Commit

Permalink
Make changes to split out email mismatch from split cpid status
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Dec 18, 2021
1 parent e40a782 commit 1a2402b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 33 deletions.
29 changes: 18 additions & 11 deletions src/gridcoin/researcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ std::optional<Cpid> FallbackToCpidByEmail(
//! \param projects Map of local projects loaded from BOINC's client_state.xml
//! file.
//!
bool DetectSplitCpid(const MiningProjectMap& projects)
ResearcherCpidErrorStatus DetectSplitCpid(const MiningProjectMap& projects)
{
std::unordered_map<Cpid, std::string> eligible_cpids;
bool mismatched_email = false;
Expand All @@ -418,7 +418,14 @@ bool DetectSplitCpid(const MiningProjectMap& projects)
}
}

if (mismatched_email || eligible_cpids.size() > 1) {
if (mismatched_email && eligible_cpids.size() == 1) {
LogPrintf("WARN: %s: Detected email mismatch between email specified in config file and BOINC project "
"registration.");

return ResearcherCpidErrorStatus::MISMATCHED_EMAIL;
}

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

Expand All @@ -429,10 +436,10 @@ bool DetectSplitCpid(const MiningProjectMap& projects)

LogPrintf("%s", warning);

return true;
return ResearcherCpidErrorStatus::SPLIT_CPID;
}

return false;
return ResearcherCpidErrorStatus::NONE;
}

//!
Expand Down Expand Up @@ -1056,12 +1063,12 @@ Researcher::Researcher(
MiningId mining_id,
MiningProjectMap projects,
const GRC::BeaconError beacon_error,
const bool has_split_cpid
const ResearcherCpidErrorStatus cpid_error_status
)
: m_mining_id(std::move(mining_id))
, m_projects(std::move(projects))
, m_beacon_error(beacon_error)
, m_has_split_cpid(has_split_cpid)
, m_cpid_error_status(cpid_error_status)
{
}

Expand Down Expand Up @@ -1217,17 +1224,17 @@ void Researcher::Reload(MiningProjectMap projects, GRC::BeaconError beacon_error
}
}

bool has_split_cpid = false;
ResearcherCpidErrorStatus cpid_error_status;

if (const CpidOption cpid = mining_id.TryCpid()) {
has_split_cpid = DetectSplitCpid(projects);
cpid_error_status = 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, has_split_cpid));
Researcher(std::move(mining_id), std::move(projects), beacon_error, cpid_error_status));
}

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

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

bool Researcher::ChangeMode(const ResearcherMode mode, std::string email)
Expand Down
26 changes: 16 additions & 10 deletions src/gridcoin/researcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ enum class ResearcherStatus
NO_BEACON, //!< No active beacon public key advertised.
};

enum class ResearcherCpidErrorStatus
{
NONE, //!< No error
MISMATCHED_EMAIL, //!< Email specified in config file is likely mismatched with BOINC projects
SPLIT_CPID, //!< More than one cpid encountered across active projects
};

//!
//! \brief Represents a Gridcoin pool that stakes on behalf of its users.
//!
Expand Down Expand Up @@ -389,11 +396,10 @@ class Researcher
//! \param beacon_error Last beacon advertisement error, if any.
//! \param has_split_cpid Existence of split cpid.
//!
Researcher(
MiningId mining_id,
Researcher(MiningId mining_id,
MiningProjectMap projects,
const BeaconError beacon_error = GRC::BeaconError::NONE,
bool has_split_cpid = false);
ResearcherCpidErrorStatus researcher_error_status = ResearcherCpidErrorStatus::NONE);

//!
//! \brief Set up the local researcher context.
Expand Down Expand Up @@ -580,11 +586,11 @@ class Researcher
GRC::BeaconError BeaconError() const;

//!
//! \brief Returns true if a split CPID situation exists (i.e. project list
//! \brief Returns error status related to email mismatch or split CPID situation (i.e. project list
//! refers to more than one CPID).
//! \return boolean of split cpid existence
//! \return enum providing error status of cpid for researcher
//!
bool hasSplitCpid() const;
ResearcherCpidErrorStatus hasSplitCpid() const;

//!
//! \brief Update how a user prefers to participate in the research reward
Expand Down Expand Up @@ -643,10 +649,10 @@ class Researcher
AdvertiseBeaconResult RevokeBeacon(const Cpid cpid);

private:
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
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.
ResearcherCpidErrorStatus m_cpid_error_status; //!< Enum that indicates project list email mismatch or more than one CPID
}; // Researcher
}

Expand Down
12 changes: 6 additions & 6 deletions src/qt/researcher/researchermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ 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
} else if (hasSplitCpid() > ResearcherCpidErrorStatus::NONE) {
// If there is a split CPID/email mismatch situation, then the actionNeeded is also set, but
// in this case we want to go to the PageSummary screen, where they will see the warning for
// the email mismatch or split CPID. This is more important than renewing the beacon
wizard->setStartId(ResearcherWizard::PageSummary);
} else if (hasRenewableBeacon()) {
wizard->setStartId(ResearcherWizard::PageBeacon);
Expand Down Expand Up @@ -240,7 +240,7 @@ bool ResearcherModel::actionNeeded() const
}

if (hasEligibleProjects()) {
return hasSplitCpid() || (!hasActiveBeacon() && !hasPendingBeacon());
return hasSplitCpid() > ResearcherCpidErrorStatus::NONE || (!hasActiveBeacon() && !hasPendingBeacon());
}

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

bool ResearcherModel::hasSplitCpid() const
ResearcherCpidErrorStatus ResearcherModel::hasSplitCpid() const
{
return m_researcher->hasSplitCpid();
}
Expand Down
6 changes: 4 additions & 2 deletions src/qt/researcher/researchermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace GRC {
class Beacon;
class Researcher;

enum class ResearcherCpidErrorStatus;

//!
//! \brief A smart pointer around the global BOINC researcher context.
//!
Expand Down Expand Up @@ -94,7 +96,7 @@ class ResearcherModel : public QObject
bool hasRenewableBeacon() const;
bool hasMagnitude() const;
bool hasRAC() const;
bool hasSplitCpid() const;
GRC::ResearcherCpidErrorStatus hasSplitCpid() const;
bool needsBeaconAuth() const;

QString email() const;
Expand Down Expand Up @@ -122,7 +124,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_cpid_error_status;
bool m_privacy_enabled;
QString m_theme_suffix;

Expand Down
16 changes: 12 additions & 4 deletions src/qt/researcher/researcherwizardsummarypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "qt/researcher/researchermodel.h"
#include "qt/researcher/researcherwizardsummarypage.h"

#include "gridcoin/researcher.h"

// -----------------------------------------------------------------------------
// Class: ResearcherWizardSummaryPage
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -128,11 +130,17 @@ void ResearcherWizardSummaryPage::refreshOverallStatus()
} else if (!m_researcher_model->hasMagnitude()) {
status = tr("Waiting for magnitude.");
icon = QIcon(":/icons/scraper_waiting_light");
} else if (m_researcher_model->hasSplitCpid()) {
} else if (m_researcher_model->hasSplitCpid() == GRC::ResearcherCpidErrorStatus::MISMATCHED_EMAIL) {
status = tr("Email mismatch - your projects all are linked to the same CPID but the email does\n"
"not match what is configured here in the client. Please ensure that the email used\n"
"here matches that used for your BOINC projects.");
icon = QIcon(":/icons/warning");
} else if (m_researcher_model->hasSplitCpid() == GRC::ResearcherCpidErrorStatus::SPLIT_CPID) {
status = tr("Likely split CPID - projects refer to more than one CPID. Please ensure all\n"
"of your projects are attached using the same email address and if you added\n"
"a project recently, update that project and then all other projects using the\n"
"update button in the BOINC manager, then go to the projects tab and refresh.");
"of your projects are attached using the same email address, that this email\n"
"is the same as you used here in the Gridcoin client, and if you added a project\n"
"recently, update that project and then all other projects using the update\n"
"button in the BOINC manager, then go to the projects tab and refresh.");
icon = QIcon(":/icons/warning");
} else {
status = tr("Everything looks good.");
Expand Down

0 comments on commit 1a2402b

Please sign in to comment.