Skip to content

Commit 4910488

Browse files
authored
Merge pull request #1583 from cyrossignol/tally
Overhaul the core tally and accrual system
2 parents 7d39b3b + 8ef8990 commit 4910488

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2138
-2067
lines changed

gridcoinresearch.pro

-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ HEADERS += src/qt/bitcoingui.h \
259259
src/qt/diagnosticsdialog.h \
260260
src/backup.h \
261261
src/appcache.h \
262-
src/tally.h \
263262
src/grcrestarter.h \
264263
src/neuralnet.h \
265264
src/qt/clicklabel.h
@@ -342,7 +341,6 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
342341
src/allocators.cpp \
343342
src/backup.cpp \
344343
src/appcache.cpp \
345-
src/tally.cpp \
346344
src/grcrestarter.cpp \
347345
src/neuralnet.cpp \
348346
src/qt/clicklabel.cpp

src/Makefile.am

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ GRIDCOIN_CORE_H = \
100100
neuralnet/project.h \
101101
neuralnet/researcher.h \
102102
neuralnet/superblock.h \
103+
neuralnet/tally.h \
103104
netbase.h \
104105
net.h \
105106
pbkdf2.h \
@@ -125,7 +126,6 @@ GRIDCOIN_CORE_H = \
125126
support/cleanse.h \
126127
support/lockedpool.h \
127128
sync.h \
128-
tally.h \
129129
threadsafety.h \
130130
tinyformat.h \
131131
txdb.h \
@@ -171,6 +171,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
171171
neuralnet/project.cpp \
172172
neuralnet/researcher.cpp \
173173
neuralnet/superblock.cpp \
174+
neuralnet/tally.cpp \
174175
netbase.cpp \
175176
net.cpp \
176177
noui.cpp \
@@ -199,7 +200,6 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
199200
support/cleanse.cpp \
200201
support/lockedpool.cpp \
201202
sync.cpp \
202-
tally.cpp \
203203
txdb-leveldb.cpp \
204204
uint256.cpp \
205205
util/strencodings.cpp \

