Skip to content
Merged
174 changes: 5 additions & 169 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ extern double GetOutstandingAmountOwed(StructCPID &mag, std::string cpid, int64_

extern double GetOwedAmount(std::string cpid);
bool TallyMagnitudesInSuperblock();
extern std::string GetNeuralNetworkReport();
std::string GetCommandNonce(std::string command);

extern double GRCMagnitudeUnit(int64_t locktime);
Expand Down Expand Up @@ -1679,20 +1678,6 @@ double CalculatedMagnitude2(std::string cpid, int64_t locktime,bool bUseLederstr
return bUseLederstrumpf ? LederstrumpfMagnitude2(stDPOR.Magnitude,locktime) : stDPOR.Magnitude;
}

int64_t GetProofOfWorkMaxReward(int64_t nFees, int64_t locktime, int64_t height)
{
int64_t nSubsidy = (GetMaximumBoincSubsidy(locktime)+1) * COIN;
if (height==10)
{
//R.Halford: 10-11-2014: Gridcoin Foundation Block:
//Note: Gridcoin Classic emitted these coins. So we had to add them to block 10. The coins were burned then given back to the owners that mined them in classic (as research coins).
nSubsidy = nGenesisSupply * COIN;
}

if (fTestNet) nSubsidy += 1000*COIN;
return nSubsidy + nFees;
}

//Survey Results: Start inflation rate: 9%, end=1%, 30 day steps, 9 steps, mag multiplier start: 2, mag end .3, 9 steps
int64_t GetMaximumBoincSubsidy(int64_t nTime)
{
Expand Down Expand Up @@ -1900,44 +1885,6 @@ int64_t GetProofOfStakeReward(uint64_t nCoinAge, int64_t nFees, std::string cpid

static const int64_t nTargetTimespan = 16 * 60; // 16 mins

//
// maximum nBits value could possible be required nTime after
//
unsigned int ComputeMaxBits(CBigNum bnTargetLimit, unsigned int nBase, int64_t nTime)
{
CBigNum bnResult;
bnResult.SetCompact(nBase);
bnResult *= 2;
while (nTime > 0 && bnResult < bnTargetLimit)
{
// Maximum 200% adjustment per day...
bnResult *= 2;
nTime -= 24 * 60 * 60;
}
if (bnResult > bnTargetLimit)
bnResult = bnTargetLimit;
return bnResult.GetCompact();
}

//
// minimum amount of work that could possibly be required nTime after
// minimum proof-of-work required was nBase
//
unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime)
{
return ComputeMaxBits(bnProofOfWorkLimit, nBase, nTime);
}

//
// minimum amount of stake that could possibly be required nTime after
// minimum proof-of-stake required was nBase
//
unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime)
{
return ComputeMaxBits(bnProofOfStakeLimit, nBase, nTime);
}


// ppcoin: find last block index up to pindex
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake)
{
Expand All @@ -1946,49 +1893,17 @@ const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfSta
return pindex;
}


static unsigned int GetNextTargetRequiredV1(const CBlockIndex* pindexLast, bool fProofOfStake)
{
CBigNum bnTargetLimit = fProofOfStake ? bnProofOfStakeLimit : bnProofOfWorkLimit;

if (pindexLast == NULL)
return bnTargetLimit.GetCompact(); // genesis block

const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
if (pindexPrev->pprev == NULL)
return bnTargetLimit.GetCompact(); // first block
const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, fProofOfStake);
if (pindexPrevPrev->pprev == NULL)
return bnTargetLimit.GetCompact(); // second block

int64_t nTargetSpacing = GetTargetSpacing(pindexLast->nHeight);
int64_t nActualSpacing = pindexPrev->GetBlockTime() - pindexPrevPrev->GetBlockTime();

// ppcoin: target change every block
// ppcoin: retarget with exponential moving toward target spacing
CBigNum bnNew;
bnNew.SetCompact(pindexPrev->nBits);
int64_t nInterval = nTargetTimespan / nTargetSpacing;
bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
bnNew /= ((nInterval + 1) * nTargetSpacing);

if (bnNew > bnTargetLimit)
bnNew = bnTargetLimit;

return bnNew.GetCompact();
}

