X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=blobdiff_plain;f=src%2Fwallet.cpp;h=ca331361a1f8ea88e8550d50e4ad1ff0380fd7fd;hp=898ba674e594ee8a8020a8e8561e47d7f1e8a0d1;hb=d8f8063eda45b8dec864b28bb98839a2dd3a8170;hpb=68fbc35ade50af7e8b0ec0fe80e9a1372bccba2c diff --git a/src/wallet.cpp b/src/wallet.cpp index 898ba67..ca33136 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1513,28 +1513,25 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint continue; } - unsigned int nTime = pcoin.first->nTime; - - // Kernel hash weight starts from 0 at the 30-day min age - // this change increases active coins participating the hash and helps - // to secure the network when proof-of-stake difficulty is low - // - // Maximum TimeWeight is 90 days. - int64 nTimeWeight = min((int64)GetTime() - nTime - nStakeMinAge, (int64)nStakeMaxAge); + int64 nTimeWeight = GetWeight((int64)pcoin.first->nTime, (int64)GetTime()); CBigNum bnCoinDayWeight = CBigNum(pcoin.first->vout[pcoin.second].nValue) * nTimeWeight / COIN / (24 * 60 * 60); - // Count input that is more than 90 days old - if (nTime + nStakeMaxAge < GetTime()) + // Weight is greater than zero + if (nTimeWeight > 0) { - nMaxWeight += bnCoinDayWeight.getuint64(); nWeight += bnCoinDayWeight.getuint64(); } - // Count input that is more than 30 days old and less than 90 days old - if (nTime + nStakeMinAge < GetTime() && nTime + nStakeMaxAge > GetTime()) + // Weight is greater than zero, but the maximum value isn't reached yet + if (nTimeWeight > 0 && nTimeWeight < nStakeMaxAge) { nMinWeight += bnCoinDayWeight.getuint64(); - nWeight += bnCoinDayWeight.getuint64(); + } + + // Maximum weight was reached + if (nTimeWeight == nStakeMaxAge) + { + nMaxWeight += bnCoinDayWeight.getuint64(); } } @@ -1543,9 +1540,8 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew, CKey& key) { - // The following split & combine thresholds are important to security + // The following combine threshold is important to security // Should not be adjusted if you don't understand the consequences - static unsigned int nStakeSplitAge = (60 * 60 * 24 * 90); int64 nCombineThreshold = GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nBits) / 3; CBigNum bnTargetPerCoinDay; @@ -1691,7 +1687,8 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int nCredit += pcoin.first->vout[pcoin.second].nValue; vwtxPrev.push_back(pcoin.first); txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); - if (block.GetBlockTime() + nStakeSplitAge > txNew.nTime) + + if (GetWeight(block.GetBlockTime(), (int64)txNew.nTime) < nStakeMaxAge) txNew.vout.push_back(CTxOut(0, scriptPubKeyOut)); //split stake if (fDebug && GetBoolArg("-printcoinstake")) printf("CreateCoinStake : added kernel type=%d\n", whichType); @@ -1714,6 +1711,8 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int if (txNew.vout.size() == 2 && ((pcoin.first->vout[pcoin.second].scriptPubKey == scriptPubKeyKernel || pcoin.first->vout[pcoin.second].scriptPubKey == txNew.vout[1].scriptPubKey)) && pcoin.first->GetHash() != txNew.vin[0].prevout.hash) { + int64 nTimeWeight = GetWeight((int64)pcoin.first->nTime, (int64)txNew.nTime); + // Stop adding more inputs if already too many inputs if (txNew.vin.size() >= 100) break; @@ -1727,8 +1726,9 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int if (pcoin.first->vout[pcoin.second].nValue > nCombineThreshold) continue; // Do not add input that is still too young - if (pcoin.first->nTime + nStakeMaxAge > txNew.nTime) + if (nTimeWeight < nStakeMaxAge) continue; + txNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second)); nCredit += pcoin.first->vout[pcoin.second].nValue; vwtxPrev.push_back(pcoin.first);