Skip to content

Commit 6cdffb1

Browse files
committed
Update documentation and naming for legacy accrual code
This clarifies the usage of legacy tally and accrual code for blocks version 10 and below. Blocks version 11 and higher follow superblock snapshot accrual rules.
1 parent 1bbcfc7 commit 6cdffb1

File tree

6 files changed

+39
-32
lines changed

6 files changed

+39
-32
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ bool AppInit2(ThreadHandlerPtr threads)
11661166
uiInterface.InitMessage(_("Loading Network Averages..."));
11671167
if (fDebug3) LogPrintf("Loading network averages");
11681168

1169-
NN::Tally::LegacyRecount(NN::Tally::FindTrigger(pindexBest));
1169+
NN::Tally::LegacyRecount(NN::Tally::FindLegacyTrigger(pindexBest));
11701170
}
11711171

11721172
if (!threads->createThread(StartNode, NULL, "Start Thread"))

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,7 +2956,7 @@ bool DisconnectBlocksBatch(CTxDB& txdb, list<CTransaction>& vResurrect, unsigned
29562956

29572957
// Tally research averages.
29582958
if(IsV9Enabled_Tally(nBestHeight) && !IsV11Enabled(nBestHeight)) {
2959-
assert(NN::Tally::IsTrigger(nBestHeight));
2959+
assert(NN::Tally::IsLegacyTrigger(nBestHeight));
29602960
NN::Tally::LegacyRecount(pindexBest);
29612961
}
29622962
}
@@ -2998,7 +2998,7 @@ bool ReorganizeChain(CTxDB& txdb, unsigned &cnt_dis, unsigned &cnt_con, CBlock &
29982998
//
29992999
if (!IsV11Enabled(pcommon->nHeight) && pcommon != pindexBest)
30003000
{
3001-
pcommon = NN::Tally::FindTrigger(pcommon);
3001+
pcommon = NN::Tally::FindLegacyTrigger(pcommon);
30023002
if(!pcommon)
30033003
return error("ReorganizeChain: unable to find fork root with tally point");
30043004
}
@@ -3128,7 +3128,7 @@ bool ReorganizeChain(CTxDB& txdb, unsigned &cnt_dis, unsigned &cnt_con, CBlock &
31283128

31293129
if (IsV9Enabled_Tally(nBestHeight)
31303130
&& !IsV11Enabled(nBestHeight)
3131-
&& NN::Tally::IsTrigger(nBestHeight))
3131+
&& NN::Tally::IsLegacyTrigger(nBestHeight))
31323132
{
31333133
NN::Tally::LegacyRecount(pindexBest);
31343134
}

src/neuralnet/accrual/newbie.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using namespace NN;
88

99
//!
1010
//! \brief An accrual calculator for a CPID that never earned a research reward
11-
//! before.
11+
//! before. Used for legacy accrual calculations in block version 10 and below.
1212
//!
1313
class NewbieAccrualComputer : public IAccrualComputer
1414
{

src/neuralnet/accrual/research_age.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ int64_t GetMaxResearchSubsidy(const int64_t nTime)
3737

3838
//!
3939
//! \brief A calculator that computes the accrued research rewards for a
40-
//! research account using research age rules.
40+
//! research account using legacy research age rules in block version 10
41+
//! and below.
4142
//!
4243
class ResearchAgeComputer : public IAccrualComputer
4344
{

src/neuralnet/tally.cpp

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ using namespace NN;
1414
using LogFlags = BCLog::LogFlags;
1515

1616
namespace {
17-
//!
18-
//! \brief Number of days that the tally scans backward from to calculate
19-
//! the average network payment.
20-
//!
21-
constexpr size_t TALLY_DAYS = 14;
22-
2317
//!
2418
//! \brief Set the correct CPID from the block claim when the block index
2519
//! contains a zero CPID.
@@ -55,25 +49,27 @@ void RepairZeroCpidIndex(CBlockIndex* const pindex)
5549
}
5650
}
5751

58-
//!
59-
//! \brief Round a value to intervals of 0.025.
60-
//!
61-
//! Used to calculate the network magnitude unit.
62-
//!
63-
double SnapToGrid(double d)
64-
{
65-
double dDither = .04;
66-
double dOut = RoundFromString(RoundToString(d * dDither, 3), 3) / dDither;
67-
return dOut;
68-
}
69-
7052
//!
7153
//! \brief Contains the two-week network average tally used to produce the
72-
//! magnitude unit for research age reward calculations.
54+
//! magnitude unit for legacy research age reward calculations (version 10
55+
//! blocks and below).
56+
//!
57+
//! Before block version 11, the network used a feedback filter to limit the
58+
//! total research reward generated over a rolling two week window. To scale
59+
//! rewards accordingly, the magnitude unit acts as a multiplier and changes
60+
//! in response to the amount of research rewards minted over the two weeks.
61+
//! This class holds state for the parameters that produce a magnitude units
62+
//! at a point in time.
7363
//!
7464
class NetworkTally
7565
{
7666
public:
67+
//!
68+
//! \brief Number of days that the tally scans backward from to calculate
69+
//! the average network payment.
70+
//!
71+
static constexpr size_t TALLY_DAYS = 14;
72+
7773
//!
7874
//! \brief Get the maximum network-wide research reward amount per day.
7975
//!
@@ -137,6 +133,16 @@ class NetworkTally
137133
private:
138134
uint32_t m_total_magnitude = 0; //!< Sum of the magnitude of all CPIDs.
139135
double m_two_week_research_subsidy = 0; //!< Sum of research subsidy payments.
136+
137+
//!
138+
//! \brief Round a magnitude unit value to intervals of 0.025.
139+
//!
140+
static double SnapToGrid(double d)
141+
{
142+
double dDither = .04;
143+
double dOut = RoundFromString(RoundToString(d * dDither, 3), 3) / dDither;
144+
return dOut;
145+
}
140146
}; // NetworkTally
141147

142148
//!
@@ -380,7 +386,7 @@ class ResearcherTally
380386
}; // ResearcherTally
381387

382388
ResearcherTally g_researcher_tally; //!< Tracks lifetime research rewards.
383-
NetworkTally g_network_tally; //!< Tracks two-week network averages.
389+
NetworkTally g_network_tally; //!< Tracks legacy two-week network averages.
384390

385391
} // Anonymous namespace
386392

