Merge pull request #7 from lateminer/patch-1

Get parameters from chainparams.cpp...
This commit is contained in:
janko33bd
2017-12-30 03:07:31 +01:00
committed by GitHub
11 changed files with 22 additions and 22 deletions

View File

@@ -101,7 +101,10 @@ public:
consensus.nProtocolV2Time = 1407053625;
consensus.nProtocolV3Time = 1444028400;
consensus.nLastPOWBlock = 10000;
consensus.nStakeTimestampMask = 0xf;
consensus.nStakeTimestampMask = 0xf; // 15
consensus.nCoinbaseMaturity = 500;
consensus.nStakeMinConfirmations = 500;
consensus.nStakeMinAge = 8 * 60 * 60; // 8 hours
/**
* The message start string is designed to be unlikely to occur in normal data.

View File

@@ -70,6 +70,9 @@ struct Params {
unsigned int GetTargetSpacing(int nHeight) { return IsProtocolV2(nHeight) ? 64 : 60; }
int nLastPOWBlock;
int nStakeTimestampMask;
int nCoinbaseMaturity;
int nStakeMinConfirmations;
unsigned int nStakeMinAge;
};
} // namespace Consensus

View File

@@ -1915,7 +1915,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
// If prev is coinbase or coinstake, check that it's matured
if (coins->IsCoinBase() || coins->IsCoinStake()) {
if (nSpendHeight - coins->nHeight < COINBASE_MATURITY)
if (nSpendHeight - coins->nHeight < Params().nCoinbaseMaturity)
return state.Invalid(
error("CheckInputs(): tried to spend %s at depth %d", coins->IsCoinBase() ? "coinbase" : "coinstake", nSpendHeight - coins->nHeight),
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase");
@@ -2476,7 +2476,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
REJECT_INVALID, "bad-cs-kernel");
// Check proof-of-stake min confirmations
if (pindex->nHeight - coins->nHeight < STAKE_MIN_CONFIRMATIONS)
if (pindex->nHeight - coins->nHeight < chainparams.GetConsensus().nStakeMinConfirmations)
return state.DoS(100,
error("%s: tried to stake at depth %d", __func__, pindex->nHeight - coins->nHeight),
REJECT_INVALID, "bad-cs-premature");
@@ -3437,7 +3437,7 @@ bool GetCoinAge(const CTransaction& tx, CBlockTreeDB& txdb, const CBlockIndex* p
if (Params().GetConsensus().IsProtocolV3(tx.nTime))
{
int nSpendDepth;
if (IsConfirmedInNPrevBlocks(txindex, pindexPrev, nStakeMinConfirmations - 1, nSpendDepth))
if (IsConfirmedInNPrevBlocks(txindex, pindexPrev, Params().GetConsensus().nStakeMinConfirmations - 1, nSpendDepth))
{
LogPrint("coinage", "coin age skip nSpendDepth=%d\n", nSpendDepth + 1);
continue; // only count coins meeting min confirmations requirement
@@ -3450,7 +3450,7 @@ bool GetCoinAge(const CTransaction& tx, CBlockTreeDB& txdb, const CBlockIndex* p
const CDiskBlockPos& pos = CDiskBlockPos(txindex.nFile, txindex.nPos);
if (!ReadBlockFromDisk(block, pos, Params().GetConsensus()))
return false; // unable to read block of previous transaction
if (block.GetBlockTime() + nStakeMinAge > tx.nTime)
if (block.GetBlockTime() + Params().GetConsensus().nStakeMinAge > tx.nTime)
continue; // only count coins meeting min age requirement
}

View File

@@ -417,7 +417,7 @@ void static BitcoinMiner(const CChainParams& chainparams)
}
//check the block height
if (chainActive.Tip()->nHeight > Params().LastPOWBlock() + nStakeMinConfirmations)
if (chainActive.Tip()->nHeight > Params().LastPOWBlock() + Params().GetConsensus().nStakeMinConfirmations)
{
// The stake is confirmed, stop the PoW miner
throw boost::thread_interrupted();
@@ -568,7 +568,7 @@ bool SignBlock(CBlock& block, CWallet& wallet, int64_t& nFees)
CMutableTransaction txCoinBase(block.vtx[0]);
CMutableTransaction txCoinStake;
txCoinStake.nTime = GetAdjustedTime();
txCoinStake.nTime &= ~STAKE_TIMESTAMP_MASK;
txCoinStake.nTime &= ~Params().GetConsensus().nStakeTimestampMask;
int64_t nSearchTime = txCoinStake.nTime; // search to current time

View File

@@ -132,7 +132,7 @@ bool CheckProofOfStake(CBlockIndex* pindexPrev, const CTransaction& tx, unsigned
// Min age requirement
int nDepth;
if (IsConfirmedInNPrevBlocks(txindex, pindexPrev, nStakeMinConfirmations - 1, nDepth))
if (IsConfirmedInNPrevBlocks(txindex, pindexPrev, Params().GetConsensus().nStakeMinConfirmations - 1, nDepth))
return state.DoS(100, error("CheckProofOfStake() : tried to stake at depth %d", nDepth + 1));
if (!CheckStakeKernelHash(pindexPrev, nBits, new CCoins(txPrev, pindexPrev->nHeight), txin.prevout, tx.nTime))

View File

@@ -21,12 +21,6 @@ using namespace std;
/** Compute the hash modifier for proof-of-stake */
uint256 ComputeStakeModifier(const CBlockIndex* pindexPrev, const uint256& kernel);
static const int nStakeMinConfirmations = 500;
static const unsigned int nStakeMinAge = 8 * 60 * 60; // 8 hours
// To decrease granularity of timestamp
// Supposed to be 2^n-1
static const int STAKE_TIMESTAMP_MASK = 15;
// Check whether the coinstake timestamp meets protocol
bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx);
bool CheckStakeBlockTimestamp(int64_t nTimeBlock);

