diff --git a/src/kernel.cpp b/src/kernel.cpp index 62f78b1..c2dabfb 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -43,6 +43,16 @@ int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd) return min(nIntervalEnd - nIntervalBeginning - nStakeMinAge, (int64)nStakeMaxAge); } +// Get time weight 2 - This is added for informational purposes since staking takes 9.1 days min approx. because of bug +int64 GetWeight2(int64 nIntervalBeginning, int64 nIntervalEnd) +{ + // Kernel hash weight starts from 0 at the min age + // this change increases active coins participating the hash and helps + // to secure the network when proof-of-stake difficulty is low + int64 nStakeMinAgeV2 = 60 * 60 * 24 * 9.1; + return min(nIntervalEnd - nIntervalBeginning - nStakeMinAgeV2, (int64)nStakeMaxAge); +} + // Get the last stake modifier and its generation time from a given block static bool GetLastStakeModifier(const CBlockIndex* pindex, uint64& nStakeModifier, int64& nModifierTime) { diff --git a/src/kernel.h b/src/kernel.h index 2f41c6c..c8e71d2 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -38,5 +38,6 @@ bool CheckStakeModifierCheckpoints(int nHeight, unsigned int nStakeModifierCheck // Get time weight using supplied timestamps int64 GetWeight(int64 nIntervalBeginning, int64 nIntervalEnd); +int64 GetWeight2(int64 nIntervalBeginning, int64 nIntervalEnd); #endif // PPCOIN_KERNEL_H diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 5a6a371..3b59bba 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -994,7 +994,7 @@ void BitcoinGUI::updateMintingWeights() nWeight = 0; if (pwalletMain) - pwalletMain->GetStakeWeight(*pwalletMain, nMinMax, nMinMax, nWeight); + pwalletMain->GetStakeWeight2(*pwalletMain, nMinMax, nMinMax, nWeight); nNetworkWeight = GetPoSKernelPS(); } diff --git a/src/wallet.cpp b/src/wallet.cpp index 9d2e992..50cf07e 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -1429,6 +1429,63 @@ bool CWallet::GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint return true; } +//This is added for informational purposes since staking takes 9.1 days min approx. because of bug +bool CWallet::GetStakeWeight2(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight) +{ + // Choose coins to use + int64 nBalance = GetBalance(); + + int64 nReserveBalance = 0; + if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance)) + return error("CreateCoinStake : invalid reserve balance amount"); + if (nBalance <= nReserveBalance) + return false; + + set > setCoins; + vector vwtxPrev; + int64 nValueIn = 0; + + if (!SelectCoins(nBalance - nReserveBalance, GetTime(), setCoins, nValueIn)) + return false; + + if (setCoins.empty()) + return false; + + CTxDB txdb("r"); + BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) + { + CTxIndex txindex; + { + LOCK2(cs_main, cs_wallet); + if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex)) + continue; + } + + int64 nTimeWeight = GetWeight2((int64)pcoin.first->nTime, (int64)GetTime()); + CBigNum bnCoinDayWeight = CBigNum(pcoin.first->vout[pcoin.second].nValue) * nTimeWeight / COIN / (24 * 60 * 60); + + // Weight is greater than zero + if (nTimeWeight > 0) + { + nWeight += bnCoinDayWeight.getuint64(); + } + + // Weight is greater than zero, but the maximum value isn't reached yet + if (nTimeWeight > 0 && nTimeWeight < nStakeMaxAge) + { + nMinWeight += bnCoinDayWeight.getuint64(); + } + + // Maximum weight was reached + if (nTimeWeight == nStakeMaxAge) + { + nMaxWeight += bnCoinDayWeight.getuint64(); + } + } + + return true; +} + // ppcoin: create coin stake transaction bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew) { diff --git a/src/wallet.h b/src/wallet.h index 899f95a..6d50897 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -179,6 +179,7 @@ class CWallet : public CCryptoKeyStore bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet, const CCoinControl *coinControl=NULL); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); bool GetStakeWeight(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight); + bool GetStakeWeight2(const CKeyStore& keystore, uint64& nMinWeight, uint64& nMaxWeight, uint64& nWeight); bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew); std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false); std::string SendMoneyToDestination(const CTxDestination &address, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);