Skip to content

Commit f27114f

Browse files
committed
Refactor applicaton for magnitudes with greater precision
1 parent 4a74978 commit f27114f

File tree

9 files changed

+30
-24
lines changed

9 files changed

+30
-24
lines changed

src/beacon.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int64_t MaxBeaconAge()
7878
int64_t BeaconAgeAdvertiseThreshold()
7979
{
8080
// 5 months in seconds.
81-
return 3600 * 24 * 30 * 5;
81+
return 3600 * 24 * 30 * 5;
8282
}
8383

8484
void GetBeaconElements(const std::string& sBeacon, std::string& out_cpid, std::string& out_address, std::string& out_publickey)
@@ -101,7 +101,7 @@ std::string GetBeaconPublicKey(const std::string& cpid, bool bAdvertisingBeacon)
101101
std::string sBeacon = RetrieveBeaconValueWithMaxAge(cpid, iMaxSeconds);
102102
if (sBeacon.empty())
103103
return "";
104-
104+
105105
// Beacon data structure: CPID,hashRand,Address,beacon public key: base64 encoded
106106
std::string sContract = DecodeBase64(sBeacon);
107107
std::vector<std::string> vContract = split(sContract.c_str(),";");
@@ -244,14 +244,14 @@ bool VerifyBeaconContractTx(const CTransaction& tx)
244244
}
245245

246246
bool ImportBeaconKeysFromConfig(const std::string& cpid, CWallet* wallet)
247-
{
247+
{
248248
if(cpid.empty())
249249
return error("Empty CPID");
250250

251251
std::string strSecret = GetArgument("privatekey" + cpid + (fTestNet ? "testnet" : ""), "");
252252
if(strSecret.empty())
253253
return false;
254-
254+
255255
auto vecsecret = ParseHex(strSecret);
256256

257257
CKey key;
@@ -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));
338+
beacon_status.dPriorSBMagnitude = NN::Tally::GetMagnitude(NN::MiningId::Parse(sCPID)).Floating();
339339
beacon_status.is_mine = (sCPID == NN::GetPrimaryCpid());
340340

341341
return beacon_status;

src/contract/polls.cpp

Lines changed: 1 addition & 1 deletion
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();
102+
double dmag = NN::Tally::MyMagnitude().Floating();
103103
double poll_duration = PollDuration(sTitle) * 86400;
104104

105105
// Prevent Double Voting

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void GetGlobalStatus()
569569

