Skip to content

Commit

Permalink
Implement a warning about split CPID condition in gui
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Dec 12, 2021
1 parent 2214a0b commit 6ca17e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
29 changes: 24 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,17 @@ void Researcher::Reload(MiningProjectMap projects, GRC::BeaconError beacon_error
}
}

bool has_split_cpid = false;

if (const CpidOption cpid = mining_id.TryCpid()) {
DetectSplitCpid(projects);
has_split_cpid = 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 +1375,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
6 changes: 6 additions & 0 deletions src/qt/researcher/researcherwizardsummarypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ 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()) {
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.");
icon = QIcon(":/icons/warning");
} else {
status = tr("Everything looks good.");
icon = QIcon(":/icons/round_green_check");
Expand Down

0 comments on commit 6ca17e4

Please sign in to comment.