Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
362d052
Refactor to remove GlobalCPUMiningCPID
cyrossignol Jul 19, 2019
04db66b
Move GetAlternativeBeaconKeys() function to beacon.cpp
cyrossignol Jul 25, 2019
c05d8c8
Implement Parse() and ToString() methods for CPubKey
cyrossignol Aug 20, 2019
8f3b108
Add constant for the scale of COIN money values
cyrossignol Aug 24, 2019
57a3fab
Parse quorum hash of empty legacy superblock to invalid
cyrossignol Oct 7, 2019
f315d2a
Create NN::Claim class (new MiningCPID)
cyrossignol Jul 20, 2019
e5e1025
Add placeholder threshold for block version 11
cyrossignol Aug 20, 2019
12789e2
Store claim in generated block v11
cyrossignol Jul 29, 2019
27ad942
Add support for minting version 11 blocks to miner
cyrossignol Aug 20, 2019
d6647ae
Refactor miner to use NN Claim and Superblock classes
cyrossignol Jul 29, 2019
b6d3608
Update getblock RPC method for structured claim/superblock data
cyrossignol Jul 29, 2019
0d00884
Refactor remaining usage of MiningCPID to NN::Claim
cyrossignol Jul 29, 2019
4a12c07
Remove unused lederstrumpf flag from CalculatedMagnitude() functions
cyrossignol Aug 19, 2019
ef14790
Remove informational last payment time from claims
cyrossignol Aug 25, 2019
948ead0
Remove informational last PoR block hash from claims
cyrossignol Aug 25, 2019
b95b9d2
Remove informational research age from claims
cyrossignol Aug 25, 2019
f1fee5a
Remove informational average magnitude from claims
cyrossignol Aug 25, 2019
ccd5725
Remove informational public key from claims
cyrossignol Aug 25, 2019
270d0de
Refactor to remove last block hash from claims
cyrossignol Oct 8, 2019
12747c7
Truncate version to 30 and org to 50 characters in claims
cyrossignol Oct 8, 2019
7097eb4
Verify claims in CheckBlock() for block version 11
cyrossignol Oct 8, 2019
7da38c9
Fix failure to stake as researcher with expired beacon
cyrossignol Oct 8, 2019
c0325b6
Check that superblock size <= 4 MB
cyrossignol Oct 14, 2019
e559116
Remove now unused GetLastPaymentTimeByCPID() function
cyrossignol Oct 15, 2019
269c55c
Stake zero research reward blocks for CPID as investor
cyrossignol Oct 15, 2019
50a75bf
Use NN::GetPrimaryCpid() in global status to track CPID string
cyrossignol Oct 20, 2019
8af173b
Remove deleted "operation" argument for ComputeResearchAccrual()
cyrossignol Oct 20, 2019
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
4 changes: 3 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ GRIDCOIN_CORE_H = \
main.h \
miner.h \
mruset.h \
neuralnet/claim.h \
neuralnet/cpid.h \
neuralnet/neuralnet.h \
neuralnet/neuralnet_native.h \
Expand Down Expand Up @@ -158,10 +159,11 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
keystore.cpp \
main.cpp \
miner.cpp \
neuralnet/claim.cpp \
neuralnet/cpid.cpp \
neuralnet/neuralnet.cpp \
neuralnet/neuralnet_native.cpp \
neuralnet/neuralnet_stub.cpp \
neuralnet/cpid.cpp \
neuralnet/project.cpp \
neuralnet/researcher.cpp \
neuralnet/superblock.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ GRIDCOIN_TESTS =\
test/mruset_tests.cpp \
test/multisig_tests.cpp \
test/netbase_tests.cpp \
test/neuralnet/claim_tests.cpp \
test/neuralnet/cpid_tests.cpp \
test/neuralnet/project_tests.cpp \
test/neuralnet/researcher_tests.cpp \
Expand Down
23 changes: 23 additions & 0 deletions src/beacon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ std::string GetBeaconPublicKey(const std::string& cpid, bool bAdvertisingBeacon)
return sBeaconPublicKey;
}

std::set<std::string> GetAlternativeBeaconKeys(const std::string& cpid)
{
int64_t iMaxSeconds = 60 * 24 * 30 * 6 * 60;
std::set<std::string> result;

for(const auto& item : ReadCacheSection(Section::BEACONALT))
{
const std::string& key = item.first;
const std::string& value = item.second.value;
if(!std::equal(cpid.begin(), cpid.end(), key.begin()))
continue;

const int64_t iAge = pindexBest != NULL
? pindexBest->nTime - item.second.timestamp
: 0;
if (iAge > iMaxSeconds)
continue;

result.emplace(value);
}
return result;
}