@@ -433,17 +439,17 @@ bool Tally::ActivateSnapshotAccrual(const CBlockIndex* const pindex)
433439
Quorum::CurrentSuperblock());
434440
}
435441

436-
bool Tally::IsTrigger(const uint64_t height)
442+
bool Tally::IsLegacyTrigger(const uint64_t height)
437443
{
438444
return height % TALLY_GRANULARITY == 0;
439445
}
440446

441-
CBlockIndex* Tally::FindTrigger(CBlockIndex* pindex)
447+
CBlockIndex* Tally::FindLegacyTrigger(CBlockIndex* pindex)
442448
{
443449
// Scan backwards until we find one where accepting it would
444450
// trigger a tally.
445451
for (;
446-
pindex && pindex->pprev && !IsTrigger(pindex->nHeight);
452+
pindex && pindex->pprev && !IsLegacyTrigger(pindex->nHeight);
447453
pindex = pindex->pprev);
448454

449455
return pindex;
@@ -582,7 +588,7 @@ void Tally::LegacyRecount(const CBlockIndex* pindex)
582588
LogPrint(LogFlags::TALLY, "Tally::LegacyRecount(%" PRId64 ")", pindex->nHeight);
583589

584590
const int64_t consensus_depth = pindex->nHeight - CONSENSUS_LOOKBACK;
585-
const int64_t lookback_depth = BLOCKS_PER_DAY * TALLY_DAYS;
591+
const int64_t lookback_depth = BLOCKS_PER_DAY * NetworkTally::TALLY_DAYS;
586592

587593
int64_t max_depth = consensus_depth - (consensus_depth % TALLY_GRANULARITY);
588594
int64_t min_depth = max_depth - lookback_depth;

src/neuralnet/tally.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Tally
5656
//!
5757
//! \return \c true if the block height should trigger a recount.
5858
//!
59-
static bool IsTrigger(const uint64_t height);
59+
static bool IsLegacyTrigger(const uint64_t height);
6060

6161
//!
6262
//! \brief Find the previous tally trigger below the specified block.
@@ -65,7 +65,7 @@ class Tally
6565
//!
6666
//! \return Index of the first tally trigger block.
6767
//!
68-
static CBlockIndex* FindTrigger(CBlockIndex* pindex);
68+
static CBlockIndex* FindLegacyTrigger(CBlockIndex* pindex);
6969

7070
//!
7171
//! \brief Get the maximum network-wide research reward amount per day.

0 commit comments

Comments
 (0)