Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul the core tally and accrual system #1583

Merged
merged 17 commits into from
Nov 3, 2019
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
2 changes: 0 additions & 2 deletions gridcoinresearch.pro
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ HEADERS += src/qt/bitcoingui.h \
src/qt/diagnosticsdialog.h \
src/backup.h \
src/appcache.h \
src/tally.h \
src/grcrestarter.h \
src/neuralnet.h \
src/qt/clicklabel.h
Expand Down Expand Up @@ -342,7 +341,6 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
src/allocators.cpp \
src/backup.cpp \
src/appcache.cpp \
src/tally.cpp \
src/grcrestarter.cpp \
src/neuralnet.cpp \
src/qt/clicklabel.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ GRIDCOIN_CORE_H = \
neuralnet/project.h \
neuralnet/researcher.h \
neuralnet/superblock.h \
neuralnet/tally.h \
netbase.h \
net.h \
pbkdf2.h \
Expand All @@ -125,7 +126,6 @@ GRIDCOIN_CORE_H = \
support/cleanse.h \
support/lockedpool.h \
sync.h \
tally.h \
threadsafety.h \
tinyformat.h \
txdb.h \
Expand Down Expand Up @@ -171,6 +171,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
neuralnet/project.cpp \
neuralnet/researcher.cpp \
neuralnet/superblock.cpp \
neuralnet/tally.cpp \
netbase.cpp \
net.cpp \
noui.cpp \
Expand Down Expand Up @@ -199,7 +200,6 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
support/cleanse.cpp \
support/lockedpool.cpp \
sync.cpp \
tally.cpp \
txdb-leveldb.cpp \
uint256.cpp \
util/strencodings.cpp \
Expand Down
1 change: 0 additions & 1 deletion src/appcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace
{
{ "beacon", Section::BEACON },
{ "beaconalt", Section::BEACONALT },
{ "superblock", Section::SUPERBLOCK },
{ "global", Section::GLOBAL },
{ "protocol", Section::PROTOCOL },
{ "neuralsecurity", Section::NEURALSECURITY },
Expand Down
1 change: 0 additions & 1 deletion src/appcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ enum class Section
{
BEACON,
BEACONALT,
SUPERBLOCK,
GLOBAL,
PROTOCOL,
NEURALSECURITY,
Expand Down
18 changes: 1 addition & 17 deletions src/beacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,14 @@ std::set<std::string> GetAlternativeBeaconKeys(const std::string& cpid)
return result;
}

int64_t BeaconTimeStamp(const std::string& cpid, bool bZeroOutAfterPOR)
int64_t BeaconTimeStamp(const std::string& cpid)
{
if (!IsResearcher(cpid)) {
return 0;
}

AssertLockHeld(cs_main);

const StructCPID& stMagnitude = GetInitializedStructCPID2(cpid, mvMagnitudes);
const StructCPID& stLifetime = GetInitializedStructCPID2(cpid, mvResearchAge);

// New rules - 12-4-2015 - Pay newbie from the moment beacon was sent as
// long as it is within 6 months old and NN mag > 0 and newbie is in the
// superblock and their lifetime paid is zero.
//
// Note: If Magnitude is zero, or the researcher is not in a superblock,
// or lifetimepaid > 0, this function returns zero:
//
if (bZeroOutAfterPOR
&& (stMagnitude.Magnitude <= 0 || stLifetime.ResearchSubsidy != 0))
{
return 0;
}

const AppCacheEntry& entry = ReadCache(Section::BEACON, cpid);

if (fDebug10) {
Expand Down
2 changes: 1 addition & 1 deletion src/beacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int64_t BeaconAgeAdvertiseThreshold();
void GetBeaconElements(const std::string& sBeacon, std::string& out_cpid, std::string& out_address, std::string& out_publickey);
std::string GetBeaconPublicKey(const std::string& cpid, bool bAdvertisingBeacon);
std::set<std::string> GetAlternativeBeaconKeys(const std::string& cpid);
int64_t BeaconTimeStamp(const std::string& cpid, bool bZeroOutAfterPOR);
int64_t BeaconTimeStamp(const std::string& cpid);
bool HasActiveBeacon(const std::string& cpid);

bool VerifyBeaconContractTx(const CTransaction& tx);
Expand Down
16 changes: 7 additions & 9 deletions src/contract/polls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
#include "appcache.h"
#include "init.h" // for pwalletMain
#include "block.h"
#include "neuralnet/tally.h"

double GetTotalBalance();
std::string TimestampToHRDate(double dtm);
double CoinToDouble(double surrogate);
double DoubleFromAmount(int64_t amount);
std::string PubKeyToAddress(const CScript& scriptPubKey);
bool GetEarliestStakeTime(std::string grcaddress, std::string cpid);
CBlockIndex* GetHistoricalMagnitude(std::string cpid);
const CBlockIndex* GetHistoricalMagnitude(const NN::MiningId mining_id);
bool WalletOutOfSync();

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

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

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

double GetMoneySupplyFactor()
{
StructCPID structcpid = mvNetwork["NETWORK"];
double TotalCPIDS = mvMagnitudes.size();
double AvgMagnitude = structcpid.NetworkAvgMagnitude;
double TotalNetworkMagnitude = TotalCPIDS*AvgMagnitude;
const NN::NetworkStats stats = NN::Tally::GetNetworkStats();

double TotalNetworkMagnitude = stats.m_total_cpids * stats.m_average_magnitude;
if (TotalNetworkMagnitude < 100) TotalNetworkMagnitude=100;
double MoneySupply = DoubleFromAmount(pindexBest->nMoneySupply);
double Factor = (MoneySupply/TotalNetworkMagnitude+.01);
Expand Down
3 changes: 0 additions & 3 deletions src/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class CNetAddr;
class CTransaction;
class CWallet;

// Gridcoin
struct StructCPID;

class ThreadHandler;
typedef std::shared_ptr<ThreadHandler> ThreadHandlerPtr;

Expand Down
28 changes: 0 additions & 28 deletions src/global_objects_noui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,10 @@

extern int nBoincUtilization;
extern std::string sRegVer;
extern bool bNetAveragesLoaded;
extern bool bForceUpdate;
extern bool fQtActive;
extern bool bGridcoinGUILoaded;

struct StructCPID
{
bool initialized;

double Magnitude;
double payments;
double TotalMagnitude;
uint32_t LowLockTime;
double Accuracy;
double ResearchSubsidy;
/* double ResearchAverageMagnitude; TotalMagnitude / (Accuracy+0.01) */
double EarliestPaymentTime;
double InterestSubsidy;
int32_t LastBlock;
double NetworkMagnitude;
double NetworkAvgMagnitude;
std::string cpid;
std::string BlockHash;
std::set<const CBlockIndex*> rewardBlocks;
};

//Network Averages
extern std::map<std::string, StructCPID> mvNetwork;
extern std::map<std::string, StructCPID> mvNetworkCopy;
extern std::map<std::string, StructCPID> mvMagnitudes;
extern std::map<std::string, StructCPID> mvMagnitudesCopy;

// Timers
extern std::map<std::string, int> mvTimers; // Contains event timers that reset after max ms duration iterator is exceeded

Expand Down
7 changes: 6 additions & 1 deletion src/gridcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ namespace
uint256S("d5441f7c35eb9ea1b786bbbed820b7f327504301ae70ef2ac3ca3cbc7106236b"), //T479114
uint256S("18e2ed822c4c5686c0189f60ffbe828fa51e90873cc1ed3e534a257d2f09c360"), //T479282
uint256S("7cb49bc17ecdb7b3a56e1290496d4866330fc9c7974c65b2034e1c6b951ea0fe"), //T511839
uint256S("ef0276ace2209c836a84d16e0ce787358a8a1d3da1a8795b6e7697f5c7a26c45"), //T539246 (block span)
jamescowens marked this conversation as resolved.
Show resolved Hide resolved
uint256S("66a809c99fd224a9631d38c326c69e8c7e1507ad1a997117a7dd1e7780764d6c"), //T578074 (block span)
uint256S("8f4f6c5cb17fda158229a627d18d5cff30621e3612f464526f6f356e7a699838"), //T578162 (block span)
uint256S("c1aa0511add3bed3f2e366d38b954285a7602cae10a7244e7fe35e4002e90cd5"), //T629408
uint256S("639756cf39bf12a4a0ab4ea5ec10938fd0f463cc7bc1bd2916529a445ceba2ab"), //T680406
};


}

std::set<uint256> GetBadBlocks()
const std::set<uint256>& GetBadBlocks()
{
return fTestNet
? bad_blocks_testnet
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
//!
//! \return A list of currently known bad blocks.
//!
std::set<uint256> GetBadBlocks();
const std::set<uint256>& GetBadBlocks();
13 changes: 8 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#include "rpcserver.h"
#include "init.h"
#include "ui_interface.h"
#include "tally.h"
#include "beacon.h"
#include "scheduler.h"
#include "neuralnet/neuralnet.h"
#include "neuralnet/researcher.h"
#include "neuralnet/tally.h"

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

void TallyResearchAverages(CBlockIndex* index);
extern void ThreadAppInit2(void* parg);

bool IsConfigFileEmpty();
Expand Down Expand Up @@ -816,6 +815,12 @@ bool AppInit2(ThreadHandlerPtr threads)
}
LogPrintf(" block index %15" PRId64 "ms", GetTimeMillis() - nStart);

if (IsV9Enabled(pindexBest->nHeight)) {
uiInterface.InitMessage(_("Loading superblock cache..."));
LogPrintf("Loading superblock cache...");
NN::Tally::LoadSuperblockIndex(pindexBest);
}

if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))
{
PrintBlockTree();
Expand Down Expand Up @@ -1011,9 +1016,7 @@ bool AppInit2(ThreadHandlerPtr threads)
uiInterface.InitMessage(_("Loading Network Averages..."));
if (fDebug3) LogPrintf("Loading network averages");

CBlockIndex* tallyHeight = FindTallyTrigger(pindexBest);
if(tallyHeight)
TallyResearchAverages(tallyHeight);
NN::Tally::LegacyRecount(NN::Tally::FindTrigger(pindexBest));

if (!threads->createThread(StartNode, NULL, "Start Thread"))
InitError(_("Error: could not start node"));
Expand Down
2 changes: 0 additions & 2 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

using namespace std;

StructCPID GetStructCPID();

namespace {
//!
//! \brief Calculate a legacy RSA weight value from the supplied claim block.
Expand Down
Loading