From d452787a2c4cf8412e6e400f2c5b434fdb39de28 Mon Sep 17 00:00:00 2001 From: lateminer Date: Fri, 12 Oct 2018 00:04:41 +0300 Subject: [PATCH] Completely remove coinage --- src/main.cpp | 57 ------------------------------------- src/main.h | 2 -- src/wallet/wallet.cpp | 66 +++++++++++++++---------------------------- 3 files changed, 23 insertions(+), 102 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bbb3be712..9e2b964da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3273,63 +3273,6 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { return true; } -// ppcoin: total coin age spent in transaction, in the unit of coin-days. -// Only those coins meeting minimum age requirement counts. As those -// transactions not in main chain are not currently indexed so we -// might not find out about their coin age. Older transactions are -// guaranteed to be in main chain by sync-checkpoint. This rule is -// introduced to help nodes establish a consistent view of the coin -// age (trust score) of competing branches. -bool GetCoinAge(const CTransaction& tx, CBlockTreeDB& txdb, const CBlockIndex* pindexPrev, uint64_t& nCoinAge) -{ - arith_uint256 bnCentSecond = 0; // coin age in the unit of cent-seconds - nCoinAge = 0; - - if (tx.IsCoinBase()) - return true; - - BOOST_FOREACH(const CTxIn& txin, tx.vin) - { - // First try finding the previous transaction in database - CTransaction txPrev; - CDiskTxPos txindex; - if (!ReadFromDisk(txPrev, txindex, *pblocktree, txin.prevout)) - continue; // previous transaction not in main chain - if (tx.nTime < txPrev.nTime) - return false; // Transaction timestamp violation - - if (Params().GetConsensus().IsProtocolV3(tx.nTime)) - { - int 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 - } - } - else - { - // Read block header - CBlock block; - 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() + Params().GetConsensus().nStakeMinAge > tx.nTime) - continue; // only count coins meeting min age requirement - } - - int64_t nValueIn = txPrev.vout[txin.prevout.n].nValue; - bnCentSecond += arith_uint256(nValueIn) * (tx.nTime-txPrev.nTime) / CENT; - - LogPrint("coinage", "coin age nValueIn=%d nTimeDiff=%d bnCentSecond=%s\n", nValueIn, tx.nTime - txPrev.nTime, bnCentSecond.ToString()); - } - - arith_uint256 bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60); - LogPrint("coinage", "coin age bnCoinDay=%s\n", bnCoinDay.ToString()); - nCoinAge = bnCoinDay.GetLow64(); - return true; -} - static CBlockIndex* AddToBlockIndex(const CBlockHeader& block) { // Check for duplicate diff --git a/src/main.h b/src/main.h index deddb3903..0a0fa81af 100644 --- a/src/main.h +++ b/src/main.h @@ -556,8 +556,6 @@ int GetSpendHeight(const CCoinsViewCache& inputs); */ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params); -bool GetCoinAge(const CTransaction& tx, CBlockTreeDB& txdb, const CBlockIndex* pindexPrev, uint64_t& nCoinAge); - /** Reject codes greater or equal to this can be returned by AcceptToMemPool * for transactions, to signal internal conditions. They cannot and should not * be sent over the P2P network. diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1e307a9fe..f5e8d108e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -664,20 +664,6 @@ bool CWallet::SelectCoinsForStaking(CAmount& nTargetValue, std::setnTime)) - nSubsidy = COIN * 3 / 2; - else - nSubsidy = nCoinAge * 1 * CENT * 33 / (365 * 33 + 8); - - LogPrint("creation", "GetProofOfStakeReward(): create=%s nCoinAge=%d\n", FormatMoney(nSubsidy), nCoinAge); - - return nSubsidy + nFees; -} - bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64_t nSearchInterval, CAmount& nFees, CMutableTransaction& tx, CKey& key) { CBlockIndex* pindexPrev = pindexBestHeader; @@ -697,7 +683,7 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int CAmount nBalance = GetBalance(); if (nBalance <= nReserveBalance) - return false; + return false; vector vwtxPrev; @@ -707,25 +693,24 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int // Select coins with suitable depth CAmount nTargetValue = nBalance - nReserveBalance; if (!SelectCoinsForStaking(nTargetValue, setCoins, nValueIn)) - return false; - + return false; if (setCoins.empty()) - return false; + return false; static std::map stakeCache; if(stakeCache.size() > setCoins.size() + 100){ - //Determining if the cache is still valid is harder than just clearing it when it gets too big, so instead just clear it - //when it has more than 100 entries more than the actual setCoins. - stakeCache.clear(); + //Determining if the cache is still valid is harder than just clearing it when it gets too big, so instead just clear it + //when it has more than 100 entries more than the actual setCoins. + stakeCache.clear(); } if(GetBoolArg("-stakecache", DEFAULT_STAKE_CACHE)) { - BOOST_FOREACH(const PAIRTYPE(const CWalletTx*, unsigned int)& pcoin, setCoins) - { - boost::this_thread::interruption_point(); - COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second); - CacheKernel(stakeCache, prevoutStake); //this will do a 2 disk loads per op - } + BOOST_FOREACH(const PAIRTYPE(const CWalletTx*, unsigned int)& pcoin, setCoins) + { + boost::this_thread::interruption_point(); + COutPoint prevoutStake = COutPoint(pcoin.first->GetHash(), pcoin.second); + CacheKernel(stakeCache, prevoutStake); //this will do a 2 disk loads per op + } } @@ -833,31 +818,26 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int } } - // Calculate coin age reward - { - uint64_t nCoinAge; - if (!GetCoinAge(txNew, *pblocktree, pindexPrev, nCoinAge)) - return error("CreateCoinStake : failed to calculate coin age"); - - int64_t nReward = GetProofOfStakeReward(pindexPrev, nCoinAge, nFees); - if (nReward <= 0) - return false; - - nCredit += nReward; - } + // Calculate reward + { + int64_t nReward = GetProofOfStakeSubsidy() + nFees; + if (nReward < 0) + return false; + nCredit += nReward; + } if (nCredit >= GetStakeSplitThreshold()) - txNew.vout.push_back(CTxOut(0, txNew.vout[1].scriptPubKey)); //split stake + txNew.vout.push_back(CTxOut(0, txNew.vout[1].scriptPubKey)); //split stake // Set output amount if (txNew.vout.size() == 3) { - txNew.vout[1].nValue = (nCredit / 2 / CENT) * CENT; - txNew.vout[2].nValue = nCredit - txNew.vout[1].nValue; + txNew.vout[1].nValue = (nCredit / 2 / CENT) * CENT; + txNew.vout[2].nValue = nCredit - txNew.vout[1].nValue; } else - txNew.vout[1].nValue = nCredit; + txNew.vout[1].nValue = nCredit; // Sign int nIn = 0;