Skip to content

Commit 400b7e3

Browse files
committed
Move GetMagnitude() methods from Tally to Quorum
After adding the Quorum API, these methods just pull from data stored in the Quorum classes so this is a more appropriate location for the code.
1 parent 3aa4279 commit 400b7e3

File tree

9 files changed

+60
-58
lines changed

9 files changed

+60
-58
lines changed

src/beacon.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "contract/contract.h"
1010
#include "key.h"
1111
#include "neuralnet/researcher.h"
12-
#include "neuralnet/tally.h"
12+
#include "neuralnet/quorum.h"
1313

1414
std::string RetrieveBeaconValueWithMaxAge(const std::string& cpid, int64_t iMaxSeconds);
1515
std::string ExtractXML(const std::string& XMLdata, const std::string& key, const std::string& key_end);
@@ -335,7 +335,7 @@ BeaconStatus GetBeaconStatus(std::string& sCPID)
335335
beacon_status.iBeaconTimestamp = BeaconTimeStamp(sCPID);
336336
beacon_status.timestamp = TimestampToHRDate(beacon_status.iBeaconTimestamp);
337337
beacon_status.hasBeacon = HasActiveBeacon(sCPID);
338-
beacon_status.dPriorSBMagnitude = NN::Tally::GetMagnitude(NN::MiningId::Parse(sCPID)).Floating();
338+
beacon_status.dPriorSBMagnitude = NN::Quorum::GetMagnitude(NN::MiningId::Parse(sCPID)).Floating();
339339
beacon_status.is_mine = (sCPID == NN::GetPrimaryCpid());
340340

341341
return beacon_status;