src/appcache.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace
1717
{
1818
{ "beacon", Section::BEACON },
1919
{ "beaconalt", Section::BEACONALT },
20-
{ "superblock", Section::SUPERBLOCK },
2120
{ "global", Section::GLOBAL },
2221
{ "protocol", Section::PROTOCOL },
2322
{ "neuralsecurity", Section::NEURALSECURITY },

src/appcache.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ enum class Section
88
{
99
BEACON,
1010
BEACONALT,
11-
SUPERBLOCK,
1211
GLOBAL,
1312
PROTOCOL,
1413
NEURALSECURITY,

src/beacon.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -131,30 +131,14 @@ std::set<std::string> GetAlternativeBeaconKeys(const std::string& cpid)
131131
return result;
132132
}
133133

134-
int64_t BeaconTimeStamp(const std::string& cpid, bool bZeroOutAfterPOR)
134+
int64_t BeaconTimeStamp(const std::string& cpid)
135135
{
136136
if (!IsResearcher(cpid)) {
137137
return 0;
138138
}
139139

140140
AssertLockHeld(cs_main);
141141

142-
const StructCPID& stMagnitude = GetInitializedStructCPID2(cpid, mvMagnitudes);
143-
const StructCPID& stLifetime = GetInitializedStructCPID2(cpid, mvResearchAge);
144-
145-
// New rules - 12-4-2015 - Pay newbie from the moment beacon was sent as
146-
// long as it is within 6 months old and NN mag > 0 and newbie is in the
147-
// superblock and their lifetime paid is zero.
148-
//
149-
// Note: If Magnitude is zero, or the researcher is not in a superblock,
150-
// or lifetimepaid > 0, this function returns zero:
151-
//
152-
if (bZeroOutAfterPOR
153-
&& (stMagnitude.Magnitude <= 0 || stLifetime.ResearchSubsidy != 0))
154-
{
155-
return 0;
156-
}
157-
158142
const AppCacheEntry& entry = ReadCache(Section::BEACON, cpid);
159143

160144
if (fDebug10) {

src/beacon.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int64_t BeaconAgeAdvertiseThreshold();
7171
void GetBeaconElements(const std::string& sBeacon, std::string& out_cpid, std::string& out_address, std::string& out_publickey);
7272
std::string GetBeaconPublicKey(const std::string& cpid, bool bAdvertisingBeacon);
7373
std::set<std::string> GetAlternativeBeaconKeys(const std::string& cpid);
74-
int64_t BeaconTimeStamp(const std::string& cpid, bool bZeroOutAfterPOR);
74+
int64_t BeaconTimeStamp(const std::string& cpid);
7575
bool HasActiveBeacon(const std::string& cpid);
7676

7777
bool VerifyBeaconContractTx(const CTransaction& tx);

src/contract/polls.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
#include "appcache.h"
1010
#include "init.h" // for pwalletMain
1111
#include "block.h"
12+
#include "neuralnet/tally.h"
1213

1314
double GetTotalBalance();
1415
std::string TimestampToHRDate(double dtm);
1516
double CoinToDouble(double surrogate);
1617
double DoubleFromAmount(int64_t amount);
1718
std::string PubKeyToAddress(const CScript& scriptPubKey);
1819
bool GetEarliestStakeTime(std::string grcaddress, std::string cpid);
19-
CBlockIndex* GetHistoricalMagnitude(std::string cpid);
20+
const CBlockIndex* GetHistoricalMagnitude(const NN::MiningId mining_id);
2021
bool WalletOutOfSync();
2122

2223
namespace NN { std::string GetPrimaryCpid(); }
@@ -97,8 +98,7 @@ std::pair<std::string, std::string> CreateVoteContract(std::string sTitle, std::
9798
const std::string primary_cpid = NN::GetPrimaryCpid();
9899

99100
std::string GRCAddress = DefaultWalletAddress();
100-
StructCPID& structMag = GetInitializedStructCPID2(primary_cpid, mvMagnitudes);
101-
double dmag = structMag.Magnitude;
101+
double dmag = NN::Tally::MyMagnitude();
102102
double poll_duration = PollDuration(sTitle) * 86400;
103103

104104
// Prevent Double Voting
@@ -293,8 +293,7 @@ std::string GetProvableVotingWeightXML()
293293
//Retrieve the historical magnitude
294294
if (IsResearcher(primary_cpid))
295295
{
296-
GetLifetimeCPID(primary_cpid); // Rescan...
297-
CBlockIndex* pHistorical = GetHistoricalMagnitude(primary_cpid);
296+
const CBlockIndex* pHistorical = GetHistoricalMagnitude(NN::MiningId::Parse(primary_cpid));
298297
if (pHistorical->nHeight > 1 && pHistorical->nMagnitude > 0)
299298
{
300299
std::string sBlockhash = pHistorical->GetBlockHash().GetHex();
@@ -462,10 +461,9 @@ double ReturnVerifiedVotingMagnitude(std::string sXML, bool bCreatedAfterSecurit
462461

463462
double GetMoneySupplyFactor()
464463
{
465-
StructCPID structcpid = mvNetwork["NETWORK"];
466-
double TotalCPIDS = mvMagnitudes.size();
467-
double AvgMagnitude = structcpid.NetworkAvgMagnitude;
468-
double TotalNetworkMagnitude = TotalCPIDS*AvgMagnitude;
464+
const NN::NetworkStats stats = NN::Tally::GetNetworkStats();
465+
466+
double TotalNetworkMagnitude = stats.m_total_cpids * stats.m_average_magnitude;
469467
if (TotalNetworkMagnitude < 100) TotalNetworkMagnitude=100;
470468
double MoneySupply = DoubleFromAmount(pindexBest->nMoneySupply);
471469
double Factor = (MoneySupply/TotalNetworkMagnitude+.01);

src/fwd.h

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class CNetAddr;
99
class CTransaction;
1010
class CWallet;
1111

12-
// Gridcoin
13-
struct StructCPID;
14-
1512
class ThreadHandler;
1613
typedef std::shared_ptr<ThreadHandler> ThreadHandlerPtr;
1714

src/global_objects_noui.hpp

-28
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,10 @@
88

99
extern int nBoincUtilization;
1010
extern std::string sRegVer;
11-
extern bool bNetAveragesLoaded;
1211
extern bool bForceUpdate;
1312
extern bool fQtActive;
1413
extern bool bGridcoinGUILoaded;
1514

16-
struct StructCPID
17-
{
18-
bool initialized;
19-
20-
double Magnitude;
21-
double payments;
22-
double TotalMagnitude;
23-
uint32_t LowLockTime;
24-
double Accuracy;
25-
double ResearchSubsidy;
26-
/* double ResearchAverageMagnitude; TotalMagnitude / (Accuracy+0.01) */
27-
double EarliestPaymentTime;
28-
double InterestSubsidy;
29-
int32_t LastBlock;
30-
double NetworkMagnitude;
31-
double NetworkAvgMagnitude;
32-
std::string cpid;
33-
std::string BlockHash;
34-
std::set<const CBlockIndex*> rewardBlocks;
35-
};
36-
37-
//Network Averages
38-
extern std::map<std::string, StructCPID> mvNetwork;
39-
extern std::map<std::string, StructCPID> mvNetworkCopy;
40-
extern std::map<std::string, StructCPID> mvMagnitudes;
41-
extern std::map<std::string, StructCPID> mvMagnitudesCopy;
42-
4315
// Timers
4416
extern std::map<std::string, int> mvTimers; // Contains event timers that reset after max ms duration iterator is exceeded
4517

src/gridcoin.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ namespace
2929
uint256S("d5441f7c35eb9ea1b786bbbed820b7f327504301ae70ef2ac3ca3cbc7106236b"), //T479114
3030
uint256S("18e2ed822c4c5686c0189f60ffbe828fa51e90873cc1ed3e534a257d2f09c360"), //T479282
3131
uint256S("7cb49bc17ecdb7b3a56e1290496d4866330fc9c7974c65b2034e1c6b951ea0fe"), //T511839
32+
uint256S("ef0276ace2209c836a84d16e0ce787358a8a1d3da1a8795b6e7697f5c7a26c45"), //T539246 (block span)
33+
uint256S("66a809c99fd224a9631d38c326c69e8c7e1507ad1a997117a7dd1e7780764d6c"), //T578074 (block span)
34+
uint256S("8f4f6c5cb17fda158229a627d18d5cff30621e3612f464526f6f356e7a699838"), //T578162 (block span)
3235
uint256S("c1aa0511add3bed3f2e366d38b954285a7602cae10a7244e7fe35e4002e90cd5"), //T629408
3336
uint256S("639756cf39bf12a4a0ab4ea5ec10938fd0f463cc7bc1bd2916529a445ceba2ab"), //T680406
3437
};
38+
39+
3540
}
3641

37-
std::set<uint256> GetBadBlocks()
42+
const std::set<uint256>& GetBadBlocks()
3843
{
3944
return fTestNet
4045
? bad_blocks_testnet

src/gridcoin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
//!
1313
//! \return A list of currently known bad blocks.
1414
//!
15-
std::set<uint256> GetBadBlocks();
15+
const std::set<uint256>& GetBadBlocks();

src/init.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include "rpcserver.h"
1313
#include "init.h"
1414
#include "ui_interface.h"
15-
#include "tally.h"
1615
#include "beacon.h"
1716
#include "scheduler.h"
1817
#include "neuralnet/neuralnet.h"
1918
#include "neuralnet/researcher.h"
19+
#include "neuralnet/tally.h"
2020

2121
#include <boost/filesystem.hpp>
2222
#include <boost/filesystem/fstream.hpp>
@@ -34,7 +34,6 @@ bool LoadAdminMessages(bool bFullTableScan,std::string& out_errors);
3434
static boost::thread_group threadGroup;
3535
static CScheduler scheduler;
3636

37-
void TallyResearchAverages(CBlockIndex* index);
3837
extern void ThreadAppInit2(void* parg);
3938

4039
bool IsConfigFileEmpty();
@@ -816,6 +815,12 @@ bool AppInit2(ThreadHandlerPtr threads)
816815
}
817816
LogPrintf(" block index %15" PRId64 "ms", GetTimeMillis() - nStart);
818817

818+
if (IsV9Enabled(pindexBest->nHeight)) {
819+
uiInterface.InitMessage(_("Loading superblock cache..."));
820+
LogPrintf("Loading superblock cache...");
821+
NN::Tally::LoadSuperblockIndex(pindexBest);
822+
}
823+
819824
if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
820825
{
821826
PrintBlockTree();
@@ -1011,9 +1016,7 @@ bool AppInit2(ThreadHandlerPtr threads)
10111016
uiInterface.InitMessage(_("Loading Network Averages..."));
10121017
if (fDebug3) LogPrintf("Loading network averages");
10131018

1014-
CBlockIndex* tallyHeight = FindTallyTrigger(pindexBest);
1015-
if(tallyHeight)
1016-
TallyResearchAverages(tallyHeight);
1019+
NN::Tally::LegacyRecount(NN::Tally::FindTrigger(pindexBest));
10171020

10181021
if (!threads->createThread(StartNode, NULL, "Start Thread"))
10191022
InitError(_("Error: could not start node"));

src/kernel.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
using namespace std;
1414

15-
StructCPID GetStructCPID();
16-
1715
namespace {
1816
//!
1917
//! \brief Calculate a legacy RSA weight value from the supplied claim block.

0 commit comments

Comments
 (0)