570570
try
571571
{
572-
double boincmagnitude = NN::Tally::MyMagnitude();
572+
double boincmagnitude = NN::Tally::MyMagnitude().Floating();
573573
uint64_t nWeight = 0;
574574
pwalletMain->GetStakeWeight(nWeight);
575575
nBoincUtilization = boincmagnitude; //Legacy Support for the about screen
@@ -2601,7 +2601,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
26012601
{
26022602
// 6-4-2017 - Verify researchers stored block magnitude
26032603
// 2018 02 04 - Moved here for better effect.
2604-
double dNeuralNetworkMagnitude = NN::Tally::GetMagnitude(claim.m_mining_id);
2604+
double dNeuralNetworkMagnitude = NN::Tally::GetMagnitude(claim.m_mining_id).Floating();
26052605
if (claim.m_magnitude > (dNeuralNetworkMagnitude * 1.25)
26062606
&& (fTestNet || (!fTestNet && (pindex->nHeight-1) > 947000)))
26072607
{

src/miner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ bool CreateGridcoinReward(CBlock &blocknew, CBlockIndex* pindexPrev, int64_t &nR
10311031
}
10321032

10331033
if (const NN::CpidOption cpid = claim.m_mining_id.TryCpid()) {
1034-
claim.m_magnitude = NN::Tally::GetMagnitude(*cpid);
1034+
claim.m_magnitude = NN::Tally::GetMagnitude(*cpid).Floating();
10351035
}
10361036

10371037
LogPrintf(

src/neuralnet/tally.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ class ResearcherTally
127127
const Cpid& cpid = account_pair.first;
128128
ResearchAccount& account = account_pair.second;
129129

130-
account.m_magnitude = m_current_superblock->m_cpids.MagnitudeOf(cpid);
130+
// TODO: this only supports legacy magnitudes, but the upcoming
131+
// superblock window accrual changes remove these shenanigans:
132+
//
133+
account.m_magnitude = m_current_superblock->m_cpids.MagnitudeOf(cpid).Compact();
131134
}
132135

133136
return ResearchAccountRange(m_researchers);
@@ -143,7 +146,10 @@ class ResearcherTally
143146
//!
144147
const ResearchAccount& GetAccount(const Cpid cpid)
145148
{
146-
const uint16_t magnitude = m_current_superblock->m_cpids.MagnitudeOf(cpid);
149+
// TODO: this only supports legacy magnitudes, but the upcoming
150+
// superblock window accrual changes remove these shenanigans:
151+
//
152+
const uint16_t magnitude = m_current_superblock->m_cpids.MagnitudeOf(cpid).Compact();
147153
auto iter = m_researchers.find(cpid);
148154

149155
if (iter == m_researchers.end()) {
@@ -299,13 +305,13 @@ double Tally::GetMagnitudeUnit(const int64_t payment_time)
299305
return g_network_tally.GetMagnitudeUnit(payment_time);
300306
}
301307

302-
uint16_t Tally::MyMagnitude()
308+
Magnitude Tally::MyMagnitude()
303309
{
304310
if (const auto cpid_option = NN::Researcher::Get()->Id().TryCpid()) {
305311
return Quorum::CurrentSuperblock()->m_cpids.MagnitudeOf(*cpid_option);
306312
}
307313

308-
return 0;
314+
return Magnitude::Zero();
309315
}
310316

311317
ResearchAccountRange Tally::Accounts()
@@ -341,18 +347,18 @@ AccrualComputer Tally::GetComputer(
341347
last_block_ptr->nHeight);
342348
}
343349

344-
uint16_t Tally::GetMagnitude(const Cpid cpid)
350+
Magnitude Tally::GetMagnitude(const Cpid cpid)
345351
{
346352
return Quorum::CurrentSuperblock()->m_cpids.MagnitudeOf(cpid);
347353
}
348354

349-
uint16_t Tally::GetMagnitude(const MiningId mining_id)
355+
Magnitude Tally::GetMagnitude(const MiningId mining_id)
350356
{
351357
if (const auto cpid_option = mining_id.TryCpid()) {
352358
return GetMagnitude(*cpid_option);
353359
}
354360

355-
return 0;
361+
return Magnitude::Zero();
356362
}
357363

358364
void Tally::RecordRewardBlock(const CBlockIndex* const pindex)

src/neuralnet/tally.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Tally
6666
//! \return The wallet user's magnitude or zero if the wallet started in
6767
//! investor mode.
6868
//!
69-
static uint16_t MyMagnitude();
69+
static Magnitude MyMagnitude();
7070

7171
//!
7272
//! \brief Get a traversable object for the research accounts stored in
@@ -107,7 +107,7 @@ class Tally
107107
//!
108108
//! \return Magnitude as of the last tallied superblock.
109109
//!
110-
static uint16_t GetMagnitude(const Cpid cpid);
110+
static Magnitude GetMagnitude(const Cpid cpid);
111111

112112
//!
113113
//! \brief Get the current magnitude for the specified mining ID.
@@ -117,7 +117,7 @@ class Tally
117117
//! \return Magnitude as of the last tallied superblock or zero if the
118118
//! mining ID represents an investor.
119119
//!
120-
static uint16_t GetMagnitude(const MiningId mining_id);
120+
static Magnitude GetMagnitude(const MiningId mining_id);
121121

122122
//!
123123
//! \brief Record a block's research reward data in the tally.

src/rpcblockchain.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ UniValue SuperblockToJson(const NN::Superblock& superblock)
8484
{
8585
UniValue magnitudes(UniValue::VOBJ);
8686

87-
for (const auto& cpid_pair : superblock.m_cpids) {
88-
magnitudes.pushKV(cpid_pair.first.ToString(), cpid_pair.second);
87+
for (const auto& cpid_iter : superblock.m_cpids) {
88+
magnitudes.pushKV(cpid_iter.Cpid().ToString(), cpid_iter.Magnitude().Floating());
8989
}
9090

9191
UniValue projects(UniValue::VOBJ);
@@ -1897,7 +1897,7 @@ UniValue SuperblockReport(int lookback, bool displaycontract, std::string cpid)
18971897

18981898
if (cpid_parsed)
18991899
{
1900-
c.pushKV("Magnitude", superblock.m_cpids.MagnitudeOf(*cpid_parsed));
1900+
c.pushKV("Magnitude", superblock.m_cpids.MagnitudeOf(*cpid_parsed).Floating());
19011901
}
19021902

19031903
if (displaycontract)

src/scraper/scraper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int64_t SCRAPER_CMANIFEST_RETENTION_TIME = 48 * 3600;
7070
bool SCRAPER_CMANIFEST_INCLUDE_NONCURRENT_PROJ_FILES = false;
7171
double MAG_ROUND = 0.01;
7272
double NEURALNETWORKMULTIPLIER = 115000;
73-
double CPID_MAG_LIMIT = 32767;
73+
double CPID_MAG_LIMIT = NN::Magnitude::MAX;
7474
// This settings below are important. This sets the minimum number of scrapers
7575
// that must be available to form a convergence. Above this minimum, the ratio
7676
// is followed. For example, if there are 4 scrapers, a ratio of 0.6 would require

src/test/neuralnet/claim_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ NN::Superblock GetTestSuperblock(uint32_t version = NN::Superblock::CURRENT_VERS
6161
NN::Superblock superblock;
6262

6363
superblock.m_version = version;
64-
superblock.m_cpids.Add(NN::Cpid(), 123);
64+
superblock.m_cpids.Add(NN::Cpid(), NN::Magnitude::RoundFrom(123));
6565
superblock.m_projects.Add("project", NN::Superblock::ProjectStats());
6666

6767
return superblock;

0 commit comments

Comments
 (0)