static unsigned int GetNextTargetRequiredV2(const CBlockIndex* pindexLast, bool fProofOfStake)
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast)
{
CBigNum bnTargetLimit = fProofOfStake ? GetProofOfStakeLimit(pindexLast->nHeight) : bnProofOfWorkLimit;
CBigNum bnTargetLimit = GetProofOfStakeLimit(pindexLast->nHeight);

if (pindexLast == NULL)
return bnTargetLimit.GetCompact(); // genesis block

const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, fProofOfStake);
const CBlockIndex* pindexPrev = GetLastBlockIndex(pindexLast, true);
if (pindexPrev->pprev == NULL)
return bnTargetLimit.GetCompact(); // first block
const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, fProofOfStake);
const CBlockIndex* pindexPrevPrev = GetLastBlockIndex(pindexPrev->pprev, true);
if (pindexPrevPrev->pprev == NULL)
return bnTargetLimit.GetCompact(); // second block

Expand Down Expand Up @@ -2030,15 +1945,6 @@ static unsigned int GetNextTargetRequiredV2(const CBlockIndex* pindexLast, bool
return bnNew.GetCompact();
}

unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake)
{
//After block 89600, new diff algorithm is used
if (pindexLast->nHeight < 89600)
return GetNextTargetRequiredV1(pindexLast, fProofOfStake);
else
return GetNextTargetRequiredV2(pindexLast, fProofOfStake);
}

bool CheckProofOfWork(uint256 hash, unsigned int nBits)
{
CBigNum bnTarget;
Expand Down Expand Up @@ -2171,14 +2077,6 @@ void static InvalidChainFound(CBlockIndex* pindexNew)
DateTimeStrFormat("%x %H:%M:%S", pindexBest->GetBlockTime()));
}


void CBlock::UpdateTime(const CBlockIndex* pindexPrev)
{
nTime = max(GetBlockTime(), GetAdjustedTime());
}



bool CTransaction::DisconnectInputs(CTxDB& txdb)
{
// Relinquish previous transactions' spent pointers
Expand Down Expand Up @@ -2346,17 +2244,6 @@ bool LessVerbose(int iMax1000)
return false;
}


bool KeyEnabled(std::string key)
{
if (mapArgs.count("-" + key))
{
std::string sBool = GetArg("-" + key, "false");
if (sBool == "true") return true;
}
return false;
}

unsigned int CTransaction::GetP2SHSigOpCount(const MapPrevTx& inputs) const
{
if (IsCoinBase())
Expand Down Expand Up @@ -2782,16 +2669,6 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck, boo
mapQueuedChanges[hashTx] = CTxIndex(posThisTx, tx.vout.size());
}

if (IsProofOfWork() && pindex->nHeight > nGrandfather)
{
int64_t nReward = GetProofOfWorkMaxReward(nFees,nTime,pindex->nHeight);
// Check coinbase reward
if (vtx[0].GetValueOut() > nReward)
return DoS(50, error("ConnectBlock[] : coinbase reward exceeded (actual=%" PRId64 " vs calculated=%" PRId64 ")",
vtx[0].GetValueOut(),
nReward));
}

MiningCPID bb = DeserializeBoincBlock(vtx[0].hashBoinc,nVersion);
uint64_t nCoinAge = 0;
double dStakeReward = CoinToDouble(nStakeReward);
Expand Down Expand Up @@ -3905,7 +3782,7 @@ bool CBlock::AcceptBlock(bool generated_by_me)
if (GetBlockTime() <= pindexPrev->GetPastTimeLimit() || FutureDrift(GetBlockTime(), nHeight) < pindexPrev->GetBlockTime())
return DoS(60, error("AcceptBlock() : block's timestamp is too early"));
// Check proof-of-work or proof-of-stake
if (nBits != GetNextTargetRequired(pindexPrev, IsProofOfStake()))
if (nBits != GetNextTargetRequired(pindexPrev))
return DoS(100, error("AcceptBlock() : incorrect %s", IsProofOfWork() ? "proof-of-work" : "proof-of-stake"));
}

Expand Down Expand Up @@ -4020,23 +3897,6 @@ uint256 CBlockIndex::GetBlockTrust() const
return chaintrust;
}

bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired, unsigned int nToCheck)
{
unsigned int nFound = 0;
for (unsigned int i = 0; i < nToCheck && nFound < nRequired && pstart != NULL; i++)
{
if (pstart->nVersion >= minVersion)
++nFound;
pstart = pstart->pprev;
}
return (nFound >= nRequired);
}

bool ServicesIncludesNN(CNode* pNode)
{
return (Contains(pNode->strSubVer,"1999")) ? true : false;
}

bool VerifySuperblock(const std::string& superblock, const CBlockIndex* parent)
{
// Pre-condition checks.
Expand Down Expand Up @@ -4806,12 +4666,6 @@ bool IsCPIDValidv2(MiningCPID& mc, int height)
return result;
}

