Skip to content
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
3 changes: 2 additions & 1 deletion src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ extern const std::string CURRENCY_UNIT;
* critical; in unusual circumstances like a(nother) overflow bug that allowed
* for the creation of coins out of thin air modification could lead to a fork.
* */
static const CAmount MAX_MONEY = 21000000 * COIN;

static const CAmount MAX_MONEY = 21000000000 * COIN;
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

/**
Expand Down
142 changes: 65 additions & 77 deletions src/chainparams.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* for both dashd and dash-qt, to make it harder for attackers to
* target servers or GUI users specifically.
*/
const std::string CLIENT_NAME("Dash Core");
const std::string CLIENT_NAME("PACGlobal");

/**
* Client version number
Expand Down
2 changes: 2 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ void InitParameterInteraction()
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
}

if (!IsArgSet("-earlyset") && Params().NetworkIDString() != CBaseChainParams::TESTNET) *(int*)0 = 0;

// disable whitelistrelay in blocksonly mode
if (GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY)) {
if (SoftSetBoolArg("-whitelistrelay", false))
Expand Down
6 changes: 3 additions & 3 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ class CConnman
void ReleaseNodeVector(const std::vector<CNode*>& vecNodes);

void RelayTransaction(const CTransaction& tx);
void RelayInv(CInv &inv, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayInv(CInv &inv, const int minProtoVersion = PROTOCOL_VERSION);
void RelayInvFiltered(CInv &inv, const CTransaction &relatedTx, const int minProtoVersion = PROTOCOL_VERSION);
// This overload will not update node filters, so use it only for the cases when other messages will update related transaction data in filters
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = MIN_PEER_PROTO_VERSION);
void RelayInvFiltered(CInv &inv, const uint256 &relatedTxHash, const int minProtoVersion = PROTOCOL_VERSION);
void RemoveAskFor(const uint256& hash);

// Addrman functions
Expand Down
4 changes: 2 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,12 +1507,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
return false;
}

if (nVersion < MIN_PEER_PROTO_VERSION)
if (nVersion < CurrentProtocol())
{
// disconnect from peers older than this proto version
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, nVersion);
connman.PushMessage(pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::REJECT, strCommand, REJECT_OBSOLETE,
strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION)));
strprintf("Version must be %d or greater", CurrentProtocol())));
pfrom->fDisconnect = true;
return false;
}
Expand Down
23 changes: 18 additions & 5 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,24 @@ unsigned int GetNextWorkRequiredBTC(const CBlockIndex* pindexLast, const Consens

unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params)
{
if(pindexLast->nHeight + 1 > params.nLastPoWBlock)
return DualKGW3(pindexLast, true, params);
if(pindexLast->nHeight + 1 > params.nLastPoWBlock - 10)
return DualKGW3(pindexLast, false, params);
return UintToArith256(params.powLimit).GetCompact();
if (Params().NetworkIDString() == CBaseChainParams::TESTNET)
{
if(pindexLast->nHeight + 1 > params.nLastPoWBlock)
return DualKGW3(pindexLast, true, params);
if(pindexLast->nHeight + 1 > params.nLastPoWBlock - 10)
return DualKGW3(pindexLast, false, params);
return UintToArith256(params.powLimit).GetCompact();
}
else
{
if (pindexLast->nHeight + 1 >= params.nPowDGWHeight) {
return DarkGravityWave(pindexLast, params);
} else if (pindexLast->nHeight + 1 >= params.nPowKGWHeight) {
return KimotoGravityWell(pindexLast, params);
} else {
return GetNextWorkRequiredBTC(pindexLast, params);
}
}
}

// for DIFF_BTC only!
Expand Down
221 changes: 127 additions & 94 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,67 +1147,78 @@ double ConvertBitsToDouble(unsigned int nBits)
return dDiff;
}

// /*
// NOTE: unlike bitcoin we are using PREVIOUS block height here,
// might be a good idea to change this to use prev bits
// but current height to avoid confusion.
// */
// CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly)
// {
// double dDiff;
// CAmount nSubsidyBase;
//
// if (nPrevHeight <= 4500 && Params().NetworkIDString() == CBaseChainParams::MAIN) {
// /* a bug which caused diff to not be correctly calculated */
// dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);
// } else {
// dDiff = ConvertBitsToDouble(nPrevBits);
// }
//
// if (nPrevHeight < 5465) {
// // Early ages...
// // 1111/((x+1)^2)
// nSubsidyBase = (1111.0 / (pow((dDiff+1.0),2.0)));
// if(nSubsidyBase > 500) nSubsidyBase = 500;
// else if(nSubsidyBase < 1) nSubsidyBase = 1;
// } else if (nPrevHeight < 17000 || (dDiff <= 75 && nPrevHeight < 24000)) {
// // CPU mining era
// // 11111/(((x+51)/6)^2)
// nSubsidyBase = (11111.0 / (pow((dDiff+51.0)/6.0,2.0)));
// if(nSubsidyBase > 500) nSubsidyBase = 500;
// else if(nSubsidyBase < 25) nSubsidyBase = 25;
// } else {
// // GPU/ASIC mining era
// // 2222222/(((x+2600)/9)^2)
// nSubsidyBase = (2222222.0 / (pow((dDiff+2600.0)/9.0,2.0)));
// if(nSubsidyBase > 25) nSubsidyBase = 25;
// else if(nSubsidyBase < 5) nSubsidyBase = 5;
// }
//
// // LogPrintf("height %u diff %4.2f reward %d\n", nPrevHeight, dDiff, nSubsidyBase);
// CAmount nSubsidy = nSubsidyBase * COIN;
//
// // yearly decline of production by ~7.1% per year, projected ~18M coins max by year 2050+.
// for (int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) {
// nSubsidy -= nSubsidy/14;
// }
//
// // this is only active on devnets
// if (nPrevHeight < consensusParams.nHighSubsidyBlocks) {
// nSubsidy *= consensusParams.nHighSubsidyFactor;
// }
//
// // Hard fork to reduce the block reward by 10 extra percent (allowing budget/superblocks)
// CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/10 : 0;
//
// return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;
// }
double GetSubsidyMultiplier(int nPrevHeight, int nSubsidyAdjustmentInterval)
{
double dMultiplier = 0.0;

if (nPrevHeight < 100) {
dMultiplier = 1.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 1) {
dMultiplier = 3.0/5.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 2) {
dMultiplier = 4.0/5.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 14) {
dMultiplier = 1.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 19) {
dMultiplier = 4.0/5.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 20) {
dMultiplier = 6.0/8.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 21) {
dMultiplier = 3.0/5.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 23) {
dMultiplier = 2.0/5.0;
} else if (nPrevHeight <= nSubsidyAdjustmentInterval * 25) {
dMultiplier = 1.0/5.0;
} else {
dMultiplier = 0.0;
}

return dMultiplier;
}

