From af6e26a2880256a667438566034a976ed6f9e230 Mon Sep 17 00:00:00 2001 From: lateminer Date: Mon, 4 Dec 2017 23:43:49 +0300 Subject: [PATCH] Get staking parameters from chainparams.cpp nStakeTimestampMask, nStakeMinConfirmations, nStakeMinAge --- src/chainparams.cpp | 4 +++- src/consensus/params.h | 2 ++ src/main.cpp | 4 ++-- src/miner.cpp | 4 ++-- src/pos.cpp | 2 +- src/pos.h | 6 ------ src/rpcmining.cpp | 2 +- src/wallet/wallet.cpp | 6 +++--- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 2979a7502..e69b8c7a5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -101,7 +101,9 @@ public: consensus.nProtocolV2Time = 1407053625; consensus.nProtocolV3Time = 1444028400; consensus.nLastPOWBlock = 10000; - consensus.nStakeTimestampMask = 0xf; + consensus.nStakeTimestampMask = 0xf; // 15 + consensus.nStakeMinConfirmations = 500; + consensus.nStakeMinAge = 8 * 60 * 60; // 8 hours /** * The message start string is designed to be unlikely to occur in normal data. diff --git a/src/consensus/params.h b/src/consensus/params.h index b9813a2ab..f2d916869 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -70,6 +70,8 @@ struct Params { unsigned int GetTargetSpacing(int nHeight) { return IsProtocolV2(nHeight) ? 64 : 60; } int nLastPOWBlock; int nStakeTimestampMask; + int nStakeMinConfirmations; + unsigned int nStakeMinAge; }; } // namespace Consensus diff --git a/src/main.cpp b/src/main.cpp index 8f1c08a83..166e1e8ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 } diff --git a/src/miner.cpp b/src/miner.cpp index 48f269d81..5d793e46f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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 diff --git a/src/pos.cpp b/src/pos.cpp index 4554db3a7..55957b7db 100644 --- a/src/pos.cpp +++ b/src/pos.cpp @@ -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)) diff --git a/src/pos.h b/src/pos.h index eb3532b30..827c85bae 100644 --- a/src/pos.h +++ b/src/pos.h @@ -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); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 50c4028e8..b7ee47c16 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -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]; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 255fe8610..1209c3fec 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -580,7 +580,7 @@ void CWallet::AvailableCoinsForStaking(std::vector& 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; }