Skip to content

Commit ada5486

Browse files
committed
Implement a warning about split CPID condition in gui
1 parent 2214a0b commit ada5486

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

src/gridcoin/researcher.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,24 @@ std::optional<Cpid> FallbackToCpidByEmail(
401401
//! \param projects Map of local projects loaded from BOINC's client_state.xml
402402
//! file.
403403
//!
404-
void DetectSplitCpid(const MiningProjectMap& projects)
404+
bool DetectSplitCpid(const MiningProjectMap& projects)
405405
{
406406
std::unordered_map<Cpid, std::string> eligible_cpids;
407+
bool has_split_cpid = false;
407408

408409
for (const auto& project_pair : projects) {
409410
if (project_pair.second.Eligible()) {
410411
eligible_cpids.emplace(
411412
project_pair.second.m_cpid,
412413
project_pair.second.m_name);
413414
}
415+
416+
if (project_pair.second.m_error == MiningProject::Error::MISMATCHED_CPID) {
417+
has_split_cpid = true;
418+
}
414419
}
415420

416-
if (eligible_cpids.size() > 1) {
421+
if (has_split_cpid || eligible_cpids.size() > 1) {
417422
std::string warning = "WARNING: Detected potential CPID split. ";
418423
warning += "Eligible CPIDs: \n";
419424

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

425430
LogPrintf("%s", warning);
431+
432+
return true;
426433
}
434+
435+
return false;
427436
}
428437

429438
//!
@@ -1046,10 +1055,13 @@ Researcher::Researcher()
10461055
Researcher::Researcher(
10471056
MiningId mining_id,
10481057
MiningProjectMap projects,
1049-
const GRC::BeaconError beacon_error)
1058+
const GRC::BeaconError beacon_error,
1059+
const bool has_split_cpid
1060+
)
10501061
: m_mining_id(std::move(mining_id))
10511062
, m_projects(std::move(projects))
10521063
, m_beacon_error(beacon_error)
1064+
, m_has_split_cpid(has_split_cpid)
10531065
{
10541066
}
10551067

@@ -1205,15 +1217,17 @@ void Researcher::Reload(MiningProjectMap projects, GRC::BeaconError beacon_error
12051217
}
12061218
}
12071219

1220+
bool has_split_cpid = false;
1221+
12081222
if (const CpidOption cpid = mining_id.TryCpid()) {
1209-
DetectSplitCpid(projects);
1223+
has_split_cpid = DetectSplitCpid(projects);
12101224
LogPrintf("Selected primary CPID: %s", cpid->ToString());
12111225
} else if (!projects.empty()) {
12121226
LogPrintf("WARNING: no projects eligible for research rewards.");
12131227
}
12141228

12151229
StoreResearcher(
1216-
Researcher(std::move(mining_id), std::move(projects), beacon_error));
1230+
Researcher(std::move(mining_id), std::move(projects), beacon_error, has_split_cpid));
12171231
}
12181232

12191233
void Researcher::Refresh()
@@ -1361,6 +1375,11 @@ GRC::BeaconError Researcher::BeaconError() const
13611375
return m_beacon_error;
13621376
}
13631377

1378+
bool Researcher::hasSplitCpid() const
1379+
{
1380+
return m_has_split_cpid;
1381+
}
1382+
13641383
bool Researcher::ChangeMode(const ResearcherMode mode, std::string email)
13651384
{
13661385
email = ToLower(email);

src/gridcoin/researcher.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,13 @@ class Researcher
387387
//! \param mining_id Represents a CPID or an investor.
388388
//! \param projects A set of local projects loaded from BOINC.
389389
//! \param beacon_error Last beacon advertisement error, if any.
390+
//! \param has_split_cpid Existence of split cpid.
390391
//!
391392
Researcher(
392393
MiningId mining_id,
393394
MiningProjectMap projects,
394-
const BeaconError beacon_error = GRC::BeaconError::NONE);
395+
const BeaconError beacon_error = GRC::BeaconError::NONE,
396+
bool has_split_cpid = false);
395397