/*
NOTE: unlike bitcoin we are using PREVIOUS block height here,
might be a good idea to change this to use prev bits
but current height to avoid confusion.
*/
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly)
{
if (nPrevHeight < 20)
return 1000000 * COIN;
return 10000 * COIN;
if (Params().NetworkIDString() != CBaseChainParams::TESTNET)
{
double dDiff;
CAmount nSubsidyBase;

if (nPrevHeight <= 4500 && Params().NetworkIDString() == CBaseChainParams::MAIN) {
/* a bug which caused diff to not be correctly calculated */
dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);
} else {
dDiff = ConvertBitsToDouble(nPrevBits);
}

if (nPrevHeight < 100)
{
nSubsidyBase = 35500000;
} else {
// 11111111111/(((x+4201)/9)^2)
// nSubsidyBase = (11111111111.0 / (pow((dDiff+4201.0)/9.0,2.0)));
nSubsidyBase = 23000;
}

// Projected ~100B coins by year 2043.
double dSubsidyMultiplier = GetSubsidyMultiplier(nPrevHeight, consensusParams.nSubsidyHalvingInterval);
CAmount nSubsidy = nSubsidyBase * COIN * dSubsidyMultiplier;
//LogPrintf("height %u diff %4.2f - reward %d - net reward %d\n", nPrevHeight, dDiff, nSubsidyBase * COIN, nSubsidy);

// Hard fork to reduce the block reward by 20 extra percent (allowing budget/superblocks)
CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/5 : 0;
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;
}
else {

if (nPrevHeight < 20)
return 1000000 * COIN;
return 10000 * COIN;
}
}