int64_t BeaconTimeStamp(const std::string& cpid, bool bZeroOutAfterPOR)
{
if (!IsResearcher(cpid)) {
Expand Down
2 changes: 2 additions & 0 deletions src/beacon.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "util.h"
#include <string>
#include <map>
#include <set>

// This is modelled after AppCacheEntry/Section but named separately.
struct BeaconEntry
Expand Down Expand Up @@ -69,6 +70,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);
bool HasActiveBeacon(const std::string& cpid);

Expand Down
13 changes: 7 additions & 6 deletions src/contract/polls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ std::pair<std::string, std::string> CreateVoteContract(std::string sTitle, std::
std::string acceptable_answers = PollAnswers(sTitle);
return std::make_pair("Error", "Sorry, Answer " + sAnswer + " is not one of the acceptable answers, allowable answers are: " + acceptable_answers + ". If you are voting multiple choice, please use a semicolon delimited vote string such as : 'dog;cat'.");
}
std::string sParam = SerializeBoincBlock(GlobalCPUMiningCPID, pindexBest->nVersion);

const std::string primary_cpid = NN::GetPrimaryCpid();

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

// Prevent Double Voting
std::string cpid1 = GlobalCPUMiningCPID.cpid;
std::string GRCAddress1 = DefaultWalletAddress();
GetEarliestStakeTime(GRCAddress1, cpid1);
GetEarliestStakeTime(GRCAddress1, primary_cpid);
double cpid_age = GetAdjustedTime() - ReadCache(Section::GLOBAL, "nCPIDTime").timestamp;
double stake_age = GetAdjustedTime() - ReadCache(Section::GLOBAL, "nGRCTime").timestamp;

Expand All @@ -123,12 +124,12 @@ std::pair<std::string, std::string> CreateVoteContract(std::string sTitle, std::
else
{
std::string voter = "<CPID>"
+ GlobalCPUMiningCPID.cpid + "</CPID><GRCADDRESS>" + GRCAddress + "</GRCADDRESS><RND>"
+ primary_cpid + "</CPID><GRCADDRESS>" + GRCAddress + "</GRCADDRESS><RND>"
+ hashRand.GetHex() + "</RND><BALANCE>" + RoundToString(nBalance,2)
+ "</BALANCE><MAGNITUDE>" + RoundToString(dmag,0) + "</MAGNITUDE>";
// Add the provable balance and the provable magnitude - this goes into effect July 1 2017
voter += GetProvableVotingWeightXML();
std::string pk = sTitle + ";" + GRCAddress + ";" + GlobalCPUMiningCPID.cpid;
std::string pk = sTitle + ";" + GRCAddress + ";" + primary_cpid;
std::string contract = "<TITLE>" + sTitle + "</TITLE><ANSWER>" + sAnswer + "</ANSWER>" + voter;
std::string result = SendContract("vote",pk,contract);
std::string narr = "Your CPID weight is " + RoundToString(dmag,0) + " and your Balance weight is " + RoundToString(nBalance,0) + ".";
Expand Down
1 change: 0 additions & 1 deletion src/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class CTransaction;
class CWallet;

// Gridcoin
struct MiningCPID;
struct StructCPID;

class ThreadHandler;
Expand Down
27 changes: 0 additions & 27 deletions src/global_objects_noui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,12 @@ struct StructCPID
std::set<const CBlockIndex*> rewardBlocks;
};

struct MiningCPID
{
bool initialized;
double Magnitude;
double LastPaymentTime;
double ResearchSubsidy;
double ResearchAge;
double ResearchMagnitudeUnit;
double ResearchAverageMagnitude;
double InterestSubsidy;

std::string cpid;
std::string clientversion;
std::string GRCAddress;
std::string lastblockhash;
std::string Organization;
std::string NeuralHash;
std::string superblock;
std::string LastPORBlockHash;
std::string CurrentNeuralHash;
std::string BoincPublicKey;
std::string BoincSignature;
};

//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;

//Global CPU Mining CPID:
extern MiningCPID GlobalCPUMiningCPID;

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

Expand Down
54 changes: 8 additions & 46 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using namespace std;

StructCPID GetStructCPID();
extern double GetLastPaymentTimeByCPID(std::string cpid);

namespace {
//!
Expand Down Expand Up @@ -260,39 +259,6 @@ bool ComputeNextStakeModifier(const CBlockIndex* pindexPrev, uint64_t& nStakeMod
return true;
}

double GetLastPaymentTimeByCPID(std::string cpid)
{
double lpt = 0;
if (mvMagnitudes.size() > 0)
{
StructCPID UntrustedHost = GetStructCPID();
UntrustedHost = mvMagnitudes[cpid]; //Contains Consensus Magnitude
if (UntrustedHost.initialized)
{
double mag_accuracy = UntrustedHost.Accuracy;
if (mag_accuracy > 0)
{
lpt = UntrustedHost.LastPaymentTime;
}
}
else
{
if (IsResearcher(cpid))
{
lpt = 0;
}
}
}
else
{
if (IsResearcher(cpid))
{
lpt=0;
}
}
return lpt;
}

// Get stake modifier checksum
unsigned int GetStakeModifierChecksum(const CBlockIndex* pindex)
{
Expand Down Expand Up @@ -392,10 +358,11 @@ bool CalculateLegacyV3HashProof(
// after the coins mature!

CBigNum CalculateStakeHashV8(
const CBlock &CoinBlock, const CTransaction &CoinTx,
unsigned CoinTxN, unsigned nTimeTx,
uint64_t StakeModifier,
const MiningCPID &BoincData)
const CBlock &CoinBlock,
const CTransaction &CoinTx,
unsigned CoinTxN,
unsigned nTimeTx,
uint64_t StakeModifier)
{
CDataStream ss(SER_GETHASH, 0);
ss << StakeModifier;
Expand All @@ -407,9 +374,7 @@ CBigNum CalculateStakeHashV8(
return hashProofOfStake;
}

int64_t CalculateStakeWeightV8(
const CTransaction &CoinTx, unsigned CoinTxN,
const MiningCPID &BoincData)
int64_t CalculateStakeWeightV8(const CTransaction &CoinTx, unsigned CoinTxN)
{
int64_t nValueIn = CoinTx.vout[CoinTxN].nValue;
nValueIn /= 1250000;
Expand Down Expand Up @@ -489,16 +454,13 @@ bool CheckProofOfStakeV8(
if (blockPrev.nTime + nStakeMinAge > tx.nTime) // Min age requirement
return error("CheckProofOfStakeV8: min age violation");

MiningCPID boincblock = DeserializeBoincBlock(Block.vtx[0].hashBoinc,Block.nVersion);

//
uint64_t StakeModifier = 0;
if(!FindStakeModifierRev(StakeModifier,pindexPrev))
return error("CheckProofOfStakeV8: unable to find stake modifier");

//Stake refactoring TomasBrod
int64_t Weight= CalculateStakeWeightV8(txPrev,txin.prevout.n,boincblock);
CBigNum bnHashProof= CalculateStakeHashV8(blockPrev,txPrev,txin.prevout.n,tx.nTime,StakeModifier,boincblock);
int64_t Weight = CalculateStakeWeightV8(txPrev, txin.prevout.n);
CBigNum bnHashProof = CalculateStakeHashV8(blockPrev, txPrev, txin.prevout.n, tx.nTime, StakeModifier);

// Base target
CBigNum bnTarget;
Expand Down
14 changes: 7 additions & 7 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ bool FindStakeModifierRev(uint64_t& StakeModifier,CBlockIndex* pindexPrev);

// Kernel for V8
CBigNum CalculateStakeHashV8(
const CBlock &CoinBlock, const CTransaction &CoinTx,
unsigned CoinTxN, unsigned nTimeTx,
uint64_t StakeModifier,
const MiningCPID &BoincData);
int64_t CalculateStakeWeightV8(
const CTransaction &CoinTx, unsigned CoinTxN,
const MiningCPID &BoincData);
const CBlock &CoinBlock,
const CTransaction &CoinTx,
unsigned CoinTxN,
unsigned nTimeTx,
uint64_t StakeModifier);

int64_t CalculateStakeWeightV8(const CTransaction &CoinTx, unsigned CoinTxN);

#endif // PPCOIN_KERNEL_H
16 changes: 15 additions & 1 deletion src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CPubKey {

public:
CPubKey() { }
CPubKey(const std::vector<unsigned char> &vchPubKeyIn) : vchPubKey(vchPubKeyIn) { }
CPubKey(std::vector<unsigned char> vchPubKeyIn) : vchPubKey(std::move(vchPubKeyIn)) { }
friend bool operator==(const CPubKey &a, const CPubKey &b) { return a.vchPubKey == b.vchPubKey; }
friend bool operator!=(const CPubKey &a, const CPubKey &b) { return a.vchPubKey != b.vchPubKey; }
friend bool operator<(const CPubKey &a, const CPubKey &b) { return a.vchPubKey < b.vchPubKey; }
Expand All @@ -81,6 +81,15 @@ class CPubKey {
READWRITE(vchPubKey);
}

static CPubKey Parse(const std::string& input)
{
if (input.empty()) {
return CPubKey();
}

return CPubKey(ParseHex(input));
}

CKeyID GetID() const {
return CKeyID(Hash160(vchPubKey));
}
Expand All @@ -100,6 +109,11 @@ class CPubKey {
std::vector<unsigned char> Raw() const {
return vchPubKey;
}

std::string ToString() const
{
return HexStr(vchPubKey);
}
};


Expand Down
Loading