Skip to content

Commit c290fae

Browse files
committed
Augment Tally:RecordRewardBlock and ForgetRewardBlock to handle MRCs
1 parent 624e32c commit c290fae

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

src/gridcoin/tally.cpp

+30-8
Original file line numberDiff line numberDiff line change
@@ -1182,25 +1182,47 @@ AccrualComputer Tally::GetLegacyComputer(
11821182
last_block_ptr->nHeight);
11831183
}
11841184

1185+
// TODO: Verify RecordRewardBlock works correctly with MRC's
11851186
void Tally::RecordRewardBlock(const CBlockIndex* const pindex)
11861187
{
1187-
if (!pindex || pindex->ResearchSubsidy() <= 0) {
1188-
return;
1188+
if (!pindex) return;
1189+
1190+
// Record tally for staker's research
1191+
if (pindex->ResearchSubsidy() > 0) {
1192+
if (const CpidOption cpid = pindex->GetMiningId().TryCpid()) {
1193+
g_researcher_tally.RecordRewardBlock(*cpid, pindex);
1194+
}
11891195
}
11901196

1191-
if (const CpidOption cpid = pindex->GetMiningId().TryCpid()) {
1192-
g_researcher_tally.RecordRewardBlock(*cpid, pindex);
1197+
// Record tally for manual reward claims
1198+
if (pindex->ResearchMRCSubsidy() > 0) {
1199+
for (const auto& mrc_researcher : pindex->m_mrc_researchers) {
1200+
Cpid cpid = mrc_researcher->m_cpid;
1201+
1202+
g_researcher_tally.RecordRewardBlock(cpid, pindex);
1203+
}
11931204
}
11941205
}
11951206

1207+
// TODO: Verify ForgetRewardBlock works correctly with MRC's
11961208
void Tally::ForgetRewardBlock(const CBlockIndex* const pindex)
11971209
{
1198-
if (!pindex || pindex->ResearchSubsidy() <= 0) {
1199-
return;
1210+
if (!pindex) return;
1211+
1212+
// Un-record tally for staker's research
1213+
if (pindex->ResearchSubsidy() > 0) {
1214+
if (const CpidOption cpid = pindex->GetMiningId().TryCpid()) {
1215+
g_researcher_tally.ForgetRewardBlock(*cpid, pindex);
1216+
}
12001217
}
12011218

1202-
if (const CpidOption cpid = pindex->GetMiningId().TryCpid()) {
1203-
g_researcher_tally.ForgetRewardBlock(*cpid, pindex);
1219+
// Un-record tally for manual reward claims
1220+
if (pindex->ResearchMRCSubsidy() > 0) {
1221+
for (const auto& mrc_researcher : pindex->m_mrc_researchers) {
1222+
Cpid cpid = mrc_researcher->m_cpid;
1223+
1224+
g_researcher_tally.ForgetRewardBlock(cpid, pindex);
1225+
}
12041226
}
12051227
}
12061228

src/main.h

+11
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,17 @@ class CBlockIndex
713713
return 0;
714714
}
715715

716+
int64_t ResearchMRCSubsidy() const
717+
{
718+
int64_t mrc_subsidy = 0;
719+
720+
for (const auto& mrc_researcher : m_mrc_researchers) {
721+
mrc_subsidy += mrc_researcher->m_research_subsidy;
722+
}
723+
724+
return mrc_subsidy;
725+
}
726+
716727
double Magnitude() const
717728
{
718729
if (m_researcher) {

0 commit comments

Comments
 (0)