396398
//!
397399
//! \brief Set up the local researcher context.
@@ -577,6 +579,13 @@ class Researcher
577579
//!
578580
GRC::BeaconError BeaconError() const;
579581

582+
//!
583+
//! \brief Returns true if a split CPID situation exists (i.e. project list
584+
//! refers to more than one CPID).
585+
//! \return boolean of split cpid existence
586+
//!
587+
bool hasSplitCpid() const;
588+
580589
//!
581590
//! \brief Update how a user prefers to participate in the research reward
582591
//! protocol and set the node's BOINC account email address used to detect
@@ -637,6 +646,7 @@ class Researcher
637646
MiningId m_mining_id; //!< CPID or INVESTOR variant.
638647
MiningProjectMap m_projects; //!< Local projects loaded from BOINC.
639648
GRC::BeaconError m_beacon_error; //!< Last beacon error that occurred, if any.
649+
bool m_has_split_cpid; //!< Flag that indicates project list has more than one CPID
640650
}; // Researcher
641651
}
642652

src/qt/researcher/researchermodel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ void ResearcherModel::showWizard(WalletModel* wallet_model)
186186
wizard->setStartId(ResearcherWizard::PageInvestor);
187187
} else if (detectedPoolMode()) {
188188
wizard->setStartId(ResearcherWizard::PagePoolSummary);
189+
} else if (hasSplitCpid()) {
190+
// If there is a split CPID situation, then the actionNeeded is also set, but
191+
// in the case of a split CPID we want to go to the PageSummary screen, where they
192+
// will see the warning for the split CPID. This is more important than renewing the beacon
193+
wizard->setStartId(ResearcherWizard::PageSummary);
189194
} else if (hasRenewableBeacon()) {
190195
wizard->setStartId(ResearcherWizard::PageBeacon);
191196
} else if (!actionNeeded()) {
@@ -235,7 +240,7 @@ bool ResearcherModel::actionNeeded() const
235240
}
236241

237242
if (hasEligibleProjects()) {
238-
return !hasActiveBeacon() && !hasPendingBeacon();
243+
return hasSplitCpid() || (!hasActiveBeacon() && !hasPendingBeacon());
239244
}
240245

241246
return !hasPoolProjects();
@@ -276,6 +281,11 @@ bool ResearcherModel::hasRAC() const
276281
return m_researcher->HasRAC();
277282
}
278283

284+
bool ResearcherModel::hasSplitCpid() const
285+
{
286+
return m_researcher->hasSplitCpid();
287+
}
288+
279289
bool ResearcherModel::needsBeaconAuth() const
280290
{
281291
if (!hasPendingBeacon()) {

src/qt/researcher/researchermodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ResearcherModel : public QObject
9494
bool hasRenewableBeacon() const;
9595
bool hasMagnitude() const;
9696
bool hasRAC() const;
97+
bool hasSplitCpid() const;
9798
bool needsBeaconAuth() const;
9899

99100
QString email() const;
@@ -121,6 +122,7 @@ class ResearcherModel : public QObject
121122
bool m_configured_for_investor_mode;
122123
bool m_wizard_open;
123124
bool m_out_of_sync;
125+
bool m_split_cpid;
124126
bool m_privacy_enabled;
125127
QString m_theme_suffix;
126128

src/qt/researcher/researcherwizardsummarypage.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ void ResearcherWizardSummaryPage::refreshOverallStatus()
128128
} else if (!m_researcher_model->hasMagnitude()) {
129129
status = tr("Waiting for magnitude.");
130130
icon = QIcon(":/icons/scraper_waiting_light");
131+
} else if (m_researcher_model->hasSplitCpid()) {
132+
status = tr("Likely split CPID - projects refer to more than one CPID. Please ensure all\n"
133+
"of your projects are attached using the same email address and if you added\n"
134+
"a project recently, update that project and then all other projects using the\n"
135+
"update button in the BOINC manager, then go to the projects tab and refresh.");
136+
icon = QIcon(":/icons/warning");
131137
} else {
132138
status = tr("Everything looks good.");
133139
icon = QIcon(":/icons/round_green_check");

0 commit comments

Comments
 (0)