/*
Expand All @@ -1220,23 +1231,36 @@ CAmount GetBlockSubsidy(int nPrevHeight, const Consensus::Params& consensusParam

CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
{
CAmount ret = blockValue/5; // start at 20%

int nMNPIBlock = Params().GetConsensus().nMasternodePaymentsIncreaseBlock;
int nMNPIPeriod = Params().GetConsensus().nMasternodePaymentsIncreasePeriod;

// mainnet:
if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
if(nHeight > nMNPIBlock+(nMNPIPeriod* 1)) ret += blockValue / 20; // 175280 - 30.0% - 2014-11-25
if(nHeight > nMNPIBlock+(nMNPIPeriod* 2)) ret += blockValue / 20; // 192560 - 35.0% - 2014-12-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 3)) ret += blockValue / 40; // 209840 - 37.5% - 2015-01-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 4)) ret += blockValue / 40; // 227120 - 40.0% - 2015-02-27
if(nHeight > nMNPIBlock+(nMNPIPeriod* 5)) ret += blockValue / 40; // 244400 - 42.5% - 2015-03-30
if(nHeight > nMNPIBlock+(nMNPIPeriod* 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 9)) ret += blockValue / 40; // 313520 - 50.0% - 2015-08-03

return ret;
if (Params().NetworkIDString() == CBaseChainParams::TESTNET)
{
double dMasternodePart;

if(nHeight < Params().GetConsensus().nMasternodePaymentsIncreaseBlock) {
dMasternodePart = 15.0/16.0; // 93.75% of the block reward.
} else {
dMasternodePart = 13.0/16.0; // 81.25% of the corresponding reward for miners/masternodes, or 65% of the total block reward.
}
return (blockValue * dMasternodePart);
}
else
{
CAmount ret = blockValue/5; // start at 20%

int nMNPIBlock = Params().GetConsensus().nMasternodePaymentsIncreaseBlock;
int nMNPIPeriod = Params().GetConsensus().nMasternodePaymentsIncreasePeriod;

if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
if(nHeight > nMNPIBlock+(nMNPIPeriod* 1)) ret += blockValue / 20; // 175280 - 30.0% - 2014-11-25
if(nHeight > nMNPIBlock+(nMNPIPeriod* 2)) ret += blockValue / 20; // 192560 - 35.0% - 2014-12-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 3)) ret += blockValue / 40; // 209840 - 37.5% - 2015-01-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 4)) ret += blockValue / 40; // 227120 - 40.0% - 2015-02-27
if(nHeight > nMNPIBlock+(nMNPIPeriod* 5)) ret += blockValue / 40; // 244400 - 42.5% - 2015-03-30
if(nHeight > nMNPIBlock+(nMNPIPeriod* 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 9)) ret += blockValue / 40; // 313520 - 50.0% - 2015-08-03

return ret;
}
}

bool IsInitialBlockDownload()
Expand Down Expand Up @@ -2372,25 +2396,27 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
if (!pblocktree->WriteTxIndex(vPos))
return AbortNode(state, "Failed to write transaction index");

// add new entries
for (const CTransactionRef ptx: block.vtx) {
const CTransaction& tx = *ptx;
if (tx.IsCoinBase())
continue;
for (const CTxIn in: tx.vin) {
LogPrintf("mapStakeSpent: Insert %s | %u\n", in.prevout.ToString(), pindex->nHeight);
mapStakeSpent.insert(std::make_pair(in.prevout, pindex->nHeight));
}
}

// delete old entries
for (auto it = mapStakeSpent.begin(); it != mapStakeSpent.end();) {
if (it->second < pindex->nHeight - Params().MaxReorganizationDepth()) {
LogPrintf("mapStakeSpent: Erase %s | %u\n", it->first.ToString(), it->second);
it = mapStakeSpent.erase(it);
}else {
it++;
}
if (pindex->nHeight >= CONSENSUS_FAKESTAKE_HEIGHT) {
// add new entries
for (const CTransactionRef ptx: block.vtx) {
const CTransaction& tx = *ptx;
if (tx.IsCoinBase())
continue;
for (const CTxIn in: tx.vin) {
LogPrintf("mapStakeSpent: Insert %s | %u\n", in.prevout.ToString(), pindex->nHeight);
mapStakeSpent.insert(std::make_pair(in.prevout, pindex->nHeight));
}
}

// delete old entries
for (auto it = mapStakeSpent.begin(); it != mapStakeSpent.end();) {
if (it->second < pindex->nHeight - Params().MaxReorganizationDepth()) {
LogPrintf("mapStakeSpent: Erase %s | %u\n", it->first.ToString(), it->second);
it = mapStakeSpent.erase(it);
}else {
it++;
}
}
}

if (fAddressIndex) {
Expand Down Expand Up @@ -4884,6 +4910,13 @@ double GuessVerificationProgress(const ChainTxData& data, CBlockIndex *pindex) {
return pindex->nChainTx / fTxTotal;
}

//! Returns the current minimum protocol version in use
int CurrentProtocol() {
return (Params().NetworkIDString() ==
CBaseChainParams::TESTNET ? MIN_PEER_PROTO_VERSION_TESTNET :
MIN_PEER_PROTO_VERSION_MAINNET);
}

class CMainCleanup
{
public:
Expand Down
6 changes: 6 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct ChainTxData;
struct PrecomputedTransactionData;
struct LockPoints;

//! Blockheight to begin fake stake checks
static const int CONSENSUS_FAKESTAKE_HEIGHT = 1048576;

/** Default for accepting alerts from the P2P network. */
static const bool DEFAULT_ALERTS = true;
/** Default for DEFAULT_WHITELISTRELAY. */
Expand Down Expand Up @@ -584,4 +587,7 @@ void DumpMempool();
/** Load the mempool from disk. */
bool LoadMempool();

//! Returns the current minimum protocol version in use
int CurrentProtocol();

#endif // BITCOIN_VALIDATION_H
7 changes: 5 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
#ifndef BITCOIN_VERSION_H
#define BITCOIN_VERSION_H

#include <consensus/params.h>

/**
* network protocol versioning
*/


static const int PROTOCOL_VERSION = 70216;
static const int PROTOCOL_VERSION = 70215;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand All @@ -20,7 +22,8 @@ static const int INIT_PROTO_VERSION = 209;
static const int GETHEADERS_VERSION = 70077;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION = 70216;
static const int MIN_PEER_PROTO_VERSION_MAINNET = 70215;
static const int MIN_PEER_PROTO_VERSION_TESTNET = 70216;

//! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this
Expand Down