src/contract/polls.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ std::pair<std::string, std::string> CreateVoteContract(std::string sTitle, std::
9999
const std::string primary_cpid = NN::GetPrimaryCpid();
100100

101101
std::string GRCAddress = DefaultWalletAddress();
102-
double dmag = NN::Tally::MyMagnitude().Floating();
102+
double dmag = NN::Quorum::MyMagnitude().Floating();
103103
double poll_duration = PollDuration(sTitle) * 86400;
104104

105105
// Prevent Double Voting

src/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void GetGlobalStatus()
570570

571571
try
572572
{
573-
double boincmagnitude = NN::Tally::MyMagnitude().Floating();
573+
double boincmagnitude = NN::Quorum::MyMagnitude().Floating();
574574
uint64_t nWeight = 0;
575575
pwalletMain->GetStakeWeight(nWeight);
576576
nBoincUtilization = boincmagnitude; //Legacy Support for the about screen
@@ -2623,7 +2623,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
26232623
{
26242624
// 6-4-2017 - Verify researchers stored block magnitude
26252625
// 2018 02 04 - Moved here for better effect.
2626-
double dNeuralNetworkMagnitude = NN::Tally::GetMagnitude(claim.m_mining_id).Floating();
2626+
double dNeuralNetworkMagnitude = NN::Quorum::GetMagnitude(claim.m_mining_id).Floating();
26272627
if (claim.m_magnitude > (dNeuralNetworkMagnitude * 1.25)
26282628
&& (fTestNet || (!fTestNet && (pindex->nHeight-1) > 947000)))
26292629
{

src/miner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ bool CreateGridcoinReward(CBlock &blocknew, CBlockIndex* pindexPrev, int64_t &nR
10601060
}
10611061

10621062
if (const NN::CpidOption cpid = claim.m_mining_id.TryCpid()) {
1063-
claim.m_magnitude = NN::Tally::GetMagnitude(*cpid).Floating();
1063+
claim.m_magnitude = NN::Quorum::GetMagnitude(*cpid).Floating();
10641064
}
10651065

10661066
LogPrintf(

src/neuralnet/quorum.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "base58.h"
22
#include "main.h"
33
#include "neuralnet/claim.h"
4+
#include "neuralnet/magnitude.h"
45
#include "neuralnet/quorum.h"
6+
#include "neuralnet/researcher.h"
57
#include "neuralnet/superblock.h"
68
#include "scraper_net.h"
79
#include "util/reverse_iterator.h"
@@ -1537,6 +1539,29 @@ bool Quorum::ValidateSuperblock(
15371539
return result != Result::INVALID;
15381540
}
15391541

1542+
Magnitude Quorum::MyMagnitude()
1543+
{
1544+
if (const auto cpid_option = NN::Researcher::Get()->Id().TryCpid()) {
1545+
return Quorum::CurrentSuperblock()->m_cpids.MagnitudeOf(*cpid_option);
1546+
}
1547+
1548+
return Magnitude::Zero();
1549+
}
1550+
1551+
Magnitude Quorum::GetMagnitude(const Cpid cpid)
1552+
{
1553+
return Quorum::CurrentSuperblock()->m_cpids.MagnitudeOf(cpid);
1554+
}
1555+
1556+
Magnitude Quorum::GetMagnitude(const MiningId mining_id)
1557+
{
1558+
if (const auto cpid_option = mining_id.TryCpid()) {
1559+
return GetMagnitude(*cpid_option);
1560+
}
1561+
1562+
return Magnitude::Zero();
1563+
}
1564+
15401565
SuperblockPtr Quorum::CurrentSuperblock()
15411566
{
15421567
return g_superblock_index.Current();

src/neuralnet/quorum.h

+28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class CBlockIndex;
88
namespace NN {
99

1010
class Claim;
11+
class Magnitude;
1112
class QuorumHash;
1213
class Superblock;
1314

@@ -195,6 +196,33 @@ class Quorum
195196
const bool use_cache = true,
196197
const size_t hint_bits = 32);
197198

199+
//!
200+
//! \brief Get the current magnitude of the CPID loaded by the wallet.
201+
//!
202+
//! \return The wallet user's magnitude or zero if the wallet started in
203+
//! investor mode.
204+
//!
205+
static Magnitude MyMagnitude();
206+
207+
//!
208+
//! \brief Get the current magnitude for the specified CPID.
209+
//!
210+
//! \param cpid The CPID to fetch the magnitude for.
211+
//!
212+
//! \return Magnitude as of the last tallied superblock.
213+
//!
214+
static Magnitude GetMagnitude(const Cpid cpid);
215+
216+
//!
217+
//! \brief Get the current magnitude for the specified mining ID.
218+
//!
219+
//! \param cpid May contain a CPID to fetch the magnitude for.
220+
//!
221+
//! \return Magnitude as of the last tallied superblock or zero if the
222+
//! mining ID represents an investor.
223+
//!
224+
static Magnitude GetMagnitude(const MiningId mining_id);
225+
198226
//!
199227
//! \brief Get a reference to the current active superblock.
200228
//!

src/neuralnet/tally.cpp

-24
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "neuralnet/accrual/research_age.h"
55
#include "neuralnet/cpid.h"
66
#include "neuralnet/quorum.h"
7-
#include "neuralnet/researcher.h"
87
#include "neuralnet/tally.h"
98
#include "util.h"
109

@@ -305,15 +304,6 @@ double Tally::GetMagnitudeUnit(const int64_t payment_time)
305304
return g_network_tally.GetMagnitudeUnit(payment_time);
306305
}
307306

308-
Magnitude Tally::MyMagnitude()
309-
{
310-
if (const auto cpid_option = NN::Researcher::Get()->Id().TryCpid()) {
311-
return Quorum::CurrentSuperblock()->m_cpids.MagnitudeOf(*cpid_option);
312-
}
313-
314-
return Magnitude::Zero();
315-
}
316-
317307
ResearchAccountRange Tally::Accounts()
318308
{
319309
return g_researcher_tally.Accounts();
@@ -347,20 +337,6 @@ AccrualComputer Tally::GetComputer(
347337
last_block_ptr->nHeight);
348338
}
349339

350-
Magnitude Tally::GetMagnitude(const Cpid cpid)
351-
{
352-
return Quorum::CurrentSuperblock()->m_cpids.MagnitudeOf(cpid);
353-
}
354-
355-
Magnitude Tally::GetMagnitude(const MiningId mining_id)
356-
{
357-
if (const auto cpid_option = mining_id.TryCpid()) {
358-
return GetMagnitude(*cpid_option);
359-
}
360-
361-
return Magnitude::Zero();
362-
}
363-
364340
void Tally::RecordRewardBlock(const CBlockIndex* const pindex)
365341
{
366342
if (!pindex || pindex->nResearchSubsidy <= 0) {

src/neuralnet/tally.h

-27
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ class Tally
6060
//!
6161
static double GetMagnitudeUnit(const int64_t payment_time);
6262

63-
//!
64-
//! \brief Get the current magnitude of the CPID loaded by the wallet.
65-
//!
66-
//! \return The wallet user's magnitude or zero if the wallet started in
67-
//! investor mode.
68-
//!
69-
static Magnitude MyMagnitude();
70-
7163
//!
7264
//! \brief Get a traversable object for the research accounts stored in
7365
//! the tally.
@@ -100,25 +92,6 @@ class Tally
10092
const int64_t payment_time,
10193
const CBlockIndex* const last_block_ptr);
10294

103-
//!
104-
//! \brief Get the current magnitude for the specified CPID.
105-
//!
106-
//! \param cpid The CPID to fetch the magnitude for.
107-
//!
108-
//! \return Magnitude as of the last tallied superblock.
109-
//!
110-
static Magnitude GetMagnitude(const Cpid cpid);
111-
112-
//!
113-
//! \brief Get the current magnitude for the specified mining ID.
114-
//!
115-
//! \param cpid May contain a CPID to fetch the magnitude for.
116-
//!
117-
//! \return Magnitude as of the last tallied superblock or zero if the
118-
//! mining ID represents an investor.
119-
//!
120-
static Magnitude GetMagnitude(const MiningId mining_id);
121-
12295
//!
12396
//! \brief Record a block's research reward data in the tally.
12497
//!

src/rpcblockchain.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,7 @@ UniValue MagnitudeReport(const NN::Cpid cpid)
19241924
const NN::AccrualComputer calc = NN::Tally::GetComputer(cpid, now, pindexBest);
19251925

19261926
json.pushKV("CPID", cpid.ToString());
1927-
json.pushKV("Magnitude (Last Superblock)", account.m_magnitude);
1927+
json.pushKV("Magnitude (Last Superblock)", NN::Quorum::GetMagnitude(cpid).Floating());
19281928
json.pushKV("Current Magnitude Unit", calc->MagnitudeUnit());
19291929

19301930
json.pushKV("First Payment Time", TimestampToHRDate(account.FirstRewardTime()));

0 commit comments

Comments
 (0)