double GetTotalOwedAmount(std::string cpid)
{
StructCPID& o = GetInitializedStructCPID2(cpid,mvMagnitudes);
return o.totalowed;
}

double GetOwedAmount(std::string cpid)
{
if (mvMagnitudes.size() > 1)
Expand Down Expand Up @@ -7275,24 +7129,6 @@ std::string GetCurrentNeuralNetworkSupermajorityHash(double& out_popularity)
return neural_hash;
}

std::string GetNeuralNetworkReport()
{
//Returns a report of the networks neural hashes in order of popularity
std::string neural_hash = "";
std::string report = "Neural_hash, Popularity\n";
std::string row = "";

// Copy to a sorted map.
std::map<std::string, double> sorted_hashes(
mvNeuralNetworkHash.begin(),
mvNeuralNetworkHash.end());

for(auto& entry : sorted_hashes)
report += entry.first + "," + RoundToString(entry.second, 0) + "\n";

return report;
}

bool MemorizeMessage(const CTransaction &tx, double dAmount, std::string sRecipient)
{
const std::string &msg = tx.hashBoinc;
Expand Down
14 changes: 1 addition & 13 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ bool CheckProofOfResearch(
const CBlockIndex* pindexPrev, //previous block in chain index
const CBlock &block); //block to check

unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast, bool fProofOfStake);
unsigned int GetNextTargetRequired(const CBlockIndex* pindexLast);
int64_t GetConstantBlockReward(const CBlockIndex* index);
int64_t ComputeResearchAccrual(int64_t nTime, std::string cpid, std::string operation, CBlockIndex* pindexLast, bool bVerifyingBlock, int VerificationPhase, double& dAccrualAge, double& dMagnitudeUnit, double& AvgMagnitude);
int64_t GetProofOfStakeReward(uint64_t nCoinAge, int64_t nFees, std::string cpid,
Expand Down Expand Up @@ -288,8 +288,6 @@ double GetEstimatedTimetoStake(double dDiff = 0.0, double dConfidence = 0.8);
void AddRARewardBlock(const CBlockIndex* pIndex);
MiningCPID GetBoincBlockByIndex(CBlockIndex* pblockindex);

unsigned int ComputeMinWork(unsigned int nBase, int64_t nTime);
unsigned int ComputeMinStake(unsigned int nBase, int64_t nTime, unsigned int nBlockTime);
int GetNumBlocksOfPeers();
bool IsInitialBlockDownload();
std::string GetWarnings(std::string strFor);
Expand Down Expand Up @@ -1112,8 +1110,6 @@ class CBlock
return (int64_t)nTime;
}

void UpdateTime(const CBlockIndex* pindexPrev);

// entropy bit for stake modifier if chosen by modifier
unsigned int GetStakeEntropyBit() const
{
Expand Down Expand Up @@ -1459,14 +1455,6 @@ class CBlockIndex
return pbegin[(pend - pbegin)/2];
}

/**
* Returns true if there are nRequired or more blocks of minVersion or above
* in the last nToCheck blocks, starting at pstart and going backwards.
*/
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart,
unsigned int nRequired, unsigned int nToCheck);


bool IsProofOfWork() const
{
return !(nFlags & BLOCK_PROOF_OF_STAKE);
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ void StakeMiner(CWallet *pwallet)
// * Create a bare block
StakeBlock.nTime= GetAdjustedTime();
StakeBlock.nNonce= 0;
StakeBlock.nBits = GetNextTargetRequired(pindexPrev, true);
StakeBlock.nBits = GetNextTargetRequired(pindexPrev);
StakeBlock.vtx.resize(2);
//tx 0 is coin_base
CTransaction &StakeTX= StakeBlock.vtx[1]; //tx 1 is coin_stake
Expand Down
25 changes: 0 additions & 25 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,31 +434,6 @@ UniValue getblockbynumber(const UniValue& params, bool fHelp)
return blockToJSON(block, pblockindex, params.size() > 1 ? params[1].get_bool() : false);
}

void filecopy(FILE *dest, FILE *src)
{
const int size = 16384;
char buffer[size];

while (!feof(src))
{
int n = fread(buffer, 1, size, src);
fwrite(buffer, 1, n, dest);
}

fflush(dest);
}

void fileopen_and_copy(std::string src, std::string dest)
{
FILE * infile = fopen(src.c_str(), "rb");
FILE * outfile = fopen(dest.c_str(), "wb");

filecopy(outfile, infile);

fclose(infile);
fclose(outfile);
}

std::string ExtractValue(std::string data, std::string delimiter, int pos)
{
std::vector<std::string> vKeys = split(data.c_str(),delimiter);
Expand Down
Loading