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 ac4d112
Show file tree
Hide file tree
Showing 5 changed files with 49 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 has_split_cpid = 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) {
has_split_cpid = true;
}
}

if (eligible_cpids.size() > 1) {
if (has_split_cpid || 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
7 changes: 6 additions & 1 deletion src/qt/researcher/researchermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool ResearcherModel::actionNeeded() const
}

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

return !hasPoolProjects();
Expand Down Expand Up @@ -276,6 +276,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.");
icon = QIcon(":/icons/warning");
} else {
status = tr("Everything looks good.");
icon = QIcon(":/icons/round_green_check");
Expand Down

0 comments on commit ac4d112

Please sign in to comment.