Skip to content

Commit

Permalink
Fix GUI stake calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Jul 14, 2014
1 parent 8c927c1 commit a457f7a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
57 changes: 57 additions & 0 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pair<const CWalletTx*,unsigned int> > setCoins;
vector<const CWalletTx*> 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)
{
Expand Down
1 change: 1 addition & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a457f7a

Please sign in to comment.