"getmininginfo\n"
"Returns an object containing mining-related information.");
- int64 nTargetSpacingWorkMin = 30;
- int64 nTargetSpacingWork = nTargetSpacingWorkMin;
- int64 nPoWInterval = 72;
- int64 nTargetSpacingStake = 600;
+ double dStakeKernelsTriedAvg = 0;
+ int nPoWInterval = 72, nPoSInterval = 72, nStakesHandled = 0, nStakesTime = 0;
+ int64 nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30;
CBlockIndex* pindex = pindexGenesisBlock;
CBlockIndex* pindexPrevWork = pindexGenesisBlock;
+ CBlockIndex* pindexPrevStake = NULL;
while (pindex)
{
pindex = pindex->pnext;
}
+
+ pindex = pindexBest;
+
+ while (pindex && nStakesHandled < nPoSInterval)
+ {
+ if (pindex->IsProofOfStake())
+ {
+ dStakeKernelsTriedAvg += GetDifficulty(pindex) * 4294967296;
+ nStakesTime += pindexPrevStake ? (pindexPrevStake->nTime - pindex->nTime) : 0;
+ pindexPrevStake = pindex;
+ nStakesHandled++;
+ }
+
+ pindex = pindex->pprev;
+ }
+
double dNetworkMhps = GetDifficulty() * 4294.967296 / nTargetSpacingWork;
- int nNetworkWeight = GetDifficulty(GetLastBlockIndex(pindexBest, true)) * 4294967296 / nTargetSpacingStake;
+ double dNetworkWeight = dStakeKernelsTriedAvg / nStakesTime;
Object obj;
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("blockvalue", (uint64_t)GetProofOfWorkReward(GetLastBlockIndex(pindexBest, false)->nBits)));
obj.push_back(Pair("netmhashps", dNetworkMhps));
- obj.push_back(Pair("netstakeweight", (uint64_t) nNetworkWeight));
+ obj.push_back(Pair("netstakeweight", dNetworkWeight));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
- obj.push_back(Pair("stakeweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_NORMAL)));
- obj.push_back(Pair("minweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_MINWEIGHT)));
- obj.push_back(Pair("maxweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_MAXWEIGHT)));
- obj.push_back(Pair("passiveweight", (uint64_t)pwalletMain->GetStakeMintPower(*pwalletMain, STAKE_BELOWMIN)));
+ obj.push_back(Pair("stakeweight", (uint64_t)pwalletMain->GetStakeWeight(*pwalletMain, STAKE_NORMAL)));
+ obj.push_back(Pair("minweight", (uint64_t)pwalletMain->GetStakeWeight(*pwalletMain, STAKE_MINWEIGHT)));
+ obj.push_back(Pair("maxweight", (uint64_t)pwalletMain->GetStakeWeight(*pwalletMain, STAKE_MAXWEIGHT)));
obj.push_back(Pair("stakeinterest", (uint64_t)GetProofOfStakeReward(0, GetLastBlockIndex(pindexBest, true)->nBits, GetLastBlockIndex(pindexBest, true)->nTime, true)));
obj.push_back(Pair("testnet", fTestNet));
return obj;
return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet);
}
-// NovaCoin: get current stake generation power
-uint64 CWallet::GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMode mode)
+// NovaCoin: get current stake weight
+uint64 CWallet::GetStakeWeight(const CKeyStore& keystore, enum StakeWeightMode mode)
{
LOCK2(cs_main, cs_wallet);
if (mapArgs.count("-reservebalance") && !ParseMoney(mapArgs["-reservebalance"], nReserveBalance))
{
- error("GetStakeMintPower : invalid reserve balance amount");
+ error("GetStakeWeight : invalid reserve balance amount");
return 0;
}
if (!txdb.ReadTxIndex(pcoin.first->GetHash(), txindex))
continue;
+ unsigned int nTime = pcoin.first->nTime;
+
switch(mode)
{
case STAKE_NORMAL:
// Do not count input that is still less than 30 days old
- if (pcoin.first->nTime + nStakeMinAge > GetTime())
+ if (nTime + nStakeMinAge > GetTime())
continue;
break;
case STAKE_MAXWEIGHT:
// Do not count input that is still less than 90 days old
- if (pcoin.first->nTime + nStakeMaxAge > GetTime())
+ if (nTime + nStakeMaxAge > GetTime())
continue;
break;
case STAKE_MINWEIGHT:
// Count only inputs with suitable age (from 30 to 90 days old)
- if (pcoin.first->nTime + nStakeMaxAge < GetTime())
- continue;
- if (pcoin.first->nTime + nStakeMinAge > GetTime())
+ if (nTime + nStakeMaxAge < GetTime())
continue;
- break;
- case STAKE_BELOWMIN:
- // Count only inputs with suitable age (less than 30 days old)
- if (pcoin.first->nTime + nStakeMinAge < GetTime())
+ if (nTime + nStakeMinAge > GetTime())
continue;
break;
}
- CBigNum bnCentSecond = CBigNum(pcoin.first->vout[pcoin.second].nValue) * (GetTime()-pcoin.first->nTime) / CENT;
- CBigNum bnCoinDay = bnCentSecond * CENT / COIN / (24 * 60 * 60);
+ int64 nTimeWeight;
+
+ // 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
+ //
+ if(fTestNet || (STAKEWEIGHT_SWITCH_TIME < nTime))
+ {
+ // New rule since 01 Jan 2014: Maximum TimeWeight is 90 days.
+ nTimeWeight = min((int64)GetTime() - nTime - nStakeMinAge, (int64)nStakeMaxAge);
+ }
+ else
+ {
+ // Current rule: Maximum TimeWeight is 60 days.
+ nTimeWeight = min((int64)GetTime() - nTime, (int64)nStakeMaxAge) - nStakeMinAge;
+ }
+ CBigNum bnCoinDayWeight = CBigNum(pcoin.first->vout[pcoin.second].nValue) * nTimeWeight / COIN / (24 * 60 * 60);
- nCoinAge += bnCoinDay.getuint64();
+ nCoinAge += bnCoinDayWeight.getuint64();
}
if (fDebug && GetBoolArg("-printcoinage"))
- printf("StakePower bnCoinDay=%"PRI64d"\n", nCoinAge);
+ printf("StakeWeight bnCoinDay=%"PRI64d"\n", nCoinAge);
return nCoinAge;
}
{
STAKE_NORMAL = 0, // all 30+ days old inputs
STAKE_MAXWEIGHT = 1, // only 90+ days old inputs
- STAKE_MINWEIGHT = 3, // only [30-90] days old inputs
- STAKE_BELOWMIN = 4 // only less than 30 days old inputs
+ STAKE_MINWEIGHT = 3 // only [30-90] days old inputs
};
/** A key pool entry */
bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet);
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
- uint64 GetStakeMintPower(const CKeyStore& keystore, enum StakeWeightMode mode=STAKE_NORMAL);
+ uint64 GetStakeWeight(const CKeyStore& keystore, enum StakeWeightMode mode=STAKE_NORMAL);
bool CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, int64 nSearchInterval, CTransaction& txNew);
std::string SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, bool fAskFee=false);