View File

@@ -262,7 +262,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
if (wtx.IsCoinBase())
{
quint32 numBlocksToMaturity = COINBASE_MATURITY + 1;
quint32 numBlocksToMaturity = Params().GetConsensus().nCoinbaseMaturity + 1;
strHTML += "<br>" + tr("Generated coins must mature %1 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(numBlocksToMaturity)) + "<br>";
}

View File

@@ -769,7 +769,7 @@ UniValue checkkernel(const UniValue& params, bool fHelp)
CBlockHeader blockHeader = pindexPrev->GetBlockHeader();
unsigned int nBits = GetNextTargetRequired(pindexPrev, &blockHeader, true, Params().GetConsensus());
int64_t nTime = GetAdjustedTime();
nTime &= ~STAKE_TIMESTAMP_MASK;
nTime &= ~Params().GetConsensus().nStakeTimestampMask;
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
const UniValue& input = inputs[idx];

View File

@@ -101,7 +101,7 @@ TestChain100Setup::TestChain100Setup() : TestingSetup(CBaseChainParams::REGTEST)
// Generate a 100-block chain:
coinbaseKey.MakeNewKey(true);
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
for (int i = 0; i < COINBASE_MATURITY; i++)
for (int i = 0; i < Params().GetConsensus().nCoinbaseMaturity; i++)
{
std::vector<CMutableTransaction> noTxns;
CBlock b = CreateAndProcessBlock(noTxns, scriptPubKey);

View File

@@ -665,7 +665,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
continue;
const CCoins *coins = pcoins->AccessCoins(txin.prevout.hash);
if (nCheckFrequency != 0) assert(coins);
if (!coins || (coins->IsCoinBase() || coins->IsCoinStake() && ((signed long)nMemPoolHeight) - coins->nHeight < COINBASE_MATURITY)) {
if (!coins || (coins->IsCoinBase() || coins->IsCoinStake() && ((signed long)nMemPoolHeight) - coins->nHeight < Params().GetConsensus().nCoinbaseMaturity)) {
transactionsToRemove.push_back(tx);
break;
}

View File

@@ -580,7 +580,7 @@ void CWallet::AvailableCoinsForStaking(std::vector<COutput>& vCoins) const
if (nDepth < 1)
continue;
if (nDepth < nStakeMinConfirmations)
if (nDepth < Params().GetConsensus().nStakeMinConfirmations)
continue;
if (pcoin->GetBlocksToMaturity() > 0)
@@ -654,7 +654,7 @@ bool CheckKernel(CBlockIndex* pindexPrev, unsigned int nBits, int64_t nTime, con
return false;
int nDepth;
if (IsConfirmedInNPrevBlocks(txindex, pindexPrev, nStakeMinConfirmations - 1, nDepth))
if (IsConfirmedInNPrevBlocks(txindex, pindexPrev, Params().GetConsensus().nStakeMinConfirmations - 1, nDepth))
return false;
if (pBlockTime)
@@ -3315,7 +3315,7 @@ uint64_t CWallet::GetStakeWeight() const
LOCK2(cs_main, cs_wallet);
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
if (pcoin.first->GetDepthInMainChain() >= nStakeMinConfirmations)
if (pcoin.first->GetDepthInMainChain() >= Params().GetConsensus().nStakeMinConfirmations)
nWeight += pcoin.first->vout[pcoin.second].nValue;
}
@@ -3520,7 +3520,7 @@ int CMerkleTx::GetBlocksToMaturity() const
{
if (!(IsCoinBase() || IsCoinStake()))
return 0;
return max(0, (COINBASE_MATURITY+1) - GetDepthInMainChain());
return max(0, (Params().GetConsensus().nCoinbaseMaturity+1) - GetDepthInMainChain());
}