Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/gridcoin/accrual/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,29 @@ class SnapshotCalculator
// more bits. Arithmetic with the big integer type is much slower and
// unnecessary in the majority of cases so switch only when required:
//
CAmount accrual = 0;

if (base_accrual > std::numeric_limits<uint64_t>::max() / COIN) {
arith_uint256 accrual_bn(base_accrual);
accrual_bn *= COIN;
accrual_bn /= 86400;
accrual_bn /= Magnitude::SCALE_FACTOR;
accrual_bn /= MAG_UNIT_DENOMINATOR;

return accrual_bn.GetLow64();
accrual = accrual_bn.GetLow64();
} else {
accrual = base_accrual
* COIN
/ 86400
/ Magnitude::SCALE_FACTOR
/ MAG_UNIT_DENOMINATOR;
}

return base_accrual
* COIN
/ 86400
/ Magnitude::SCALE_FACTOR
/ MAG_UNIT_DENOMINATOR;
LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: CPID = %s, LastRewardHeight() = %u, accrual_timespan = %" PRId64 ", "
"accrual = %" PRId64 ".", __func__, cpid.ToString(), account.LastRewardHeight(),
accrual_timespan, accrual);

return accrual;
}

protected:
Expand Down Expand Up @@ -369,6 +377,9 @@ class SnapshotAccrualComputer : public IAccrualComputer, SnapshotCalculator
return AccrualDelta(m_cpid, m_account);
}

LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: CPID = %s, m_account.m_accrual = %" PRId64 ", ",
__func__, m_cpid.ToString(), m_account.m_accrual);

return m_account.m_accrual + AccrualDelta(m_cpid, m_account);
}

Expand Down
39 changes: 39 additions & 0 deletions src/gridcoin/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,21 @@ class ResearcherTally
return m_snapshots.EraseAll();
}

//!
//! \brief Return the CBlockIndex pointer for the tally baseline.
//!
const CBlockIndex* GetBaseline()
{
if (m_snapshots.HasBaseline())
{
return m_snapshot_baseline_pindex;
}
else
{
return nullptr;
}
}

private:
//!
//! \brief An empty account to return as a reference when requesting an
Expand Down Expand Up @@ -541,6 +556,9 @@ class ResearcherTally
{
const SnapshotCalculator calc(superblock.m_timestamp, m_current_superblock);

LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: m_researchers.size() = %u",
__func__, m_researchers.size());

for (auto& account_pair : m_researchers) {
const Cpid cpid = account_pair.first;
ResearchAccount& account = account_pair.second;
Expand Down Expand Up @@ -568,6 +586,15 @@ class ResearcherTally
if (m_researchers.find(iter.Cpid()) == m_researchers.end()) {
ResearchAccount& account = m_researchers[iter.Cpid()];
account.m_accrual = calc.AccrualDelta(iter.Cpid(), account);

LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: accrual account not found"
"for CPID %s. Creating account with accrual %" PRId64" from "
"AccrualDelta() = %" PRId64 ". m_researchers.size() now %u",
__func__,
iter.Cpid().ToString(),
account.m_accrual,
calc.AccrualDelta(iter.Cpid(), account),
m_researchers.size());
}
}
}
Expand Down Expand Up @@ -748,6 +775,13 @@ bool Tally::Initialize(CBlockIndex* pindex)

g_newbie_snapshot_fix_enabled = pindex->nHeight + 1 >= GetNewbieSnapshotFixHeight();

LogPrint(BCLog::LogFlags::ACCRUAL, "INFO %s: pindex->nHeight + 1 = %i, GetNewbieSnapshotFixHeight() = %i, "
"g_newbie_snapshot_fix_enabled = %i",
__func__,
pindex->nHeight + 1,
GetNewbieSnapshotFixHeight(),
g_newbie_snapshot_fix_enabled);

const int64_t start_time = GetTimeMillis();

g_researcher_tally.Initialize(pindex, Quorum::CurrentSuperblock());
Expand Down Expand Up @@ -977,3 +1011,8 @@ void Tally::LegacyRecount(const CBlockIndex* pindex)

g_network_tally.Reset(total_research_subsidy);
}

const CBlockIndex* Tally::GetBaseline()
{
return g_researcher_tally.GetBaseline();
}
6 changes: 6 additions & 0 deletions src/gridcoin/tally.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,11 @@ class Tally
//! \param pindex Index of the block to start recounting backward from.
//!
static void LegacyRecount(const CBlockIndex* pindex);

//!
//! \brief Return the baseline snapshot height for the tally.
//!
const static CBlockIndex* GetBaseline();

};
}
2 changes: 2 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "superblocks" , 1 },

// Developer
{ "auditsnapshotaccrual" , 1 },
{ "auditsnapshotaccruals" , 0 },
{ "convergencereport" , 0 },
{ "debug" , 0 },
{ "debug10" , 0 },
Expand Down
Loading